dlaima commited on
Commit
8045af0
·
verified ·
1 Parent(s): 060e212

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -37,13 +37,27 @@ class MyAgent:
37
  {"role": "user", "content": question}
38
  ]
39
  try:
40
- # Correct usage: model is callable, pass messages directly
41
- response = self.model(messages)
42
- return extract_final_answer(response)
43
- except Exception as e:
44
- import traceback
45
- traceback.print_exc()
46
- return f"AGENT ERROR: {e}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")