Download agent.py from agents-course/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 816 Bytes
-
https://huggingface.co/spaces/agents-course/Final_Assignment_Template/resolve/refs%2Fpr%2F423/agent.py
- Command line
-
hf download hf://spaces/agents-course/Final_Assignment_Template@refs/pr/423/agent.py
-
curl -L -o agent.py https://huggingface.co/spaces/agents-course/Final_Assignment_Template/resolve/refs%2Fpr%2F423/agent.py
816 Bytes
| import os | |
| from huggingface_hub import InferenceClient | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| client = InferenceClient( | |
| model="Qwen/Qwen2.5-7B-Instruct", | |
| token=HF_TOKEN | |
| ) if HF_TOKEN else None | |
| def agent(task): | |
| """ | |
| Robust agent for GAIA-style evaluation. | |
| Accepts dict OR string safely. | |
| """ | |
| # Extract input safely | |
| if isinstance(task, dict): | |
| query = task.get("input") or task.get("question") or str(task) | |
| else: | |
| query = str(task) | |
| if client is None: | |
| return "" | |
| try: | |
| response = client.chat_completion( | |
| messages=[ | |
| {"role": "user", "content": query} | |
| ], | |
| max_tokens=512, | |
| temperature=0.1 | |
| ) | |
| return response.choices[0].message.content.strip() | |
| except: | |
| return "" |