Update app.py
Browse filesadded wiki_tool
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, LiteLLMModel, load_tool, tool
|
2 |
import datetime
|
3 |
import pytz
|
4 |
import time
|
|
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
|
@@ -28,8 +29,31 @@ model = LiteLLMModel(
|
|
28 |
# Import tool from Hub
|
29 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
@tool
|
32 |
-
def
|
33 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
34 |
"""A tool that provides web search via duckduckgo
|
35 |
Args:
|
@@ -60,7 +84,7 @@ class BasicAgent:
|
|
60 |
prompt_templates = yaml.safe_load(stream)
|
61 |
self.agent = CodeAgent(
|
62 |
model=model,
|
63 |
-
tools=[final_answer,
|
64 |
max_steps=6,
|
65 |
verbosity_level=1,
|
66 |
grammar=None,
|
|
|
1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, Tool, HfApiModel, LiteLLMModel, load_tool, tool
|
2 |
import datetime
|
3 |
import pytz
|
4 |
import time
|
5 |
+
import wikipediaapi
|
6 |
import yaml
|
7 |
from tools.final_answer import FinalAnswerTool
|
8 |
|
|
|
29 |
# Import tool from Hub
|
30 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
31 |
|
32 |
+
class WikipediaSearchTool(Tool):
|
33 |
+
name = "wikipedia_search"
|
34 |
+
description = "Fetches a summary of a Wikipedia page based on a given search query (only one word or group of words)."
|
35 |
+
|
36 |
+
inputs = {
|
37 |
+
"query": {"type": "string", "description": "The search term for the Wikipedia page (only one word or group of words)."}
|
38 |
+
}
|
39 |
+
|
40 |
+
output_type = "string"
|
41 |
+
|
42 |
+
def __init__(self, lang="en"):
|
43 |
+
super().__init__()
|
44 |
+
self.wiki = wikipediaapi.Wikipedia(
|
45 |
+
language=lang, user_agent="MinimalAgent/1.0")
|
46 |
+
|
47 |
+
def forward(self, query: str):
|
48 |
+
page = self.wiki.page(query)
|
49 |
+
if not page.exists():
|
50 |
+
return "No Wikipedia page found."
|
51 |
+
return page.summary[:1000]
|
52 |
+
|
53 |
+
wiki_tool = WikipediaSearchTool()
|
54 |
+
|
55 |
@tool
|
56 |
+
def search_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
57 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
58 |
"""A tool that provides web search via duckduckgo
|
59 |
Args:
|
|
|
84 |
prompt_templates = yaml.safe_load(stream)
|
85 |
self.agent = CodeAgent(
|
86 |
model=model,
|
87 |
+
tools=[final_answer, search_tool, wiki_tool],
|
88 |
max_steps=6,
|
89 |
verbosity_level=1,
|
90 |
grammar=None,
|