Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,37 @@ 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 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +78,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer, get_current_time_in_timezone,
|
| 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 |
+
def web_search_tool(query: str, num_results: int = 3) -> str:
|
| 13 |
+
"""A tool that performs a web search and fetches up-to-date information.
|
| 14 |
+
|
| 15 |
Args:
|
| 16 |
+
query: The search query or topic to look up on the web.
|
| 17 |
+
num_results: The number of top search results to return (default is 3).
|
| 18 |
+
|
| 19 |
+
Returns:
|
| 20 |
+
A string containing summarized up-to-date information from the web.
|
| 21 |
"""
|
| 22 |
+
try:
|
| 23 |
+
from openai import web # ✅ Built-in OpenAI web capability (like web.search)
|
| 24 |
+
|
| 25 |
+
# Perform the web search
|
| 26 |
+
results = web.search(f"{query}")
|
| 27 |
+
|
| 28 |
+
# Extract and format results
|
| 29 |
+
info_list = []
|
| 30 |
+
for i, r in enumerate(results[:num_results]):
|
| 31 |
+
title = r.get("title", "No title")
|
| 32 |
+
url = r.get("url", "No URL")
|
| 33 |
+
snippet = r.get("snippet", "No summary available.")
|
| 34 |
+
info_list.append(f"{i+1}. {title}\n{snippet}\n({url})")
|
| 35 |
+
|
| 36 |
+
# Combine into one response string
|
| 37 |
+
combined = "\n\n".join(info_list)
|
| 38 |
+
return f"Here are the top {num_results} results for '{query}':\n\n{combined}"
|
| 39 |
+
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return f"Error performing web search for '{query}': {str(e)}"
|
| 42 |
+
|
| 43 |
|
| 44 |
@tool
|
| 45 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 78 |
|
| 79 |
agent = CodeAgent(
|
| 80 |
model=model,
|
| 81 |
+
tools=[final_answer, get_current_time_in_timezone, web_search_tool], ## add your tools here (don't remove final answer)
|
| 82 |
max_steps=6,
|
| 83 |
verbosity_level=1,
|
| 84 |
grammar=None,
|