Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,49 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
Args:
|
| 16 |
-
arg1:
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +90,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,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 13 |
+
import datetime
|
| 14 |
+
import requests
|
| 15 |
+
import pytz
|
| 16 |
+
import yaml
|
| 17 |
+
from tools.final_answer import FinalAnswerTool
|
| 18 |
+
from Gradio_UI import GradioUI
|
| 19 |
+
|
| 20 |
+
@tool
|
| 21 |
+
def my_custom_tool(arg1: str) -> str:
|
| 22 |
+
"""
|
| 23 |
+
A tool that uses the provided argument as a search query and returns the search results
|
| 24 |
+
along with the current UTC time, all formatted in YAML.
|
| 25 |
+
|
| 26 |
Args:
|
| 27 |
+
arg1: The search query string.
|
|
|
|
| 28 |
"""
|
| 29 |
+
# Initialize the DuckDuckGo search tool and perform the search using arg1.
|
| 30 |
+
search_tool = DuckDuckGoSearchTool()
|
| 31 |
+
# Assuming the search tool has a method 'search' that returns a list of results.
|
| 32 |
+
search_results = search_tool.search(arg1)
|
| 33 |
+
|
| 34 |
+
# Get the current time in UTC with timezone information.
|
| 35 |
+
now_utc = datetime.datetime.now(pytz.utc)
|
| 36 |
+
formatted_time = now_utc.strftime("%Y-%m-%d %H:%M:%S %Z")
|
| 37 |
+
|
| 38 |
+
# Build a response dictionary with the search query, current time, and search results.
|
| 39 |
+
response = {
|
| 40 |
+
"search_query": arg1,
|
| 41 |
+
"current_time": formatted_time,
|
| 42 |
+
"search_results": search_results
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
# Convert the response dictionary to a YAML-formatted string.
|
| 46 |
+
yaml_response = yaml.dump(response, default_flow_style=False)
|
| 47 |
+
|
| 48 |
+
# Optionally, pass the result to a final answer tool or UI component if desired.
|
| 49 |
+
# For instance, FinalAnswerTool could be used to format the final output.
|
| 50 |
+
# final_answer = FinalAnswerTool(yaml_response)
|
| 51 |
+
# return final_answer
|
| 52 |
+
|
| 53 |
+
return yaml_response
|
| 54 |
+
|
| 55 |
|
| 56 |
@tool
|
| 57 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 90 |
|
| 91 |
agent = CodeAgent(
|
| 92 |
model=model,
|
| 93 |
+
tools=[final_answer, my_custom_tool], ## add your tools here (don't remove final answer)
|
| 94 |
max_steps=6,
|
| 95 |
verbosity_level=1,
|
| 96 |
grammar=None,
|