Cheangys commited on
Commit
476882d
·
verified ·
1 Parent(s): e6dfe62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -26
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
- # Try to extract the stock price from the first result
62
- first_result = search_results[0]
63
-
64
- # Attempt to find a pattern like "123.45 USD" in the text
65
- match = re.search(r"(\d+\.\d+)\s*(USD|EUR|CAD|GBP)", first_result, re.IGNORECASE)
66
-
67
- if match:
68
- price = match.group(1)
69
- currency = match.group(2)
70
- return f"The current price for {stock} is: {price} {currency}"
71
- else:
72
- return f"Could not extract stock price from search results for {stock}."
73
- elif isinstance(search_results, str):
74
- # Try to directly find a price in the string
75
- match = re.search(r"(\d+\.\d+)\s*(USD|EUR|CAD|GBP)", search_results, re.IGNORECASE)
76
- if match:
77
- price = match.group(1)
78
- currency = match.group(2)
79
- return f"The current price for {stock} is: {price} {currency}"
80
- else:
81
- return f"Could not extract stock price from search results for {stock}."
82
- else:
83
- return f"No search results found for {stock}."
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)}"