Spaces:
Sleeping
Sleeping
Update agent.py
Browse files12345672 unmodified lines10111213141516171819202122232425262728293031323334353637import osfrom transformers import pipeline# Assuming you still want to use your local Flan-T5 model# from tools.search_tool import search_duckduckgo # REMOVE THIS LINE# NEW IMPORTS for smolagentsfrom smolagents import CodeAgent, DuckDuckGoSearchTool2 unmodified linesclass GaiaAgent:def __init__(self, model_id: str = "google/flan-t5-large"):# Initialize your LLM using smolagents's TransformersModel# This allows smolagents to manage the interaction with your local modelself.llm_model = TransformersModel(model_id=model_id)# Initialize the smolagents CodeAgent# Pass the DuckDuckGoSearchTool directly to the agent's tools list# You can add other tools here if neededself.agent = CodeAgent(model=self.llm_model,tools=[DuckDuckGoSearchTool()],# 'add_base_tools=True' can add common basic tools (like a Python interpreter)# You might need to experiment with this. For now, let's keep it explicit.add_base_tools=False,verbose=True # This is helpful for debugging on Hugging Face Spaces logs)def process_task(self, task_description: str) -> str:# The smolagents agent.run() method handles the entire process# of planning, tool use, and generating a final answer.try:# The agent will decide when to use DuckDuckGoSearchTool based on the promptresponse = self.agent.run(task_description)return responseexcept Exception as e:return f"An error occurred during agent processing: {e}"123452 unmodified lines89101112131415161718192021222324252627282930313233343536import os# from transformers import pipeline # No longer directly using pipeline here# NEW IMPORTS for smolagentsfrom smolagents import CodeAgent, DuckDuckGoSearchTool2 unmodified linesclass GaiaAgent:def __init__(self, model_id: str = "google/flan-t5-large"):# Initialize your LLM using smolagents's TransformersModel# This is the crucial part. Flan-T5 is a 'text2text-generation' model.# TransformersModel probably builds a pipeline, which needs the correct task.self.llm_model = TransformersModel(model_id=model_id,# Specify the task type for Flan-T5 modelstask="text2text-generation",# You might need to add device mapping if running into memory issues# e.g., device_map="auto" if on GPU)# Initialize the smolagents CodeAgentself.agent = CodeAgent(model=self.llm_model,tools=[DuckDuckGoSearchTool()],add_base_tools=False,verbose=True)def process_task(self, task_description: str) -> str:try:response = self.agent.run(task_description)return responseexcept Exception as e:return f"An error occurred during agent processing: {e}"
agent.py+13-14