FD900 commited on
Commit
ad3a04e
·
verified ·
1 Parent(s): 713b432

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +20 -26
agent.py CHANGED
@@ -1,42 +1,36 @@
1
  import os
2
  import requests
3
 
4
- API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-base"
5
- HF_TOKEN = os.getenv("HF_TOKEN")
6
 
7
  system_prompt = (
8
- "You are a helpful assistant participating in the GAIA benchmark. "
9
- "Always return direct, factual answers with no explanation. Output only the final answer."
 
 
10
  )
11
 
12
- headers = {
13
- "Authorization": f"Bearer {HF_TOKEN}",
14
- "Content-Type": "application/json"
15
- }
16
-
17
  class BasicAgent:
18
  def __init__(self):
19
- print("Flan-T5 Agent initialized using Hugging Face API")
20
 
21
  def __call__(self, question: str) -> str:
22
- prompt = f"{system_prompt}\n\nQuestion:\n{question}\n\nAnswer:"
23
- payload = {
24
- "inputs": prompt,
25
- "parameters": {
26
- "temperature": 0.0,
27
- "max_new_tokens": 128
28
- }
29
- }
30
-
31
  try:
32
- response = requests.post(API_URL, headers=headers, json=payload, timeout=30)
 
 
 
 
 
33
  response.raise_for_status()
34
- data = response.json()
35
- if isinstance(data, list) and "generated_text" in data[0]:
36
- return data[0]["generated_text"].strip()
37
- elif "generated_text" in data[0]:
38
- return data[0]["generated_text"].strip()
39
  else:
40
- return str(data)
41
  except Exception as e:
42
  return f"AGENT ERROR: {e}"
 
1
  import os
2
  import requests
3
 
4
+ API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-alpha"
5
+ HEADERS = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
6
 
7
  system_prompt = (
8
+ "You are an expert AI assistant taking a benchmark test for reasoning. "
9
+ "Answer only the main question directly. Do not explain. Do not show work. "
10
+ "If you see images or documents mentioned, assume you have access and extract answer. "
11
+ "Use search or tools if needed. Answer format must be plain with no prefix or suffix."
12
  )
13
 
 
 
 
 
 
14
  class BasicAgent:
15
  def __init__(self):
16
+ print(" Agent initialized with Zephyr 7B.")
17
 
18
  def __call__(self, question: str) -> str:
19
+ prompt = f"{system_prompt}\n\nQuestion: {question}\nAnswer:"
 
 
 
 
 
 
 
 
20
  try:
21
+ response = requests.post(
22
+ API_URL,
23
+ headers=HEADERS,
24
+ json={"inputs": prompt},
25
+ timeout=40
26
+ )
27
  response.raise_for_status()
28
+ result = response.json()
29
+ if isinstance(result, list):
30
+ return result[0]["generated_text"].split("Answer:")[-1].strip()
31
+ elif "generated_text" in result:
32
+ return result["generated_text"].strip()
33
  else:
34
+ return "ERROR: Unexpected response format"
35
  except Exception as e:
36
  return f"AGENT ERROR: {e}"