smarted cooldown
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
| 6 |
|
| 7 |
from time import time, sleep
|
| 8 |
from agent import MyAgent
|
|
@@ -95,16 +96,20 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 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}")
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from litellm import RateLimitError
|
| 7 |
|
| 8 |
from time import time, sleep
|
| 9 |
from agent import MyAgent
|
|
|
|
| 96 |
additional_data = {"Content-Type": response.headers['Content-Type'],
|
| 97 |
"Content-Length": response.headers['Content-Length'],
|
| 98 |
"content": response.content}
|
| 99 |
+
|
| 100 |
+
cooldown_attempts = 2
|
| 101 |
+
while cooldown_attempts > 0:
|
| 102 |
+
try:
|
| 103 |
+
submitted_answer = agent(question_text, additional_data=additional_data)
|
| 104 |
+
break
|
| 105 |
+
except RateLimitError as e:
|
| 106 |
+
print(f"cooldown due to {e}")
|
| 107 |
+
sleep(61)
|
| 108 |
+
cooldown_attempts -= 1
|
| 109 |
+
if cooldown_attempts == 0:
|
| 110 |
+
raise e
|
| 111 |
|
|
|
|
|
|
|
|
|
|
| 112 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 114 |
except Exception as e:
|
| 115 |
print(f"Error running agent on task {task_id}: {e}")
|