Pixedar commited on
Commit
595424b
·
verified ·
1 Parent(s): f85b856

Add OpenAI client fallback for MindVisualizer explanations

Browse files
mindVisualizer/src/region_analyzer.py CHANGED
@@ -93,6 +93,21 @@ def _call_direct_responses_api(question: str, model: str) -> str:
93
  "Be concrete, not generic."
94
  )
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  resp = client.responses.create(
97
  model=model,
98
  instructions=instructions,
 
93
  "Be concrete, not generic."
94
  )
95
 
96
+ if not hasattr(client, "responses"):
97
+ # Older openai-python builds do not expose client.responses. Keep the
98
+ # deployed Space useful instead of failing with "'OpenAI' has no
99
+ # attribute 'responses'"; requirements should still install a newer SDK.
100
+ chat = client.chat.completions.create(
101
+ model=model,
102
+ messages=[
103
+ {"role": "system", "content": instructions},
104
+ {"role": "user", "content": question},
105
+ ],
106
+ temperature=0.3,
107
+ max_tokens=1500,
108
+ )
109
+ return (chat.choices[0].message.content or "").strip() or "[GPT ERROR] Chat API returned no visible text."
110
+
111
  resp = client.responses.create(
112
  model=model,
113
  instructions=instructions,