Spaces:
Sleeping
Sleeping
File size: 1,852 Bytes
78683dc af9ad40 78683dc 7828173 90c6fb1 7828173 90c6fb1 9453361 7828173 9323159 90c6fb1 7828173 90c6fb1 36dac61 7cb9551 133de3a 90c6fb1 39ec4fe 133de3a 7557d12 7828173 36dac61 0e701d6 7828173 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import smolagents, numpy, math, xlrd, os
from smolagents import (
CodeAgent,
HfApiModel,
InferenceClientModel,
WebSearchTool,
PythonInterpreterTool,
FinalAnswerTool,
DuckDuckGoSearchTool,
GoogleSearchTool,
VisitWebPageTool
)
#model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"
#model_id = 'meta-llama/Llama-3.3-70B-Instruct'
#model = HfApiModel(model_id=model_id, token="HUGGINGFACEHUB_API_TOKEN")
#agent = CodeAgent(tools=[], model=model, add_base_tools=True)
#max_steps=5
#import os
#from smolagents import CodeAgent, HfApiModel, InferenceClientModel, WebSearchTool
class newAgent:
"""Adapts smolagents.CodeAgent to the HF course template API."""
def __init__(self):
model_id = "meta-llama/Meta-Llama-3-70B-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)
# add_base_tools=True already gives you search, python, etc.
self.agent = CodeAgent(tools=[], model=model, add_base_tools=True)
#*
# include FinalAnswerTool in tools so agent knows when to stop
tools = [FinalAnswerTool()]
self.agent = CodeAgent(
tools=tools,
model=model,
add_base_tools=True
)
#*
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 answer
#answer = self.run
#agent.run(
# "At what temperature and for how long should I bake French baguettes made with type 65 flour?",
#) |