Update app.py
Browse files
app.py
CHANGED
|
@@ -29,6 +29,30 @@ nest_asyncio.apply()
|
|
| 29 |
|
| 30 |
|
| 31 |
#Tools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
@function_tool
|
| 34 |
def visit_website(url: str) -> str:
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
#Tools
|
| 32 |
+
@function_tool
|
| 33 |
+
def tavily_search(query: str) -> str:
|
| 34 |
+
"""
|
| 35 |
+
Perform a Tavily web search.
|
| 36 |
+
Args:
|
| 37 |
+
query (str): The search query string.
|
| 38 |
+
Returns:
|
| 39 |
+
str: Formatted search results.
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
client = TavilyClient(os.getenv("TAVILY_API_KEY"))
|
| 44 |
+
results = client.search(query=query, max_results=5)
|
| 45 |
+
|
| 46 |
+
formatted = []
|
| 47 |
+
for result in results.get("results", []):
|
| 48 |
+
formatted.append(f"**Title**: {result['title']}\n**URL**: {result['url']}\n**Content**: {result['content']}\n")
|
| 49 |
+
|
| 50 |
+
return "\n\n".join(formatted) or "No results found."
|
| 51 |
+
|
| 52 |
+
except Exception as e:
|
| 53 |
+
return f"Error using Tavily Search: {e}"
|
| 54 |
+
|
| 55 |
+
|
| 56 |
|
| 57 |
@function_tool
|
| 58 |
def visit_website(url: str) -> str:
|