FD900 commited on
Commit
828c08e
·
verified ·
1 Parent(s): d164b02

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +30 -1
agent.py CHANGED
@@ -1 +1,30 @@
1
- # agent.py - Core agent logic
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ import yaml
4
+ from tools import web_search, wikipedia_search, visit_webpage, final_answer
5
+
6
+ with open("prompts.yaml", "r") as f:
7
+ prompts = yaml.safe_load(f)
8
+
9
+ SYSTEM_PROMPT = prompts["system_prompt"]
10
+
11
+ class GaiaAgent:
12
+ def __init__(self):
13
+ self.system_prompt = SYSTEM_PROMPT
14
+ self.endpoint_url = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
15
+ self.headers = {
16
+ "Authorization": f"Bearer {os.environ['HF_TOKEN']}",
17
+ "Content-Type": "application/json"
18
+ }
19
+
20
+ def __call__(self, task):
21
+ prompt = self.system_prompt + "\nTask:\n" + task
22
+ payload = {"inputs": prompt}
23
+ try:
24
+ response = requests.post(self.endpoint_url, headers=self.headers, json=payload)
25
+ output = response.json()
26
+ if isinstance(output, list) and "generated_text" in output[0]:
27
+ return output[0]["generated_text"]
28
+ return output
29
+ except Exception as e:
30
+ return f"AGENT ERROR: {str(e)}"