arlindkadra commited on
Commit
eb97e64
·
1 Parent(s): 35b8943

Retrying failed tasks until they get solved, adding arxiv tool

Browse files
Files changed (2) hide show
  1. app.py +16 -8
  2. utilities.py +2 -2
app.py CHANGED
@@ -20,6 +20,7 @@ from tools import (
20
  multiply,
21
  subtract,
22
  wikipedia_search,
 
23
  search_tool,
24
  )
25
 
@@ -52,6 +53,7 @@ class BasicAgent:
52
  subtract,
53
  wikipedia_search,
54
  search_tool,
 
55
  ]
56
  chat_with_tools = chat.bind_tools(tools)
57
 
@@ -131,16 +133,22 @@ async def answer_all_questions(agent: BasicAgent, questions: list[dict]) -> list
131
  tasks = [agent.run(*question_info) for question_info in question_infos]
132
 
133
  results = await asyncio.gather(*tasks, return_exceptions=True)
134
- # Optional: handle exceptions gracefully
135
- final_results = []
136
- for result in results:
137
- if isinstance(result, Exception):
138
- final_results.append(f"ERROR: {str(result)}")
139
- else:
140
- final_results.append(result)
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  # Run all coroutines concurrently
143
- return final_results
144
 
145
  async def run_and_submit_all( profile: gr.OAuthProfile | None):
146
  """
 
20
  multiply,
21
  subtract,
22
  wikipedia_search,
23
+ arxiv_search,
24
  search_tool,
25
  )
26
 
 
53
  subtract,
54
  wikipedia_search,
55
  search_tool,
56
+ arxiv_search
57
  ]
58
  chat_with_tools = chat.bind_tools(tools)
59
 
 
133
  tasks = [agent.run(*question_info) for question_info in question_infos]
134
 
135
  results = await asyncio.gather(*tasks, return_exceptions=True)
 
 
 
 
 
 
 
136
 
137
+ failed_tasks = any(isinstance(result, Exception) for result in results)
138
+
139
+ while failed_tasks:
140
+ for result_index, result in enumerate(results):
141
+ if isinstance(result, Exception):
142
+ print(f"Retrying failed task {result_index + 1}/{len(results)}...")
143
+ try:
144
+ new_result = await agent.run(*question_infos[result_index])
145
+ results[result_index] = new_result
146
+ print(f"Task {result_index + 1} succeeded on retry.")
147
+ except Exception as e:
148
+ print(f"Task {result_index + 1} failed again: {e}")
149
+ failed_tasks = any(isinstance(result, Exception) for result in results)
150
  # Run all coroutines concurrently
151
+ return results
152
 
153
  async def run_and_submit_all( profile: gr.OAuthProfile | None):
154
  """
utilities.py CHANGED
@@ -58,11 +58,11 @@ def prepare_questions(questions_data: list) -> list:
58
  df = pd.read_excel(io.BytesIO(file.content))
59
  # Step 2: Convert the CSV data to a string
60
  csv_data = df.to_string(index=False)
61
- question_text += f"\n\nThe following is the content of the CSV file:\n{csv_data}"
62
  elif file_name.split(".")[-1] == "mp3":
63
  audio_base64 = base64.b64encode(file.content).decode("utf-8")
64
  else:
65
- question_text += f"{file.content}"
66
 
67
  question_info.append((question_text, image_base64, audio_base64))
68
 
 
58
  df = pd.read_excel(io.BytesIO(file.content))
59
  # Step 2: Convert the CSV data to a string
60
  csv_data = df.to_string(index=False)
61
+ question_text += f"\n\nThe following content is from the CSV file:\n{csv_data}"
62
  elif file_name.split(".")[-1] == "mp3":
63
  audio_base64 = base64.b64encode(file.content).decode("utf-8")
64
  else:
65
+ question_text += f"\n\nThe following content is from the python script:\n{file.content}"
66
 
67
  question_info.append((question_text, image_base64, audio_base64))
68