import{s as Ct,n as vt,o as kt}from"../chunks/scheduler.1f027d5a.js";import{S as Rt,i as Bt,e as i,s as n,c as p,h as Zt,a as r,d as t,b as a,f as ht,g as y,j as o,k as It,l as Gt,m as l,n as M,t as m,o as c,p as d}from"../chunks/index.6117a65d.js";import{C as qt}from"../chunks/CopyLLMTxtMenu.0ff8411a.js";import{D as Vt,C as U}from"../chunks/DocNotebookDropdown.316c3715.js";import{H as u,E as At}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.0eecd2bb.js";function _t($s){let J,ke,Ce,Re,j,Be,b,Ze,T,Ge,w,Ns='<em>作者: <a href="https://huggingface.co/m-ric" rel="nofollow">Aymeric Roucher</a></em>',qe,f,Qs='这个 notebook 展示了如何使用 <a href="https://huggingface.co/docs/transformers/en/agents" rel="nofollow"><strong>Transformers Agents</strong></a> 来构建出色的<strong>智能体</strong>！',Ve,g,Xs="什么是<strong>智能体</strong>？智能体是由大型语言模型（LLM）驱动的系统，它们使得 LLM（通过精心设计的提示和输出解析）能够使用特定的<em>工具</em>来解决问题。",Ae,h,zs='这些<em>工具</em>基本上是 LLM 自身无法很好执行的功能：例如，对于像 <a href="https://huggingface.co/meta-llama/Meta-Llama-3-70B-Instruct" rel="nofollow">Llama-3-70B</a> 这样的文本生成 LLM，这可能是一个图像生成工具、网络搜索工具、计算器…',_e,I,xs='什么是 <strong>Transformers Agents</strong> ？它是我们 <code>transformers</code> 库的一个扩展，提供了构建自己的智能体的构建块！在<a href="https://huggingface.co/docs/transformers/en/agents" rel="nofollow">文档</a>中了解更多信息。',Ee,C,Ss="让我们看看如何使用它，以及它能解决哪些用例。",We,v,Ys="我们从源代码安装 transformers agents ，你可以使用 <code>pip install transformers[agents]</code> 轻松安装。",$e,k,Ne,R,Hs=`Requirement already satisfied: smolagents in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (1.0.0)
Requirement already satisfied: torch in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (2.3.0)
Requirement already satisfied: torchaudio in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (2.3.0)
Requirement already satisfied: torchvision in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (0.18.0)
Requirement already satisfied: transformers>=4.0.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (4.47.1)
Requirement already satisfied: requests>=2.32.3 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (2.32.3)
Requirement already satisfied: rich>=13.9.4 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (13.9.4)
Requirement already satisfied: pandas>=2.2.3 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (2.2.3)
Requirement already satisfied: jinja2>=3.1.4 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (3.1.4)
Requirement already satisfied: pillow>=11.0.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (11.1.0)
Requirement already satisfied: markdownify>=0.14.1 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (0.14.1)
Requirement already satisfied: gradio>=5.8.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (5.9.1)
Requirement already satisfied: duckduckgo-search>=6.3.7 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (7.2.0)
Requirement already satisfied: python-dotenv>=1.0.1 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (1.0.1)
Requirement already satisfied: e2b-code-interpreter>=1.0.3 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (1.0.3)
Requirement already satisfied: litellm>=1.55.10 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from smolagents) (1.57.0)
Requirement already satisfied: click>=8.1.7 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from duckduckgo-search>=6.3.7->smolagents) (8.1.7)
Requirement already satisfied: primp>=0.9.3 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from duckduckgo-search>=6.3.7->smolagents) (0.9.3)
Requirement already satisfied: lxml>=5.3.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from duckduckgo-search>=6.3.7->smolagents) (5.3.0)
Requirement already satisfied: attrs>=21.3.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from e2b-code-interpreter>=1.0.3->smolagents) (23.2.0)
Requirement already satisfied: e2b<2.0.0,>=1.0.4 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from e2b-code-interpreter>=1.0.3->smolagents) (1.0.5)
Requirement already satisfied: httpx<1.0.0,>=0.20.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from e2b-code-interpreter>=1.0.3->smolagents) (0.27.2)
Requirement already satisfied: aiofiles<24.0,>=22.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (23.2.1)
Requirement already satisfied: anyio<5.0,>=3.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (3.7.1)
Requirement already satisfied: fastapi<1.0,>=0.115.2 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (0.115.6)
Requirement already satisfied: ffmpy in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (0.4.0)
Requirement already satisfied: gradio-client==1.5.2 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (1.5.2)
Requirement already satisfied: huggingface-hub>=0.25.1 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (0.27.1)
Requirement already satisfied: markupsafe~=2.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (2.1.5)
Requirement already satisfied: numpy<3.0,>=1.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (2.1.3)
Requirement already satisfied: orjson~=3.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (3.10.11)
Requirement already satisfied: packaging in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (24.2)
Requirement already satisfied: pydantic>=2.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (2.9.2)
Requirement already satisfied: pydub in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (0.25.1)
Requirement already satisfied: python-multipart>=0.0.18 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (0.0.20)
Requirement already satisfied: pyyaml<7.0,>=5.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (6.0.1)
Requirement already satisfied: ruff>=0.2.2 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (0.3.4)
Requirement already satisfied: safehttpx<0.2.0,>=0.1.6 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (0.1.6)
Requirement already satisfied: semantic-version~=2.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (2.10.0)
Requirement already satisfied: starlette<1.0,>=0.40.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (0.41.3)
Requirement already satisfied: tomlkit<0.14.0,>=0.12.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (0.12.0)
Requirement already satisfied: typer<1.0,>=0.12 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (0.12.5)
Requirement already satisfied: typing-extensions~=4.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (4.12.2)
Requirement already satisfied: uvicorn>=0.14.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio>=5.8.0->smolagents) (0.30.6)
Requirement already satisfied: fsspec in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio-client==1.5.2->gradio>=5.8.0->smolagents) (2024.3.1)
Requirement already satisfied: websockets<15.0,>=10.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from gradio-client==1.5.2->gradio>=5.8.0->smolagents) (12.0)
Requirement already satisfied: aiohttp in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from litellm>=1.55.10->smolagents) (3.9.3)
Requirement already satisfied: importlib-metadata>=6.8.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from litellm>=1.55.10->smolagents) (8.5.0)
Requirement already satisfied: jsonschema<5.0.0,>=4.22.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from litellm>=1.55.10->smolagents) (4.22.0)
Requirement already satisfied: openai>=1.55.3 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from litellm>=1.55.10->smolagents) (1.59.3)
Requirement already satisfied: tiktoken>=0.7.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from litellm>=1.55.10->smolagents) (0.8.0)
Requirement already satisfied: tokenizers in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from litellm>=1.55.10->smolagents) (0.21.0)
Requirement already satisfied: beautifulsoup4<5,>=4.9 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from markdownify>=0.14.1->smolagents) (4.12.3)
Requirement already satisfied: six<2,>=1.15 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from markdownify>=0.14.1->smolagents) (1.16.0)
Requirement already satisfied: python-dateutil>=2.8.2 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from pandas>=2.2.3->smolagents) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from pandas>=2.2.3->smolagents) (2024.1)
Requirement already satisfied: tzdata>=2022.7 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from pandas>=2.2.3->smolagents) (2024.1)
Requirement already satisfied: charset-normalizer<4,>=2 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from requests>=2.32.3->smolagents) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from requests>=2.32.3->smolagents) (3.6)
Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from requests>=2.32.3->smolagents) (2.0.7)
Requirement already satisfied: certifi>=2017.4.17 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from requests>=2.32.3->smolagents) (2023.11.17)
Requirement already satisfied: markdown-it-py>=2.2.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from rich>=13.9.4->smolagents) (3.0.0)
Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from rich>=13.9.4->smolagents) (2.18.0)
Requirement already satisfied: filelock in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from transformers>=4.0.0->smolagents) (3.13.1)
Requirement already satisfied: regex!=2019.12.17 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from transformers>=4.0.0->smolagents) (2024.5.10)
Requirement already satisfied: safetensors>=0.4.1 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from transformers>=4.0.0->smolagents) (0.4.3)
Requirement already satisfied: tqdm>=4.27 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from transformers>=4.0.0->smolagents) (4.66.1)
Requirement already satisfied: sympy in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from torch->smolagents) (1.12)
Requirement already satisfied: networkx in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from torch->smolagents) (3.3)
Requirement already satisfied: sniffio>=1.1 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from anyio<5.0,>=3.0->gradio>=5.8.0->smolagents) (1.3.0)
Requirement already satisfied: soupsieve>1.2 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from beautifulsoup4<5,>=4.9->markdownify>=0.14.1->smolagents) (2.5)
Requirement already satisfied: httpcore<2.0.0,>=1.0.5 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from e2b<2.0.0,>=1.0.4->e2b-code-interpreter>=1.0.3->smolagents) (1.0.7)
Requirement already satisfied: protobuf<6.0.0,>=3.20.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from e2b<2.0.0,>=1.0.4->e2b-code-interpreter>=1.0.3->smolagents) (5.29.0)
Requirement already satisfied: h11<0.15,>=0.13 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from httpcore<2.0.0,>=1.0.5->e2b<2.0.0,>=1.0.4->e2b-code-interpreter>=1.0.3->smolagents) (0.14.0)
Requirement already satisfied: zipp>=3.20 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from importlib-metadata>=6.8.0->litellm>=1.55.10->smolagents) (3.21.0)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from jsonschema<5.0.0,>=4.22.0->litellm>=1.55.10->smolagents) (2023.12.1)
Requirement already satisfied: referencing>=0.28.4 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from jsonschema<5.0.0,>=4.22.0->litellm>=1.55.10->smolagents) (0.35.1)
Requirement already satisfied: rpds-py>=0.7.1 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from jsonschema<5.0.0,>=4.22.0->litellm>=1.55.10->smolagents) (0.18.1)
Requirement already satisfied: mdurl~=0.1 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from markdown-it-py>=2.2.0->rich>=13.9.4->smolagents) (0.1.2)
Requirement already satisfied: distro<2,>=1.7.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from openai>=1.55.3->litellm>=1.55.10->smolagents) (1.8.0)
Requirement already satisfied: jiter<1,>=0.4.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from openai>=1.55.3->litellm>=1.55.10->smolagents) (0.7.1)
Requirement already satisfied: annotated-types>=0.6.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from pydantic>=2.0->gradio>=5.8.0->smolagents) (0.6.0)
Requirement already satisfied: pydantic-core==2.23.4 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from pydantic>=2.0->gradio>=5.8.0->smolagents) (2.23.4)
Requirement already satisfied: shellingham>=1.3.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from typer<1.0,>=0.12->gradio>=5.8.0->smolagents) (1.5.4)
Requirement already satisfied: aiosignal>=1.1.2 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from aiohttp->litellm>=1.55.10->smolagents) (1.3.1)
Requirement already satisfied: frozenlist>=1.1.1 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from aiohttp->litellm>=1.55.10->smolagents) (1.4.1)
Requirement already satisfied: multidict<7.0,>=4.5 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from aiohttp->litellm>=1.55.10->smolagents) (6.0.5)
Requirement already satisfied: yarl<2.0,>=1.0 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from aiohttp->litellm>=1.55.10->smolagents) (1.9.4)
Requirement already satisfied: mpmath>=0.19 in /Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages (from sympy->torch->smolagents) (1.3.0)
`,Qe,B,Xe,Z,ze,G,Fs="对于这个用例，我们想要展示一个能够浏览网络并能够生成图像的智能体。",xe,q,Ls="为了构建它，我们只需要准备两个工具：图像生成和网络搜索。",Se,V,Ps="<li>对于图像生成，我们从 Hub 加载一个工具，该工具使用 HF 推理 API（无服务器）使用 Stable Diffusion 生成图像。</li> <li>对于网络搜索，我们加载一个 LangChain 工具。</li>",Ye,A,He,_,Ds='<img src="https://huggingface.co/datasets/huggingface/cookbook-images/resolve/main/agents_db5.png" alt="Image of an Aston Martin DB5"/>',Fe,E,Le,W,Ks="快速定义：检索增强生成（RAG）是 <strong><em>“使用大型语言模型（LLM）来回答用户查询，但基于从知识库检索到的信息来构建答案”</em></strong>。",Pe,$,Os="这种方法相比使用普通或微调的 LLM 有许多优势：列举一些，它允许将答案建立在真实事实的基础上并减少虚构，它允许为 LLM 提供特定领域的知识，并且它允许对知识库中的信息访问进行细粒度控制。",De,N,et="<li><p>现在假设我们想要执行 RAG，但增加了动态生成某些参数的约束。例如，根据用户查询，我们可能想要将搜索限制在知识库的特定子集，或者我们可能想要调整检索到的文档数量。难点在于：<strong>如何根据用户查询动态调整这些参数？</strong></p></li> <li><p>RAG 的一个常见失败案例是基于用户查询的检索没有返回任何相关的支持文档。<strong>有没有一种方法，在之前的结果不相关时，通过修改查询重新调用检索器来进行迭代？</strong></p></li>",Ke,Q,st="🔧 好吧，我们可以以简单的方式解决上述问题：我们将<strong>让我们的智能体控制检索器的参数！</strong>",Oe,X,tt="➡️ 让我们展示如何做到这一点。我们首先加载一个我们想要执行 RAG 的知识库：这个数据集是许多 <code>huggingface</code> 包的文档页面汇总，以 markdown 格式存储。",es,z,ss,x,lt="现在我们通过处理数据集并将其存储到向量数据库中来准备知识库，以便检索器使用。我们将使用 LangChain，因为它具有用于向量数据库的优秀工具：",ts,S,ls,Y,nt="现在我们已经准备好了数据库，让我们构建一个基于它回答用户查询的 RAG 系统！",ns,H,at="我们希望我们的系统根据查询只从最相关的信息来源中选择。",as,F,it="我们的文档页面来自以下来源：",is,L,rs,P,rt=`['evaluate', 'course', 'deep-rl-class', 'peft', 'hf-endpoints-documentation', 'blog', 'gradio', 'datasets', 'datasets-server', 'transformers', 'optimum', 'hub-docs', 'pytorch-image-models', 'diffusers']
`,os,D,ps,K,ys,O,ot="要将你的工具分享到 Hub，首先将检索器工具定义单元格中的代码复制粘贴到一个名为例如 <code>retriever.py</code> 的新文件中。",Ms,ee,pt="当工具从单独的文件加载后，你可以使用以下代码将其推送到 Hub（确保使用具有<code>写入</code>访问权限的 token 登录）",ms,se,cs,te,ds,le,Us,ne,yt=`Final output:
https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_lora.py
`,Js,ae,Mt="发生了什么？首先，智能体启动了检索器，并考虑了特定的来源（<code>[&#39;transformers&#39;, &#39;blog&#39;]</code>）。",us,ie,mt="但是这次检索没有产生足够的结果 ⇒ 没关系！智能体可以迭代之前的结果，因此它只是用不那么严格的搜索参数重新运行了它的检索。",js,re,ct="因此，研究成功了！",bs,oe,dt="请注意，<strong>使用调用检索器作为工具并可以动态修改查询和其他检索参数的 LLM 智能体</strong>是 RAG 的<strong>更一般的表述</strong>，这也涵盖了像迭代查询优化这样的许多 RAG 改进技术。",Ts,pe,ws,ye,fs,Me,Ut="正如你所看到的，智能体尝试了给定的代码，遇到错误，分析错误，纠正代码，并在验证代码可以正常工作后返回它！",gs,me,Jt="最终的代码是纠正后的代码：",hs,ce,Is,de,ut=`list=[0, 1, 2]

