Álvaro Valenzuela Valdes commited on
Commit
a7fae38
·
1 Parent(s): e4adc73

fix: Detailed API error reporting for agent analysis

Browse files
Files changed (1) hide show
  1. backend/app/services/llm.py +15 -2
backend/app/services/llm.py CHANGED
@@ -120,11 +120,24 @@ def generate_analysis(tender: Tender, company: CompanyProfile, document_text: st
120
  return analysis
121
 
122
  prompt = _build_analysis_prompt(tender, company, document_text)
123
- output = call_gemini(prompt)
124
 
 
 
 
 
 
 
 
 
 
 
125
  if not output:
126
  analysis = generate_mock_analysis(tender, company)
127
- analysis.audit_log = ["❌ Error: Gemini API returned an empty response.", "Check quota or region restrictions.", "Fallback: Using mock analysis."]
 
 
 
 
128
  return analysis
129
 
130
  parse_result = _parse_gemini_response(output)
 
120
  return analysis
121
 
122
  prompt = _build_analysis_prompt(tender, company, document_text)
 
123
 
124
+ output = ""
125
+ error_detail = ""
126
+ try:
127
+ model = get_gemini_model()
128
+ response = model.generate_content(prompt)
129
+ output = response.text
130
+ except Exception as e:
131
+ error_detail = str(e)
132
+ print(f"Error calling Gemini: {e}")
133
+
134
  if not output:
135
  analysis = generate_mock_analysis(tender, company)
136
+ analysis.audit_log = [
137
+ f"❌ API Error: {error_detail or 'Empty response'}",
138
+ "Possible causes: Quota limit, Invalid Key, or Region restriction.",
139
+ "Fallback: Using system default analysis."
140
+ ]
141
  return analysis
142
 
143
  parse_result = _parse_gemini_response(output)