Kreb1907 commited on
Commit
dc652e8
·
verified ·
1 Parent(s): c1b49cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -8
app.py CHANGED
@@ -18,6 +18,7 @@ class BasicAgent:
18
  def __init__(self):
19
  from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool, PythonInterpreterTool
20
  import os
 
21
  model = LiteLLMModel(
22
  model_id="groq/llama-3.3-70b-versatile",
23
  api_key=os.environ["GROQ_API_KEY"],
@@ -25,17 +26,36 @@ class BasicAgent:
25
  self.agent = CodeAgent(
26
  tools=[DuckDuckGoSearchTool(), PythonInterpreterTool()],
27
  model=model,
28
- max_steps=8,
29
  )
30
 
 
 
 
 
 
 
 
31
  def __call__(self, question: str) -> str:
32
- try:
33
- answer = self.agent.run(
34
- f"Answer with ONLY the final answer, nothing else.\n\nQuestion: {question}"
35
- )
36
- return str(answer).strip().rstrip(".")
37
- except Exception:
38
- return "unknown"
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  def run_and_submit_all( profile: gr.OAuthProfile | None):
41
  """
 
18
  def __init__(self):
19
  from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool, PythonInterpreterTool
20
  import os
21
+
22
  model = LiteLLMModel(
23
  model_id="groq/llama-3.3-70b-versatile",
24
  api_key=os.environ["GROQ_API_KEY"],
 
26
  self.agent = CodeAgent(
27
  tools=[DuckDuckGoSearchTool(), PythonInterpreterTool()],
28
  model=model,
29
+ max_steps=6,
30
  )
31
 
32
+ def _clean(self, text: str) -> str:
33
+ text = str(text).strip()
34
+ for prefix in ["FINAL ANSWER:", "Final answer:", "Answer:", "The answer is"]:
35
+ if text.startswith(prefix):
36
+ text = text[len(prefix):].strip()
37
+ return text.strip().strip('"').rstrip(".")
38
+
39
  def __call__(self, question: str) -> str:
40
+ import traceback, time
41
+ prompt = (
42
+ "You are answering a benchmark question. Your response is graded by EXACT string match.\n"
43
+ "Output ONLY the answer itself: no explanation, no sentence, no units unless the question asks for them, "
44
+ "no trailing period, no quotes.\n"
45
+ "If the answer is a number, write just the number. If it is a name, write just the name.\n\n"
46
+ f"Question: {question}"
47
+ )
48
+ for attempt in range(2):
49
+ try:
50
+ answer = self.agent.run(prompt)
51
+ cleaned = self._clean(answer)
52
+ if cleaned:
53
+ return cleaned
54
+ except Exception as e:
55
+ print(f"[AGENT ERROR] attempt {attempt+1} | {type(e).__name__}: {e}")
56
+ traceback.print_exc()
57
+ time.sleep(3)
58
+ return "unknown"
59
 
60
  def run_and_submit_all( profile: gr.OAuthProfile | None):
61
  """