for i in range(4):
    print(list(i))
`,Cs,Ue,vs,Je,jt=`设置你自己的 LLM 引擎真的非常简单：
它只需要一个具有以下标准的<code>__call__</code>方法：`,ks,ue,bt='<li>接受<a href="https://huggingface.co/docs/transformers/main/en/chat_templating#introduction" rel="nofollow">ChatML 格式</a>的消息列表作为输入并输出答案。</li> <li>接受一个 <code>stop_sequences</code> 参数，以传递生成停止的序列。</li> <li>根据你的 LLM 接受哪种类型的消息角色，你可能还需要转换一些消息角色。</li>',Rs,je,Bs,be,Zs,Te,Tt=`my_list = [0, 1, 2]  # Renamed the list to avoid using the built-in name

for i in range(len(my_list)):  # Changed the range to be within the length of the list
    print(my_list[i])  # Corrected the list access syntax
`,Gs,we,qs,fe,wt="上述用例应该让你对我们智能体框架的可能性有了初步了解！",Vs,ge,ft='想要了解更多高级用法，请阅读<a href="https://huggingface.co/docs/transformers/en/transformers_agents" rel="nofollow">文档</a>， 以及<a href="https://github.com/aymeric-roucher/agent_reasoning_benchmark/blob/main/benchmark_gaia.ipynb" rel="nofollow">此实验</a>，它让我们能够基于 Llama-3-70B 构建自己的智能体，并在非常困难的<a href="https://huggingface.co/spaces/gaia-benchmark/leaderboard" rel="nofollow">GAIA 排行榜</a>上击败许多 GPT-4 智能体！',As,he,gt="欢迎所有反馈，这将帮助我们改进框架！ 🚀",_s,Ie,Es,ve,Ws;return j=new Vt({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/cookbook/blob/main/notebooks/zh-CN/agents.ipynb"}]}}),b=new qt({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),T=new u({props:{title:"使用 Transformers Agents 构建具有工具调用超能力的智能体 🦸",local:"使用-transformers-agents-构建具有工具调用超能力的智能体-",headingTag:"h1"}}),k=new U({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzbW9sYWdlbnRz",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>!pip install smolagents',wrap:!1}}),B=new U({props:{code:"IXBpcCUyMGluc3RhbGwlMjBkYXRhc2V0cyUyMGh1Z2dpbmdmYWNlX2h1YiUyMGxhbmdjaGFpbiUyMHNlbnRlbmNlLXRyYW5zZm9ybWVycyUyMGZhaXNzLWNwdSUyMHNlcnBhcGklMjBnb29nbGUtc2VhcmNoLXJlc3VsdHMlMjBvcGVuYWklMjAtcQ==",highlighted:"!pip install datasets huggingface_hub langchain sentence-transformers faiss-cpu serpapi google-search-results openai -q",wrap:!1}}),Z=new u({props:{title:"1. 🏞️ 多模态 + 🌐 网络浏览助手",local:"1--多模态---网络浏览助手",headingTag:"h2"}}),A=new U({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRvb2wlMkMlMjBsb2FkX3Rvb2wlMkMlMjBDb2RlQWdlbnQlMkMlMjBJbmZlcmVuY2VDbGllbnRNb2RlbCUwQSUwQSUyMyUyMEltcG9ydCUyMHRvb2wlMjBmcm9tJTIwSHViJTBBaW1hZ2VfZ2VuZXJhdGlvbl90b29sJTIwJTNEJTIwbG9hZF90b29sKCUyMm0tcmljJTJGdGV4dC10by1pbWFnZSUyMiUyQyUyMHRydXN0X3JlbW90ZV9jb2RlJTNEVHJ1ZSklMEElMEElMjMlMjBJbXBvcnQlMjB0b29sJTIwZnJvbSUyMExhbmdDaGFpbiUwQWZyb20lMjBsYW5nY2hhaW4uYWdlbnRzJTIwaW1wb3J0JTIwbG9hZF90b29scyUwQSUwQXNlYXJjaF90b29sJTIwJTNEJTIwVG9vbC5mcm9tX2xhbmdjaGFpbihsb2FkX3Rvb2xzKCU1QiUyMnNlcnBhcGklMjIlNUQpJTVCMCU1RCklMEElMEElMEFtb2RlbCUyMCUzRCUyMEluZmVyZW5jZUNsaWVudE1vZGVsKCUyMm1ldGEtbGxhbWElMkZMbGFtYS0zLjEtNzBCLUluc3RydWN0JTIyKSUwQSUyMyUyMEluaXRpYWxpemUlMjB0aGUlMjBhZ2VudCUyMHdpdGglMjBib3RoJTIwdG9vbHMlMEFhZ2VudCUyMCUzRCUyMENvZGVBZ2VudCglMEElMjAlMjAlMjAlMjB0b29scyUzRCU1QmltYWdlX2dlbmVyYXRpb25fdG9vbCUyQyUyMHNlYXJjaF90b29sJTVEJTJDJTIwbW9kZWwlM0Rtb2RlbCUwQSklMEElMEElMjMlMjBSdW4lMjBpdCElMEFyZXN1bHQlMjAlM0QlMjBhZ2VudC5ydW4oJTBBJTIwJTIwJTIwJTIwJTIyR2VuZXJhdGUlMjBtZSUyMGElMjBwaG90byUyMG9mJTIwdGhlJTIwY2FyJTIwdGhhdCUyMEphbWVzJTIwYm9uZCUyMGRyb3ZlJTIwaW4lMjB0aGUlMjBsYXRlc3QlMjBtb3ZpZS4lMjIlMkMlMEEpJTBBcmVzdWx0",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Tool, load_tool, CodeAgent, InferenceClientModel

<span class="hljs-comment"># Import tool from Hub</span>
image_generation_tool = load_tool(<span class="hljs-string">&quot;m-ric/text-to-image&quot;</span>, trust_remote_code=<span class="hljs-literal">True</span>)

<span class="hljs-comment"># Import tool from LangChain</span>
<span class="hljs-keyword">from</span> langchain.agents <span class="hljs-keyword">import</span> load_tools

search_tool = Tool.from_langchain(load_tools([<span class="hljs-string">&quot;serpapi&quot;</span>])[<span class="hljs-number">0</span>])


model = InferenceClientModel(<span class="hljs-string">&quot;meta-llama/Llama-3.1-70B-Instruct&quot;</span>)
<span class="hljs-comment"># Initialize the agent with both tools</span>
agent = CodeAgent(
    tools=[image_generation_tool, search_tool], model=model
)

<span class="hljs-comment"># Run it!</span>
result = agent.run(
    <span class="hljs-string">&quot;Generate me a photo of the car that James bond drove in the latest movie.&quot;</span>,
)
result`,wrap:!1}}),E=new u({props:{title:"2. 📚💬 带有迭代查询优化和来源选择的 RAG",local:"2--带有迭代查询优化和来源选择的-rag",headingTag:"h2"}}),z=new U({props:{code:"aW1wb3J0JTIwZGF0YXNldHMlMEElMEFrbm93bGVkZ2VfYmFzZSUyMCUzRCUyMGRhdGFzZXRzLmxvYWRfZGF0YXNldCglMjJtLXJpYyUyRmh1Z2dpbmdmYWNlX2RvYyUyMiUyQyUyMHNwbGl0JTNEJTIydHJhaW4lMjIp",highlighted:`<span class="hljs-keyword">import</span> datasets

knowledge_base = datasets.load_dataset(<span class="hljs-string">&quot;m-ric/huggingface_doc&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)`,wrap:!1}}),S=new U({props:{code:"ZnJvbSUyMGxhbmdjaGFpbi5kb2NzdG9yZS5kb2N1bWVudCUyMGltcG9ydCUyMERvY3VtZW50JTBBZnJvbSUyMGxhbmdjaGFpbi50ZXh0X3NwbGl0dGVyJTIwaW1wb3J0JTIwUmVjdXJzaXZlQ2hhcmFjdGVyVGV4dFNwbGl0dGVyJTBBZnJvbSUyMGxhbmdjaGFpbi52ZWN0b3JzdG9yZXMlMjBpbXBvcnQlMjBGQUlTUyUwQWZyb20lMjBsYW5nY2hhaW5fY29tbXVuaXR5LmVtYmVkZGluZ3MlMjBpbXBvcnQlMjBIdWdnaW5nRmFjZUVtYmVkZGluZ3MlMEElMEFzb3VyY2VfZG9jcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMERvY3VtZW50KHBhZ2VfY29udGVudCUzRGRvYyU1QiUyMnRleHQlMjIlNUQlMkMlMjBtZXRhZGF0YSUzRCU3QiUyMnNvdXJjZSUyMiUzQSUyMGRvYyU1QiUyMnNvdXJjZSUyMiU1RC5zcGxpdCglMjIlMkYlMjIpJTVCMSU1RCU3RCklMEElMjAlMjAlMjAlMjBmb3IlMjBkb2MlMjBpbiUyMGtub3dsZWRnZV9iYXNlJTBBJTVEJTBBJTBBZG9jc19wcm9jZXNzZWQlMjAlM0QlMjBSZWN1cnNpdmVDaGFyYWN0ZXJUZXh0U3BsaXR0ZXIoY2h1bmtfc2l6ZSUzRDUwMCkuc3BsaXRfZG9jdW1lbnRzKCUwQSUyMCUyMCUyMCUyMHNvdXJjZV9kb2NzJTBBKSU1QiUzQTEwMDAlNUQlMEElMEFlbWJlZGRpbmdfbW9kZWwlMjAlM0QlMjBIdWdnaW5nRmFjZUVtYmVkZGluZ3MobW9kZWxfbmFtZSUzRCUyMnRoZW5scGVyJTJGZ3RlLXNtYWxsJTIyKSUwQXZlY3RvcmRiJTIwJTNEJTIwRkFJU1MuZnJvbV9kb2N1bWVudHMoZG9jdW1lbnRzJTNEZG9jc19wcm9jZXNzZWQlMkMlMjBlbWJlZGRpbmclM0RlbWJlZGRpbmdfbW9kZWwp",highlighted:`<span class="hljs-keyword">from</span> langchain.docstore.document <span class="hljs-keyword">import</span> Document
<span class="hljs-keyword">from</span> langchain.text_splitter <span class="hljs-keyword">import</span> RecursiveCharacterTextSplitter
<span class="hljs-keyword">from</span> langchain.vectorstores <span class="hljs-keyword">import</span> FAISS
<span class="hljs-keyword">from</span> langchain_community.embeddings <span class="hljs-keyword">import</span> HuggingFaceEmbeddings

source_docs = [
    Document(page_content=doc[<span class="hljs-string">&quot;text&quot;</span>], metadata={<span class="hljs-string">&quot;source&quot;</span>: doc[<span class="hljs-string">&quot;source&quot;</span>].split(<span class="hljs-string">&quot;/&quot;</span>)[<span class="hljs-number">1</span>]})
    <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> knowledge_base
]

docs_processed = RecursiveCharacterTextSplitter(chunk_size=<span class="hljs-number">500</span>).split_documents(
    source_docs
)[:<span class="hljs-number">1000</span>]

embedding_model = HuggingFaceEmbeddings(model_name=<span class="hljs-string">&quot;thenlper/gte-small&quot;</span>)
vectordb = FAISS.from_documents(documents=docs_processed, embedding=embedding_model)`,wrap:!1}}),L=new U({props:{code:"YWxsX3NvdXJjZXMlMjAlM0QlMjBsaXN0KHNldCglNUJkb2MubWV0YWRhdGElNUIlMjJzb3VyY2UlMjIlNUQlMjBmb3IlMjBkb2MlMjBpbiUyMGRvY3NfcHJvY2Vzc2VkJTVEKSklMEFwcmludChhbGxfc291cmNlcyk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>all_sources = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">set</span>([doc.metadata[<span class="hljs-string">&quot;source&quot;</span>] <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> docs_processed]))
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(all_sources)`,wrap:!1}}),D=new U({props:{code:" ",highlighted:`<span class="hljs-keyword">import</span> json
<span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> Tool
<span class="hljs-keyword">from</span> langchain_core.vectorstores <span class="hljs-keyword">import</span> VectorStore


<span class="hljs-keyword">class</span> <span class="hljs-title class_">RetrieverTool</span>(<span class="hljs-title class_ inherited__">Tool</span>):
    name = <span class="hljs-string">&quot;retriever&quot;</span>
    description = <span class="hljs-string">&quot;Retrieves some documents from the knowledge base that have the closest embeddings to the input query.&quot;</span>
    inputs = {
        <span class="hljs-string">&quot;query&quot;</span>: {
            <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;text&quot;</span>,
            <span class="hljs-string">&quot;description&quot;</span>: <span class="hljs-string">&quot;The query to perform. This should be semantically close to your target documents. Use the affirmative form rather than a question.&quot;</span>,
        },
        <span class="hljs-string">&quot;source&quot;</span>: {<span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;text&quot;</span>, <span class="hljs-string">&quot;description&quot;</span>: <span class="hljs-string">&quot;&quot;</span>},
        <span class="hljs-string">&quot;number_of_documents&quot;</span>: {
            <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;text&quot;</span>,
            <span class="hljs-string">&quot;description&quot;</span>: <span class="hljs-string">&quot;the number of documents to retrieve. Stay under 10 to avoid drowning in docs&quot;</span>,
        },
    }
    output_type = <span class="hljs-string">&quot;text&quot;</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, vectordb: VectorStore, all_sources: <span class="hljs-built_in">str</span>, **kwargs</span>):
        <span class="hljs-built_in">super</span>().__init__(**kwargs)
        self.vectordb = vectordb
        self.inputs[<span class="hljs-string">&quot;source&quot;</span>][
            <span class="hljs-string">&quot;description&quot;</span>
        ] = <span class="hljs-string">f&quot;The source of the documents to search, as a str representation of a list. Possible values in the list are: <span class="hljs-subst">{all_sources}</span>. If this argument is not provided, all sources will be searched.&quot;</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, query: <span class="hljs-built_in">str</span>, source: <span class="hljs-built_in">str</span> = <span class="hljs-literal">None</span>, number_of_documents=<span class="hljs-number">7</span></span>) -&gt; <span class="hljs-built_in">str</span>:
        <span class="hljs-keyword">assert</span> <span class="hljs-built_in">isinstance</span>(query, <span class="hljs-built_in">str</span>), <span class="hljs-string">&quot;Your search query must be a string&quot;</span>
        number_of_documents = <span class="hljs-built_in">int</span>(number_of_documents)

        <span class="hljs-keyword">if</span> source:
            <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(source, <span class="hljs-built_in">str</span>) <span class="hljs-keyword">and</span> <span class="hljs-string">&quot;[&quot;</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> <span class="hljs-built_in">str</span>(
                source
            ):  <span class="hljs-comment"># if the source is not representing a list</span>
                source = [source]
            source = json.loads(<span class="hljs-built_in">str</span>(source).replace(<span class="hljs-string">&quot;&#x27;&quot;</span>, <span class="hljs-string">&#x27;&quot;&#x27;</span>))

        docs = self.vectordb.similarity_search(
            query,
            <span class="hljs-built_in">filter</span>=({<span class="hljs-string">&quot;source&quot;</span>: source} <span class="hljs-keyword">if</span> source <span class="hljs-keyword">else</span> <span class="hljs-literal">None</span>),
            k=number_of_documents,
        )

        <span class="hljs-keyword">if</span> <span class="hljs-built_in">len</span>(docs) == <span class="hljs-number">0</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;No documents found with this filtering. Try removing the source filter.&quot;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;Retrieved documents:\\n\\n&quot;</span> + <span class="hljs-string">&quot;\\n===Document===\\n&quot;</span>.join(
            [doc.page_content <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> docs]
        )`,wrap:!1}}),K=new u({props:{title:"可选：将你的检索器工具分享到 Hub",local:"可选将你的检索器工具分享到-hub",headingTag:"h3"}}),se=new U({props:{code:"c2hhcmVfdG9faHViJTIwJTNEJTIwRmFsc2UlMEElMEFpZiUyMHNoYXJlX3RvX2h1YiUzQSUwQSUyMCUyMCUyMCUyMGZyb20lMjBodWdnaW5nZmFjZV9odWIlMjBpbXBvcnQlMjBsb2dpbiUwQSUyMCUyMCUyMCUyMGZyb20lMjByZXRyaWV2ZXIlMjBpbXBvcnQlMjBSZXRyaWV2ZXJUb29sJTBBJTBBJTIwJTIwJTIwJTIwbG9naW4oJTIyeW91cl90b2tlbiUyMiklMEElMEElMjAlMjAlMjAlMjB0b29sJTIwJTNEJTIwUmV0cmlldmVyVG9vbCh2ZWN0b3JkYiUyQyUyMGFsbF9zb3VyY2VzKSUwQSUwQSUyMCUyMCUyMCUyMHRvb2wucHVzaF90b19odWIocmVwb19pZCUzRCUyMm0tcmljJTJGcmV0cmlldmVyLXRvb2wlMjIp",highlighted:`share_to_hub = <span class="hljs-literal">False</span>

<span class="hljs-keyword">if</span> share_to_hub:
    <span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> login
    <span class="hljs-keyword">from</span> retriever <span class="hljs-keyword">import</span> RetrieverTool

    login(<span class="hljs-string">&quot;your_token&quot;</span>)

    tool = RetrieverTool(vectordb, all_sources)

    tool.push_to_hub(repo_id=<span class="hljs-string">&quot;m-ric/retriever-tool&quot;</span>)`,wrap:!1}}),te=new u({props:{title:"运行智能体!",local:"运行智能体",headingTag:"h3"}}),le=new U({props:{code:"ZnJvbSUyMHNtb2xhZ2VudHMlMjBpbXBvcnQlMjBIZk1vZGVsJTJDJTIwVG9vbENhbGxpbmdBZ2VudCUyQyUyMGxvYWRfdG9vbCUwQSUwQW1vZGVsJTIwJTNEJTIwSGZNb2RlbCglMjJtZXRhLWxsYW1hJTJGTWV0YS1MbGFtYS0zLTcwQi1JbnN0cnVjdCUyMiklMEElMEFyZXRyaWV2ZXJfdG9vbCUyMCUzRCUyMGxvYWRfdG9vbCglMEElMjAlMjAlMjAlMjAlMjJtLXJpYyUyRnJldHJpZXZlci10b29sJTIyJTJDJTIwdmVjdG9yZGIlM0R2ZWN0b3JkYiUyQyUyMGFsbF9zb3VyY2VzJTNEYWxsX3NvdXJjZXMlMEEpJTBBYWdlbnQlMjAlM0QlMjBUb29sQ2FsbGluZ0FnZW50KHRvb2xzJTNEJTVCcmV0cmlldmVyX3Rvb2wlNUQlMkMlMjBtb2RlbCUzRG1vZGVsJTJDJTIwdmVyYm9zZSUzRDApJTBBJTBBYWdlbnRfb3V0cHV0JTIwJTNEJTIwYWdlbnQucnVuKCUyMlBsZWFzZSUyMHNob3clMjBtZSUyMGElMjBMT1JBJTIwZmluZXR1bmluZyUyMHNjcmlwdCUyMiklMEElMEFwcmludCglMjJGaW5hbCUyMG91dHB1dCUzQSUyMiklMEFwcmludChhZ2VudF9vdXRwdXQp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> HfModel, ToolCallingAgent, load_tool

<span class="hljs-meta">&gt;&gt;&gt; </span>model = HfModel(<span class="hljs-string">&quot;meta-llama/Meta-Llama-3-70B-Instruct&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>retriever_tool = load_tool(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;m-ric/retriever-tool&quot;</span>, vectordb=vectordb, all_sources=all_sources
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>agent = ToolCallingAgent(tools=[retriever_tool], model=model, verbose=<span class="hljs-number">0</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>agent_output = agent.run(<span class="hljs-string">&quot;Please show me a LORA finetuning script&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Final output:&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(agent_output)`,wrap:!1}}),pe=new u({props:{title:"3. 💻 调试 Python 代码",local:"3--调试-python-代码",headingTag:"h2"}}),ye=new U({props:{code:"ZnJvbSUyMHNtb2xhZ2VudHMlMjBpbXBvcnQlMjBDb2RlQWdlbnQlMEElMEFhZ2VudCUyMCUzRCUyMENvZGVBZ2VudCh0b29scyUzRCU1QiU1RCklMEElMEFjb2RlJTIwJTNEJTIwJTIyJTIyJTIyJTBBbGlzdCUzRCU1QjAlMkMlMjAxJTJDJTIwMiU1RCUwQSUwQWZvciUyMGklMjBpbiUyMHJhbmdlKDQpJTNBJTBBJTIwJTIwJTIwJTIwcHJpbnQobGlzdChpKSklMEElMjIlMjIlMjIlMEElMEFmaW5hbF9hbnN3ZXIlMjAlM0QlMjBhZ2VudC5ydW4oJTBBJTIwJTIwJTIwJTIwJTIySSUyMGhhdmUlMjBzb21lJTIwY29kZSUyMHRoYXQlMjBjcmVhdGVzJTIwYSUyMGJ1ZyUzQSUyMHBsZWFzZSUyMGRlYnVnJTIwaXQlMjBhbmQlMjByZXR1cm4lMjB0aGUlMjBmaW5hbCUyMGNvZGUlMjIlMkMlMEElMjAlMjAlMjAlMjBjb2RlJTNEY29kZSUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> CodeAgent

agent = CodeAgent(tools=[])

code = <span class="hljs-string">&quot;&quot;&quot;
list=[0, 1, 2]

for i in range(4):
    print(list(i))
&quot;&quot;&quot;</span>

final_answer = agent.run(
    <span class="hljs-string">&quot;I have some code that creates a bug: please debug it and return the final code&quot;</span>,
    code=code,
)`,wrap:!1}}),ce=new U({props:{code:"cHJpbnQoZmluYWxfYW5zd2VyKQ==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(final_answer)',wrap:!1}}),Ue=new u({props:{title:"4. 创建你自己的 LLM 引擎（OpenAI）",local:"4-创建你自己的-llm-引擎openai",headingTag:"h2"}}),je=new U({props:{code:"aW1wb3J0JTIwb3MlMEFmcm9tJTIwb3BlbmFpJTIwaW1wb3J0JTIwT3BlbkFJJTBBZnJvbSUyMHNtb2xhZ2VudHMubW9kZWwlMjBpbXBvcnQlMjBNZXNzYWdlUm9sZSUyQyUyMGdldF9jbGVhbl9tZXNzYWdlX2xpc3QlMEElMEFvcGVuYWlfcm9sZV9jb252ZXJzaW9ucyUyMCUzRCUyMCU3QiUwQSUyMCUyMCUyMCUyME1lc3NhZ2VSb2xlLlRPT0xfUkVTUE9OU0UlM0ElMjAlMjJ1c2VyJTIyJTJDJTBBJTdEJTBBJTBBJTBBY2xhc3MlMjBPcGVuQUlNb2RlbCUzQSUwQSUyMCUyMCUyMCUyMGRlZiUyMF9faW5pdF9fKHNlbGYlMkMlMjBtb2RlbF9uYW1lJTNEJTIyZ3B0LTRvLTIwMjQtMDUtMTMlMjIpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2VsZi5tb2RlbF9uYW1lJTIwJTNEJTIwbW9kZWxfbmFtZSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHNlbGYuY2xpZW50JTIwJTNEJTIwT3BlbkFJKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGFwaV9rZXklM0Rvcy5nZXRlbnYoJTIyT1BFTkFJX0FQSV9LRVklMjIpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUwQSUyMCUyMCUyMCUyMGRlZiUyMF9fY2FsbF9fKHNlbGYlMkMlMjBtZXNzYWdlcyUyQyUyMHN0b3Bfc2VxdWVuY2VzJTNEJTVCJTVEKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyMEdldCUyMGNsZWFuJTIwbWVzc2FnZSUyMGxpc3QlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBtZXNzYWdlcyUyMCUzRCUyMGdldF9jbGVhbl9tZXNzYWdlX2xpc3QoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWVzc2FnZXMlMkMlMjByb2xlX2NvbnZlcnNpb25zJTNEb3BlbmFpX3JvbGVfY29udmVyc2lvbnMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjApJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwR2V0JTIwTExNJTIwb3V0cHV0JTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmVzcG9uc2UlMjAlM0QlMjBzZWxmLmNsaWVudC5jaGF0LmNvbXBsZXRpb25zLmNyZWF0ZSglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBtb2RlbCUzRHNlbGYubW9kZWxfbmFtZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG1lc3NhZ2VzJTNEbWVzc2FnZXMlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBzdG9wJTNEc3RvcF9zZXF1ZW5jZXMlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmV0dXJuJTIwcmVzcG9uc2UuY2hvaWNlcyU1QjAlNUQubWVzc2FnZS5jb250ZW50JTBBJTBBJTBBb3BlbmFpX2VuZ2luZSUyMCUzRCUyME9wZW5BSU1vZGVsKCklMEFhZ2VudCUyMCUzRCUyMENvZGVBZ2VudChtb2RlbCUzRG9wZW5haV9lbmdpbmUlMkMlMjB0b29scyUzRCU1QiU1RCklMEElMEFjb2RlJTIwJTNEJTIwJTIyJTIyJTIyJTBBbGlzdCUzRCU1QjAlMkMlMjAxJTJDJTIwMiU1RCUwQSUwQWZvciUyMGklMjBpbiUyMHJhbmdlKDQpJTNBJTBBJTIwJTIwJTIwJTIwcHJpbnQobGlzdChpKSklMEElMjIlMjIlMjIlMEElMEFmaW5hbF9hbnN3ZXIlMjAlM0QlMjBhZ2VudC5ydW4oJTBBJTIwJTIwJTIwJTIwJTIySSUyMGhhdmUlMjBzb21lJTIwY29kZSUyMHRoYXQlMjBjcmVhdGVzJTIwYSUyMGJ1ZyUzQSUyMHBsZWFzZSUyMGRlYnVnJTIwaXQlMjBhbmQlMjByZXR1cm4lMjB0aGUlMjBmaW5hbCUyMGNvZGUlMjIlMkMlMEElMjAlMjAlMjAlMjBjb2RlJTNEY29kZSUyQyUwQSk=",highlighted:`<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">from</span> openai <span class="hljs-keyword">import</span> OpenAI
<span class="hljs-keyword">from</span> smolagents.model <span class="hljs-keyword">import</span> MessageRole, get_clean_message_list

openai_role_conversions = {
    MessageRole.TOOL_RESPONSE: <span class="hljs-string">&quot;user&quot;</span>,
}


<span class="hljs-keyword">class</span> <span class="hljs-title class_">OpenAIModel</span>:
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, model_name=<span class="hljs-string">&quot;gpt-4o-2024-05-13&quot;</span></span>):
        self.model_name = model_name
        self.client = OpenAI(
            api_key=os.getenv(<span class="hljs-string">&quot;OPENAI_API_KEY&quot;</span>),
        )

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__call__</span>(<span class="hljs-params">self, messages, stop_sequences=[]</span>):
        <span class="hljs-comment"># Get clean message list</span>
        messages = get_clean_message_list(
            messages, role_conversions=openai_role_conversions
        )

        <span class="hljs-comment"># Get LLM output</span>
        response = self.client.chat.completions.create(
            model=self.model_name,
            messages=messages,
            stop=stop_sequences,
        )
        <span class="hljs-keyword">return</span> response.choices[<span class="hljs-number">0</span>].message.content


openai_engine = OpenAIModel()
agent = CodeAgent(model=openai_engine, tools=[])

code = <span class="hljs-string">&quot;&quot;&quot;
list=[0, 1, 2]

for i in range(4):
    print(list(i))
&quot;&quot;&quot;</span>

final_answer = agent.run(
    <span class="hljs-string">&quot;I have some code that creates a bug: please debug it and return the final code&quot;</span>,
    code=code,
)`,wrap:!1}}),be=new U({props:{code:"cHJpbnQoZmluYWxfYW5zd2VyKQ==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(final_answer)',wrap:!1}}),we=new u({props:{title:"➡️ 结论",local:"-结论",headingTag:"h2"}}),Ie=new At({props:{source:"https://github.com/huggingface/cookbook/blob/main/notebooks/zh-CN/agents.md"}}),{c(){J=i("meta"),ke=n(),Ce=i("p"),Re=n(),p(j.$$.fragment),Be=n(),p(b.$$.fragment),Ze=n(),p(T.$$.fragment),Ge=n(),w=i("p"),w.innerHTML=Ns,qe=n(),f=i("p"),f.innerHTML=Qs,Ve=n(),g=i("p"),g.innerHTML=Xs,Ae=n(),h=i("p"),h.innerHTML=zs,_e=n(),I=i("p"),I.innerHTML=xs,Ee=n(),C=i("p"),C.textContent=Ss,We=n(),v=i("p"),v.innerHTML=Ys,$e=n(),p(k.$$.fragment),Ne=n(),R=i("pre"),R.textContent=Hs,Qe=n(),p(B.$$.fragment),Xe=n(),p(Z.$$.fragment),ze=n(),G=i("p"),G.textContent=Fs,xe=n(),q=i("p"),q.textContent=Ls,Se=n(),V=i("ul"),V.innerHTML=Ps,Ye=n(),p(A.$$.fragment),He=n(),_=i("p"),_.innerHTML=Ds,Fe=n(),p(E.$$.fragment),Le=n(),W=i("p"),W.innerHTML=Ks,Pe=n(),$=i("p"),$.textContent=Os,De=n(),N=i("ul"),N.innerHTML=et,Ke=n(),Q=i("p"),Q.innerHTML=st,Oe=n(),X=i("p"),X.innerHTML=tt,es=n(),p(z.$$.fragment),ss=n(),x=i("p"),x.textContent=lt,ts=n(),p(S.$$.fragment),ls=n(),Y=i("p"),Y.textContent=nt,ns=n(),H=i("p"),H.textContent=at,as=n(),F=i("p"),F.textContent=it,is=n(),p(L.$$.fragment),rs=n(),P=i("pre"),P.textContent=rt,os=n(),p(D.$$.fragment),ps=n(),p(K.$$.fragment),ys=n(),O=i("p"),O.innerHTML=ot,Ms=n(),ee=i("p"),ee.innerHTML=pt,ms=n(),p(se.$$.fragment),cs=n(),p(te.$$.fragment),ds=n(),p(le.$$.fragment),Us=n(),ne=i("pre"),ne.textContent=yt,Js=n(),ae=i("p"),ae.innerHTML=Mt,us=n(),ie=i("p"),ie.textContent=mt,js=n(),re=i("p"),re.textContent=ct,bs=n(),oe=i("p"),oe.innerHTML=dt,Ts=n(),p(pe.$$.fragment),ws=n(),p(ye.$$.fragment),fs=n(),Me=i("p"),Me.textContent=Ut,gs=n(),me=i("p"),me.textContent=Jt,hs=n(),p(ce.$$.fragment),Is=n(),de=i("pre"),de.textContent=ut,Cs=n(),p(Ue.$$.fragment),vs=n(),Je=i("p"),Je.innerHTML=jt,ks=n(),ue=i("ol"),ue.innerHTML=bt,Rs=n(),p(je.$$.fragment),Bs=n(),p(be.$$.fragment),Zs=n(),Te=i("pre"),Te.textContent=Tt,Gs=n(),p(we.$$.fragment),qs=n(),fe=i("p"),fe.textContent=wt,Vs=n(),ge=i("p"),ge.innerHTML=ft,As=n(),he=i("p"),he.textContent=gt,_s=n(),p(Ie.$$.fragment),Es=n(),ve=i("p"),this.h()},l(e){const s=Zt("svelte-u9bgzb",document.head);J=r(s,"META",{name:!0,content:!0}),s.forEach(t),ke=a(e),Ce=r(e,"P",{}),ht(Ce).forEach(t),Re=a(e),y(j.$$.fragment,e),Be=a(e),y(b.$$.fragment,e),Ze=a(e),y(T.$$.fragment,e),Ge=a(e),w=r(e,"P",{"data-svelte-h":!0}),o(w)!=="svelte-1ouqjzx"&&(w.innerHTML=Ns),qe=a(e),f=r(e,"P",{"data-svelte-h":!0}),o(f)!=="svelte-1aj2n89"&&(f.innerHTML=Qs),Ve=a(e),g=r(e,"P",{"data-svelte-h":!0}),o(g)!=="svelte-1krmqaz"&&(g.innerHTML=Xs),Ae=a(e),h=r(e,"P",{"data-svelte-h":!0}),o(h)!=="svelte-adzud6"&&(h.innerHTML=zs),_e=a(e),I=r(e,"P",{"data-svelte-h":!0}),o(I)!=="svelte-4p8oo0"&&(I.innerHTML=xs),Ee=a(e),C=r(e,"P",{"data-svelte-h":!0}),o(C)!=="svelte-coem00"&&(C.textContent=Ss),We=a(e),v=r(e,"P",{"data-svelte-h":!0}),o(v)!=="svelte-v3xboo"&&(v.innerHTML=Ys),$e=a(e),y(k.$$.fragment,e),Ne=a(e),R=r(e,"PRE",{"data-svelte-h":!0}),o(R)!=="svelte-1wz9bju"&&(R.textContent=Hs),Qe=a(e),y(B.$$.fragment,e),Xe=a(e),y(Z.$$.fragment,e),ze=a(e),G=r(e,"P",{"data-svelte-h":!0}),o(G)!=="svelte-kkdqgb"&&(G.textContent=Fs),xe=a(e),q=r(e,"P",{"data-svelte-h":!0}),o(q)!=="svelte-1gjy54v"&&(q.textContent=Ls),Se=a(e),V=r(e,"UL",{"data-svelte-h":!0}),o(V)!=="svelte-19kqik7"&&(V.innerHTML=Ps),Ye=a(e),y(A.$$.fragment,e),He=a(e),_=r(e,"P",{"data-svelte-h":!0}),o(_)!=="svelte-1hg95q8"&&(_.innerHTML=Ds),Fe=a(e),y(E.$$.fragment,e),Le=a(e),W=r(e,"P",{"data-svelte-h":!0}),o(W)!=="svelte-na4ngx"&&(W.innerHTML=Ks),Pe=a(e),$=r(e,"P",{"data-svelte-h":!0}),o($)!=="svelte-80vjwa"&&($.textContent=Os),De=a(e),N=r(e,"UL",{"data-svelte-h":!0}),o(N)!=="svelte-1b72t5y"&&(N.innerHTML=et),Ke=a(e),Q=r(e,"P",{"data-svelte-h":!0}),o(Q)!=="svelte-kok7hx"&&(Q.innerHTML=st),Oe=a(e),X=r(e,"P",{"data-svelte-h":!0}),o(X)!=="svelte-1o7very"&&(X.innerHTML=tt),es=a(e),y(z.$$.fragment,e),ss=a(e),x=r(e,"P",{"data-svelte-h":!0}),o(x)!=="svelte-1maw09u"&&(x.textContent=lt),ts=a(e),y(S.$$.fragment,e),ls=a(e),Y=r(e,"P",{"data-svelte-h":!0}),o(Y)!=="svelte-18cve4f"&&(Y.textContent=nt),ns=a(e),H=r(e,"P",{"data-svelte-h":!0}),o(H)!=="svelte-1uorx1q"&&(H.textContent=at),as=a(e),F=r(e,"P",{"data-svelte-h":!0}),o(F)!=="svelte-152zwsq"&&(F.textContent=it),is=a(e),y(L.$$.fragment,e),rs=a(e),P=r(e,"PRE",{"data-svelte-h":!0}),o(P)!=="svelte-87x3d8"&&(P.textContent=rt),os=a(e),y(D.$$.fragment,e),ps=a(e),y(K.$$.fragment,e),ys=a(e),O=r(e,"P",{"data-svelte-h":!0}),o(O)!=="svelte-shnfcu"&&(O.innerHTML=ot),Ms=a(e),ee=r(e,"P",{"data-svelte-h":!0}),o(ee)!=="svelte-1f95672"&&(ee.innerHTML=pt),ms=a(e),y(se.$$.fragment,e),cs=a(e),y(te.$$.fragment,e),ds=a(e),y(le.$$.fragment,e),Us=a(e),ne=r(e,"PRE",{"data-svelte-h":!0}),o(ne)!=="svelte-l44zt6"&&(ne.textContent=yt),Js=a(e),ae=r(e,"P",{"data-svelte-h":!0}),o(ae)!=="svelte-1p0xa06"&&(ae.innerHTML=Mt),us=a(e),ie=r(e,"P",{"data-svelte-h":!0}),o(ie)!=="svelte-lx9k8m"&&(ie.textContent=mt),js=a(e),re=r(e,"P",{"data-svelte-h":!0}),o(re)!=="svelte-ukynxq"&&(re.textContent=ct),bs=a(e),oe=r(e,"P",{"data-svelte-h":!0}),o(oe)!=="svelte-b42cxp"&&(oe.innerHTML=dt),Ts=a(e),y(pe.$$.fragment,e),ws=a(e),y(ye.$$.fragment,e),fs=a(e),Me=r(e,"P",{"data-svelte-h":!0}),o(Me)!=="svelte-exzkfa"&&(Me.textContent=Ut),gs=a(e),me=r(e,"P",{"data-svelte-h":!0}),o(me)!=="svelte-yhuzec"&&(me.textContent=Jt),hs=a(e),y(ce.$$.fragment,e),Is=a(e),de=r(e,"PRE",{"data-svelte-h":!0}),o(de)!=="svelte-1t45l4d"&&(de.textContent=ut),Cs=a(e),y(Ue.$$.fragment,e),vs=a(e),Je=r(e,"P",{"data-svelte-h":!0}),o(Je)!=="svelte-1keb31l"&&(Je.innerHTML=jt),ks=a(e),ue=r(e,"OL",{"data-svelte-h":!0}),o(ue)!=="svelte-vma4hg"&&(ue.innerHTML=bt),Rs=a(e),y(je.$$.fragment,e),Bs=a(e),y(be.$$.fragment,e),Zs=a(e),Te=r(e,"PRE",{"data-svelte-h":!0}),o(Te)!=="svelte-tgqz6q"&&(Te.textContent=Tt),Gs=a(e),y(we.$$.fragment,e),qs=a(e),fe=r(e,"P",{"data-svelte-h":!0}),o(fe)!=="svelte-9ugofh"&&(fe.textContent=wt),Vs=a(e),ge=r(e,"P",{"data-svelte-h":!0}),o(ge)!=="svelte-1852ggb"&&(ge.innerHTML=ft),As=a(e),he=r(e,"P",{"data-svelte-h":!0}),o(he)!=="svelte-w83c4h"&&(he.textContent=gt),_s=a(e),y(Ie.$$.fragment,e),Es=a(e),ve=r(e,"P",{}),ht(ve).forEach(t),this.h()},h(){It(J,"name","hf:doc:metadata"),It(J,"content",Et)},m(e,s){Gt(document.head,J),l(e,ke,s),l(e,Ce,s),l(e,Re,s),M(j,e,s),l(e,Be,s),M(b,e,s),l(e,Ze,s),M(T,e,s),l(e,Ge,s),l(e,w,s),l(e,qe,s),l(e,f,s),l(e,Ve,s),l(e,g,s),l(e,Ae,s),l(e,h,s),l(e,_e,s),l(e,I,s),l(e,Ee,s),l(e,C,s),l(e,We,s),l(e,v,s),l(e,$e,s),M(k,e,s),l(e,Ne,s),l(e,R,s),l(e,Qe,s),M(B,e,s),l(e,Xe,s),M(Z,e,s),l(e,ze,s),l(e,G,s),l(e,xe,s),l(e,q,s),l(e,Se,s),l(e,V,s),l(e,Ye,s),M(A,e,s),l(e,He,s),l(e,_,s),l(e,Fe,s),M(E,e,s),l(e,Le,s),l(e,W,s),l(e,Pe,s),l(e,$,s),l(e,De,s),l(e,N,s),l(e,Ke,s),l(e,Q,s),l(e,Oe,s),l(e,X,s),l(e,es,s),M(z,e,s),l(e,ss,s),l(e,x,s),l(e,ts,s),M(S,e,s),l(e,ls,s),l(e,Y,s),l(e,ns,s),l(e,H,s),l(e,as,s),l(e,F,s),l(e,is,s),M(L,e,s),l(e,rs,s),l(e,P,s),l(e,os,s),M(D,e,s),l(e,ps,s),M(K,e,s),l(e,ys,s),l(e,O,s),l(e,Ms,s),l(e,ee,s),l(e,ms,s),M(se,e,s),l(e,cs,s),M(te,e,s),l(e,ds,s),M(le,e,s),l(e,Us,s),l(e,ne,s),l(e,Js,s),l(e,ae,s),l(e,us,s),l(e,ie,s),l(e,js,s),l(e,re,s),l(e,bs,s),l(e,oe,s),l(e,Ts,s),M(pe,e,s),l(e,ws,s),M(ye,e,s),l(e,fs,s),l(e,Me,s),l(e,gs,s),l(e,me,s),l(e,hs,s),M(ce,e,s),l(e,Is,s),l(e,de,s),l(e,Cs,s),M(Ue,e,s),l(e,vs,s),l(e,Je,s),l(e,ks,s),l(e,ue,s),l(e,Rs,s),M(je,e,s),l(e,Bs,s),M(be,e,s),l(e,Zs,s),l(e,Te,s),l(e,Gs,s),M(we,e,s),l(e,qs,s),l(e,fe,s),l(e,Vs,s),l(e,ge,s),l(e,As,s),l(e,he,s),l(e,_s,s),M(Ie,e,s),l(e,Es,s),l(e,ve,s),Ws=!0},p:vt,i(e){Ws||(m(j.$$.fragment,e),m(b.$$.fragment,e),m(T.$$.fragment,e),m(k.$$.fragment,e),m(B.$$.fragment,e),m(Z.$$.fragment,e),m(A.$$.fragment,e),m(E.$$.fragment,e),m(z.$$.fragment,e),m(S.$$.fragment,e),m(L.$$.fragment,e),m(D.$$.fragment,e),m(K.$$.fragment,e),m(se.$$.fragment,e),m(te.$$.fragment,e),m(le.$$.fragment,e),m(pe.$$.fragment,e),m(ye.$$.fragment,e),m(ce.$$.fragment,e),m(Ue.$$.fragment,e),m(je.$$.fragment,e),m(be.$$.fragment,e),m(we.$$.fragment,e),m(Ie.$$.fragment,e),Ws=!0)},o(e){c(j.$$.fragment,e),c(b.$$.fragment,e),c(T.$$.fragment,e),c(k.$$.fragment,e),c(B.$$.fragment,e),c(Z.$$.fragment,e),c(A.$$.fragment,e),c(E.$$.fragment,e),c(z.$$.fragment,e),c(S.$$.fragment,e),c(L.$$.fragment,e),c(D.$$.fragment,e),c(K.$$.fragment,e),c(se.$$.fragment,e),c(te.$$.fragment,e),c(le.$$.fragment,e),c(pe.$$.fragment,e),c(ye.$$.fragment,e),c(ce.$$.fragment,e),c(Ue.$$.fragment,e),c(je.$$.fragment,e),c(be.$$.fragment,e),c(we.$$.fragment,e),c(Ie.$$.fragment,e),Ws=!1},d(e){e&&(t(ke),t(Ce),t(Re),t(Be),t(Ze),t(Ge),t(w),t(qe),t(f),t(Ve),t(g),t(Ae),t(h),t(_e),t(I),t(Ee),t(C),t(We),t(v),t($e),t(Ne),t(R),t(Qe),t(Xe),t(ze),t(G),t(xe),t(q),t(Se),t(V),t(Ye),t(He),t(_),t(Fe),t(Le),t(W),t(Pe),t($),t(De),t(N),t(Ke),t(Q),t(Oe),t(X),t(es),t(ss),t(x),t(ts),t(ls),t(Y),t(ns),t(H),t(as),t(F),t(is),t(rs),t(P),t(os),t(ps),t(ys),t(O),t(Ms),t(ee),t(ms),t(cs),t(ds),t(Us),t(ne),t(Js),t(ae),t(us),t(ie),t(js),t(re),t(bs),t(oe),t(Ts),t(ws),t(fs),t(Me),t(gs),t(me),t(hs),t(Is),t(de),t(Cs),t(vs),t(Je),t(ks),t(ue),t(Rs),t(Bs),t(Zs),t(Te),t(Gs),t(qs),t(fe),t(Vs),t(ge),t(As),t(he),t(_s),t(Es),t(ve)),t(J),d(j,e),d(b,e),d(T,e),d(k,e),d(B,e),d(Z,e),d(A,e),d(E,e),d(z,e),d(S,e),d(L,e),d(D,e),d(K,e),d(se,e),d(te,e),d(le,e),d(pe,e),d(ye,e),d(ce,e),d(Ue,e),d(je,e),d(be,e),d(we,e),d(Ie,e)}}}const Et='{"title":"使用 Transformers Agents 构建具有工具调用超能力的智能体 🦸","local":"使用-transformers-agents-构建具有工具调用超能力的智能体-","sections":[{"title":"1. 🏞️ 多模态 + 🌐 网络浏览助手","local":"1--多模态---网络浏览助手","sections":[],"depth":2},{"title":"2. 📚💬 带有迭代查询优化和来源选择的 RAG","local":"2--带有迭代查询优化和来源选择的-rag","sections":[{"title":"可选：将你的检索器工具分享到 Hub","local":"可选将你的检索器工具分享到-hub","sections":[],"depth":3},{"title":"运行智能体!","local":"运行智能体","sections":[],"depth":3}],"depth":2},{"title":"3. 💻 调试 Python 代码","local":"3--调试-python-代码","sections":[],"depth":2},{"title":"4. 创建你自己的 LLM 引擎（OpenAI）","local":"4-创建你自己的-llm-引擎openai","sections":[],"depth":2},{"title":"➡️ 结论","local":"-结论","sections":[],"depth":2}],"depth":1}';function Wt($s){return kt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class xt extends Rt{constructor(J){super(),Bt(this,J,Wt,_t,Ct,{})}}export{xt as component};
