Spaces:
Sleeping
Sleeping
Added the final_answer tool
Browse files- app.py +4 -1
- tools/final_answer.py +14 -0
app.py
CHANGED
@@ -5,6 +5,7 @@ import inspect
|
|
5 |
import yaml
|
6 |
import pandas as pd
|
7 |
from smolagents import OpenAIServerModel, ToolCallingAgent, CodeAgent, HfApiModel, DuckDuckGoSearchTool
|
|
|
8 |
|
9 |
|
10 |
# (Keep Constants as is)
|
@@ -16,6 +17,8 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
16 |
class BasicAgent:
|
17 |
def __init__(self):
|
18 |
print("BasicAgent initialized.")
|
|
|
|
|
19 |
# Initialize the agent with a model and tools
|
20 |
|
21 |
model = OpenAIServerModel(
|
@@ -31,7 +34,7 @@ class BasicAgent:
|
|
31 |
agent = CodeAgent(
|
32 |
name="Jeff's GAIA L1 Agent",
|
33 |
verbosity_level=1,
|
34 |
-
tools=[DuckDuckGoSearchTool()],
|
35 |
add_base_tools=True,
|
36 |
max_steps=5,
|
37 |
model=model,
|
|
|
5 |
import yaml
|
6 |
import pandas as pd
|
7 |
from smolagents import OpenAIServerModel, ToolCallingAgent, CodeAgent, HfApiModel, DuckDuckGoSearchTool
|
8 |
+
from tools.final_answer import FinalAnswerTool
|
9 |
|
10 |
|
11 |
# (Keep Constants as is)
|
|
|
17 |
class BasicAgent:
|
18 |
def __init__(self):
|
19 |
print("BasicAgent initialized.")
|
20 |
+
|
21 |
+
final_answer = FinalAnswerTool()
|
22 |
# Initialize the agent with a model and tools
|
23 |
|
24 |
model = OpenAIServerModel(
|
|
|
34 |
agent = CodeAgent(
|
35 |
name="Jeff's GAIA L1 Agent",
|
36 |
verbosity_level=1,
|
37 |
+
tools=[DuckDuckGoSearchTool(), final_answer],
|
38 |
add_base_tools=True,
|
39 |
max_steps=5,
|
40 |
model=model,
|
tools/final_answer.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Optional
|
2 |
+
from smolagents.tools import Tool
|
3 |
+
|
4 |
+
class FinalAnswerTool(Tool):
|
5 |
+
name = "final_answer"
|
6 |
+
description = "Provides a final answer to the given problem."
|
7 |
+
inputs = {'answer': {'type': 'any', 'description': 'The final answer to the problem'}}
|
8 |
+
output_type = "any"
|
9 |
+
|
10 |
+
def forward(self, answer: Any) -> Any:
|
11 |
+
return answer
|
12 |
+
|
13 |
+
def __init__(self, *args, **kwargs):
|
14 |
+
self.is_initialized = False
|