Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,13 +37,27 @@ class MyAgent:
|
|
| 37 |
{"role": "user", "content": question}
|
| 38 |
]
|
| 39 |
try:
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 49 |
space_id = os.getenv("SPACE_ID")
|
|
|
|
| 37 |
{"role": "user", "content": question}
|
| 38 |
]
|
| 39 |
try:
|
| 40 |
+
response = self.model(messages)
|
| 41 |
+
# If response is a dict, get the text content inside
|
| 42 |
+
if isinstance(response, dict):
|
| 43 |
+
# Adjust depending on exact structure, commonly:
|
| 44 |
+
# {'choices': [{'message': {'content': 'the text'}}], ...}
|
| 45 |
+
choices = response.get('choices')
|
| 46 |
+
if choices and len(choices) > 0:
|
| 47 |
+
text = choices[0].get('message', {}).get('content', '')
|
| 48 |
+
else:
|
| 49 |
+
text = ''
|
| 50 |
+
elif isinstance(response, str):
|
| 51 |
+
text = response
|
| 52 |
+
else:
|
| 53 |
+
text = str(response) # fallback
|
| 54 |
+
|
| 55 |
+
return extract_final_answer(text)
|
| 56 |
+
except Exception as e:
|
| 57 |
+
import traceback
|
| 58 |
+
traceback.print_exc()
|
| 59 |
+
return f"AGENT ERROR: {e}"
|
| 60 |
+
|
| 61 |
|
| 62 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 63 |
space_id = os.getenv("SPACE_ID")
|