Download basic_agent.py from kuma-rtin/Final_Assignment_Agent: direct link, hf CLI and curl.
- Browser
- Download file 926 Bytes
-
https://huggingface.co/spaces/kuma-rtin/Final_Assignment_Agent/resolve/ae6abab2f25caa137e9f0532e8801a0d3b2d69c8/basic_agent.py
- Command line
-
hf download hf://spaces/kuma-rtin/Final_Assignment_Agent@ae6abab2f25caa137e9f0532e8801a0d3b2d69c8/basic_agent.py
-
curl -L -o basic_agent.py https://huggingface.co/spaces/kuma-rtin/Final_Assignment_Agent/resolve/ae6abab2f25caa137e9f0532e8801a0d3b2d69c8/basic_agent.py
926 Bytes
| from llama_index.core.agent.workflow import AgentWorkflow | |
| from llama_index.core.workflow import Context | |
| from llama_index.core.tools import FunctionTool | |
| from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI | |
| from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec | |
| class BasicAgent: | |
| def __init__(self): | |
| llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-Coder-32B-Instruct") | |
| # Initialize tools | |
| tool_spec = DuckDuckGoSearchToolSpec() | |
| search_tool = FunctionTool.from_defaults(tool_spec.duckduckgo_full_search) | |
| # Create Alfred with all the tools | |
| self.agent = AgentWorkflow.from_tools_or_functions( | |
| [search_tool], | |
| llm=llm | |
| ) | |
| # self.ctx = Context(self.agent) | |
| async def __call__(self, question: str) -> str: | |
| response = await self.agent.run(user_msg=question) # ctx=self.ctx) | |
| return response.response.content | |