FD900 commited on
Commit
1f9850a
·
verified ·
1 Parent(s): 99427bd

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +7 -8
agent.py CHANGED
@@ -1,15 +1,13 @@
1
  import os
2
- import json
3
- from typing import Dict, List
4
  import requests
 
5
 
6
- from gaia_benchmark.questions import load_questions
7
  from gaia_benchmark.run import run_and_submit_all
8
 
9
  class GaiaAgent:
10
  def __init__(self):
11
- self.api_url = os.environ["HF_MISTRAL_ENDPOINT"] # Your Mistral endpoint
12
- self.api_key = os.environ["HF_TOKEN"] # Hugging Face token
13
  self.headers = {
14
  "Authorization": f"Bearer {self.api_key}",
15
  "Content-Type": "application/json",
@@ -27,16 +25,17 @@ class GaiaAgent:
27
  response = requests.post(self.api_url, headers=self.headers, json=payload)
28
  response.raise_for_status()
29
  output = response.json()
 
30
  if isinstance(output, dict) and "generated_text" in output:
31
  return output["generated_text"]
32
- if isinstance(output, list):
33
  return output[0]["generated_text"]
34
  return str(output)
35
 
36
  def answer_question(self, question: Dict) -> str:
37
- question_text = question["question"]
38
  prompt = f"""You are a helpful agent answering a science question.
39
- Question: {question_text}
40
  Answer:"""
41
  return self.generate(prompt).strip()
42
 
 
1
  import os
 
 
2
  import requests
3
+ from typing import Dict, List
4
 
 
5
  from gaia_benchmark.run import run_and_submit_all
6
 
7
  class GaiaAgent:
8
  def __init__(self):
9
+ self.api_url = os.environ["HF_MISTRAL_ENDPOINT"]
10
+ self.api_key = os.environ["HF_TOKEN"]
11
  self.headers = {
12
  "Authorization": f"Bearer {self.api_key}",
13
  "Content-Type": "application/json",
 
25
  response = requests.post(self.api_url, headers=self.headers, json=payload)
26
  response.raise_for_status()
27
  output = response.json()
28
+
29
  if isinstance(output, dict) and "generated_text" in output:
30
  return output["generated_text"]
31
+ elif isinstance(output, list) and "generated_text" in output[0]:
32
  return output[0]["generated_text"]
33
  return str(output)
34
 
35
  def answer_question(self, question: Dict) -> str:
36
+ q = question["question"]
37
  prompt = f"""You are a helpful agent answering a science question.
38
+ Question: {q}
39
  Answer:"""
40
  return self.generate(prompt).strip()
41