Update app.py
Browse files
app.py
CHANGED
|
@@ -5,39 +5,22 @@ import pandas as pd
|
|
| 5 |
|
| 6 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 7 |
|
| 8 |
-
from smolagents import CodeAgent, HfApiModel,
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# 1) Определяем GAIA-tool через декоратор — он автоматически
|
| 13 |
-
# заведётся как полноценный Tool с нужными атрибутами.
|
| 14 |
-
@tool
|
| 15 |
-
def gaia(input_text: str) -> str:
|
| 16 |
-
"""
|
| 17 |
-
Extracts the GAIA task in a structured format.
|
| 18 |
-
|
| 19 |
-
Args:
|
| 20 |
-
input_text: The raw GAIA question text to parse and structure.
|
| 21 |
-
"""
|
| 22 |
-
return input_text
|
| 23 |
-
|
| 24 |
-
# --- Basic Agent Definition ---
|
| 25 |
class BasicAgent:
|
| 26 |
def __init__(self):
|
| 27 |
print("Initializing smart CodeAgent...")
|
| 28 |
-
# 2) Модель
|
| 29 |
self.model = HfApiModel(
|
| 30 |
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 31 |
max_tokens=2048,
|
| 32 |
temperature=0.3,
|
| 33 |
)
|
| 34 |
-
# 3) Агент с готовыми инструментами
|
| 35 |
self.agent = CodeAgent(
|
| 36 |
model=self.model,
|
| 37 |
tools=[
|
| 38 |
-
|
| 39 |
-
PythonInterpreterTool(),
|
| 40 |
-
FinalAnswerTool(),
|
| 41 |
],
|
| 42 |
max_steps=6,
|
| 43 |
verbosity_level=2,
|
|
@@ -47,10 +30,13 @@ class BasicAgent:
|
|
| 47 |
|
| 48 |
def __call__(self, question: str) -> str:
|
| 49 |
print(f"Agent received question: {question[:80]}...")
|
| 50 |
-
|
|
|
|
| 51 |
print(f"Agent result: {result}")
|
| 52 |
return result
|
| 53 |
|
|
|
|
|
|
|
| 54 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 55 |
"""
|
| 56 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 5 |
|
| 6 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 7 |
|
| 8 |
+
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool, PythonInterpreterTool, FinalAnswerTool
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
class BasicAgent:
|
| 11 |
def __init__(self):
|
| 12 |
print("Initializing smart CodeAgent...")
|
|
|
|
| 13 |
self.model = HfApiModel(
|
| 14 |
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 15 |
max_tokens=2048,
|
| 16 |
temperature=0.3,
|
| 17 |
)
|
|
|
|
| 18 |
self.agent = CodeAgent(
|
| 19 |
model=self.model,
|
| 20 |
tools=[
|
| 21 |
+
DuckDuckGoSearchTool(), # web-поиск
|
| 22 |
+
PythonInterpreterTool(), # выполнение Python-кода
|
| 23 |
+
FinalAnswerTool(), # финализация ответа
|
| 24 |
],
|
| 25 |
max_steps=6,
|
| 26 |
verbosity_level=2,
|
|
|
|
| 30 |
|
| 31 |
def __call__(self, question: str) -> str:
|
| 32 |
print(f"Agent received question: {question[:80]}...")
|
| 33 |
+
# Передаём сюда СТРОКУ (не словарь)
|
| 34 |
+
result = self.agent.run(question)
|
| 35 |
print(f"Agent result: {result}")
|
| 36 |
return result
|
| 37 |
|
| 38 |
+
|
| 39 |
+
|
| 40 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 41 |
"""
|
| 42 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|