datdevsteve commited on
Commit
c3d15cf
·
verified ·
1 Parent(s): 0a7e683

Update nivra_agent.py

Browse files
Files changed (1) hide show
  1. nivra_agent.py +22 -18
nivra_agent.py CHANGED
@@ -162,36 +162,40 @@ Provide diagnosis:
162
  # ==================================================
163
 
164
  def nivra_vision(image_url: str, hint_text: str = "") -> str:
165
- try:
166
- tool_output = analyze_symptom_image.invoke({
167
- "image_url": image_url,
168
- "image_description": hint_text,
169
- })
170
- except Exception as e:
 
 
 
 
 
 
 
171
  return f"""
172
  [TOOLS USED] analyze_symptom_image [/TOOLS USED]
173
- [SYMPTOMS] Image could not be analyzed [/SYMPTOMS]
174
  [PRIMARY DIAGNOSIS] Inconclusive [/PRIMARY DIAGNOSIS]
175
  [DIAGNOSIS DESCRIPTION]
176
- Image analysis failed due to a technical issue.
177
  [/DIAGNOSIS DESCRIPTION]
178
- [FIRST AID] Consult a medical professional [/FIRST AID]
179
  [EMERGENCY CONSULTATION REQUIRED] No [/EMERGENCY CONSULTATION REQUIRED]
180
- """
181
 
 
182
  final_prompt = f"""
183
- You are a medical AI assistant.
184
-
185
- Vision tool result:
186
  {tool_output}
187
 
188
- User context:
189
  {hint_text}
190
 
191
- Respond STRICTLY in the medical format.
192
- Keep description under 3 sentences.
193
- """
194
-
195
 
196
  return call_groq(final_prompt)
197
 
 
162
  # ==================================================
163
 
164
  def nivra_vision(image_url: str, hint_text: str = "") -> str:
165
+ """
166
+ Image-based medical analysis using vision tool + Groq reasoning
167
+ """
168
+
169
+ print("🖼️ nivra_vision called")
170
+
171
+ tool_output = analyze_symptom_image.invoke({
172
+ "image_url": image_url,
173
+ "image_description": hint_text
174
+ })
175
+
176
+ # 🚨 If vision tool already failed, DO NOT call Groq
177
+ if "ERROR" in tool_output.upper():
178
  return f"""
179
  [TOOLS USED] analyze_symptom_image [/TOOLS USED]
180
+ [SYMPTOMS] Unable to analyze image [/SYMPTOMS]
181
  [PRIMARY DIAGNOSIS] Inconclusive [/PRIMARY DIAGNOSIS]
182
  [DIAGNOSIS DESCRIPTION]
183
+ {tool_output}
184
  [/DIAGNOSIS DESCRIPTION]
185
+ [FIRST AID] Please consult a medical professional [/FIRST AID]
186
  [EMERGENCY CONSULTATION REQUIRED] No [/EMERGENCY CONSULTATION REQUIRED]
187
+ """.strip()
188
 
189
+ # Keep Groq prompt SMALL
190
  final_prompt = f"""
191
+ VISION TOOL OUTPUT:
 
 
192
  {tool_output}
193
 
194
+ USER CONTEXT:
195
  {hint_text}
196
 
197
+ Provide a cautious preliminary medical assessment.
198
+ """.strip()
 
 
199
 
200
  return call_groq(final_prompt)
201