Spaces:
Sleeping
Sleeping
Update app.py
Browse files15 unmodified lines16171819202122232425262728293031322 unmodified lines3536373839404142434445464748495051525354555657585915 unmodified linesIMPORTANT: When calling final_answer(), ALWAYS pass your answer as a string, even for numbers. Example: final_answer("4") NOT final_answer(4)."""# --- Basic Agent Definition ---class BasicAgent:def __init__(self):print("BasicAgent initialized.")self.model = LiteLLMModel(model_id="gemini/gemini-2.0-flash",api_key=os.getenv("GEMINI_API_KEY"))self.agent = CodeAgent(tools=[DuckDuckGoSearchTool(max_results=3)],model=self.model,max_steps=6)def __call__(self, question: str) -> str:2 unmodified linestry:raw_answer = self.agent.run(full_question)except TypeError as e:print(f"Recovering from TypeError: {e}")try:last_step = self.agent.memory.steps[-1]raw_answer = getattr(last_step, "action_output", None) or "Unknown"except Exception as inner_e:print(f"Could not recover answer: {inner_e}")raw_answer = "Unknown"except Exception as e:print(f"Unexpected error running agent: {e}")raw_answer = "Unknown"raw_answer = str(raw_answer)if "FINAL ANSWER:" in raw_answer:answer = raw_answer.split("FINAL ANSWER:")[-1].strip()else:answer = raw_answer.strip()print(f"Agent returning answer: {answer}")return answer15 unmodified lines161718192021222324252627282930313233342 unmodified lines37383940414243444546474849505152535415 unmodified linesIMPORTANT: When calling final_answer(), ALWAYS pass your answer as a string, even for numbers. Example: final_answer("4") NOT final_answer(4)."""# --- Basic Agent Definition ---import timeclass BasicAgent:def __init__(self):print("BasicAgent initialized.")self.model = LiteLLMModel(model_id="groq/llama-3.1-8b-instant", # TPM plus généreux que le 70bapi_key=os.getenv("GROQ_API_KEY"))self.agent = CodeAgent(tools=[DuckDuckGoSearchTool(max_results=2)], # très limitémodel=self.model,max_steps=3 # empêche l'historique de grossir trop)def __call__(self, question: str) -> str:2 unmodified linestry:raw_answer = self.agent.run(full_question)except Exception as e:print(f"Error: {e}")try:last_step = self.agent.memory.steps[-1]raw_answer = getattr(last_step, "action_output", None) or "Unknown"except Exception:raw_answer = "Unknown"raw_answer = str(raw_answer)answer = raw_answer.split("FINAL ANSWER:")[-1].strip() if "FINAL ANSWER:" in raw_answer else raw_answer.strip()print(f"Agent returning answer: {answer}")time.sleep(3) # laisse le quota TPM se recharger avant la question suivantereturn answer
app.py+11-16