zasharepw77 commited on
Commit
d777bde
·
1 Parent(s): a400d20

Тест модели Мульти агенты

Browse files
Files changed (2) hide show
  1. _002_app.py +9 -0
  2. app.py +59 -6
_002_app.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, HfApiModel
2
+ import os
3
+
4
+ agent = ToolCallingAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel(token=os.getenv('hf_token')))
5
+
6
+ result = agent.run("Search for the best music recommendations for a party at the Wayne's mansion.")
7
+
8
+ print("\n++++\nres:\n")
9
+ print(result)
app.py CHANGED
@@ -1,9 +1,62 @@
1
- from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, HfApiModel
2
- import os
 
 
 
 
3
 
4
- agent = ToolCallingAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel(token=os.getenv('hf_token')))
 
 
 
5
 
6
- result = agent.run("Search for the best music recommendations for a party at the Wayne's mansion.")
 
 
7
 
8
- print("\n++++\nres:\n")
9
- print(result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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
6
+ from huggingface_hub import login
7
 
8
+ # Создание модели
9
+ model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"
10
+ hf_token = os.getenv('hf_token')
11
+ model = HfApiModel(model_id, token=hf_token)
12
 
13
+ # Создание инструмента для посещения веб-страниц
14
+ def visit_webpage(url: str) -> str:
15
+ """Visits a webpage at the given URL and returns its content as a markdown string.
16
 
17
+ Args:
18
+ url: The URL of the webpage to visit.
19
+
20
+ Returns:
21
+ The content of the webpage converted to Markdown, or an error message if the request fails.
22
+ """
23
+ try:
24
+ # Send a GET request to the URL
25
+ response = requests.get(url)
26
+ response.raise_for_status() # Raise an exception for bad status codes
27
+
28
+ # Convert the HTML content to Markdown
29
+ markdown_content = markdownify(response.text).strip()
30
+
31
+ # Remove multiple line breaks
32
+ markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
33
+
34
+ return markdown_content
35
+
36
+ except RequestException as e:
37
+ return f"Error fetching the webpage: {str(e)}"
38
+ except Exception as e:
39
+ return f"An unexpected error occurred: {str(e)}"
40
+
41
+ print(visit_webpage("https://en.wikipedia.org/wiki/Hugging_Face")[:500])
42
+
43
+ # Создание веб-агента
44
+ web_agent = ToolCallingAgent(
45
+ tools=[DuckDuckGoSearchTool(), visit_webpage],
46
+ model=model,
47
+ max_steps=10,
48
+ name="web_search_agent",
49
+ description="Выполняет поиск в интернете"
50
+ )
51
+
52
+ # Создание менеджера-агента
53
+ manager_agent = CodeAgent(
54
+ tools=[],
55
+ model=model,
56
+ managed_agents=[web_agent],
57
+ additional_authorized_imports=["time", "numpy", "pandas"]
58
+ )
59
+
60
+ # Запуск системы
61
+ answer = manager_agent.run("Если обучение моделей языка продолжит масштабироваться с текущим темпом до 2030 года, какова будет потребляемая электрическая мощность в ГВт, необходимая для питания крупнейших тренировочных запусков к 2030 году? Что это будет соответствовать, по сравнению с некоторыми странами? Пожалуйста, предоставьте источник для любых использованных чисел.")
62
+ print(answer)