Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,31 +35,33 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_stock_price(stock: str) -> str:
|
| 38 |
-
"""
|
| 39 |
-
|
|
|
|
| 40 |
Args:
|
| 41 |
-
stock: A
|
| 42 |
-
|
| 43 |
Returns:
|
| 44 |
-
A
|
| 45 |
"""
|
| 46 |
try:
|
| 47 |
-
# Initialize the search tool
|
| 48 |
-
search_tool = DuckDuckGoSearchTool()
|
| 49 |
|
| 50 |
-
# Perform the search
|
| 51 |
-
search_results = search_tool
|
| 52 |
-
|
| 53 |
-
#
|
| 54 |
if isinstance(search_results, list) and len(search_results) > 0:
|
| 55 |
return f"The current price for {stock} is: {search_results[0]}"
|
| 56 |
|
| 57 |
return f"Could not fetch stock price for {stock}. Please try again."
|
| 58 |
-
|
| 59 |
except Exception as e:
|
| 60 |
return f"Error fetching price for stock '{stock}': {str(e)}"
|
| 61 |
|
| 62 |
|
|
|
|
| 63 |
|
| 64 |
final_answer = FinalAnswerTool()
|
| 65 |
|
|
|
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_stock_price(stock: str) -> str:
|
| 38 |
+
"""
|
| 39 |
+
Fetches the current stock price using DuckDuckGo search.
|
| 40 |
+
|
| 41 |
Args:
|
| 42 |
+
stock (str): A stock ticker symbol or company name (e.g., 'AAPL', 'GOOGL').
|
| 43 |
+
|
| 44 |
Returns:
|
| 45 |
+
str: A message with the stock price or an error message.
|
| 46 |
"""
|
| 47 |
try:
|
| 48 |
+
# Initialize the DuckDuckGo search tool
|
| 49 |
+
search_tool = DuckDuckGoSearchTool(queries=[f"current stock price of {stock}"])
|
| 50 |
|
| 51 |
+
# Perform the search
|
| 52 |
+
search_results = search_tool()
|
| 53 |
+
|
| 54 |
+
# Check if results are available
|
| 55 |
if isinstance(search_results, list) and len(search_results) > 0:
|
| 56 |
return f"The current price for {stock} is: {search_results[0]}"
|
| 57 |
|
| 58 |
return f"Could not fetch stock price for {stock}. Please try again."
|
| 59 |
+
|
| 60 |
except Exception as e:
|
| 61 |
return f"Error fetching price for stock '{stock}': {str(e)}"
|
| 62 |
|
| 63 |
|
| 64 |
+
|
| 65 |
|
| 66 |
final_answer = FinalAnswerTool()
|
| 67 |
|