mohammedqarnuon's picture
Update app.py
473f360 verified
Raw
History Blame Contribute Delete
1.05 kB
from smolagents import CodeAgent, WebSearchTool, InferenceClientModel
class BasicAgent:
def __init__(self):
print("BasicAgent initialized.")
self.model = InferenceClientModel(
model_id="Qwen/Qwen2.5-Coder-32B-Instruct"
)
self.agent = CodeAgent(
tools=[WebSearchTool()],
model=self.model,
add_base_tools=True # يضيف: calculator, final_answer, إلخ
)
def __call__(self, question: str) -> str:
print(f"Agent received question (first 50 chars): {question[:50]}...")
try:
formatted_question = (
f"{question}\n\n"
"Answer with ONLY the final answer, no explanation, "
"no extra words, no 'The answer is', just the exact value/word/number requested."
)
answer = self.agent.run(formatted_question)
return str(answer).strip()
except Exception as e:
print(f"Error running agent: {e}")
return f"AGENT ERROR: {e}"