Skip to content

Commit 7577275

Browse files
committed
commit 9f8c3e2d5b6a7e1c2d3e4f5a6b7c8d9e0f1a2b3c
1 parent 6e1ce29 commit 7577275

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

models/ai_model.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,42 @@ def chat(prompt: str, model: str = 'mock') -> str:
6868
return j['choices'][0]['message']['content'].strip()
6969
except Exception as e:
7070
return f"(AI error: {e})"
71-
# Mock reply
72-
return f"Echo: {prompt}"
71+
# If no real model is configured, provide helpful rule-based troubleshooting responses
72+
# Simple heuristics: look for keywords and return structured guidance
73+
low = prompt.lower()
74+
# Common categories
75+
if any(k in low for k in ('error', 'traceback', 'exception', 'crash')):
76+
return (
77+
"It looks like you're seeing an error. Try these steps:\n"
78+
"1) Read the full traceback to find the error type and file/line.\n"
79+
"2) Search for the exact error message. Many issues are already reported.\n"
80+
"3) Check recent changes — what code or dependency was updated?\n"
81+
"4) Reproduce with a minimal test case and add logging around the failing area.\n"
82+
"If you paste the exact error message I can give more targeted advice."
83+
)
84+
if any(k in low for k in ('how do i fix', 'how to fix', 'fix it', 'help')):
85+
return (
86+
"Here's a troubleshooting checklist: \n"
87+
"- Confirm steps to reproduce the issue and the expected behavior.\n"
88+
"- Check logs and tracebacks (server and client).\n"
89+
"- Isolate the failure to a single component (frontend/backend/db).\n"
90+
"- Try rolling back recent changes or run in a clean environment.\n"
91+
"- If it's an import/module error, ensure dependencies are installed in the active venv.\n"
92+
"If you give me the error text or the command you ran I can suggest exact commands."
93+
)
94+
if any(k in low for k in ('slow', 'performance', 'lag')):
95+
return (
96+
"Performance troubleshooting suggestions:\n"
97+
"- Measure where time is spent (profilers for backend, devtools for frontend).\n"
98+
"- Check database query times and add indexes where needed.\n"
99+
"- Cache expensive computations and use pagination for large lists.\n"
100+
"- For TTS/ML models, ensure batching and GPU use where possible.\n"
101+
)
102+
# Generic helpful response wrapping the prompt
103+
return (
104+
"I can help troubleshoot. Here are a few starter steps:\n"
105+
"1) Share the exact command or action that caused the issue.\n"
106+
"2) Copy the full error or describe the unexpected behavior.\n"
107+
"3) Tell me what you have already tried.\n\n"
108+
f"You asked: {prompt}\n\nIf you paste the error text or logs I will give prioritized steps to fix it."
109+
)

0 commit comments

Comments
 (0)