Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Text-to-SQL","local":"text-to-sql","sections":[{"title":"Agent बनाएं","local":"agent-बनए","sections":[],"depth":3},{"title":"लेवल 2: टेबल जॉइन्स","local":"लवल-2-टबल-जइनस","sections":[],"depth":3}],"depth":1}"> | |
| <link href="/docs/smolagents/pr_2321/hi/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/entry/start.4c7058f2.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/scheduler.00b97157.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/singletons.6a07976b.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/index.78ea7f15.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/paths.373154d9.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/entry/app.3b65213b.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/preload-helper.05e26143.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/index.a7c1a7a1.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/nodes/0.579dadcd.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/nodes/6.bf5b45fb.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.d080d42c.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/CodeBlock.f041f5e5.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/DocNotebookDropdown.be7b60e3.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"Text-to-SQL","local":"text-to-sql","sections":[{"title":"Agent बनाएं","local":"agent-बनए","sections":[],"depth":3},{"title":"लेवल 2: टेबल जॉइन्स","local":"लवल-2-टबल-जइनस","sections":[],"depth":3}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <div class="flex space-x-1 " style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"> <div class="relative colab-dropdown "> <button class=" " type="button"> <img alt="Open In Colab" class="!m-0" src="https://colab.research.google.com/assets/colab-badge.svg"> </button> </div> <div class="relative colab-dropdown "> <button class=" " type="button"> <img alt="Open In Studio Lab" class="!m-0" src="https://studiolab.sagemaker.aws/studiolab.svg"> </button> </div></div> <h1 class="relative group"><a id="text-to-sql" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#text-to-sql"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Text-to-SQL</span></h1> <p data-svelte-h="svelte-1vqej36">इस ट्यूटोरियल में, हम देखेंगे कि कैसे <code>smolagents</code> का उपयोग करके एक एजेंट को SQL का उपयोग करने के लिए लागू किया जा सकता है।</p> <blockquote data-svelte-h="svelte-1c9g2y9"><p>आइए सबसे महत्वपूर्ण प्रश्न से शुरू करें: इसे साधारण क्यों नहीं रखें और एक सामान्य text-to-SQL पाइपलाइन का उपयोग करें?</p></blockquote> <p data-svelte-h="svelte-t1ybrc">एक सामान्य text-to-SQL पाइपलाइन कमजोर होती है, क्योंकि उत्पन्न SQL क्वेरी गलत हो सकती है। इससे भी बुरी बात यह है कि क्वेरी गलत हो सकती है, लेकिन कोई एरर नहीं दिखाएगी, बल्कि बिना किसी अलार्म के गलत/बेकार आउटपुट दे सकती है।</p> <p data-svelte-h="svelte-1unj2zn">👉 इसके बजाय, एक एजेंट सिस्टम आउटपुट का गंभीरता से निरीक्षण कर सकता है और तय कर सकता है कि क्वेरी को बदलने की जरूरत है या नहीं, इस प्रकार इसे बेहतर प्रदर्शन में मदद मिलती है।</p> <p data-svelte-h="svelte-5uw7zt">आइए इस एजेंट को बनाएं! 💪</p> <p data-svelte-h="svelte-7f61t4">पहले, हम SQL एनवायरनमेंट सेटअप करते हैं:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-py "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> sqlalchemy <span class="hljs-keyword">import</span> ( | |
| create_engine, | |
| MetaData, | |
| Table, | |
| Column, | |
| String, | |
| Integer, | |
| Float, | |
| insert, | |
| inspect, | |
| text, | |
| ) | |
| engine = create_engine(<span class="hljs-string">"sqlite:///:memory:"</span>) | |
| metadata_obj = MetaData() | |
| <span class="hljs-comment"># create city SQL table</span> | |
| table_name = <span class="hljs-string">"receipts"</span> | |
| receipts = Table( | |
| table_name, | |
| metadata_obj, | |
| Column(<span class="hljs-string">"receipt_id"</span>, Integer, primary_key=<span class="hljs-literal">True</span>), | |
| Column(<span class="hljs-string">"customer_name"</span>, String(<span class="hljs-number">16</span>), primary_key=<span class="hljs-literal">True</span>), | |
| Column(<span class="hljs-string">"price"</span>, Float), | |
| Column(<span class="hljs-string">"tip"</span>, Float), | |
| ) | |
| metadata_obj.create_all(engine) | |
| rows = [ | |
| {<span class="hljs-string">"receipt_id"</span>: <span class="hljs-number">1</span>, <span class="hljs-string">"customer_name"</span>: <span class="hljs-string">"Alan Payne"</span>, <span class="hljs-string">"price"</span>: <span class="hljs-number">12.06</span>, <span class="hljs-string">"tip"</span>: <span class="hljs-number">1.20</span>}, | |
| {<span class="hljs-string">"receipt_id"</span>: <span class="hljs-number">2</span>, <span class="hljs-string">"customer_name"</span>: <span class="hljs-string">"Alex Mason"</span>, <span class="hljs-string">"price"</span>: <span class="hljs-number">23.86</span>, <span class="hljs-string">"tip"</span>: <span class="hljs-number">0.24</span>}, | |
| {<span class="hljs-string">"receipt_id"</span>: <span class="hljs-number">3</span>, <span class="hljs-string">"customer_name"</span>: <span class="hljs-string">"Woodrow Wilson"</span>, <span class="hljs-string">"price"</span>: <span class="hljs-number">53.43</span>, <span class="hljs-string">"tip"</span>: <span class="hljs-number">5.43</span>}, | |
| {<span class="hljs-string">"receipt_id"</span>: <span class="hljs-number">4</span>, <span class="hljs-string">"customer_name"</span>: <span class="hljs-string">"Margaret James"</span>, <span class="hljs-string">"price"</span>: <span class="hljs-number">21.11</span>, <span class="hljs-string">"tip"</span>: <span class="hljs-number">1.00</span>}, | |
| ] | |
| <span class="hljs-keyword">for</span> row <span class="hljs-keyword">in</span> rows: | |
| stmt = insert(receipts).values(**row) | |
| <span class="hljs-keyword">with</span> engine.begin() <span class="hljs-keyword">as</span> connection: | |
| cursor = connection.execute(stmt)<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="agent-बनए" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#agent-बनए"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Agent बनाएं</span></h3> <p data-svelte-h="svelte-1tyzz1p">अब आइए हमारी SQL टेबल को एक टूल द्वारा पुनर्प्राप्त करने योग्य बनाएं।</p> <p data-svelte-h="svelte-ursnt8">टूल का विवरण विशेषता एजेंट सिस्टम द्वारा LLM के prompt में एम्बेड किया जाएगा: यह LLM को टूल का उपयोग करने के बारे में जानकारी देता है। यहीं पर हम SQL टेबल का वर्णन करना चाहते हैं।</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-py "><!-- HTML_TAG_START -->inspector = inspect(engine) | |
| columns_info = [(col[<span class="hljs-string">"name"</span>], col[<span class="hljs-string">"type"</span>]) <span class="hljs-keyword">for</span> col <span class="hljs-keyword">in</span> inspector.get_columns(<span class="hljs-string">"receipts"</span>)] | |
| table_description = <span class="hljs-string">"Columns:\n"</span> + <span class="hljs-string">"\n"</span>.join([<span class="hljs-string">f" - <span class="hljs-subst">{name}</span>: <span class="hljs-subst">{col_type}</span>"</span> <span class="hljs-keyword">for</span> name, col_type <span class="hljs-keyword">in</span> columns_info]) | |
| <span class="hljs-built_in">print</span>(table_description)<!-- HTML_TAG_END --></pre></div> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-text "><!-- HTML_TAG_START -->Columns: | |
| - receipt_id: INTEGER | |
| - customer_name: VARCHAR(16) | |
| - price: FLOAT | |
| - tip: FLOAT<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-yq70l3">अब आइए हमारा टूल बनाएं। इसे निम्नलिखित की आवश्यकता है: (अधिक जानकारी के लिए <a href="../tutorials/tools">टूल doc</a> पढ़ें)</p> <ul data-svelte-h="svelte-1ifrctn"><li>एक डॉकस्ट्रिंग जिसमें आर्ग्युमेंट्स की सूची वाला <code>Args:</code> भाग हो।</li> <li>इनपुट और आउटपुट दोनों पर टाइप हिंट्स।</li></ul> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-py "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> tool | |
| <span class="hljs-meta">@tool</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">sql_engine</span>(<span class="hljs-params">query: <span class="hljs-built_in">str</span></span>) -> <span class="hljs-built_in">str</span>: | |
| <span class="hljs-string">""" | |
| Allows you to perform SQL queries on the table. Returns a string representation of the result. | |
| The table is named 'receipts'. Its description is as follows: | |
| Columns: | |
| - receipt_id: INTEGER | |
| - customer_name: VARCHAR(16) | |
| - price: FLOAT | |
| - tip: FLOAT | |
| Args: | |
| query: The query to perform. This should be correct SQL. | |
| """</span> | |
| output = <span class="hljs-string">""</span> | |
| <span class="hljs-keyword">with</span> engine.connect() <span class="hljs-keyword">as</span> con: | |
| rows = con.execute(text(query)) | |
| <span class="hljs-keyword">for</span> row <span class="hljs-keyword">in</span> rows: | |
| output += <span class="hljs-string">"\n"</span> + <span class="hljs-built_in">str</span>(row) | |
| <span class="hljs-keyword">return</span> output<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1a4dt1e">अब आइए एक एजेंट बनाएं जो इस टूल का लाभ उठाता है।</p> <p data-svelte-h="svelte-f7seml">हम <code>CodeAgent</code> का उपयोग करते हैं, जो smolagents का मुख्य एजेंट क्लास है: एक एजेंट जो कोड में एक्शन लिखता है और ReAct फ्रेमवर्क के अनुसार पिछले आउटपुट पर पुनरावृत्ति कर सकता है।</p> <p data-svelte-h="svelte-1tggkgr">मॉडल वह LLM है जो एजेंट सिस्टम को संचालित करता है। <code>InferenceClientModel</code> आपको HF के Inference API का उपयोग करके LLM को कॉल करने की अनुमति देता है, या तो सर्वरलेस या डेडिकेटेड एंडपॉइंट के माध्यम से, लेकिन आप किसी भी प्रोप्राइटरी API का भी उपयोग कर सकते हैं।</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-py "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> CodeAgent, InferenceClientModel | |
| agent = CodeAgent( | |
| tools=[sql_engine], | |
| model=InferenceClientModel(model_id=<span class="hljs-string">"meta-llama/Meta-Llama-3.1-8B-Instruct"</span>), | |
| ) | |
| agent.run(<span class="hljs-string">"Can you give me the name of the client who got the most expensive receipt?"</span>)<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="लवल-2-टबल-जइनस" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#लवल-2-टबल-जइनस"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>लेवल 2: टेबल जॉइन्स</span></h3> <p data-svelte-h="svelte-4h942p">अब आइए इसे और चुनौतीपूर्ण बनाएं! हम चाहते हैं कि हमारा एजेंट कई टेबल्स के बीच जॉइन को संभाल सके।</p> <p data-svelte-h="svelte-12yu0em">तो आइए हम प्रत्येक receipt_id के लिए वेटर्स के नाम रिकॉर्ड करने वाली एक दूसरी टेबल बनाते हैं!</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-py "><!-- HTML_TAG_START -->table_name = <span class="hljs-string">"waiters"</span> | |
| receipts = Table( | |
| table_name, | |
| metadata_obj, | |
| Column(<span class="hljs-string">"receipt_id"</span>, Integer, primary_key=<span class="hljs-literal">True</span>), | |
| Column(<span class="hljs-string">"waiter_name"</span>, String(<span class="hljs-number">16</span>), primary_key=<span class="hljs-literal">True</span>), | |
| ) | |
| metadata_obj.create_all(engine) | |
| rows = [ | |
| {<span class="hljs-string">"receipt_id"</span>: <span class="hljs-number">1</span>, <span class="hljs-string">"waiter_name"</span>: <span class="hljs-string">"Corey Johnson"</span>}, | |
| {<span class="hljs-string">"receipt_id"</span>: <span class="hljs-number">2</span>, <span class="hljs-string">"waiter_name"</span>: <span class="hljs-string">"Michael Watts"</span>}, | |
| {<span class="hljs-string">"receipt_id"</span>: <span class="hljs-number">3</span>, <span class="hljs-string">"waiter_name"</span>: <span class="hljs-string">"Michael Watts"</span>}, | |
| {<span class="hljs-string">"receipt_id"</span>: <span class="hljs-number">4</span>, <span class="hljs-string">"waiter_name"</span>: <span class="hljs-string">"Margaret James"</span>}, | |
| ] | |
| <span class="hljs-keyword">for</span> row <span class="hljs-keyword">in</span> rows: | |
| stmt = insert(receipts).values(**row) | |
| <span class="hljs-keyword">with</span> engine.begin() <span class="hljs-keyword">as</span> connection: | |
| cursor = connection.execute(stmt)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-byj1ks">चूंकि हमने टेबल को बदल दिया है, हम LLM को इस टेबल की जानकारी का उचित उपयोग करने देने के लिए इस टेबल के विवरण के साथ <code>SQLExecutorTool</code> को अपडेट करते हैं।</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-py "><!-- HTML_TAG_START -->updated_description = <span class="hljs-string">"""Allows you to perform SQL queries on the table. Beware that this tool's output is a string representation of the execution output. | |
| It can use the following tables:"""</span> | |
| inspector = inspect(engine) | |
| <span class="hljs-keyword">for</span> table <span class="hljs-keyword">in</span> [<span class="hljs-string">"receipts"</span>, <span class="hljs-string">"waiters"</span>]: | |
| columns_info = [(col[<span class="hljs-string">"name"</span>], col[<span class="hljs-string">"type"</span>]) <span class="hljs-keyword">for</span> col <span class="hljs-keyword">in</span> inspector.get_columns(table)] | |
| table_description = <span class="hljs-string">f"Table '<span class="hljs-subst">{table}</span>':\n"</span> | |
| table_description += <span class="hljs-string">"Columns:\n"</span> + <span class="hljs-string">"\n"</span>.join([<span class="hljs-string">f" - <span class="hljs-subst">{name}</span>: <span class="hljs-subst">{col_type}</span>"</span> <span class="hljs-keyword">for</span> name, col_type <span class="hljs-keyword">in</span> columns_info]) | |
| updated_description += <span class="hljs-string">"\n\n"</span> + table_description | |
| <span class="hljs-built_in">print</span>(updated_description)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1oi9vpn">चूंकि यह रिक्वेस्ट पिछले वाले से थोड़ी कठिन है, हम LLM इंजन को अधिक शक्तिशाली <a href="https://huggingface.co/Qwen/Qwen3-Next-80B-A3B-Thinking" rel="nofollow">Qwen/Qwen3-Next-80B-A3B-Thinking</a> का उपयोग करने के लिए स्विच करेंगे!</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-py "><!-- HTML_TAG_START -->sql_engine.description = updated_description | |
| agent = CodeAgent( | |
| tools=[sql_engine], | |
| model=InferenceClientModel(model_id=<span class="hljs-string">"Qwen/Qwen3-Next-80B-A3B-Thinking"</span>), | |
| ) | |
| agent.run(<span class="hljs-string">"Which waiter got more total money from tips?"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1kgyjc3">यह सीधे काम करता है! सेटअप आश्चर्यजनक रूप से सरल था, है ना?</p> <p data-svelte-h="svelte-1kiz73b">यह उदाहरण पूरा हो गया! हमने इन अवधारणाओं को छुआ है:</p> <ul data-svelte-h="svelte-12i5qmo"><li>नए टूल्स का निर्माण।</li> <li>टूल के विवरण को अपडेट करना।</li> <li>एक मजबूत LLM में स्विच करने से एजेंट की तर्कशक्ति में मदद मिलती है।</li></ul> <p data-svelte-h="svelte-1mkvth2">✅ अब आप वह text-to-SQL सिस्टम बना सकते हैं जिसका आपने हमेशा सपना देखा है! ✨</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/smolagents/blob/main/docs/source/hi/examples/text_to_sql.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_ehst33 = { | |
| assets: "/docs/smolagents/pr_2321/hi", | |
| base: "/docs/smolagents/pr_2321/hi", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/smolagents/pr_2321/hi/_app/immutable/entry/start.4c7058f2.js"), | |
| import("/docs/smolagents/pr_2321/hi/_app/immutable/entry/app.3b65213b.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 6], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 35.3 kB
- Xet hash:
- 5f5a1777b73b88753d00d99f781871b7681d5a74bd893e7cd36d59eca60ed61d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.