benismaw commited on
Commit
5bdee2f
·
verified ·
1 Parent(s): ddc5a8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -9
app.py CHANGED
@@ -20,11 +20,11 @@ class BasicAgent:
20
  def __init__(self):
21
  print("BasicAgent initialized.")
22
  self.model = LiteLLMModel(
23
- model_id="groq/llama-3.1-8b-instant",
24
- api_key=os.getenv("GROQ_API_KEY")
25
  )
26
  self.agent = CodeAgent(
27
- tools=[DuckDuckGoSearchTool()],
28
  model=self.model,
29
  max_steps=6
30
  )
@@ -36,15 +36,10 @@ class BasicAgent:
36
  try:
37
  raw_answer = self.agent.run(full_question)
38
  except TypeError as e:
39
- # Known smolagents bug: final_answer() called with a non-string
40
- # (e.g. an int) can raise "argument of type 'int' is not iterable".
41
- # Recover by pulling the last step's output instead of losing the answer.
42
  print(f"Recovering from TypeError: {e}")
43
  try:
44
  last_step = self.agent.memory.steps[-1]
45
- raw_answer = getattr(last_step, "action_output", None)
46
- if raw_answer is None:
47
- raw_answer = "Unknown"
48
  except Exception as inner_e:
49
  print(f"Could not recover answer: {inner_e}")
50
  raw_answer = "Unknown"
 
20
  def __init__(self):
21
  print("BasicAgent initialized.")
22
  self.model = LiteLLMModel(
23
+ model_id="gemini/gemini-2.0-flash",
24
+ api_key=os.getenv("GEMINI_API_KEY")
25
  )
26
  self.agent = CodeAgent(
27
+ tools=[DuckDuckGoSearchTool(max_results=3)],
28
  model=self.model,
29
  max_steps=6
30
  )
 
36
  try:
37
  raw_answer = self.agent.run(full_question)
38
  except TypeError as e:
 
 
 
39
  print(f"Recovering from TypeError: {e}")
40
  try:
41
  last_step = self.agent.memory.steps[-1]
42
+ raw_answer = getattr(last_step, "action_output", None) or "Unknown"
 
 
43
  except Exception as inner_e:
44
  print(f"Could not recover answer: {inner_e}")
45
  raw_answer = "Unknown"