everything / apps /dr_cat.js
everydaycats's picture
Update apps/dr_cat.js
b2840a3 verified
// apps/dr_cat.js
import express from 'express';
import { generateCompletion } from '../ai_engine.js';
const router = express.Router();
const DR_CAT_SYSTEM_PROMPT = `You are Dr. Cat 🩺🐈, an expert DIY repair assistant, master mechanic, and playfully sassy handy-cat.
You have TWO modes depending on the image:
MODE 1: BROKEN ITEMS & APPLIANCES (Serious but friendly)
1. Include a severity tag on its own line: [SEVERITY: critical] or [SEVERITY: moderate] or[SEVERITY: minor]
2. Identify the item and explain what went wrong using a ## Heading.
3. Provide step-by-step DIY fixes using numbered lists.
4. Include a YouTube search tag:[YOUTUBE: how to fix XYZ]
5. Add estimated DIY vs Professional costs.
MODE 2: HUMANS, FRIENDS, & OUTFITS (Fun & Playful Roast)
If the image is a person, friend, outfit, or pet, playfully "diagnose" them as a malfunctioning machine.
- Give a very gentle, funny roast about their vibe, fashion, or expression. DO NOT be mean, insulting, or offensive.
- Offer a hilarious step-by-step "fix".
- STILL include a severity tag (e.g., [SEVERITY: critical]) and a funny YouTube tag.
CRITICAL INSTRUCTION: You must return ONLY a JSON object with a single key "response_markdown" containing your fully formatted Markdown response.`;
router.post('/diagnose', async (req, res) => {
const { image, notes, model } = req.body;
const prompt = notes && notes.trim() !== ""
? `User notes: "${notes}"\nPlease diagnose the image. Return JSON.`
: "Diagnose this image. If it's broken, tell me how to fix it. If it's a person, playfully diagnose their vibe/outfit. Return JSON.";
try {
console.log(`[DR. CAT] Diagnosing issue...`);
const result = await generateCompletion({
model: "maverick", // "qwen", // model || "qwen",
prompt: prompt,
system_prompt: DR_CAT_SYSTEM_PROMPT,
images: image ? [image] :[]
});
if (!result.success) throw new Error(result.error);
// Unwrap the JSON so the frontend still gets raw markdown
const parsedData = JSON.parse(result.data);
result.data = parsedData.response_markdown;
res.json(result);
} catch (err) {
console.error(`❌ [Dr. Cat Error]:`, err.message);
res.status(500).json({ success: false, error: err.message });
}
});
router.post('/chat', async (req, res) => {
const { image, context, question, model } = req.body;
if (!question) return res.status(400).json({ success: false, error: "Question is required." });
const chatPrompt = `=== PREVIOUS CONTEXT ===\n${context || "No context."}\n========================\n\nUser's follow-up question: "${question}"\n\nPlease answer the user's question directly based on the image and previous context. Maintain your helpful Dr. Cat persona. Return ONLY JSON with the 'response_markdown' key.`;
try {
const result = await generateCompletion({
model: "maverick", // model || "qwen",
prompt: chatPrompt,
system_prompt: DR_CAT_SYSTEM_PROMPT,
images: image ? [image] :[]
});
if (!result.success) throw new Error(result.error);
const parsedData = JSON.parse(result.data);
result.data = parsedData.response_markdown;
res.json(result);
} catch (err) {
res.status(500).json({ success: false, error: err.message });
}
});
export default router;