Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,42 +1,36 @@
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
|
| 4 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
| 5 |
-
|
| 6 |
|
| 7 |
system_prompt = (
|
| 8 |
-
"You are
|
| 9 |
-
"
|
|
|
|
|
|
|
| 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("
|
| 20 |
|
| 21 |
def __call__(self, question: str) -> str:
|
| 22 |
-
prompt = f"{system_prompt}\n\nQuestion
|
| 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(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
response.raise_for_status()
|
| 34 |
-
|
| 35 |
-
if isinstance(
|
| 36 |
-
return
|
| 37 |
-
elif "generated_text" in
|
| 38 |
-
return
|
| 39 |
else:
|
| 40 |
-
return
|
| 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}"
|