Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,10 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
@@ -34,6 +38,25 @@ 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 |
|
| 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:
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
|
| 11 |
+
from duckduckgo_search import DDGS
|
| 12 |
+
from langchain.tools import tool
|
| 13 |
+
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 38 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 39 |
|
| 40 |
|
| 41 |
+
@tool
|
| 42 |
+
def duckduckgo_search(query: str, max_results: int = 5) -> str:
|
| 43 |
+
"""Search DuckDuckGo and return concise results.
|
| 44 |
+
Args:
|
| 45 |
+
query: The search query string
|
| 46 |
+
max_results: Maximum number of results to return
|
| 47 |
+
"""
|
| 48 |
+
results = []
|
| 49 |
+
with DDGS() as ddgs:
|
| 50 |
+
for r in ddgs.text(query, max_results=max_results):
|
| 51 |
+
results.append(
|
| 52 |
+
f"- {r.get('title')}:\n {r.get('body')}\n Source: {r.get('href')}"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
if not results:
|
| 56 |
+
return "No results found."
|
| 57 |
+
|
| 58 |
+
return "\n\n".join(results)
|
| 59 |
+
|
| 60 |
final_answer = FinalAnswerTool()
|
| 61 |
|
| 62 |
# 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:
|