2tyoon commited on
Commit
234def3
·
verified ·
1 Parent(s): a628920

Attachment fallback, answer cleanup, timeouts

Browse files
Files changed (1) hide show
  1. agent.py +31 -6
agent.py CHANGED
@@ -38,12 +38,23 @@ def download_task_file(task_id: str, file_name: str) -> str | None:
38
  return None
39
  os.makedirs(FILES_DIR, exist_ok=True)
40
  path = os.path.join(FILES_DIR, file_name)
41
- if not os.path.exists(path):
42
- resp = requests.get(f"{API_URL}/files/{task_id}", timeout=60)
43
- resp.raise_for_status()
 
44
  with open(path, "wb") as f:
45
  f.write(resp.content)
46
- return path
 
 
 
 
 
 
 
 
 
 
47
 
48
 
49
  def _llm_text(messages: list[dict]) -> str:
@@ -145,7 +156,7 @@ Rules for the final answer (it is graded by EXACT MATCH):
145
 
146
  class GaiaAgent:
147
  def __init__(self):
148
- model = LiteLLMModel(model_id=MODEL_ID)
149
  self.agent = CodeAgent(
150
  model=model,
151
  tools=[
@@ -171,4 +182,18 @@ class GaiaAgent:
171
  if file_path:
172
  prompt += f"\n\nThe attached file is available locally at: {file_path}"
173
  answer = str(self.agent.run(prompt)).strip()
174
- return re.sub(r"^\s*FINAL ANSWER:\s*", "", answer, flags=re.I).strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  return None
39
  os.makedirs(FILES_DIR, exist_ok=True)
40
  path = os.path.join(FILES_DIR, file_name)
41
+ if os.path.exists(path):
42
+ return path
43
+ resp = requests.get(f"{API_URL}/files/{task_id}", timeout=60)
44
+ if resp.ok:
45
  with open(path, "wb") as f:
46
  f.write(resp.content)
47
+ return path
48
+ # The scoring server sometimes lacks the attachment; fall back to the same
49
+ # file in the (gated) GAIA dataset. Only the attachment is fetched.
50
+ from huggingface_hub import hf_hub_download
51
+
52
+ return hf_hub_download(
53
+ "gaia-benchmark/GAIA",
54
+ f"2023/validation/{file_name}",
55
+ repo_type="dataset",
56
+ local_dir=FILES_DIR,
57
+ )
58
 
59
 
60
  def _llm_text(messages: list[dict]) -> str:
 
156
 
157
  class GaiaAgent:
158
  def __init__(self):
159
+ model = LiteLLMModel(model_id=MODEL_ID, timeout=180, num_retries=2)
160
  self.agent = CodeAgent(
161
  model=model,
162
  tools=[
 
182
  if file_path:
183
  prompt += f"\n\nThe attached file is available locally at: {file_path}"
184
  answer = str(self.agent.run(prompt)).strip()
185
+ answer = re.sub(r"^\s*FINAL ANSWER:\s*", "", answer, flags=re.I).strip()
186
+ if len(answer) > 60 or "\n" in answer or "<" in answer:
187
+ answer = self._shorten(question, answer)
188
+ return answer
189
+
190
+ def _shorten(self, question: str, answer: str) -> str:
191
+ """Reduce a wordy agent reply to the bare answer the grader expects."""
192
+ return _llm_text([
193
+ {
194
+ "role": "user",
195
+ "content": SYSTEM_HINT
196
+ + f"\nQuestion:\n{question}\n\nDraft reply:\n{answer}\n\n"
197
+ "Reply with ONLY the final answer extracted from the draft, nothing else.",
198
+ }
199
+ ]).strip()