Spaces:
Sleeping
Sleeping
| import os | |
| from smolagents import (InferenceClientModel, CodeAgent, ToolCallingAgent, | |
| DuckDuckGoSearchTool, VisitWebpageTool, FinalAnswerTool, | |
| WikipediaSearchTool, PythonInterpreterTool, | |
| TransformersModel | |
| ) | |
| model_id = "deepseek-ai/DeepSeek-R1-0528-Qwen3-8B" | |
| model = InferenceClientModel( | |
| model_id, | |
| token=os.getenv('HF_TOKEN') | |
| ) | |
| #web_agent = ToolCallingAgent( | |
| # tools=[ | |
| # DuckDuckGoSearchTool(), | |
| # VisitWebpageTool(), | |
| # WikipediaSearchTool() | |
| # ], | |
| # model=model, | |
| # name="search_agent", | |
| # description="Runs web searches for you. Give it your query as an argument.", | |
| # ) | |
| #python_agent = CodeAgent( | |
| # tools=[ | |
| # PythonInterpreterTool() | |
| # ], | |
| # model=model, | |
| # name='python_agent', | |
| # description='Use additional_authorized_imports for you. You need to do actions and help to answer the questions with python code', | |
| # additional_authorized_imports=[ | |
| # "json", | |
| # "pandas", | |
| # "numpy", | |
| # "requests", | |
| # "time", | |
| # "datetime", | |
| # ], | |
| # add_base_tools=True, | |
| # ) | |
| class BasicAgent: | |
| """An agent who is able to answer questions.""" | |
| def __init__(self): | |
| # Instantiate Agent | |
| self.agent = CodeAgent(tools=[ | |
| DuckDuckGoSearchTool(), | |
| VisitWebpageTool(), | |
| WikipediaSearchTool(), | |
| FinalAnswerTool() | |
| ], | |
| model=model, | |
| additional_authorized_imports=[ | |
| "json", | |
| "pandas", | |
| "numpy", | |
| "requests", | |
| "time", | |
| "datetime", | |
| "re" | |
| ], | |
| add_base_tools=True, | |
| ) | |
| print("BasicAgent initialized.") | |
| def __call__(self, question: str) -> str: | |
| print(f"Agent received question: {question}...") | |
| answer = self.agent.run(question) | |
| print(f"Agent returning answer: {answer}") | |
| return answer |