zasharepw77 commited on
Commit
57b95ac
·
1 Parent(s): 996a290

Ошибка поправил код 3

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -2,7 +2,7 @@ import re
2
  import requests
3
  from markdownify import markdownify
4
  from requests.exceptions import RequestException
5
- from smolagents import tool, CodeAgent, ToolCallingAgent, HfApiModel, DuckDuckGoSearchTool, Tool
6
  from huggingface_hub import login
7
  import os
8
 
@@ -11,23 +11,24 @@ 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
- 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
@@ -43,12 +44,9 @@ class WebpageVisitorTool(tool.Tool):
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",
@@ -65,4 +63,4 @@ manager_agent = CodeAgent(
65
 
66
  # Запуск системы
67
  answer = manager_agent.run("Если обучение моделей языка продолжит масштабироваться с текущим темпом до 2030 года, какова будет потребляемая электрическая мощность в ГВт, необходимая для питания крупнейших тренировочных запусков к 2030 году? Что это будет соответствовать, по сравнению с некоторыми странами? Пожалуйста, предоставьте источник для любых использованных чисел.")
68
- print(answer)
 
2
  import requests
3
  from markdownify import markdownify
4
  from requests.exceptions import RequestException
5
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, HfApiModel, Tool, tool, VisitWebpageTool
6
  from huggingface_hub import login
7
  import os
8
 
 
11
  hf_token = os.getenv('hf_token')
12
  model = HfApiModel(model_id, token=hf_token)
13
 
14
+ # Создание инструмента для посещения веб-страниц
15
+ class WebpageVisitorTool(Tool):
16
+ name = "webpage_visitor"
17
+ description = "Этот инструмент посещает веб-страницу и возвращает ее содержимое в формате Markdown."
18
 
19
+ inputs = {
20
+ "url": {
21
+ "type": "string",
22
+ "description": "URL веб-страницы, которую нужно посетить.",
23
+ }
24
+ }
25
 
26
+ output_type = "string"
 
27
 
28
+ def call(self, inputs):
 
 
 
 
 
29
  try:
30
  # Send a GET request to the URL
31
+ response = requests.get(inputs["url"])
32
  response.raise_for_status() # Raise an exception for bad status codes
33
 
34
  # Convert the HTML content to Markdown
 
44
  except Exception as e:
45
  return f"An unexpected error occurred: {str(e)}"
46
 
 
 
47
  # Создание веб-агента
 
48
  web_agent = ToolCallingAgent(
49
+ tools=[DuckDuckGoSearchTool(), WebpageVisitorTool()],
50
  model=model,
51
  max_steps=10,
52
  name="web_search_agent",
 
63
 
64
  # Запуск системы
65
  answer = manager_agent.run("Если обучение моделей языка продолжит масштабироваться с текущим темпом до 2030 года, какова будет потребляемая электрическая мощность в ГВт, необходимая для питания крупнейших тренировочных запусков к 2030 году? Что это будет соответствовать, по сравнению с некоторыми странами? Пожалуйста, предоставьте источник для любых использованных чисел.")
66
+ print(answer)