Aakash010 commited on
Commit
e2267cd
·
verified ·
1 Parent(s): 592fb5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -3,7 +3,7 @@ import time
3
  import gradio as gr
4
  import requests
5
  import pandas as pd
6
- from smolagents import ToolCallingAgent, OpenAIServerModel, PythonInterpreterTool, Tool
7
  from smolagents import FinalAnswerTool
8
 
9
  # --- Constants ---
@@ -136,7 +136,7 @@ class BasicAgent:
136
  api_base="https://api.groq.com/openai/v1",
137
  api_key=os.getenv("GROQ_API_KEY")
138
  )
139
- self.agent = ToolCallingAgent(
140
  model=model,
141
  tools=[
142
  WebSearchTool(),
@@ -152,26 +152,24 @@ class BasicAgent:
152
  def __call__(self, question: str, task_id: str = "") -> str:
153
  try:
154
  prompt = f"""Answer the following question accurately.
155
- Return ONLY the final answer with no explanation, no punctuation, no extra words.
156
- - If the answer is a number, return just the number.
157
- - If the answer is a name, return just the name.
158
- - If the answer is a list, return comma separated values in alphabetical order.
159
- - If the question asks about a YouTube video, use the youtube_transcript tool.
160
- - If the question mentions Wikipedia, use the wikipedia_search tool.
161
- - If the question references an attached file, use download_file with the task_id below.
162
- Task ID: {task_id}
163
-
164
- Question: {question}"""
165
  result = self.agent.run(prompt)
166
- # handle case where result is a list of content blocks
167
  if isinstance(result, list):
168
  for block in result:
169
  if isinstance(block, dict) and block.get('type') == 'text':
170
  return block['text'].strip()
171
  return str(result).strip()
172
  except Exception as e:
173
- err = str(e)
174
- print(f"Agent error: {err}")
175
  return "I don't know"
176
 
177
 
 
3
  import gradio as gr
4
  import requests
5
  import pandas as pd
6
+ from smolagents import CodeAgent, OpenAIServerModel, PythonInterpreterTool, Tool
7
  from smolagents import FinalAnswerTool
8
 
9
  # --- Constants ---
 
136
  api_base="https://api.groq.com/openai/v1",
137
  api_key=os.getenv("GROQ_API_KEY")
138
  )
139
+ self.agent = CodeAgent( # <-- back to CodeAgent
140
  model=model,
141
  tools=[
142
  WebSearchTool(),
 
152
  def __call__(self, question: str, task_id: str = "") -> str:
153
  try:
154
  prompt = f"""Answer the following question accurately.
155
+ Return ONLY the final answer with no explanation, no punctuation, no extra words.
156
+ - If the answer is a number, return just the number.
157
+ - If the answer is a name, return just the name.
158
+ - If the answer is a list, return comma separated values in alphabetical order.
159
+ - If the question asks about a YouTube video, use the youtube_transcript tool.
160
+ - If the question mentions Wikipedia, use the wikipedia_search tool.
161
+ - If the question references an attached file, use download_file with the task_id below.
162
+ Task ID: {task_id}
163
+
164
+ Question: {question}"""
165
  result = self.agent.run(prompt)
 
166
  if isinstance(result, list):
167
  for block in result:
168
  if isinstance(block, dict) and block.get('type') == 'text':
169
  return block['text'].strip()
170
  return str(result).strip()
171
  except Exception as e:
172
+ print(f"Agent error: {e}")
 
173
  return "I don't know"
174
 
175