Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,9 +59,10 @@ def get_stock_price(stock: str) -> str:
|
|
| 59 |
except Exception as e:
|
| 60 |
return f"Error fetching price for stock '{stock}': {str(e)}"
|
| 61 |
|
|
|
|
| 62 |
|
| 63 |
@tool
|
| 64 |
-
def web_search(query: str) -> str:
|
| 65 |
"""
|
| 66 |
Fetches the result from a web search using DuckDuckGo.
|
| 67 |
|
|
@@ -69,19 +70,19 @@ def web_search(query: str) -> str:
|
|
| 69 |
query (str): A search query or question.
|
| 70 |
|
| 71 |
Returns:
|
| 72 |
-
str:
|
| 73 |
"""
|
| 74 |
try:
|
| 75 |
search_tool = DuckDuckGoSearchTool()
|
| 76 |
search_results = search_tool.run(query)
|
| 77 |
|
| 78 |
if isinstance(search_results, list) and len(search_results) > 0:
|
| 79 |
-
return
|
| 80 |
|
| 81 |
-
return
|
| 82 |
|
| 83 |
except Exception as e:
|
| 84 |
-
return f"Error during search: {str(e)}"
|
| 85 |
|
| 86 |
|
| 87 |
final_answer = FinalAnswerTool()
|
|
|
|
| 59 |
except Exception as e:
|
| 60 |
return f"Error fetching price for stock '{stock}': {str(e)}"
|
| 61 |
|
| 62 |
+
from typing import Dict
|
| 63 |
|
| 64 |
@tool
|
| 65 |
+
def web_search(query: str) -> Dict[str, str]:
|
| 66 |
"""
|
| 67 |
Fetches the result from a web search using DuckDuckGo.
|
| 68 |
|
|
|
|
| 70 |
query (str): A search query or question.
|
| 71 |
|
| 72 |
Returns:
|
| 73 |
+
Dict[str, str]: A dictionary with either the result or an error message.
|
| 74 |
"""
|
| 75 |
try:
|
| 76 |
search_tool = DuckDuckGoSearchTool()
|
| 77 |
search_results = search_tool.run(query)
|
| 78 |
|
| 79 |
if isinstance(search_results, list) and len(search_results) > 0:
|
| 80 |
+
return {"query": query, "result": search_results[0]}
|
| 81 |
|
| 82 |
+
return {"query": query, "error": "No results found."}
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
+
return {"query": query, "error": f"Error during search: {str(e)}"}
|
| 86 |
|
| 87 |
|
| 88 |
final_answer = FinalAnswerTool()
|