Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,35 +52,36 @@ def get_stock_price(stock: str) -> str:
|
|
| 52 |
|
| 53 |
# Perform the search
|
| 54 |
search_results = search_tool(f"current stock price of {stock}")
|
| 55 |
-
|
|
|
|
| 56 |
# Debugging: Print results to see what is returned
|
| 57 |
print(f"DEBUG: search results -> {search_results}")
|
| 58 |
|
| 59 |
-
# Handle different result types
|
| 60 |
-
if isinstance(search_results, list) and len(search_results) > 0:
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
elif isinstance(search_results, str):
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
else:
|
| 83 |
-
|
| 84 |
|
| 85 |
except Exception as e:
|
| 86 |
return f"Error fetching price for stock '{stock}': {str(e)}"
|
|
|
|
| 52 |
|
| 53 |
# Perform the search
|
| 54 |
search_results = search_tool(f"current stock price of {stock}")
|
| 55 |
+
return search_results
|
| 56 |
+
|
| 57 |
# Debugging: Print results to see what is returned
|
| 58 |
print(f"DEBUG: search results -> {search_results}")
|
| 59 |
|
| 60 |
+
# # Handle different result types
|
| 61 |
+
# if isinstance(search_results, list) and len(search_results) > 0:
|
| 62 |
+
# # Try to extract the stock price from the first result
|
| 63 |
+
# first_result = search_results[0]
|
| 64 |
+
|
| 65 |
+
# # Attempt to find a pattern like "123.45 USD" in the text
|
| 66 |
+
# match = re.search(r"(\d+\.\d+)\s*(USD|EUR|CAD|GBP)", first_result, re.IGNORECASE)
|
| 67 |
+
|
| 68 |
+
# if match:
|
| 69 |
+
# price = match.group(1)
|
| 70 |
+
# currency = match.group(2)
|
| 71 |
+
# return f"The current price for {stock} is: {price} {currency}"
|
| 72 |
+
# else:
|
| 73 |
+
# return f"Could not extract stock price from search results for {stock}."
|
| 74 |
+
# elif isinstance(search_results, str):
|
| 75 |
+
# # Try to directly find a price in the string
|
| 76 |
+
# match = re.search(r"(\d+\.\d+)\s*(USD|EUR|CAD|GBP)", search_results, re.IGNORECASE)
|
| 77 |
+
# if match:
|
| 78 |
+
# price = match.group(1)
|
| 79 |
+
# currency = match.group(2)
|
| 80 |
+
# return f"The current price for {stock} is: {price} {currency}"
|
| 81 |
+
# else:
|
| 82 |
+
# return f"Could not extract stock price from search results for {stock}."
|
| 83 |
+
# else:
|
| 84 |
+
# return f"No search results found for {stock}."
|
| 85 |
|
| 86 |
except Exception as e:
|
| 87 |
return f"Error fetching price for stock '{stock}': {str(e)}"
|