olcapone commited on
Commit
bf916bf
·
verified ·
1 Parent(s): b3af0f9
Files changed (1) hide show
  1. app.py +36 -11
app.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
 
5
  from smolagents import LiteLLMModel, CodeAgent, Tool
6
 
7
  # --- Constants ---
@@ -109,17 +110,37 @@ class BasicAgent:
109
  )
110
 
111
  def __call__(self, question: str) -> str:
112
- result = self.agent.run(question)
113
- # Extract only the final answer without any wrappers
114
- final_str = str(result).strip()
115
- # Remove any potential prefixes
116
- if final_str.startswith('[ANSWER]'):
117
- final_str = final_str[8:].strip()
118
- if final_str.startswith('Final answer:'):
119
- final_str = final_str[13:].strip()
120
- if final_str.startswith('Answer:'):
121
- final_str = final_str[7:].strip()
122
- return final_str
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
  # --- Main Application Functions ---
125
  def run_and_submit_all(profile: gr.OAuthProfile | None):
@@ -197,6 +218,10 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
197
  submitted_answer = agent(question_text)
198
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
199
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
 
 
 
 
200
  except Exception as e:
201
  print(f"Error running agent on task {task_id}: {e}")
202
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
 
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
5
+ import time
6
  from smolagents import LiteLLMModel, CodeAgent, Tool
7
 
8
  # --- Constants ---
 
110
  )
111
 
112
  def __call__(self, question: str) -> str:
113
+ max_retries = 3
114
+ retry_delay = 10 # Start with 10 seconds
115
+
116
+ for attempt in range(max_retries):
117
+ try:
118
+ result = self.agent.run(question)
119
+ # Extract only the final answer without any wrappers
120
+ final_str = str(result).strip()
121
+ # Remove any potential prefixes
122
+ if final_str.startswith('[ANSWER]'):
123
+ final_str = final_str[8:].strip()
124
+ if final_str.startswith('Final answer:'):
125
+ final_str = final_str[13:].strip()
126
+ if final_str.startswith('Answer:'):
127
+ final_str = final_str[7:].strip()
128
+ return final_str
129
+ except Exception as e:
130
+ # Check if it's a rate limit error
131
+ if "RateLimitError" in str(e) or "rate_limit_exceeded" in str(e):
132
+ if attempt < max_retries - 1: # Not the last attempt
133
+ print(f"Rate limit hit. Waiting {retry_delay} seconds before retry {attempt + 1}/{max_retries}")
134
+ time.sleep(retry_delay)
135
+ retry_delay *= 2 # Exponential backoff
136
+ continue
137
+ else:
138
+ return f"Rate limit error after {max_retries} attempts: {e}"
139
+ else:
140
+ # Not a rate limit error, re-raise
141
+ raise e
142
+
143
+ return f"Failed to get response after {max_retries} attempts"
144
 
145
  # --- Main Application Functions ---
146
  def run_and_submit_all(profile: gr.OAuthProfile | None):
 
218
  submitted_answer = agent(question_text)
219
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
220
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
221
+
222
+ # Add a small delay between questions to help with rate limiting
223
+ if progress_count < total_questions: # Don't delay after the last question
224
+ time.sleep(2)
225
  except Exception as e:
226
  print(f"Error running agent on task {task_id}: {e}")
227
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})