Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdding Search capability to the Agent
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
@@ -18,6 +19,26 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -55,7 +76,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from typing import List, Dict
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
|
| 22 |
+
@tool
|
| 23 |
+
def search_duckduckgo_documents(query: str, max_results: int = 10) -> List[Dict]:
|
| 24 |
+
"""
|
| 25 |
+
Search DuckDuckGo and retrieve up to 10 documents/results.
|
| 26 |
+
|
| 27 |
+
Args:
|
| 28 |
+
query (str): The search query
|
| 29 |
+
max_results (int): Maximum number of results to return (default: 10)
|
| 30 |
+
|
| 31 |
+
Returns:
|
| 32 |
+
List[Dict]: List of search results with title, url, and snippet
|
| 33 |
+
"""
|
| 34 |
+
# Initialize the DuckDuckGo search tool
|
| 35 |
+
search_tool = DuckDuckGoSearchTool()
|
| 36 |
+
|
| 37 |
+
# Perform the search
|
| 38 |
+
results = search_tool(query, max_results=max_results)
|
| 39 |
+
|
| 40 |
+
return results
|
| 41 |
+
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 44 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 76 |
|
| 77 |
agent = CodeAgent(
|
| 78 |
model=model,
|
| 79 |
+
tools=[final_answer, search_duckduckgo_documents], ## add your tools here (don't remove final answer)
|
| 80 |
max_steps=6,
|
| 81 |
verbosity_level=1,
|
| 82 |
grammar=None,
|