dlaima commited on
Commit
cfef47f
·
verified ·
1 Parent(s): 88c671e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -9,7 +9,6 @@ import pandas as pd
9
  from smolagents import CodeAgent, DuckDuckGoSearchTool
10
  from smolagents.models import OpenAIServerModel
11
 
12
- # System prompt for GAIA evaluation
13
  SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question.
14
  Report your thoughts, and finish your answer with the following template:
15
  FINAL ANSWER: [YOUR FINAL ANSWER].
@@ -18,10 +17,9 @@ of numbers and/or strings. If you are asked for a number, don't use comma to wri
18
 
19
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
20
 
21
- def extract_final_answer(response: str) -> str:
22
- """Extract the FINAL ANSWER: portion from the model's response."""
23
- match = re.search(r"FINAL ANSWER:\s*(.*)", response, re.IGNORECASE)
24
- return match.group(1).strip() if match else response.strip()
25
 
26
  class MyAgent:
27
  def __init__(self):
@@ -37,11 +35,9 @@ class MyAgent:
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', '')
@@ -50,14 +46,13 @@ class MyAgent:
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")
@@ -179,3 +174,4 @@ if __name__ == "__main__":
179
  demo.launch(debug=True, share=False)
180
 
181
 
 
 
9
  from smolagents import CodeAgent, DuckDuckGoSearchTool
10
  from smolagents.models import OpenAIServerModel
11
 
 
12
  SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question.
13
  Report your thoughts, and finish your answer with the following template:
14
  FINAL ANSWER: [YOUR FINAL ANSWER].
 
17
 
18
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
19
 
20
+ def extract_final_answer(response_text: str) -> str:
21
+ match = re.search(r"FINAL ANSWER:\s*(.*)", response_text, re.IGNORECASE)
22
+ return match.group(1).strip() if match else response_text.strip()
 
23
 
24
  class MyAgent:
25
  def __init__(self):
 
35
  {"role": "user", "content": question}
36
  ]
37
  try:
38
+ response = self.model(messages)
39
+ # Extract the actual text from response
40
+ if isinstance(response, dict):
 
 
41
  choices = response.get('choices')
42
  if choices and len(choices) > 0:
43
  text = choices[0].get('message', {}).get('content', '')
 
46
  elif isinstance(response, str):
47
  text = response
48
  else:
49
+ text = str(response)
 
 
 
 
 
 
50
 
51
+ return extract_final_answer(text)
52
+ except Exception as e:
53
+ import traceback
54
+ traceback.print_exc()
55
+ return f"AGENT ERROR: {e}"
56
 
57
  def run_and_submit_all(profile: gr.OAuthProfile | None):
58
  space_id = os.getenv("SPACE_ID")
 
174
  demo.launch(debug=True, share=False)
175
 
176
 
177
+