Spaces:
Sleeping
Sleeping
Update app.py
Browse filesadd visit_webpage,web_search
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import datetime
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
-
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
@@ -36,6 +36,35 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 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:
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 41 |
|
|
@@ -55,7 +84,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer,get_current_time_in_timezone,image_generation_tool], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
from tools.final_answer import FinalAnswerTool,VisitWebpageTool,DuckDuckGoSearchTool
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
+
@tool
|
| 40 |
+
def visit_webpage(url: str) -> str:
|
| 41 |
+
"""A tool that visits a webpage at the given URL and reads its content as a markdown string.
|
| 42 |
+
|
| 43 |
+
Args:
|
| 44 |
+
url: The URL of the webpage to visit.
|
| 45 |
+
"""
|
| 46 |
+
# Initialize the VisitWebpageTool
|
| 47 |
+
webpage_tool = VisitWebpageTool()
|
| 48 |
+
|
| 49 |
+
# Call the forward method of VisitWebpageTool to get the markdown content
|
| 50 |
+
return webpage_tool.forward(url)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
@tool
|
| 54 |
+
def web_search(query: str, max_results: int = 5) -> str:
|
| 55 |
+
"""A tool that performs a DuckDuckGo web search based on your query and returns the top search results.
|
| 56 |
+
|
| 57 |
+
Args:
|
| 58 |
+
query: The search query to perform.
|
| 59 |
+
max_results: The maximum number of results to return.
|
| 60 |
+
"""
|
| 61 |
+
# Initialize the DuckDuckGoSearchTool
|
| 62 |
+
search_tool = DuckDuckGoSearchTool(max_results=max_results)
|
| 63 |
+
|
| 64 |
+
# Call the forward method of DuckDuckGoSearchTool to get the search results
|
| 65 |
+
return search_tool.forward(query)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
# 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:
|
| 69 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 70 |
|
|
|
|
| 84 |
|
| 85 |
agent = CodeAgent(
|
| 86 |
model=model,
|
| 87 |
+
tools=[final_answer,get_current_time_in_timezone,image_generation_tool,visit_webpage,web_search], ## add your tools here (don't remove final answer)
|
| 88 |
max_steps=6,
|
| 89 |
verbosity_level=1,
|
| 90 |
grammar=None,
|