Fix: Enabled descriptive AI error reporting in Dashboard and generator (Phase 9 Debug)
Browse files
backend/routers/generator.py
CHANGED
|
@@ -83,7 +83,7 @@ async def generate_project(
|
|
| 83 |
|
| 84 |
# Use llama3-70b-8192 as a more stable fallback/default
|
| 85 |
model_name = provider_config.get("default_model") or "llama3-70b-8192"
|
| 86 |
-
logger.info("Calling Groq with model: %s", model_name)
|
| 87 |
|
| 88 |
response = await client.chat.completions.create(
|
| 89 |
model=model_name,
|
|
@@ -92,20 +92,17 @@ async def generate_project(
|
|
| 92 |
{"role": "user", "content": user_message}
|
| 93 |
],
|
| 94 |
temperature=0.3,
|
| 95 |
-
max_tokens=2048
|
| 96 |
-
#
|
| 97 |
-
response_format={"type": "json_object"}
|
| 98 |
)
|
| 99 |
|
| 100 |
response_text = response.choices[0].message.content
|
| 101 |
-
logger.
|
| 102 |
data = _parse_json_output(response_text)
|
| 103 |
return data
|
| 104 |
|
| 105 |
except Exception as e:
|
| 106 |
logger.exception("Project generation failed")
|
|
|
|
| 107 |
error_msg = str(e)
|
| 108 |
-
|
| 109 |
-
if "api_key" in error_msg.lower():
|
| 110 |
-
error_msg = "Invalid or missing API Key"
|
| 111 |
-
raise HTTPException(status_code=500, detail=f"AI Generation failed: {error_msg}")
|
|
|
|
| 83 |
|
| 84 |
# Use llama3-70b-8192 as a more stable fallback/default
|
| 85 |
model_name = provider_config.get("default_model") or "llama3-70b-8192"
|
| 86 |
+
logger.info("Calling Groq with model: %s (Key: %s...)", model_name, api_key[:8] if api_key else "None")
|
| 87 |
|
| 88 |
response = await client.chat.completions.create(
|
| 89 |
model=model_name,
|
|
|
|
| 92 |
{"role": "user", "content": user_message}
|
| 93 |
],
|
| 94 |
temperature=0.3,
|
| 95 |
+
max_tokens=2048
|
| 96 |
+
# response_format={"type": "json_object"} # Disabled for stability testing
|
|
|
|
| 97 |
)
|
| 98 |
|
| 99 |
response_text = response.choices[0].message.content
|
| 100 |
+
logger.info("Groq raw response received (%d chars)", len(response_text) if response_text else 0)
|
| 101 |
data = _parse_json_output(response_text)
|
| 102 |
return data
|
| 103 |
|
| 104 |
except Exception as e:
|
| 105 |
logger.exception("Project generation failed")
|
| 106 |
+
error_type = type(e).__name__
|
| 107 |
error_msg = str(e)
|
| 108 |
+
raise HTTPException(status_code=500, detail=f"AI Error ({error_type}): {error_msg}")
|
|
|
|
|
|
|
|
|
frontend/src/components/Dashboard.tsx
CHANGED
|
@@ -111,9 +111,9 @@ const Dashboard: React.FC<DashboardProps> = ({ onNewProject, onOpenProject }) =>
|
|
| 111 |
body: formData
|
| 112 |
});
|
| 113 |
|
| 114 |
-
if (!response.ok) throw new Error('AI Generation failed');
|
| 115 |
-
|
| 116 |
const data = await response.json();
|
|
|
|
|
|
|
| 117 |
onNewProject(data); // Open NewProject wizard with pre-filled data
|
| 118 |
setAiPrompt('');
|
| 119 |
setMagicFiles([]);
|
|
|
|
| 111 |
body: formData
|
| 112 |
});
|
| 113 |
|
|
|
|
|
|
|
| 114 |
const data = await response.json();
|
| 115 |
+
if (!response.ok) throw new Error(data.detail || 'AI Generation failed');
|
| 116 |
+
|
| 117 |
onNewProject(data); // Open NewProject wizard with pre-filled data
|
| 118 |
setAiPrompt('');
|
| 119 |
setMagicFiles([]);
|