Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,7 +33,29 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
# 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:
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
# Note: based on https://medium.com/@laurentkubaski/smolagents-duckduckgosearchtool-to-search-in-wikipedia-2578973bb131
|
| 37 |
+
class CustomDuckDuckGoSearchTool(DuckDuckGoSearchTool):
|
| 38 |
+
name = "web_search"
|
| 39 |
+
description = "Performs a web search for a query and returns a list of the top search results formatted as markdown with page titles and urls."
|
| 40 |
+
inputs = {"query": {"type": "string", "description": "The search query to perform."}}
|
| 41 |
+
output_type = "string"
|
| 42 |
+
|
| 43 |
+
def __init__(self, max_results: int = 10, rate_limit: float | None = 1.0, backend: str = "auto", **kwargs):
|
| 44 |
+
super().__init__(max_results=max_results, rate_limit=rate_limit, **kwargs)
|
| 45 |
+
self.backend = backend # Add "backend" as new parameter
|
| 46 |
+
|
| 47 |
+
def forward(self, query: str) -> str:
|
| 48 |
+
self._enforce_rate_limit()
|
| 49 |
+
results = self.ddgs.text(
|
| 50 |
+
query=query,
|
| 51 |
+
max_results=self.max_results,
|
| 52 |
+
backend=self.backend) # there you go
|
| 53 |
+
if len(results) == 0:
|
| 54 |
+
raise Exception("No results found! Try a less restrictive/shorter query.")
|
| 55 |
+
postprocessed_results = [f"[{result['title']}]({result['href']})\n{result['body']}" for result in results]
|
| 56 |
+
return "## Search Results\n\n" + "\n\n".join(postprocessed_results)
|
| 57 |
+
|
| 58 |
+
search_tool = CustomDuckDuckGoSearchTool(backend="wikipedia")
|
| 59 |
final_answer = FinalAnswerTool()
|
| 60 |
|
| 61 |
# 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:
|