| 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. |
| """ |
|
|
| |
| 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 "" |