adding tools
Browse files
agent.py
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
|
|
| 1 |
from smolagents import (
|
| 2 |
CodeAgent, InferenceClientModel, HfApiModel,
|
| 3 |
-
DuckDuckGoSearchTool
|
| 4 |
)
|
| 5 |
|
| 6 |
-
# Initialize the Hugging Face model
|
| 7 |
-
# model = InferenceClientModel()
|
| 8 |
-
model = HfApiModel()
|
| 9 |
|
| 10 |
-
|
| 11 |
-
DuckDuckGoSearchTool(),
|
| 12 |
-
]
|
| 13 |
-
|
| 14 |
-
def create_agent():
|
| 15 |
"""
|
| 16 |
-
|
| 17 |
"""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
)
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
| 1 |
+
import os
|
| 2 |
from smolagents import (
|
| 3 |
CodeAgent, InferenceClientModel, HfApiModel,
|
| 4 |
+
DuckDuckGoSearchTool, LiteLLMModel
|
| 5 |
)
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
class MyAgent(CodeAgent):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
"""
|
| 10 |
+
Custom agent class that extends CodeAgent.
|
| 11 |
"""
|
| 12 |
+
tools = [
|
| 13 |
+
DuckDuckGoSearchTool(),
|
| 14 |
+
]
|
| 15 |
+
model = LiteLLMModel(
|
| 16 |
+
model_id="gemini/gemini-2.0-flash", api_key=os.getenv("GEMINI_API_KEY", "")
|
| 17 |
)
|
| 18 |
+
|
| 19 |
+
def __init__(self, *args, **kwargs) -> None:
|
| 20 |
+
super().__init__(
|
| 21 |
+
tools=self.tools,
|
| 22 |
+
model=self.model,
|
| 23 |
+
additional_authorized_imports=[
|
| 24 |
+
"markdownify",
|
| 25 |
+
"requests",
|
| 26 |
+
"pandas",
|
| 27 |
+
"io",
|
| 28 |
+
],
|
| 29 |
+
name="MyAgent",
|
| 30 |
+
description = "A custom agent that can search the web and generate code.",
|
| 31 |
+
add_base_tools=True,
|
| 32 |
+
max_steps=30,
|
| 33 |
+
)
|
| 34 |
|
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import requests
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
-
from agent import
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
@@ -32,7 +32,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 32 |
|
| 33 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 34 |
try:
|
| 35 |
-
agent =
|
| 36 |
except Exception as e:
|
| 37 |
print(f"Error instantiating agent: {e}")
|
| 38 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
+
from agent import MyAgent
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
|
|
| 32 |
|
| 33 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 34 |
try:
|
| 35 |
+
agent = MyAgent() # Call the function to create your agent
|
| 36 |
except Exception as e:
|
| 37 |
print(f"Error instantiating agent: {e}")
|
| 38 |
return f"Error initializing agent: {e}", None
|
tools.py
CHANGED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from smolagents import tools
|