Spaces:
Running
Running
Create apps/dr_cat.js
Browse files- apps/dr_cat.js +54 -0
apps/dr_cat.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// apps/dr_cat.js
|
| 2 |
+
import express from 'express';
|
| 3 |
+
import { generateCompletion } from '../ai_engine.js';
|
| 4 |
+
// import { createClient } from '@supabase/supabase-js';
|
| 5 |
+
|
| 6 |
+
const router = express.Router();
|
| 7 |
+
|
| 8 |
+
// 🔒 The Secret Sauce: Stored on the server so nobody can steal your prompt
|
| 9 |
+
const DR_CAT_SYSTEM_PROMPT = `You are Dr. Cat 🩺🐈, an expert DIY repair assistant, master mechanic, and all-around handy-cat.
|
| 10 |
+
Your job is to analyze images of broken items, plumbing, appliances, or car parts, and tell the user:
|
| 11 |
+
1. What the item/issue is.
|
| 12 |
+
2. What went wrong.
|
| 13 |
+
3. Step-by-step instructions on how to fix it.
|
| 14 |
+
|
| 15 |
+
Rules:
|
| 16 |
+
- Keep it concise, friendly, and easy for beginners to understand.
|
| 17 |
+
- Add a brief safety warning if the repair is dangerous (like electrical work).
|
| 18 |
+
- If it's something that absolutely requires a professional, tell them so they don't get scammed.
|
| 19 |
+
- Format your output in clean Markdown.
|
| 20 |
+
- End your response with a supportive, cat-themed sign-off!`;
|
| 21 |
+
|
| 22 |
+
router.post('/diagnose', async (req, res) => {
|
| 23 |
+
// We expect the 'image' (base64 string) and optional 'notes' from the CatKit App
|
| 24 |
+
const { image, notes, model } = req.body;
|
| 25 |
+
|
| 26 |
+
// TODO: Later, uncomment your Supabase 'get_daily_usage' rate-limit check here
|
| 27 |
+
|
| 28 |
+
const prompt = notes && notes.trim() !== ""
|
| 29 |
+
? `Here is the broken item. User notes: "${notes}"\nPlease diagnose and provide a fix.`
|
| 30 |
+
: "What is this, what is broken, and how do I fix it?";
|
| 31 |
+
|
| 32 |
+
try {
|
| 33 |
+
console.log(`[DR. CAT] Diagnosing issue... Model: ${model || 'maverick'}`);
|
| 34 |
+
|
| 35 |
+
const result = await generateCompletion({
|
| 36 |
+
model: model || "maverick", // Defaults to Llama 4 Maverick 17B for super cheap vision
|
| 37 |
+
prompt: prompt,
|
| 38 |
+
system_prompt: DR_CAT_SYSTEM_PROMPT,
|
| 39 |
+
images: image ? [image] :[] // ai_engine expects an array of images
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
// result already contains { success: true, data: "...", usage: {...} }
|
| 43 |
+
res.json(result);
|
| 44 |
+
|
| 45 |
+
// TODO: Async log the usage to Supabase here so the user doesn't wait
|
| 46 |
+
// await supabase.from('ai_usage_logs').insert({...})
|
| 47 |
+
|
| 48 |
+
} catch (err) {
|
| 49 |
+
console.error(`❌ [Dr. Cat Error]:`, err.message);
|
| 50 |
+
res.status(500).json({ success: false, error: err.message });
|
| 51 |
+
}
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
export default router;
|