Update app.py
Browse files
app.py
CHANGED
|
@@ -27,6 +27,22 @@ SYSTEM_HINT = (
|
|
| 27 |
)
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
class BasicAgent:
|
| 31 |
def __init__(self):
|
| 32 |
self.agent = CodeAgent(
|
|
@@ -36,30 +52,20 @@ class BasicAgent:
|
|
| 36 |
token=os.getenv("HF_TOKEN"),
|
| 37 |
),
|
| 38 |
max_steps=12,
|
| 39 |
-
additional_authorized_imports=["pandas", "numpy"],
|
| 40 |
)
|
| 41 |
-
GAIA_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:
|
| 42 |
-
FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 43 |
-
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 44 |
-
If you are asked for a number, don't use commas to write your number, and don't use units such as $ or percent sign unless specified otherwise.
|
| 45 |
-
If you are asked for a string, don't use articles, don't use abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
|
| 46 |
-
If you are asked for a comma separated list, apply the above rules depending on whether the element to be put in the list is a number or a string."""
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
def __call__(self, question: str) -> str:
|
| 50 |
-
try:
|
| 51 |
-
raw = str(self.agent.run(f"{GAIA_SYSTEM_PROMPT}\n\nQuestion: {question}"))
|
| 52 |
-
# Извлекаем только то, что после "FINAL ANSWER:"
|
| 53 |
-
if "FINAL ANSWER:" in raw:
|
| 54 |
-
answer = raw.split("FINAL ANSWER:")[-1].strip()
|
| 55 |
-
# Убираем точку в конце, если есть
|
| 56 |
-
answer = answer.rstrip(".").strip()
|
| 57 |
-
return answer
|
| 58 |
-
return raw.strip()
|
| 59 |
-
except Exception as e:
|
| 60 |
-
print(f"Agent failed: {e}")
|
| 61 |
-
return "unable to answer"
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
|
|
|
|
| 27 |
)
|
| 28 |
|
| 29 |
|
| 30 |
+
import os
|
| 31 |
+
from smolagents import (
|
| 32 |
+
CodeAgent,
|
| 33 |
+
DuckDuckGoSearchTool,
|
| 34 |
+
InferenceClientModel,
|
| 35 |
+
WikipediaSearchTool,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
GAIA_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:
|
| 39 |
+
FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 40 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 41 |
+
If you are asked for a number, don't use commas to write your number, and don't use units such as $ or percent sign unless specified otherwise.
|
| 42 |
+
If you are asked for a string, don't use articles, don't use abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
|
| 43 |
+
If you are asked for a comma separated list, apply the above rules depending on whether the element to be put in the list is a number or a string."""
|
| 44 |
+
|
| 45 |
+
|
| 46 |
class BasicAgent:
|
| 47 |
def __init__(self):
|
| 48 |
self.agent = CodeAgent(
|
|
|
|
| 52 |
token=os.getenv("HF_TOKEN"),
|
| 53 |
),
|
| 54 |
max_steps=12,
|
| 55 |
+
additional_authorized_imports=["pandas", "numpy", "datetime", "re", "json", "math"],
|
| 56 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
def __call__(self, question: str) -> str:
|
| 59 |
+
try:
|
| 60 |
+
raw = str(self.agent.run(f"{GAIA_SYSTEM_PROMPT}\n\nQuestion: {question}"))
|
| 61 |
+
if "FINAL ANSWER:" in raw:
|
| 62 |
+
answer = raw.split("FINAL ANSWER:")[-1].strip()
|
| 63 |
+
answer = answer.rstrip(".").strip()
|
| 64 |
+
return answer
|
| 65 |
+
return raw.strip()
|
| 66 |
+
except Exception as e:
|
| 67 |
+
print(f"Agent failed: {e}")
|
| 68 |
+
return "unable to answer"
|
| 69 |
|
| 70 |
|
| 71 |
|