Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,8 +30,8 @@ class BasicAgent:
|
|
| 30 |
def __init__(self):
|
| 31 |
print("BasicAgent initialized.")
|
| 32 |
sambanova_api_key = os.getenv("SAMBANOVA_API_KEY")
|
| 33 |
-
model = OpenAIServerModel(
|
| 34 |
-
model_id="Meta-Llama-3.
|
| 35 |
api_base="https://api.sambanova.ai/v1",
|
| 36 |
api_key=sambanova_api_key,
|
| 37 |
)
|
|
@@ -41,21 +41,31 @@ class BasicAgent:
|
|
| 41 |
PythonInterpreterTool(),
|
| 42 |
get_current_date_time,
|
| 43 |
]
|
| 44 |
-
self.
|
| 45 |
-
tools=tools,
|
| 46 |
-
model=model,
|
| 47 |
-
max_steps=8,
|
| 48 |
-
)
|
| 49 |
|
| 50 |
def __call__(self, question: str) -> str:
|
| 51 |
print(f"Agent received question (first 50 chars): {question[:50]}")
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
# --- run_and_submit_all function (Keep as is) ---
|
|
@@ -111,8 +121,8 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 111 |
except Exception as e:
|
| 112 |
print(f"Error running agent on task {task_id}: {e}")
|
| 113 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 114 |
-
#
|
| 115 |
-
time.sleep(
|
| 116 |
|
| 117 |
if not answers_payload:
|
| 118 |
print("Agent did not produce any answers to submit.")
|
|
|
|
| 30 |
def __init__(self):
|
| 31 |
print("BasicAgent initialized.")
|
| 32 |
sambanova_api_key = os.getenv("SAMBANOVA_API_KEY")
|
| 33 |
+
self.model = OpenAIServerModel(
|
| 34 |
+
model_id="Meta-Llama-3.3-70B-Instruct",
|
| 35 |
api_base="https://api.sambanova.ai/v1",
|
| 36 |
api_key=sambanova_api_key,
|
| 37 |
)
|
|
|
|
| 41 |
PythonInterpreterTool(),
|
| 42 |
get_current_date_time,
|
| 43 |
]
|
| 44 |
+
self.tools = tools
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
def __call__(self, question: str) -> str:
|
| 47 |
print(f"Agent received question (first 50 chars): {question[:50]}")
|
| 48 |
+
# Retry up to 3 times with backoff on rate limit errors
|
| 49 |
+
for attempt in range(3):
|
| 50 |
+
try:
|
| 51 |
+
agent = ToolCallingAgent(
|
| 52 |
+
tools=self.tools,
|
| 53 |
+
model=self.model,
|
| 54 |
+
max_steps=8,
|
| 55 |
+
)
|
| 56 |
+
answer = agent.run(question)
|
| 57 |
+
print(f"Agent answer: {str(answer)[:100]}")
|
| 58 |
+
return str(answer)
|
| 59 |
+
except Exception as e:
|
| 60 |
+
err = str(e)
|
| 61 |
+
if "429" in err or "rate_limit" in err.lower() or "rate limit" in err.lower():
|
| 62 |
+
wait = 60 * (attempt + 1)
|
| 63 |
+
print(f"Rate limit hit, waiting {wait}s before retry {attempt+1}/3...")
|
| 64 |
+
time.sleep(wait)
|
| 65 |
+
else:
|
| 66 |
+
print(f"Agent error: {e}")
|
| 67 |
+
return f"Error: {e}"
|
| 68 |
+
return "Error: Rate limit exceeded after retries"
|
| 69 |
|
| 70 |
|
| 71 |
# --- run_and_submit_all function (Keep as is) ---
|
|
|
|
| 121 |
except Exception as e:
|
| 122 |
print(f"Error running agent on task {task_id}: {e}")
|
| 123 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 124 |
+
# Pause between questions to avoid per-minute rate limits
|
| 125 |
+
time.sleep(3)
|
| 126 |
|
| 127 |
if not answers_payload:
|
| 128 |
print("Agent did not produce any answers to submit.")
|