Spaces:
Sleeping
Sleeping
Delete agent.py
Browse files
agent.py
DELETED
|
@@ -1,66 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import requests
|
| 3 |
-
from typing import Dict, List
|
| 4 |
-
|
| 5 |
-
from run import run_and_submit_all # Adjust path if needed
|
| 6 |
-
|
| 7 |
-
class GaiaAgent:
|
| 8 |
-
def __init__(self):
|
| 9 |
-
self.api_url = os.environ.get("HF_MISTRAL_ENDPOINT")
|
| 10 |
-
self.api_key = os.environ.get("HF_TOKEN")
|
| 11 |
-
self.model_id = os.environ.get("LLM_MODEL_ID")
|
| 12 |
-
|
| 13 |
-
assert self.api_url, " HF_MISTRAL_ENDPOINT is missing!"
|
| 14 |
-
assert self.api_key, " HF_TOKEN is missing!"
|
| 15 |
-
assert self.model_id, " LLM_MODEL_ID is missing!"
|
| 16 |
-
|
| 17 |
-
print(f"[INIT] Model ID: {self.model_id}")
|
| 18 |
-
print(f"[INIT] Endpoint: {self.api_url}")
|
| 19 |
-
|
| 20 |
-
self.headers = {
|
| 21 |
-
"Authorization": f"Bearer {self.api_key}",
|
| 22 |
-
"Content-Type": "application/json",
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
def generate(self, prompt: str, stop: List[str] = []) -> str:
|
| 26 |
-
print("🧠 [GENERATE] Prompt sent to model:")
|
| 27 |
-
print(prompt)
|
| 28 |
-
|
| 29 |
-
payload = {
|
| 30 |
-
"inputs": prompt,
|
| 31 |
-
"parameters": {
|
| 32 |
-
"temperature": 0.0,
|
| 33 |
-
"max_new_tokens": 1024,
|
| 34 |
-
"stop": stop,
|
| 35 |
-
}
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
try:
|
| 39 |
-
response = requests.post(self.api_url, headers=self.headers, json=payload)
|
| 40 |
-
response.raise_for_status()
|
| 41 |
-
except Exception as e:
|
| 42 |
-
print(f"❌ [ERROR] Request failed: {e}")
|
| 43 |
-
return "ERROR: Model call failed"
|
| 44 |
-
|
| 45 |
-
output = response.json()
|
| 46 |
-
print(f"✅ [RESPONSE] Raw output: {output}")
|
| 47 |
-
|
| 48 |
-
if isinstance(output, dict) and "generated_text" in output:
|
| 49 |
-
return output["generated_text"]
|
| 50 |
-
elif isinstance(output, list) and "generated_text" in output[0]:
|
| 51 |
-
return output[0]["generated_text"]
|
| 52 |
-
else:
|
| 53 |
-
return str(output)
|
| 54 |
-
|
| 55 |
-
def answer_question(self, question: Dict) -> str:
|
| 56 |
-
print("[DEBUG] Raw question object:", question)
|
| 57 |
-
q = question.get("question") or question.get("Question") or question.get("input")
|
| 58 |
-
if not q:
|
| 59 |
-
raise ValueError(f"No question text found in: {question}")
|
| 60 |
-
system_prompt = """You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string."""
|
| 61 |
-
prompt = f"{system_prompt}\n\nQuestion: {q}\nAnswer:"
|
| 62 |
-
return self.generate(prompt).strip()
|
| 63 |
-
|
| 64 |
-
def run(self):
|
| 65 |
-
print("🚀 [RUN] Starting submission...")
|
| 66 |
-
return run_and_submit_all(self)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|