File size: 1,061 Bytes
828c08e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import requests
import yaml
from tools import web_search, wikipedia_search, visit_webpage, final_answer

with open("prompts.yaml", "r") as f:
    prompts = yaml.safe_load(f)

SYSTEM_PROMPT = prompts["system_prompt"]

class GaiaAgent:
    def __init__(self):
        self.system_prompt = SYSTEM_PROMPT
        self.endpoint_url = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
        self.headers = {
            "Authorization": f"Bearer {os.environ['HF_TOKEN']}",
            "Content-Type": "application/json"
        }

    def __call__(self, task):
        prompt = self.system_prompt + "\nTask:\n" + task
        payload = {"inputs": prompt}
        try:
            response = requests.post(self.endpoint_url, headers=self.headers, json=payload)
            output = response.json()
            if isinstance(output, list) and "generated_text" in output[0]:
                return output[0]["generated_text"]
            return output
        except Exception as e:
            return f"AGENT ERROR: {str(e)}"