a-ge commited on
Commit
1171fe9
·
verified ·
1 Parent(s): f29763a

Update new_agent.py

Browse files
Files changed (1) hide show
  1. new_agent.py +6 -23
new_agent.py CHANGED
@@ -8,7 +8,7 @@ from smolagents import (
8
  InferenceClientModel,
9
  CodeAgent,
10
  VisitWebpageTool,
11
- WebSearchTool,
12
  WikipediaSearchTool,
13
  tool,
14
  )
@@ -21,22 +21,6 @@ token = os.environ["HF_KEY"]
21
  model_id = "meta-llama/Llama-3.3-70B-Instruct"
22
 
23
 
24
- @tool
25
- def arxiv_search(query: str) -> str:
26
- """Search Arxiv for a query and return maximum 3 result.
27
-
28
- Args:
29
- query: The search query."""
30
- search_docs = ArxivLoader(query=query, load_max_docs=3).load()
31
- formatted_search_docs = "\n\n---\n\n".join(
32
- [
33
- f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
34
- for doc in search_docs
35
- ]
36
- )
37
- return {"arxiv_results": formatted_search_docs}
38
-
39
-
40
  # (Keep Constants as is)
41
  # --- Constants ---
42
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -50,9 +34,8 @@ class BasicAgent:
50
  self.agent = CodeAgent(
51
  tools=[
52
  VisitWebpageTool(),
53
- WebSearchTool(),
54
  WikipediaSearchTool(),
55
- arxiv_search,
56
  ],
57
  model=model,
58
  additional_authorized_imports=[
@@ -88,10 +71,10 @@ class BasicAgent:
88
  try:
89
  if file_path.endswith(".xlsx"):
90
  df = pd.read_excel(file_path)
91
- file_info = f"\n[Attached Excel file preview (first 10 rows)]:\n{df.head(10).to_string(index=False)}\n"
92
  elif file_path.endswith(".py"):
93
  with open(file_path, "r", encoding="utf-8") as f:
94
- code = "".join([line for _, line in zip(range(400), f)])
95
  file_info = f"\n[Attached Python file]:\n{code}\n"
96
  elif file_path.endswith(".png"):
97
  with open(file_path, "rb") as img_file:
@@ -172,14 +155,14 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
172
  for item in questions_data:
173
  task_id = item.get("task_id")
174
  question_text = item.get("question")
175
- file_name = item.get("file") # Check for file key
176
  file_path = None
177
 
178
  if not task_id or question_text is None:
179
  print(f"Skipping item with missing task_id or question: {item}")
180
  continue
181
 
182
- # Download file if present
183
  if file_name:
184
  files_url = f"{api_url}/files/{task_id}"
185
  print(f"Downloading file for task {task_id} from {files_url}")
 
8
  InferenceClientModel,
9
  CodeAgent,
10
  VisitWebpageTool,
11
+ DuckDuckGoSearchTool,
12
  WikipediaSearchTool,
13
  tool,
14
  )
 
21
  model_id = "meta-llama/Llama-3.3-70B-Instruct"
22
 
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # (Keep Constants as is)
25
  # --- Constants ---
26
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
34
  self.agent = CodeAgent(
35
  tools=[
36
  VisitWebpageTool(),
37
+ DuckDuckGoSearchTool(),
38
  WikipediaSearchTool(),
 
39
  ],
40
  model=model,
41
  additional_authorized_imports=[
 
71
  try:
72
  if file_path.endswith(".xlsx"):
73
  df = pd.read_excel(file_path)
74
+ file_info = f"\n[Attached Excel file preview]:\n{df.head(500).to_string(index=False)}\n"
75
  elif file_path.endswith(".py"):
76
  with open(file_path, "r", encoding="utf-8") as f:
77
+ code = "".join([line for _, line in zip(range(500), f)])
78
  file_info = f"\n[Attached Python file]:\n{code}\n"
79
  elif file_path.endswith(".png"):
80
  with open(file_path, "rb") as img_file:
 
155
  for item in questions_data:
156
  task_id = item.get("task_id")
157
  question_text = item.get("question")
158
+ file_name = item.get("file_name") # Updated key
159
  file_path = None
160
 
161
  if not task_id or question_text is None:
162
  print(f"Skipping item with missing task_id or question: {item}")
163
  continue
164
 
165
+ # Download file if present and file_name is not empty
166
  if file_name:
167
  files_url = f"{api_url}/files/{task_id}"
168
  print(f"Downloading file for task {task_id} from {files_url}")