Duibonduil commited on
Commit
f0bef62
·
verified ·
1 Parent(s): 8bde9b2

Upload multiagents.md

Browse files
Files changed (1) hide show
  1. docs/source/hi/multiagents.md +184 -0
docs/source/hi/multiagents.md ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # मल्टी-एजेंट सिस्टम का आयोजन करें 🤖🤝🤖
2
+
3
+ [[open-in-colab]]
4
+
5
+ इस नोटबुक में हम एक **मल्टी-एजेंट वेब ब्राउज़र बनाएंगे: एक एजेंटिक सिस्टम जिसमें कई एजेंट वेब का उपयोग करके समस्याओं को हल करने के लिए सहयोग करते हैं!**
6
+
7
+ यह एक सरल संरचना होगी, जो प्रबंधित वेब खोज एजेंट को रैप करने के लिए `ManagedAgent` ऑब्जेक्ट का उपयोग करता है:
8
+
9
+ ```
10
+ +----------------+
11
+ | Manager agent |
12
+ +----------------+
13
+ |
14
+ _______________|______________
15
+ | |
16
+ Code interpreter +--------------------------------+
17
+ tool | Managed agent |
18
+ | +------------------+ |
19
+ | | Web Search agent | |
20
+ | +------------------+ |
21
+ | | | |
22
+ | Web Search tool | |
23
+ | Visit webpage tool |
24
+ +--------------------------------+
25
+ ```
26
+ आइए इस सिस्टम को सेट करें।
27
+
28
+ आवश्यक डिपेंडेंसी इंस्टॉल करने के लिए नीचे दी गई लाइन चलाएं:
29
+
30
+ ```
31
+ !pip install markdownify duckduckgo-search smolagents --upgrade -q
32
+ ```
33
+
34
+ HF Inference API को कॉल करने के लिए लॉगिन करें:
35
+
36
+ ```
37
+ from huggingface_hub import login
38
+
39
+ login()
40
+ ```
41
+
42
+ ⚡️ हमारा एजेंट [Qwen/Qwen2.5-Coder-32B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-32B-Instruct) द्वारा संचालित होगा जो `InferenceClientModel` क्लास का उपयोग करता है जो HF के Inference API का उपयोग करता है: Inference API किसी भी OS मॉडल को जल्दी और आसानी से चलाने की अनुमति देता है।
43
+
44
+ _नोट:_ The Inference API विभिन्न मानदंडों के आधार पर मॉडल होस्ट करता है, और डिप्लॉय किए गए मॉडल बिना पूर्व सूचना के अपडेट या बदले जा सकते हैं। इसके बारे में अधिक जानें [यहां](https://huggingface.co/docs/api-inference/supported-models)।
45
+
46
+ ```py
47
+ model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"
48
+ ```
49
+
50
+ ## 🔍 एक वेब सर्च टूल बनाएं
51
+
52
+ वेब ब्राउज़िंग के लिए, हम पहले से मौजूद [`WebSearchTool`] टूल का उपयोग कर सकते हैं जो Google search के समान सुविधा प्रदान करता है।
53
+
54
+ लेकिन फिर हमें `WebSearchTool` द्वारा खोजे गए पेज को देखने में भी सक्षम होने की आवश्यकता होगी।
55
+ ऐसा करने के लिए, हम लाइब्रेरी के बिल्ट-इन `VisitWebpageTool` को इम्पोर्ट कर सकते हैं, लेकिन हम इसे फिर से बनाएंगे यह देखने के लिए कि यह कैसे किया जाता है।
56
+
57
+ तो आइए `markdownify` का उपयोग करके शुरू से अपना `VisitWebpageTool` टूल बनाएं।
58
+
59
+ ```py
60
+ import re
61
+ import requests
62
+ from markdownify import markdownify
63
+ from requests.exceptions import RequestException
64
+ from smolagents import tool
65
+
66
+
67
+ @tool
68
+ def visit_webpage(url: str) -> str:
69
+ """Visits a webpage at the given URL and returns its content as a markdown string.
70
+
71
+ Args:
72
+ url: The URL of the webpage to visit.
73
+
74
+ Returns:
75
+ The content of the webpage converted to Markdown, or an error message if the request fails.
76
+ """
77
+ try:
78
+ # Send a GET request to the URL
79
+ response = requests.get(url)
80
+ response.raise_for_status() # Raise an exception for bad status codes
81
+
82
+ # Convert the HTML content to Markdown
83
+ markdown_content = markdownify(response.text).strip()
84
+
85
+ # Remove multiple line breaks
86
+ markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
87
+
88
+ return markdown_content
89
+
90
+ except RequestException as e:
91
+ return f"Error fetching the webpage: {str(e)}"
92
+ except Exception as e:
93
+ return f"An unexpected error occurred: {str(e)}"
94
+ ```
95
+
96
+ ठीक है, अब चलिए हमारे टूल को टेस्ट करें!
97
+
98
+ ```py
99
+ print(visit_webpage("https://en.wikipedia.org/wiki/Hugging_Face")[:500])
100
+ ```
101
+
102
+ ## हमारी मल्टी-एजेंट सिस्टम का निर्माण करें 🤖🤝🤖
103
+
104
+ अब जब हमारे पास सभी टूल्स `search` और `visit_webpage` हैं, हम उनका उपयोग वेब एजेंट बनाने के लिए कर सकते हैं।
105
+
106
+ इस एजेंट के लिए कौन सा कॉन्फ़िगरेशन चुनें?
107
+ - वेब ब्राउज़िंग एक सिंगल-टाइमलाइन टास्क है जिसे समानांतर टूल कॉल की आवश्यकता नहीं है, इसलिए JSON टूल कॉलिंग इसके लिए अच्छी तरह काम करती है। इसलिए हम `ToolCallingAgent` चुनते हैं।
108
+ - साथ ही, चूंकि कभी-कभी वेब सर्च में सही उत्तर खोजने से पहले कई पेजों की सर्च करने की आवश्यकता होती है, हम `max_steps` को बढ़ाकर 10 करना पसंद करते हैं।
109
+
110
+ ```py
111
+ from smolagents import (
112
+ CodeAgent,
113
+ ToolCallingAgent,
114
+ InferenceClientModel,
115
+ ManagedAgent,
116
+ WebSearchTool,
117
+ LiteLLMModel,
118
+ )
119
+
120
+ model = InferenceClientModel(model_id=model_id)
121
+
122
+ web_agent = ToolCallingAgent(
123
+ tools=[WebSearchTool(), visit_webpage],
124
+ model=model,
125
+ max_steps=10,
126
+ )
127
+ ```
128
+
129
+ फिर हम इस एजेंट को एक `ManagedAgent` में रैप करते हैं जो इसे इसके मैनेजर एजेंट द्वारा कॉल करने योग्य बनाएगा।
130
+
131
+ ```py
132
+ managed_web_agent = ManagedAgent(
133
+ agent=web_agent,
134
+ name="search",
135
+ description="Runs web searches for you. Give it your query as an argument.",
136
+ )
137
+ ```
138
+
139
+ अंत में हम एक मैनेजर एजेंट बनाते हैं, और इनिशियलाइजेशन पर हम अपने मैनेज्ड एजेंट को इसके `managed_agents` आर्गुमेंट में पास करते हैं।
140
+
141
+ चूंकि यह एजेंट योजना बनाने और सोचने का काम करता है, उन्नत तर्क लाभदायक होगा, इसलिए `CodeAgent` सबसे अच्छा विकल्प होगा।
142
+
143
+ साथ ही, हम एक ऐसा प्रश्न पूछना चाहते हैं जिसमें वर्तमान वर्ष और अतिरिक्त डेटा गणना शामिल है: इसलिए आइए `additional_authorized_imports=["time", "numpy", "pandas"]` जोड़ें, यदि एजेंट को इन पैकेजों की आवश्यकता हो।
144
+
145
+ ```py
146
+ manager_agent = CodeAgent(
147
+ tools=[],
148
+ model=model,
149
+ managed_agents=[managed_web_agent],
150
+ additional_authorized_imports=["time", "numpy", "pandas"],
151
+ )
152
+ ```
153
+
154
+ बस इतना ही! अब चलिए हमारे सिस्टम को चलाते हैं! हम एक ऐसा प्रश्न चुनते हैं जिसमें गणना और शोध दोनों की आवश्यकता है।
155
+
156
+ ```py
157
+ answer = manager_agent.run("If LLM training continues to scale up at the current rhythm until 2030, what would be the electric power in GW required to power the biggest training runs by 2030? What would that correspond to, compared to some countries? Please provide a source for any numbers used.")
158
+ ```
159
+
160
+ We get this report as the answer:
161
+ ```
162
+ Based on current growth projections and energy consumption estimates, if LLM trainings continue to scale up at the
163
+ current rhythm until 2030:
164
+
165
+ 1. The electric power required to power the biggest training runs by 2030 would be approximately 303.74 GW, which
166
+ translates to about 2,660,762 GWh/year.
167
+
168
+ 2. Comparing this to countries' electricity consumption:
169
+ - It would be equivalent to about 34% of China's total electricity consumption.
170
+ - It would exceed the total electricity consumption of India (184%), Russia (267%), and Japan (291%).
171
+ - It would be nearly 9 times the electricity consumption of countries like Italy or Mexico.
172
+
173
+ 3. Source of numbers:
174
+ - The initial estimate of 5 GW for future LLM training comes from AWS CEO Matt Garman.
175
+ - The growth projection used a CAGR of 79.80% from market research by Springs.
176
+ - Country electricity consumption data is from the U.S. Energy Information Administration, primarily for the year
177
+ 2021.
178
+ ```
179
+
180
+ लगता है कि यदि [स्केलिंग हाइपोथिसिस](https://gwern.net/scaling-hypothesis) सत्य बनी रहती है तो हमें कुछ बड़े पावरप्लांट्स की आवश्यकता होगी।
181
+
182
+ हमारे एजेंट्स ने कार्य को हल करने के लिए कुशलतापूर्वक सहयोग किया! ✅
183
+
184
+ 💡 आप इस ऑर्केस्ट्रेशन को आसानी से अधिक एजेंट्स में विस्तारित कर सकते हैं: एक कोड एक्जीक्यूशन करता है, एक वेब सर्च करता है, एक फाइल लोडिंग को संभालता है।