aynot commited on
Commit
e1064c3
·
1 Parent(s): 73cb1ca

addded files support

Browse files
Files changed (2) hide show
  1. agent.py +19 -2
  2. app.py +23 -3
agent.py CHANGED
@@ -1,6 +1,7 @@
1
  from smolagents import CodeAgent, LiteLLMModel
2
  import os
3
  from cloudpathlib import AnyPath
 
4
 
5
  from tools import initialize_all_available_tools
6
 
@@ -23,8 +24,12 @@ class MyAgent:
23
  with AnyPath("gaia_prompt.txt").open("r", encoding='utf-8') as f:
24
  self.gaia_prompt = f.read()
25
 
26
- def get_answer(self, question):
27
- answer = self.agent.run(self.gaia_prompt + '\n' + question)
 
 
 
 
28
 
29
  answer = str(answer)
30
 
@@ -32,5 +37,17 @@ class MyAgent:
32
  if answer.startswith(fa_tmlp):
33
  answer = answer[len(fa_tmlp):]
34
  return answer.strip()
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
 
 
1
  from smolagents import CodeAgent, LiteLLMModel
2
  import os
3
  from cloudpathlib import AnyPath
4
+ from google.genai import types
5
 
6
  from tools import initialize_all_available_tools
7
 
 
24
  with AnyPath("gaia_prompt.txt").open("r", encoding='utf-8') as f:
25
  self.gaia_prompt = f.read()
26
 
27
+ def get_answer(self, question, additional_data: dict | None = None):
28
+
29
+ prompt = self.make_prompt(question)
30
+ additional_args = self.make_additional_args(additional_data)
31
+
32
+ answer = self.agent.run(prompt, additional_args=additional_args)
33
 
34
  answer = str(answer)
35
 
 
37
  if answer.startswith(fa_tmlp):
38
  answer = answer[len(fa_tmlp):]
39
  return answer.strip()
40
+
41
+ def make_prompt(self, question):
42
+ return self.gaia_prompt + '\n' + question
43
+
44
+ def make_additional_args(self, additional_data: dict | None = None):
45
+ if additional_data is None:
46
+ return None
47
+
48
+ return {"additional_file": types.Part.from_bytes(
49
+ data=additional_data['content'],
50
+ mime_type=additional_data['Content-Type'],
51
+ )}
52
 
53
 
app.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
 
7
  from agent import MyAgent
8
 
9
  # (Keep Constants as is)
@@ -16,9 +17,9 @@ class BasicAgent:
16
  def __init__(self):
17
  self.agent = MyAgent()
18
  print("BasicAgent initialized.")
19
- def __call__(self, question: str) -> str:
20
  print(f"Agent received question (first 50 chars): {question[:50]}...")
21
- answer = self.agent.get_answer(question)
22
  print(f"Agent returning fixed answer: {answer}")
23
  return answer
24
 
@@ -83,8 +84,27 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
83
  print(f"Skipping item with missing task_id or question: {item}")
84
  continue
85
  try:
86
- submitted_answer = agent(question_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
 
 
 
 
 
88
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
89
  except Exception as e:
90
  print(f"Error running agent on task {task_id}: {e}")
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ from time import time, sleep
8
  from agent import MyAgent
9
 
10
  # (Keep Constants as is)
 
17
  def __init__(self):
18
  self.agent = MyAgent()
19
  print("BasicAgent initialized.")
20
+ def __call__(self, question: str, additional_data: dict | None = None) -> str:
21
  print(f"Agent received question (first 50 chars): {question[:50]}...")
22
+ answer = self.agent.get_answer(question, additional_data=additional_data)
23
  print(f"Agent returning fixed answer: {answer}")
24
  return answer
25
 
 
84
  print(f"Skipping item with missing task_id or question: {item}")
85
  continue
86
  try:
87
+ additional_data = None
88
+ file_name = item.get("file_name")
89
+ if file_name:
90
+ task_id_url = f"{api_url}/files/{task_id}"
91
+
92
+ response = requests.get(task_id_url, timeout=15)
93
+ response.raise_for_status()
94
+
95
+ additional_data = {"Content-Type": response.headers['Content-Type'],
96
+ "Content-Length": response.headers['Content-Length'],
97
+ "content": response.content}
98
+
99
+ t0_inner = time()
100
+ submitted_answer = agent(question_text, additional_data=additional_data)
101
+ t1_inner = time()
102
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
103
+
104
+ if t1_inner - t0_inner > 60: # cooldown
105
+ print("cooldown...")
106
+ sleep(61)
107
+
108
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
109
  except Exception as e:
110
  print(f"Error running agent on task {task_id}: {e}")