Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,17 +16,19 @@ If you are asked for a comma separated list, apply the above rules depending of
|
|
| 16 |
IMPORTANT: When calling final_answer(), ALWAYS pass your answer as a string, even for numbers. Example: final_answer("4") NOT final_answer(4)."""
|
| 17 |
|
| 18 |
# --- Basic Agent Definition ---
|
|
|
|
|
|
|
| 19 |
class BasicAgent:
|
| 20 |
def __init__(self):
|
| 21 |
print("BasicAgent initialized.")
|
| 22 |
self.model = LiteLLMModel(
|
| 23 |
-
model_id="
|
| 24 |
-
api_key=os.getenv("
|
| 25 |
)
|
| 26 |
self.agent = CodeAgent(
|
| 27 |
-
tools=[DuckDuckGoSearchTool(max_results=
|
| 28 |
model=self.model,
|
| 29 |
-
max_steps=
|
| 30 |
)
|
| 31 |
|
| 32 |
def __call__(self, question: str) -> str:
|
|
@@ -35,25 +37,18 @@ class BasicAgent:
|
|
| 35 |
|
| 36 |
try:
|
| 37 |
raw_answer = self.agent.run(full_question)
|
| 38 |
-
except
|
| 39 |
-
print(f"
|
| 40 |
try:
|
| 41 |
last_step = self.agent.memory.steps[-1]
|
| 42 |
raw_answer = getattr(last_step, "action_output", None) or "Unknown"
|
| 43 |
-
except Exception
|
| 44 |
-
print(f"Could not recover answer: {inner_e}")
|
| 45 |
raw_answer = "Unknown"
|
| 46 |
-
except Exception as e:
|
| 47 |
-
print(f"Unexpected error running agent: {e}")
|
| 48 |
-
raw_answer = "Unknown"
|
| 49 |
|
| 50 |
raw_answer = str(raw_answer)
|
| 51 |
-
if "FINAL ANSWER:" in raw_answer
|
| 52 |
-
answer = raw_answer.split("FINAL ANSWER:")[-1].strip()
|
| 53 |
-
else:
|
| 54 |
-
answer = raw_answer.strip()
|
| 55 |
-
|
| 56 |
print(f"Agent returning answer: {answer}")
|
|
|
|
| 57 |
return answer
|
| 58 |
|
| 59 |
|
|
|
|
| 16 |
IMPORTANT: When calling final_answer(), ALWAYS pass your answer as a string, even for numbers. Example: final_answer("4") NOT final_answer(4)."""
|
| 17 |
|
| 18 |
# --- Basic Agent Definition ---
|
| 19 |
+
import time
|
| 20 |
+
|
| 21 |
class BasicAgent:
|
| 22 |
def __init__(self):
|
| 23 |
print("BasicAgent initialized.")
|
| 24 |
self.model = LiteLLMModel(
|
| 25 |
+
model_id="groq/llama-3.1-8b-instant", # TPM plus généreux que le 70b
|
| 26 |
+
api_key=os.getenv("GROQ_API_KEY")
|
| 27 |
)
|
| 28 |
self.agent = CodeAgent(
|
| 29 |
+
tools=[DuckDuckGoSearchTool(max_results=2)], # très limité
|
| 30 |
model=self.model,
|
| 31 |
+
max_steps=3 # empêche l'historique de grossir trop
|
| 32 |
)
|
| 33 |
|
| 34 |
def __call__(self, question: str) -> str:
|
|
|
|
| 37 |
|
| 38 |
try:
|
| 39 |
raw_answer = self.agent.run(full_question)
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"Error: {e}")
|
| 42 |
try:
|
| 43 |
last_step = self.agent.memory.steps[-1]
|
| 44 |
raw_answer = getattr(last_step, "action_output", None) or "Unknown"
|
| 45 |
+
except Exception:
|
|
|
|
| 46 |
raw_answer = "Unknown"
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
raw_answer = str(raw_answer)
|
| 49 |
+
answer = raw_answer.split("FINAL ANSWER:")[-1].strip() if "FINAL ANSWER:" in raw_answer else raw_answer.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
print(f"Agent returning answer: {answer}")
|
| 51 |
+
time.sleep(3) # laisse le quota TPM se recharger avant la question suivante
|
| 52 |
return answer
|
| 53 |
|
| 54 |
|