Cheangys commited on
Commit
88141c7
·
verified ·
1 Parent(s): 6bc9ac3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -2
app.py CHANGED
@@ -84,7 +84,39 @@ def get_stock_price(stock: str) -> str:
84
 
85
  except Exception as e:
86
  return f"Error fetching price for stock '{stock}': {str(e)}"
87
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  final_answer = FinalAnswerTool()
89
 
90
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
@@ -107,7 +139,7 @@ with open("prompts.yaml", 'r') as stream:
107
 
108
  agent = CodeAgent(
109
  model=model,
110
- tools=[final_answer, get_stock_price, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
111
  max_steps=6,
112
  verbosity_level=1,
113
  grammar=None,
 
84
 
85
  except Exception as e:
86
  return f"Error fetching price for stock '{stock}': {str(e)}"
87
+
88
+ @tool
89
+ def web_search(query: str) -> str:
90
+ """
91
+ Fetches the information using DuckDuckGo search.
92
+ Args:
93
+ query: A query or question # Added description here
94
+ Returns:
95
+ str: A message with the search result or an error message.
96
+ """
97
+ try:
98
+ # Initialize the DuckDuckGo search tool
99
+ search_tool = DuckDuckGoSearchTool()
100
+
101
+ # Perform the search
102
+ search_results = search_tool(query)
103
+
104
+ # Debugging: Print results to see what is returned
105
+ print(f"DEBUG: search results -> {search_results}")
106
+
107
+ # Handle different result types
108
+ if isinstance(search_results, list) and len(search_results) > 0:
109
+ # Try to extract the stock price from the first result
110
+ first_result = search_results[0]
111
+
112
+ # Attempt to find a pattern like "123.45 USD" in the text
113
+
114
+ else:
115
+ return f"No search results found for {query}."
116
+
117
+ except Exception as e:
118
+ return f"Error fetching price for stock '{query}': {str(e)}"
119
+
120
  final_answer = FinalAnswerTool()
121
 
122
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
139
 
140
  agent = CodeAgent(
141
  model=model,
142
+ tools=[final_answer, get_stock_price, get_current_time_in_timezone, web_search], ## add your tools here (don't remove final answer)
143
  max_steps=6,
144
  verbosity_level=1,
145
  grammar=None,