Astro / agents /hf_code_agent.py
Abraham E. Tavarez
Astro final challenge agent
2125ce6
import sys
import os
# Add the Project Root to sys.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
from smolagents import (
HfApiModel,
CodeAgent,
load_tool,
Tool,
InferenceClientModel,
ToolCallingAgent,
FinalAnswerTool,
DuckDuckGoSearchTool,
VisitWebpageTool,
GoogleSearchTool,
PythonInterpreterTool,
)
import os
from huggingface_hub import login
from dotenv import load_dotenv
from data.sample_questions import QUESTIONS
# from tools.visit_website import VisitWebpageTool
load_dotenv()
login(os.environ["HF_API_KEY"])
# Tools
# wikipedia = Tool.from_langchain(load_tool("wikipedia", trust_remote_code=True))
tools = [
# DuckDuckGoSearchTool(),
# VisitWebpageTool(),
PythonInterpreterTool(),
FinalAnswerTool(),
# wikipedia
]
question = QUESTIONS[0]
# LLM Model
model = HfApiModel(
"deepseek-ai/DeepSeek-R1",
provider="together",
# max_tokens=40096,
# temperature=0.1,
# token=get_huggingface_token(),
)
# Code Agent
hf_code_agent = CodeAgent(
model=model,
tools=tools,
max_steps=20,
additional_authorized_imports=["pandas", "numpy", "time", "bs4", "time"],
verbosity_level=2,
name="python_interpreter_agent",
description="Can run and execute python code."
)
hf_code_agent.logger.console.width = 66
if __name__ == "__main__":
answer = hf_code_agent.run(question)
print(answer)