Download app.py from agents-course/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/agents-course/Final_Assignment_Template/resolve/refs%2Fpr%2F605/app.py
- Command line
-
hf download hf://spaces/agents-course/Final_Assignment_Template@refs/pr/605/app.py
-
curl -L -o app.py https://huggingface.co/spaces/agents-course/Final_Assignment_Template/resolve/refs%2Fpr%2F605/app.py
1.02 kB
| from smolagents import ( | |
| CodeAgent, | |
| DuckDuckGoSearchTool, | |
| VisitWebpageTool, | |
| InferenceClientModel, | |
| ) | |
| class BasicAgent: | |
| def __init__(self): | |
| token = os.getenv("HF_TOKEN") | |
| if not token: | |
| raise ValueError("Add HF_TOKEN in your Space's Settings → Secrets.") | |
| model = InferenceClientModel(token=token) | |
| self.agent = CodeAgent( | |
| tools=[ | |
| DuckDuckGoSearchTool(), | |
| VisitWebpageTool(), | |
| ], | |
| model=model, | |
| max_steps=12, | |
| ) | |
| def __call__(self, question: str) -> str: | |
| prompt = ( | |
| "Answer the following question accurately. " | |
| "Use web search and visit source pages when needed. " | |
| "Follow the requested answer format exactly. " | |
| "Return only the answer, without explanations, citations, " | |
| "or a 'FINAL ANSWER' prefix.\n\n" | |
| + question | |
| ) | |
| return str(self.agent.run(prompt, reset=True)).strip() |