Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
import os
|
|
|
|
|
|
|
| 2 |
from tools import TOOLS
|
| 3 |
from metadata import load_metadata
|
| 4 |
from mistral_hf_wrapper import MistralInference
|
|
@@ -6,22 +8,26 @@ from mistral_hf_wrapper import MistralInference
|
|
| 6 |
API_URL = os.getenv("HF_MISTRAL_ENDPOINT")
|
| 7 |
API_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
|
|
|
|
|
|
|
| 9 |
def load_tasks():
|
| 10 |
tasks = []
|
| 11 |
with open("metadata.jsonl", "r", encoding="utf-8") as f:
|
| 12 |
for line in f:
|
| 13 |
item = json.loads(line)
|
| 14 |
-
question_id = item.get("question_id")
|
| 15 |
question = item.get("Question") or item.get("question")
|
| 16 |
if question_id and question:
|
| 17 |
tasks.append({
|
| 18 |
-
"question_id":
|
| 19 |
"question": question
|
| 20 |
})
|
| 21 |
return tasks
|
| 22 |
|
| 23 |
def solve_task(task, tools=TOOLS):
|
| 24 |
-
system_prompt =
|
|
|
|
|
|
|
| 25 |
user_prompt = task["question"]
|
| 26 |
|
| 27 |
prompt = f"<s>[INST] <<SYS>>\n{system_prompt}\n<</SYS>>\n{user_prompt} [/INST]"
|
|
@@ -29,5 +35,6 @@ def solve_task(task, tools=TOOLS):
|
|
| 29 |
|
| 30 |
return {
|
| 31 |
"question_id": task["question_id"],
|
| 32 |
-
"
|
|
|
|
| 33 |
}
|
|
|
|
| 1 |
import os
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
from tools import TOOLS
|
| 5 |
from metadata import load_metadata
|
| 6 |
from mistral_hf_wrapper import MistralInference
|
|
|
|
| 8 |
API_URL = os.getenv("HF_MISTRAL_ENDPOINT")
|
| 9 |
API_TOKEN = os.getenv("HF_TOKEN")
|
| 10 |
|
| 11 |
+
mistral = MistralInference(api_url=API_URL, api_token=API_TOKEN)
|
| 12 |
+
|
| 13 |
def load_tasks():
|
| 14 |
tasks = []
|
| 15 |
with open("metadata.jsonl", "r", encoding="utf-8") as f:
|
| 16 |
for line in f:
|
| 17 |
item = json.loads(line)
|
| 18 |
+
question_id = item.get("task_id") or item.get("question_id")
|
| 19 |
question = item.get("Question") or item.get("question")
|
| 20 |
if question_id and question:
|
| 21 |
tasks.append({
|
| 22 |
+
"question_id": question_id,
|
| 23 |
"question": question
|
| 24 |
})
|
| 25 |
return tasks
|
| 26 |
|
| 27 |
def solve_task(task, tools=TOOLS):
|
| 28 |
+
system_prompt = (
|
| 29 |
+
"You are a helpful agent. Use reasoning, tools if needed, and return the answer only."
|
| 30 |
+
)
|
| 31 |
user_prompt = task["question"]
|
| 32 |
|
| 33 |
prompt = f"<s>[INST] <<SYS>>\n{system_prompt}\n<</SYS>>\n{user_prompt} [/INST]"
|
|
|
|
| 35 |
|
| 36 |
return {
|
| 37 |
"question_id": task["question_id"],
|
| 38 |
+
"question": task["question"],
|
| 39 |
+
"submitted_answer": response.strip() if response else "ERROR: Empty model response"
|
| 40 |
}
|