testAgent / BasicAgent.py
optionEdge's picture
Update BasicAgent.py
3716a9b verified
raw
history blame
1.38 kB
import smolagents, numpy, math, xlrd, os
from smolagents import (
CodeAgent,
HfApiModel,
InferenceClientModel,
WebSearchTool,
PythonInterpreterTool,
FinalAnswerTool,
DuckDuckGoSearchTool,
GoogleSearchTool,
)
class newAgent:
"""Adapts smolagents.CodeAgent to the HF course template API."""
def __init__(self):
model_id = "Qwen/Qwen2.5-Coder-32B-Instruct" # correct repo name
hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN") # read real secret
if not hf_token:
raise RuntimeError("HUGGINGFACEHUB_API_TOKEN not set in Space secrets")
model = HfApiModel(model_id=model_id, token=hf_token)
# include FinalAnswerTool in tools so agent knows when to stop
tools = [FinalAnswerTool()]
self.agent = CodeAgent(
tools=tools,
model=model,
add_base_tools=True,
max_steps=5 # limit reasoning time
)
def __call__(self, question: str) -> str:
"""ONE question in β†’ ONE pure-text answer out."""
#↓ Replace .run with whatever method actually returns the answer string.
result = self.agent.run(question)
return result
#answer = self.run
#agent.run(
# "At what temperature and for how long should I bake French baguettes made with type 65 flour?",
#)