CoralLeiCN
commited on
Commit
·
0b3f86d
1
Parent(s):
4b4e7fa
Refactor agent tools: add WikipediaSearchTool for querying Wikipedia and update imports
Browse files- agent/agents.py +5 -2
- agent/tools.py +23 -0
agent/agents.py
CHANGED
@@ -5,16 +5,17 @@ from google import genai
|
|
5 |
from google.genai import types
|
6 |
from google.genai.types import GenerateContentConfig, ThinkingConfig
|
7 |
from pydantic import BaseModel
|
8 |
-
from smolagents import CodeAgent, VisitWebpageTool, WebSearchTool
|
9 |
|
10 |
from agent.prompts import system_prompt
|
11 |
from agent.tools import (
|
|
|
12 |
DownloadFile,
|
13 |
ReadExcelFileBytes,
|
14 |
TranscribeAudioBytes,
|
15 |
TranscribeYoutubeVideo,
|
16 |
UnderstandImageBytes,
|
17 |
-
|
18 |
)
|
19 |
from agent.utils import gemini_client, gemini_model_liteLLM
|
20 |
|
@@ -54,6 +55,7 @@ class BasicAgent:
|
|
54 |
read_excel_file_tool = ReadExcelFileBytes()
|
55 |
understand_image_bytes = UnderstandImageBytes()
|
56 |
code_execution_tool = CodeExecutionTool()
|
|
|
57 |
|
58 |
model = gemini_model_liteLLM(self.model)
|
59 |
|
@@ -71,6 +73,7 @@ class BasicAgent:
|
|
71 |
read_excel_file_tool,
|
72 |
understand_image_bytes,
|
73 |
code_execution_tool,
|
|
|
74 |
],
|
75 |
model=model,
|
76 |
step_callbacks=STEP_CALLBACKS,
|
|
|
5 |
from google.genai import types
|
6 |
from google.genai.types import GenerateContentConfig, ThinkingConfig
|
7 |
from pydantic import BaseModel
|
8 |
+
from smolagents import CodeAgent, Tool, VisitWebpageTool, WebSearchTool
|
9 |
|
10 |
from agent.prompts import system_prompt
|
11 |
from agent.tools import (
|
12 |
+
CodeExecutionTool,
|
13 |
DownloadFile,
|
14 |
ReadExcelFileBytes,
|
15 |
TranscribeAudioBytes,
|
16 |
TranscribeYoutubeVideo,
|
17 |
UnderstandImageBytes,
|
18 |
+
WikipediaSearchTool,
|
19 |
)
|
20 |
from agent.utils import gemini_client, gemini_model_liteLLM
|
21 |
|
|
|
55 |
read_excel_file_tool = ReadExcelFileBytes()
|
56 |
understand_image_bytes = UnderstandImageBytes()
|
57 |
code_execution_tool = CodeExecutionTool()
|
58 |
+
wiki_retriever = WikipediaSearchTool()
|
59 |
|
60 |
model = gemini_model_liteLLM(self.model)
|
61 |
|
|
|
73 |
read_excel_file_tool,
|
74 |
understand_image_bytes,
|
75 |
code_execution_tool,
|
76 |
+
wiki_retriever,
|
77 |
],
|
78 |
model=model,
|
79 |
step_callbacks=STEP_CALLBACKS,
|
agent/tools.py
CHANGED
@@ -3,10 +3,33 @@ import io
|
|
3 |
import requests
|
4 |
from google import genai
|
5 |
from google.genai import types
|
|
|
6 |
from PIL import Image
|
7 |
from smolagents import Tool
|
8 |
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
class CodeExecutionTool(Tool):
|
11 |
name = "execute_code"
|
12 |
description = """Execute Python code and answer the question if provided.
|
|
|
3 |
import requests
|
4 |
from google import genai
|
5 |
from google.genai import types
|
6 |
+
from langchain_community.retrievers import WikipediaRetriever
|
7 |
from PIL import Image
|
8 |
from smolagents import Tool
|
9 |
|
10 |
|
11 |
+
class WikipediaSearchTool(Tool):
|
12 |
+
name = "wikipedia_search"
|
13 |
+
description = """Search Wikipedia for a given query and return the summary of the first result.
|
14 |
+
This tool uses the WikipediaRetriever to fetch the summary of the first search result.
|
15 |
+
"""
|
16 |
+
inputs = {
|
17 |
+
"query": {
|
18 |
+
"type": "string",
|
19 |
+
"description": "The search query to look up on Wikipedia",
|
20 |
+
},
|
21 |
+
}
|
22 |
+
output_type = "string"
|
23 |
+
|
24 |
+
def forward(self, query: str):
|
25 |
+
retriever = WikipediaRetriever()
|
26 |
+
docs = retriever.invoke(query)
|
27 |
+
if docs:
|
28 |
+
return docs
|
29 |
+
else:
|
30 |
+
return "No results found."
|
31 |
+
|
32 |
+
|
33 |
class CodeExecutionTool(Tool):
|
34 |
name = "execute_code"
|
35 |
description = """Execute Python code and answer the question if provided.
|