Spaces:
Sleeping
Sleeping
zasharepw77
commited on
Commit
·
fc3458d
1
Parent(s):
b75495a
Ошибка поправил код
Browse files
app.py
CHANGED
|
@@ -11,39 +11,44 @@ model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"
|
|
| 11 |
hf_token = os.getenv('hf_token')
|
| 12 |
model = HfApiModel(model_id, token=hf_token)
|
| 13 |
|
| 14 |
-
# Создание инструмента для посещения веб-страниц
|
| 15 |
-
def visit_webpage(url: str) -> str:
|
| 16 |
-
"""Visits a webpage at the given URL and returns its content as a markdown string.
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
"""
|
| 24 |
-
try:
|
| 25 |
-
# Send a GET request to the URL
|
| 26 |
-
response = requests.get(url)
|
| 27 |
-
response.raise_for_status() # Raise an exception for bad status codes
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
print(visit_webpage("https://en.wikipedia.org/wiki/Hugging_Face")[:500])
|
| 43 |
|
| 44 |
# Создание веб-агента
|
|
|
|
| 45 |
web_agent = ToolCallingAgent(
|
| 46 |
-
tools=[DuckDuckGoSearchTool(),
|
| 47 |
model=model,
|
| 48 |
max_steps=10,
|
| 49 |
name="web_search_agent",
|
|
|
|
| 11 |
hf_token = os.getenv('hf_token')
|
| 12 |
model = HfApiModel(model_id, token=hf_token)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
class WebpageVisitorTool(tool.Tool):
|
| 16 |
+
def __init__(self):
|
| 17 |
+
self.name = "Webpage Visitor"
|
| 18 |
|
| 19 |
+
def visit_webpage(self, url: str) -> str:
|
| 20 |
+
"""Visits a webpage at the given URL and returns its content as a markdown string.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
Args:
|
| 23 |
+
url: The URL of the webpage to visit.
|
| 24 |
|
| 25 |
+
Returns:
|
| 26 |
+
The content of the webpage converted to Markdown, or an error message if the request fails.
|
| 27 |
+
"""
|
| 28 |
+
try:
|
| 29 |
+
# Send a GET request to the URL
|
| 30 |
+
response = requests.get(url)
|
| 31 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
| 32 |
|
| 33 |
+
# Convert the HTML content to Markdown
|
| 34 |
+
markdown_content = markdownify(response.text).strip()
|
| 35 |
|
| 36 |
+
# Remove multiple line breaks
|
| 37 |
+
markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
|
| 38 |
+
|
| 39 |
+
return markdown_content
|
| 40 |
+
|
| 41 |
+
except RequestException as e:
|
| 42 |
+
return f"Error fetching the webpage: {str(e)}"
|
| 43 |
+
except Exception as e:
|
| 44 |
+
return f"An unexpected error occurred: {str(e)}"
|
| 45 |
|
| 46 |
print(visit_webpage("https://en.wikipedia.org/wiki/Hugging_Face")[:500])
|
| 47 |
|
| 48 |
# Создание веб-агента
|
| 49 |
+
web_visitor_tool = WebpageVisitorTool()
|
| 50 |
web_agent = ToolCallingAgent(
|
| 51 |
+
tools=[DuckDuckGoSearchTool(), web_visitor_tool],
|
| 52 |
model=model,
|
| 53 |
max_steps=10,
|
| 54 |
name="web_search_agent",
|