Spaces:
Runtime error
Runtime error
Added a duckduckgo search tool to test
Browse files
app.py
CHANGED
|
@@ -34,6 +34,29 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
model = HfApiModel(
|
| 39 |
max_tokens=2096,
|
|
@@ -51,7 +74,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 51 |
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
|
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
| 37 |
+
@tool
|
| 38 |
+
def get_search_results(query: str) -> str:
|
| 39 |
+
"""A tool that uses duckduckgosearchtool to search for a query provided by user and summarise the response
|
| 40 |
+
Args:
|
| 41 |
+
query: A string which represents the search query
|
| 42 |
+
Returns:
|
| 43 |
+
A summarised response from the search results
|
| 44 |
+
"""
|
| 45 |
+
try:
|
| 46 |
+
search_tool = DuckDuckGoSearchTool()
|
| 47 |
+
results = search_tool.run(query)
|
| 48 |
+
|
| 49 |
+
if not results:
|
| 50 |
+
return f"No results available for {query}"
|
| 51 |
+
|
| 52 |
+
summary = "\n".join(results[3])
|
| 53 |
+
|
| 54 |
+
return f"Here are the top 3 search results for '{query}': \n{summary}"
|
| 55 |
+
|
| 56 |
+
except Exception as e:
|
| 57 |
+
return f"Error fetching result for the '{query}': {str(e)}"
|
| 58 |
+
|
| 59 |
+
|
| 60 |
final_answer = FinalAnswerTool()
|
| 61 |
model = HfApiModel(
|
| 62 |
max_tokens=2096,
|
|
|
|
| 74 |
|
| 75 |
agent = CodeAgent(
|
| 76 |
model=model,
|
| 77 |
+
tools=[final_answer, DuckDuckGoSearchTool()], ## add your tools here (don't remove final answer)
|
| 78 |
max_steps=6,
|
| 79 |
verbosity_level=1,
|
| 80 |
grammar=None,
|