import{s as ml,a as pl,n as ul,o as bl}from"../chunks/scheduler.00b97157.js";import{S as dl,i as rl,e as a,s as n,c as M,h as cl,a as i,d as l,b as o,f as Ml,g as m,j as p,k as Ue,l as hl,m as s,n as u,t as b,o as d,p as r}from"../chunks/index.a7c1a7a1.js";import{C as fl,H as he,E as yl}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.4292aef9.js";import{C as c}from"../chunks/CodeBlock.afb4ac0c.js";import{D as Ul}from"../chunks/DocNotebookDropdown.eca57a73.js";function gl(vt){let h,we,ge,Je,U,je,g,Ce,T,ve,w,_t="在这里，我们将学习高级工具的使用。",_e,f,It='<p>如果你是构建 agent 的新手，请确保先阅读 <a href="../conceptual_guides/intro_agents">agent 介绍</a> 和 <a href="../guided_tour">smolagents 导览</a>。</p>',Ie,J,$t='<li><a href="#%E5%B7%A5%E5%85%B7">工具</a><ul><li><a href="#%E4%BB%80%E4%B9%88%E6%98%AF%E5%B7%A5%E5%85%B7%E5%A6%82%E4%BD%95%E6%9E%84%E5%BB%BA%E4%B8%80%E4%B8%AA%E5%B7%A5%E5%85%B7">什么是工具，如何构建一个工具？</a></li> <li><a href="#%E5%B0%86%E4%BD%A0%E7%9A%84%E5%B7%A5%E5%85%B7%E5%88%86%E4%BA%AB%E5%88%B0-hub">将你的工具分享到 Hub</a></li> <li><a href="#%E5%B0%86-space-%E5%AF%BC%E5%85%A5%E4%B8%BA%E5%B7%A5%E5%85%B7">将 Space 导入为工具</a></li> <li><a href="#%E4%BD%BF%E7%94%A8-langchain-%E5%B7%A5%E5%85%B7">使用 LangChain 工具</a></li> <li><a href="#%E7%AE%A1%E7%90%86%E4%BD%A0%E7%9A%84-agent-%E5%B7%A5%E5%85%B7%E7%AE%B1">管理你的 agent 工具箱</a></li> <li><a href="#%E4%BD%BF%E7%94%A8%E5%B7%A5%E5%85%B7%E9%9B%86%E5%90%88">使用工具集合</a></li></ul></li>',$e,j,Be,C,Bt="工具主要是 LLM 可以在 agent 系统中使用的函数。",Ze,v,Zt="但要使用它，LLM 需要被提供一个 API：名称、工具描述、输入类型和描述、输出类型。",Ge,_,Gt="所以它不能仅仅是一个函数。它应该是一个类。",He,I,Ht="因此，核心上，工具是一个类，它包装了一个函数，并带有帮助 LLM 理解如何使用它的元数据。",xe,$,xt="以下是它的结构：",Ee,B,We,Z,Et='自定义工具继承 <a href="/docs/smolagents/v1.22.0/zh/reference/tools#smolagents.Tool">Tool</a> 以继承有用的方法。子类还定义了：',ke,G,Wt='<li>一个属性 <code>name</code>，对应于工具本身的名称。名称通常描述工具的功能。由于代码返回任务中下载量最多的模型，我们将其命名为 <code>model_download_counter</code>。</li> <li>一个属性 <code>description</code>，用于填充 agent 的系统提示。</li> <li>一个 <code>inputs</code> 属性，它是一个带有键 <code>&quot;type&quot;</code> 和 <code>&quot;description&quot;</code> 的字典。它包含帮助 Python 解释器对输入做出明智选择的信息。</li> <li>一个 <code>output_type</code> 属性，指定输出类型。<code>inputs</code> 和 <code>output_type</code> 的类型应为 <a href="https://docs.pydantic.dev/latest/concepts/json_schema/#generating-json-schema" rel="nofollow">Pydantic 格式</a>，它们可以是以下之一：<code>~AUTHORIZED_TYPES()</code>。</li> <li>一个 <code>forward</code> 方法，包含要执行的推理代码。</li>',Re,H,kt="这就是它在 agent 中使用所需的全部内容！",Qe,x,Rt='还有另一种构建工具的方法。在 <a href="../guided_tour">guided_tour</a> 中，我们使用 <code>@tool</code> 装饰器实现了一个工具。<a href="/docs/smolagents/v1.22.0/zh/reference/tools#smolagents.tool">tool()</a> 装饰器是定义简单工具的推荐方式，但有时你需要更多：在类中使用多个方法以获得更清晰的代码，或使用额外的类属性。',Ae,E,Qt='在这种情况下，你可以通过如上所述继承 <a href="/docs/smolagents/v1.22.0/zh/reference/tools#smolagents.Tool">Tool</a> 来构建你的工具。',Ve,W,Se,k,At='你可以通过调用 <a href="/docs/smolagents/v1.22.0/zh/reference/tools#smolagents.Tool.push_to_hub">push_to_hub()</a> 将你的自定义工具分享到 Hub。确保你已经在 Hub 上为其创建了一个仓库，并且使用的是具有读取权限的 token。',Le,R,Ne,Q,Vt="为了使推送到 Hub 正常工作，你的工具需要遵守一些规则：",ze,A,St='<li>所有方法都是自包含的，例如使用来自其参数中的变量。</li> <li>根据上述要点，<strong>所有导入应直接在工具的函数中定义</strong>，否则在尝试使用 <a href="/docs/smolagents/v1.22.0/zh/reference/tools#smolagents.Tool.save">save()</a> 或 <a href="/docs/smolagents/v1.22.0/zh/reference/tools#smolagents.Tool.push_to_hub">push_to_hub()</a> 调用你的自定义工具时会出现错误。</li> <li>如果你继承了 <code>__init__</code> 方法，除了 <code>self</code> 之外，你不能给它任何其他参数。这是因为在特定工具实例初始化期间设置的参数很难跟踪，这阻碍了将它们正确分享到 Hub。无论如何，创建特定类的想法是你已经可以为任何需要硬编码的内容设置类属性（只需在 <code>class YourTool(Tool):</code> 行下直接设置 <code>your_variable=(...)</code>）。当然，你仍然可以通过将内容分配给 <code>self.your_variable</code> 在代码中的任何地方创建类属性。</li>',qe,V,Lt='一旦你的工具被推送到 Hub，你就可以查看它。<a href="https://huggingface.co/spaces/m-ric/hf-model-downloads" rel="nofollow">这里</a> 是我推送的 <code>model_downloads_tool</code>。它有一个漂亮的 gradio 界面。',Fe,S,Nt='在深入工具文件时，你可以发现所有工具的逻辑都在 <a href="https://huggingface.co/spaces/m-ric/hf-model-downloads/blob/main/tool.py" rel="nofollow">tool.py</a> 下。这是你可以检查其他人分享的工具的地方。',Ye,L,zt=`然后你可以使用 <a href="/docs/smolagents/v1.22.0/zh/reference/tools#smolagents.load_tool">load_tool()</a> 加载工具或使用 <a href="/docs/smolagents/v1.22.0/zh/reference/tools#smolagents.Tool.from_hub">from_hub()</a> 创建它，并将其传递给 agent 中的 <code>tools</code> 参数。
由于运行工具意味着运行自定义代码，你需要确保你信任该仓库，因此我们需要传递 <code>trust_remote_code=True</code> 来从 Hub 加载工具。`,Xe,N,Pe,z,De,q,qt='你可以使用 <a href="/docs/smolagents/v1.22.0/zh/reference/tools#smolagents.Tool.from_space">Tool.from_space()</a> 方法直接从 Hub 导入一个 Space 作为工具！',Ke,F,Ft='你只需要提供 Hub 上 Space 的 id、它的名称和一个帮助你的 agent 理解工具功能的描述。在底层，这将使用 <a href="https://pypi.org/project/gradio-client/" rel="nofollow"><code>gradio-client</code></a> 库来调用 Space。',Oe,Y,Yt='例如，让我们从 Hub 导入 <a href="https://huggingface.co/black-forest-labs/FLUX.1-dev" rel="nofollow">FLUX.1-dev</a> Space 并使用它生成一张图片。',et,X,tt,P,Xt="瞧，这是你的图片！🏖️",lt,fe,Pt,st,D,Dt="然后你可以像使用任何其他工具一样使用这个工具。例如，让我们改进提示 <code>A rabbit wearing a space suit</code> 并生成它的图片。",nt,K,ot,O,at,ye,Kt,it,ee,Ot="这得有多酷？🤩",pt,te,Mt,le,el=`我们喜欢 Langchain，并认为它有一套非常吸引人的工具。
要从 LangChain 导入工具，请使用 <code>from_langchain()</code> 方法。`,mt,se,tl=`以下是如何使用它来重现介绍中的搜索结果，使用 LangChain 的 web 搜索工具。
这个工具需要 <code>pip install langchain google-search-results -q</code> 才能正常工作。`,ut,ne,bt,oe,dt,ae,ll="你可以通过添加或替换工具来管理 agent 的工具箱。",rt,ie,sl="让我们将 <code>model_download_tool</code> 添加到一个仅使用默认工具箱初始化的现有 agent 中。",ct,pe,ht,Me,nl="现在我们可以利用新工具：",ft,me,yt,y,ol="<p>注意不要向 agent 添加太多工具：这可能会让较弱的 LLM 引擎不堪重负。</p>",Ut,ue,gt,be,al=`你可以通过使用 ToolCollection 对象来利用工具集合，使用你想要使用的集合的 slug。
然后将它们作为列表传递给 agent 初始化，并开始使用它们！`,Tt,de,wt,re,il="为了加快启动速度，工具仅在 agent 调用时加载。",Jt,ce,jt,Te,Ct;return U=new fl({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),g=new he({props:{title:"工具",local:"工具",headingTag:"h1"}}),T=new Ul({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/smolagents_doc/zh/tools.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/smolagents_doc/zh/pytorch/tools.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/smolagents_doc/zh/tensorflow/tools.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/smolagents_doc/zh/tools.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/smolagents_doc/zh/pytorch/tools.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/smolagents_doc/zh/tensorflow/tools.ipynb"}]}}),j=new he({props:{title:"什么是工具，如何构建一个工具？",local:"什么是工具如何构建一个工具",headingTag:"h3"}}),B=new c({props:{code:"ZnJvbSUyMHNtb2xhZ2VudHMlMjBpbXBvcnQlMjBUb29sJTBBJTBBY2xhc3MlMjBIRk1vZGVsRG93bmxvYWRzVG9vbChUb29sKSUzQSUwQSUyMCUyMCUyMCUyMG5hbWUlMjAlM0QlMjAlMjJtb2RlbF9kb3dubG9hZF9jb3VudGVyJTIyJTBBJTIwJTIwJTIwJTIwZGVzY3JpcHRpb24lMjAlM0QlMjAlMjIlMjIlMjIlMEElMjAlMjAlMjAlMjBUaGlzJTIwaXMlMjBhJTIwdG9vbCUyMHRoYXQlMjByZXR1cm5zJTIwdGhlJTIwbW9zdCUyMGRvd25sb2FkZWQlMjBtb2RlbCUyMG9mJTIwYSUyMGdpdmVuJTIwdGFzayUyMG9uJTIwdGhlJTIwSHVnZ2luZyUyMEZhY2UlMjBIdWIuJTBBJTIwJTIwJTIwJTIwSXQlMjByZXR1cm5zJTIwdGhlJTIwbmFtZSUyMG9mJTIwdGhlJTIwY2hlY2twb2ludC4lMjIlMjIlMjIlMEElMjAlMjAlMjAlMjBpbnB1dHMlMjAlM0QlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ0YXNrJTIyJTNBJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydHlwZSUyMiUzQSUyMCUyMnN0cmluZyUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmRlc2NyaXB0aW9uJTIyJTNBJTIwJTIydGhlJTIwdGFzayUyMGNhdGVnb3J5JTIwKHN1Y2glMjBhcyUyMHRleHQtY2xhc3NpZmljYXRpb24lMkMlMjBkZXB0aC1lc3RpbWF0aW9uJTJDJTIwZXRjKSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3RCUwQSUyMCUyMCUyMCUyMCU3RCUwQSUyMCUyMCUyMCUyMG91dHB1dF90eXBlJTIwJTNEJTIwJTIyc3RyaW5nJTIyJTBBJTBBJTIwJTIwJTIwJTIwZGVmJTIwZm9yd2FyZChzZWxmJTJDJTIwdGFzayUzQSUyMHN0ciklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmcm9tJTIwaHVnZ2luZ2ZhY2VfaHViJTIwaW1wb3J0JTIwbGlzdF9tb2RlbHMlMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBtb2RlbCUyMCUzRCUyMG5leHQoaXRlcihsaXN0X21vZGVscyhmaWx0ZXIlM0R0YXNrJTJDJTIwc29ydCUzRCUyMmRvd25sb2FkcyUyMiUyQyUyMGRpcmVjdGlvbiUzRC0xKSkpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmV0dXJuJTIwbW9kZWwuaWQlMEElMEFtb2RlbF9kb3dubG9hZHNfdG9vbCUyMCUzRCUyMEhGTW9kZWxEb3dubG9hZHNUb29sKCk=",highlighted:`<span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> Tool

<span class="hljs-keyword">class</span> <span class="hljs-title class_">HFModelDownloadsTool</span>(<span class="hljs-title class_ inherited__">Tool</span>):
    name = <span class="hljs-string">&quot;model_download_counter&quot;</span>
    description = <span class="hljs-string">&quot;&quot;&quot;
    This is a tool that returns the most downloaded model of a given task on the Hugging Face Hub.
    It returns the name of the checkpoint.&quot;&quot;&quot;</span>
    inputs = {
        <span class="hljs-string">&quot;task&quot;</span>: {
            <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;string&quot;</span>,
            <span class="hljs-string">&quot;description&quot;</span>: <span class="hljs-string">&quot;the task category (such as text-classification, depth-estimation, etc)&quot;</span>,
        }
    }
    output_type = <span class="hljs-string">&quot;string&quot;</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, task: <span class="hljs-built_in">str</span></span>):
        <span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> list_models

        model = <span class="hljs-built_in">next</span>(<span class="hljs-built_in">iter</span>(list_models(<span class="hljs-built_in">filter</span>=task, sort=<span class="hljs-string">&quot;downloads&quot;</span>, direction=-<span class="hljs-number">1</span>)))
        <span class="hljs-keyword">return</span> model.<span class="hljs-built_in">id</span>

model_downloads_tool = HFModelDownloadsTool()`,wrap:!1}}),W=new he({props:{title:"将你的工具分享到 Hub",local:"将你的工具分享到-hub",headingTag:"h3"}}),R=new c({props:{code:"bW9kZWxfZG93bmxvYWRzX3Rvb2wucHVzaF90b19odWIoJTIyJTdCeW91cl91c2VybmFtZSU3RCUyRmhmLW1vZGVsLWRvd25sb2FkcyUyMiUyQyUyMHRva2VuJTNEJTIyJTNDWU9VUl9IVUdHSU5HRkFDRUhVQl9BUElfVE9LRU4lM0UlMjIp",highlighted:'model_downloads_tool.push_to_hub(<span class="hljs-string">&quot;{your_username}/hf-model-downloads&quot;</span>, token=<span class="hljs-string">&quot;&lt;YOUR_HUGGINGFACEHUB_API_TOKEN&gt;&quot;</span>)',wrap:!1}}),N=new c({props:{code:"ZnJvbSUyMHNtb2xhZ2VudHMlMjBpbXBvcnQlMjBsb2FkX3Rvb2wlMkMlMjBDb2RlQWdlbnQlMEElMEFtb2RlbF9kb3dubG9hZF90b29sJTIwJTNEJTIwbG9hZF90b29sKCUwQSUyMCUyMCUyMCUyMCUyMiU3QnlvdXJfdXNlcm5hbWUlN0QlMkZoZi1tb2RlbC1kb3dubG9hZHMlMjIlMkMlMEElMjAlMjAlMjAlMjB0cnVzdF9yZW1vdGVfY29kZSUzRFRydWUlMEEp",highlighted:`<span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> load_tool, CodeAgent

model_download_tool = load_tool(
    <span class="hljs-string">&quot;{your_username}/hf-model-downloads&quot;</span>,
    trust_remote_code=<span class="hljs-literal">True</span>
)`,wrap:!1}}),z=new he({props:{title:"将 Space 导入为工具",local:"将-space-导入为工具",headingTag:"h3"}}),X=new c({props:{code:"aW1hZ2VfZ2VuZXJhdGlvbl90b29sJTIwJTNEJTIwVG9vbC5mcm9tX3NwYWNlKCUwQSUyMCUyMCUyMCUyMCUyMmJsYWNrLWZvcmVzdC1sYWJzJTJGRkxVWC4xLXNjaG5lbGwlMjIlMkMlMEElMjAlMjAlMjAlMjBuYW1lJTNEJTIyaW1hZ2VfZ2VuZXJhdG9yJTIyJTJDJTBBJTIwJTIwJTIwJTIwZGVzY3JpcHRpb24lM0QlMjJHZW5lcmF0ZSUyMGFuJTIwaW1hZ2UlMjBmcm9tJTIwYSUyMHByb21wdCUyMiUwQSklMEElMEFpbWFnZV9nZW5lcmF0aW9uX3Rvb2woJTIyQSUyMHN1bm55JTIwYmVhY2glMjIp",highlighted:`image_generation_tool = Tool.from_space(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-schnell&quot;</span>,
    name=<span class="hljs-string">&quot;image_generator&quot;</span>,
    description=<span class="hljs-string">&quot;Generate an image from a prompt&quot;</span>
)

image_generation_tool(<span class="hljs-string">&quot;A sunny beach&quot;</span>)`,wrap:!1}}),K=new c({props:{code:"ZnJvbSUyMHNtb2xhZ2VudHMlMjBpbXBvcnQlMjBDb2RlQWdlbnQlMkMlMjBJbmZlcmVuY2VDbGllbnRNb2RlbCUwQSUwQW1vZGVsJTIwJTNEJTIwSW5mZXJlbmNlQ2xpZW50TW9kZWwobW9kZWxfaWQlM0QlMjJRd2VuJTJGUXdlbjIuNS1Db2Rlci0zMkItSW5zdHJ1Y3QlMjIpJTBBYWdlbnQlMjAlM0QlMjBDb2RlQWdlbnQodG9vbHMlM0QlNUJpbWFnZV9nZW5lcmF0aW9uX3Rvb2wlNUQlMkMlMjBtb2RlbCUzRG1vZGVsKSUwQSUwQWFnZW50LnJ1biglMEElMjAlMjAlMjAlMjAlMjJJbXByb3ZlJTIwdGhpcyUyMHByb21wdCUyQyUyMHRoZW4lMjBnZW5lcmF0ZSUyMGFuJTIwaW1hZ2UlMjBvZiUyMGl0LiUyMiUyQyUyMGFkZGl0aW9uYWxfYXJncyUzRCU3Qid1c2VyX3Byb21wdCclM0ElMjAnQSUyMHJhYmJpdCUyMHdlYXJpbmclMjBhJTIwc3BhY2UlMjBzdWl0JyU3RCUwQSk=",highlighted:`<span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> CodeAgent, InferenceClientModel

model = InferenceClientModel(model_id=<span class="hljs-string">&quot;Qwen/Qwen2.5-Coder-32B-Instruct&quot;</span>)
agent = CodeAgent(tools=[image_generation_tool], model=model)

agent.run(
    <span class="hljs-string">&quot;Improve this prompt, then generate an image of it.&quot;</span>, additional_args={<span class="hljs-string">&#x27;user_prompt&#x27;</span>: <span class="hljs-string">&#x27;A rabbit wearing a space suit&#x27;</span>}
)`,wrap:!1}}),O=new c({props:{code:"JTBBQWdlbnQlMjBpcyUyMGV4ZWN1dGluZyUyMHRoZSUyMGNvZGUlMjBiZWxvdyUzQQ==",highlighted:`=== Agent thoughts:
improved_prompt could be &quot;A bright blue space suit wearing rabbit, on the surface of the moon, under a bright orange sunset, with the Earth visible in the background&quot;

Now that I have improved the prompt, I can use the image generator tool to generate an image based on this prompt.
&gt;&gt;&gt; Agent is executing the code below:
image = image_generator(prompt=&quot;A bright blue space suit wearing rabbit, on the surface of the moon, under a bright orange sunset, with the Earth visible in the background&quot;)
final_answer(image)`,wrap:!1}}),te=new he({props:{title:"使用 LangChain 工具",local:"使用-langchain-工具",headingTag:"h3"}}),ne=new c({props:{code:"ZnJvbSUyMGxhbmdjaGFpbi5hZ2VudHMlMjBpbXBvcnQlMjBsb2FkX3Rvb2xzJTBBJTBBc2VhcmNoX3Rvb2wlMjAlM0QlMjBUb29sLmZyb21fbGFuZ2NoYWluKGxvYWRfdG9vbHMoJTVCJTIyc2VycGFwaSUyMiU1RCklNUIwJTVEKSUwQSUwQWFnZW50JTIwJTNEJTIwQ29kZUFnZW50KHRvb2xzJTNEJTVCc2VhcmNoX3Rvb2wlNUQlMkMlMjBtb2RlbCUzRG1vZGVsKSUwQSUwQWFnZW50LnJ1biglMjJIb3clMjBtYW55JTIwbW9yZSUyMGJsb2NrcyUyMChhbHNvJTIwZGVub3RlZCUyMGFzJTIwbGF5ZXJzKSUyMGFyZSUyMGluJTIwQkVSVCUyMGJhc2UlMjBlbmNvZGVyJTIwY29tcGFyZWQlMjB0byUyMHRoZSUyMGVuY29kZXIlMjBmcm9tJTIwdGhlJTIwYXJjaGl0ZWN0dXJlJTIwcHJvcG9zZWQlMjBpbiUyMEF0dGVudGlvbiUyMGlzJTIwQWxsJTIwWW91JTIwTmVlZCUzRiUyMik=",highlighted:`<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>])

agent = CodeAgent(tools=[search_tool], model=model)

agent.run(<span class="hljs-string">&quot;How many more blocks (also denoted as layers) are in BERT base encoder compared to the encoder from the architecture proposed in Attention is All You Need?&quot;</span>)`,wrap:!1}}),oe=new he({props:{title:"管理你的 agent 工具箱",local:"管理你的-agent-工具箱",headingTag:"h3"}}),pe=new c({props:{code:"ZnJvbSUyMHNtb2xhZ2VudHMlMjBpbXBvcnQlMjBJbmZlcmVuY2VDbGllbnRNb2RlbCUwQSUwQW1vZGVsJTIwJTNEJTIwSW5mZXJlbmNlQ2xpZW50TW9kZWwobW9kZWxfaWQlM0QlMjJRd2VuJTJGUXdlbjIuNS1Db2Rlci0zMkItSW5zdHJ1Y3QlMjIpJTBBJTBBYWdlbnQlMjAlM0QlMjBDb2RlQWdlbnQodG9vbHMlM0QlNUIlNUQlMkMlMjBtb2RlbCUzRG1vZGVsJTJDJTIwYWRkX2Jhc2VfdG9vbHMlM0RUcnVlKSUwQWFnZW50LnRvb2xzJTVCbW9kZWxfZG93bmxvYWRfdG9vbC5uYW1lJTVEJTIwJTNEJTIwbW9kZWxfZG93bmxvYWRfdG9vbA==",highlighted:`<span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> InferenceClientModel

model = InferenceClientModel(model_id=<span class="hljs-string">&quot;Qwen/Qwen2.5-Coder-32B-Instruct&quot;</span>)

agent = CodeAgent(tools=[], model=model, add_base_tools=<span class="hljs-literal">True</span>)
agent.tools[model_download_tool.name] = model_download_tool`,wrap:!1}}),me=new c({props:{code:"YWdlbnQucnVuKCUwQSUyMCUyMCUyMCUyMCUyMkNhbiUyMHlvdSUyMGdpdmUlMjBtZSUyMHRoZSUyMG5hbWUlMjBvZiUyMHRoZSUyMG1vZGVsJTIwdGhhdCUyMGhhcyUyMHRoZSUyMG1vc3QlMjBkb3dubG9hZHMlMjBpbiUyMHRoZSUyMCd0ZXh0LXRvLXZpZGVvJyUyMHRhc2slMjBvbiUyMHRoZSUyMEh1Z2dpbmclMjBGYWNlJTIwSHViJTIwYnV0JTIwcmV2ZXJzZSUyMHRoZSUyMGxldHRlcnMlM0YlMjIlMEEp",highlighted:`agent.run(
    <span class="hljs-string">&quot;Can you give me the name of the model that has the most downloads in the &#x27;text-to-video&#x27; task on the Hugging Face Hub but reverse the letters?&quot;</span>
)`,wrap:!1}}),ue=new he({props:{title:"使用工具集合",local:"使用工具集合",headingTag:"h3"}}),de=new c({props:{code:"ZnJvbSUyMHNtb2xhZ2VudHMlMjBpbXBvcnQlMjBUb29sQ29sbGVjdGlvbiUyQyUyMENvZGVBZ2VudCUwQSUwQWltYWdlX3Rvb2xfY29sbGVjdGlvbiUyMCUzRCUyMFRvb2xDb2xsZWN0aW9uLmZyb21faHViKCUwQSUyMCUyMCUyMCUyMGNvbGxlY3Rpb25fc2x1ZyUzRCUyMmh1Z2dpbmdmYWNlLXRvb2xzJTJGZGlmZnVzaW9uLXRvb2xzLTY2MzBiYjE5YTk0MmMyMzA2YTJjZGI2ZiUyMiUyQyUwQSUyMCUyMCUyMCUyMHRva2VuJTNEJTIyJTNDWU9VUl9IVUdHSU5HRkFDRUhVQl9BUElfVE9LRU4lM0UlMjIlMEEpJTBBYWdlbnQlMjAlM0QlMjBDb2RlQWdlbnQodG9vbHMlM0QlNUIqaW1hZ2VfdG9vbF9jb2xsZWN0aW9uLnRvb2xzJTVEJTJDJTIwbW9kZWwlM0Rtb2RlbCUyQyUyMGFkZF9iYXNlX3Rvb2xzJTNEVHJ1ZSklMEElMEFhZ2VudC5ydW4oJTIyUGxlYXNlJTIwZHJhdyUyMG1lJTIwYSUyMHBpY3R1cmUlMjBvZiUyMHJpdmVycyUyMGFuZCUyMGxha2VzLiUyMik=",highlighted:`<span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> ToolCollection, CodeAgent

image_tool_collection = ToolCollection.from_hub(
    collection_slug=<span class="hljs-string">&quot;huggingface-tools/diffusion-tools-6630bb19a942c2306a2cdb6f&quot;</span>,
    token=<span class="hljs-string">&quot;&lt;YOUR_HUGGINGFACEHUB_API_TOKEN&gt;&quot;</span>
)
agent = CodeAgent(tools=[*image_tool_collection.tools], model=model, add_base_tools=<span class="hljs-literal">True</span>)

agent.run(<span class="hljs-string">&quot;Please draw me a picture of rivers and lakes.&quot;</span>)`,wrap:!1}}),ce=new yl({props:{source:"https://github.com/huggingface/smolagents/blob/main/docs/source/zh/tutorials/tools.md"}}),{c(){h=a("meta"),we=n(),ge=a("p"),Je=n(),M(U.$$.fragment),je=n(),M(g.$$.fragment),Ce=n(),M(T.$$.fragment),ve=n(),w=a("p"),w.textContent=_t,_e=n(),f=a("blockquote"),f.innerHTML=It,Ie=n(),J=a("ul"),J.innerHTML=$t,$e=n(),M(j.$$.fragment),Be=n(),C=a("p"),C.textContent=Bt,Ze=n(),v=a("p"),v.textContent=Zt,Ge=n(),_=a("p"),_.textContent=Gt,He=n(),I=a("p"),I.textContent=Ht,xe=n(),$=a("p"),$.textContent=xt,Ee=n(),M(B.$$.fragment),We=n(),Z=a("p"),Z.innerHTML=Et,ke=n(),G=a("ul"),G.innerHTML=Wt,Re=n(),H=a("p"),H.textContent=kt,Qe=n(),x=a("p"),x.innerHTML=Rt,Ae=n(),E=a("p"),E.innerHTML=Qt,Ve=n(),M(W.$$.fragment),Se=n(),k=a("p"),k.innerHTML=At,Le=n(),M(R.$$.fragment),Ne=n(),Q=a("p"),Q.textContent=Vt,ze=n(),A=a("ul"),A.innerHTML=St,qe=n(),V=a("p"),V.innerHTML=Lt,Fe=n(),S=a("p"),S.innerHTML=Nt,Ye=n(),L=a("p"),L.innerHTML=zt,Xe=n(),M(N.$$.fragment),Pe=n(),M(z.$$.fragment),De=n(),q=a("p"),q.innerHTML=qt,Ke=n(),F=a("p"),F.innerHTML=Ft,Oe=n(),Y=a("p"),Y.innerHTML=Yt,et=n(),M(X.$$.fragment),tt=n(),P=a("p"),P.textContent=Xt,lt=n(),fe=a("img"),st=n(),D=a("p"),D.innerHTML=Dt,nt=n(),M(K.$$.fragment),ot=n(),M(O.$$.fragment),at=n(),ye=a("img"),it=n(),ee=a("p"),ee.textContent=Ot,pt=n(),M(te.$$.fragment),Mt=n(),le=a("p"),le.innerHTML=el,mt=n(),se=a("p"),se.innerHTML=tl,ut=n(),M(ne.$$.fragment),bt=n(),M(oe.$$.fragment),dt=n(),ae=a("p"),ae.textContent=ll,rt=n(),ie=a("p"),ie.innerHTML=sl,ct=n(),M(pe.$$.fragment),ht=n(),Me=a("p"),Me.textContent=nl,ft=n(),M(me.$$.fragment),yt=n(),y=a("blockquote"),y.innerHTML=ol,Ut=n(),M(ue.$$.fragment),gt=n(),be=a("p"),be.textContent=al,Tt=n(),M(de.$$.fragment),wt=n(),re=a("p"),re.textContent=il,Jt=n(),M(ce.$$.fragment),jt=n(),Te=a("p"),this.h()},l(e){const t=cl("svelte-u9bgzb",document.head);h=i(t,"META",{name:!0,content:!0}),t.forEach(l),we=o(e),ge=i(e,"P",{}),Ml(ge).forEach(l),Je=o(e),m(U.$$.fragment,e),je=o(e),m(g.$$.fragment,e),Ce=o(e),m(T.$$.fragment,e),ve=o(e),w=i(e,"P",{"data-svelte-h":!0}),p(w)!=="svelte-143y1x4"&&(w.textContent=_t),_e=o(e),f=i(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),p(f)!=="svelte-13sctmd"&&(f.innerHTML=It),Ie=o(e),J=i(e,"UL",{"data-svelte-h":!0}),p(J)!=="svelte-1ob3z02"&&(J.innerHTML=$t),$e=o(e),m(j.$$.fragment,e),Be=o(e),C=i(e,"P",{"data-svelte-h":!0}),p(C)!=="svelte-tzzqok"&&(C.textContent=Bt),Ze=o(e),v=i(e,"P",{"data-svelte-h":!0}),p(v)!=="svelte-mmees0"&&(v.textContent=Zt),Ge=o(e),_=i(e,"P",{"data-svelte-h":!0}),p(_)!=="svelte-8tjsnw"&&(_.textContent=Gt),He=o(e),I=i(e,"P",{"data-svelte-h":!0}),p(I)!=="svelte-1marvpp"&&(I.textContent=Ht),xe=o(e),$=i(e,"P",{"data-svelte-h":!0}),p($)!=="svelte-1ezxif7"&&($.textContent=xt),Ee=o(e),m(B.$$.fragment,e),We=o(e),Z=i(e,"P",{"data-svelte-h":!0}),p(Z)!=="svelte-1xli9gd"&&(Z.innerHTML=Et),ke=o(e),G=i(e,"UL",{"data-svelte-h":!0}),p(G)!=="svelte-114q23d"&&(G.innerHTML=Wt),Re=o(e),H=i(e,"P",{"data-svelte-h":!0}),p(H)!=="svelte-150sce8"&&(H.textContent=kt),Qe=o(e),x=i(e,"P",{"data-svelte-h":!0}),p(x)!=="svelte-nh0799"&&(x.innerHTML=Rt),Ae=o(e),E=i(e,"P",{"data-svelte-h":!0}),p(E)!=="svelte-g0rxsz"&&(E.innerHTML=Qt),Ve=o(e),m(W.$$.fragment,e),Se=o(e),k=i(e,"P",{"data-svelte-h":!0}),p(k)!=="svelte-6948rv"&&(k.innerHTML=At),Le=o(e),m(R.$$.fragment,e),Ne=o(e),Q=i(e,"P",{"data-svelte-h":!0}),p(Q)!=="svelte-f7adnf"&&(Q.textContent=Vt),ze=o(e),A=i(e,"UL",{"data-svelte-h":!0}),p(A)!=="svelte-4okem9"&&(A.innerHTML=St),qe=o(e),V=i(e,"P",{"data-svelte-h":!0}),p(V)!=="svelte-ek1m24"&&(V.innerHTML=Lt),Fe=o(e),S=i(e,"P",{"data-svelte-h":!0}),p(S)!=="svelte-15ghlir"&&(S.innerHTML=Nt),Ye=o(e),L=i(e,"P",{"data-svelte-h":!0}),p(L)!=="svelte-10vgpjf"&&(L.innerHTML=zt),Xe=o(e),m(N.$$.fragment,e),Pe=o(e),m(z.$$.fragment,e),De=o(e),q=i(e,"P",{"data-svelte-h":!0}),p(q)!=="svelte-198hi9i"&&(q.innerHTML=qt),Ke=o(e),F=i(e,"P",{"data-svelte-h":!0}),p(F)!=="svelte-4qew2a"&&(F.innerHTML=Ft),Oe=o(e),Y=i(e,"P",{"data-svelte-h":!0}),p(Y)!=="svelte-1tvwij"&&(Y.innerHTML=Yt),et=o(e),m(X.$$.fragment,e),tt=o(e),P=i(e,"P",{"data-svelte-h":!0}),p(P)!=="svelte-1ubl722"&&(P.textContent=Xt),lt=o(e),fe=i(e,"IMG",{src:!0}),st=o(e),D=i(e,"P",{"data-svelte-h":!0}),p(D)!=="svelte-ecwb7g"&&(D.innerHTML=Dt),nt=o(e),m(K.$$.fragment,e),ot=o(e),m(O.$$.fragment,e),at=o(e),ye=i(e,"IMG",{src:!0}),it=o(e),ee=i(e,"P",{"data-svelte-h":!0}),p(ee)!=="svelte-frli2c"&&(ee.textContent=Ot),pt=o(e),m(te.$$.fragment,e),Mt=o(e),le=i(e,"P",{"data-svelte-h":!0}),p(le)!=="svelte-m1ii5p"&&(le.innerHTML=el),mt=o(e),se=i(e,"P",{"data-svelte-h":!0}),p(se)!=="svelte-17sjd0f"&&(se.innerHTML=tl),ut=o(e),m(ne.$$.fragment,e),bt=o(e),m(oe.$$.fragment,e),dt=o(e),ae=i(e,"P",{"data-svelte-h":!0}),p(ae)!=="svelte-p6yc33"&&(ae.textContent=ll),rt=o(e),ie=i(e,"P",{"data-svelte-h":!0}),p(ie)!=="svelte-u6gh5x"&&(ie.innerHTML=sl),ct=o(e),m(pe.$$.fragment,e),ht=o(e),Me=i(e,"P",{"data-svelte-h":!0}),p(Me)!=="svelte-1dm2bi"&&(Me.textContent=nl),ft=o(e),m(me.$$.fragment,e),yt=o(e),y=i(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),p(y)!=="svelte-q94bc0"&&(y.innerHTML=ol),Ut=o(e),m(ue.$$.fragment,e),gt=o(e),be=i(e,"P",{"data-svelte-h":!0}),p(be)!=="svelte-17n2ifn"&&(be.textContent=al),Tt=o(e),m(de.$$.fragment,e),wt=o(e),re=i(e,"P",{"data-svelte-h":!0}),p(re)!=="svelte-nvusln"&&(re.textContent=il),Jt=o(e),m(ce.$$.fragment,e),jt=o(e),Te=i(e,"P",{}),Ml(Te).forEach(l),this.h()},h(){Ue(h,"name","hf:doc:metadata"),Ue(h,"content",Tl),Ue(f,"class","tip"),pl(fe.src,Pt="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/sunny_beach.webp")||Ue(fe,"src",Pt),pl(ye.src,Kt="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit_spacesuit_flux.webp")||Ue(ye,"src",Kt),Ue(y,"class","tip")},m(e,t){hl(document.head,h),s(e,we,t),s(e,ge,t),s(e,Je,t),u(U,e,t),s(e,je,t),u(g,e,t),s(e,Ce,t),u(T,e,t),s(e,ve,t),s(e,w,t),s(e,_e,t),s(e,f,t),s(e,Ie,t),s(e,J,t),s(e,$e,t),u(j,e,t),s(e,Be,t),s(e,C,t),s(e,Ze,t),s(e,v,t),s(e,Ge,t),s(e,_,t),s(e,He,t),s(e,I,t),s(e,xe,t),s(e,$,t),s(e,Ee,t),u(B,e,t),s(e,We,t),s(e,Z,t),s(e,ke,t),s(e,G,t),s(e,Re,t),s(e,H,t),s(e,Qe,t),s(e,x,t),s(e,Ae,t),s(e,E,t),s(e,Ve,t),u(W,e,t),s(e,Se,t),s(e,k,t),s(e,Le,t),u(R,e,t),s(e,Ne,t),s(e,Q,t),s(e,ze,t),s(e,A,t),s(e,qe,t),s(e,V,t),s(e,Fe,t),s(e,S,t),s(e,Ye,t),s(e,L,t),s(e,Xe,t),u(N,e,t),s(e,Pe,t),u(z,e,t),s(e,De,t),s(e,q,t),s(e,Ke,t),s(e,F,t),s(e,Oe,t),s(e,Y,t),s(e,et,t),u(X,e,t),s(e,tt,t),s(e,P,t),s(e,lt,t),s(e,fe,t),s(e,st,t),s(e,D,t),s(e,nt,t),u(K,e,t),s(e,ot,t),u(O,e,t),s(e,at,t),s(e,ye,t),s(e,it,t),s(e,ee,t),s(e,pt,t),u(te,e,t),s(e,Mt,t),s(e,le,t),s(e,mt,t),s(e,se,t),s(e,ut,t),u(ne,e,t),s(e,bt,t),u(oe,e,t),s(e,dt,t),s(e,ae,t),s(e,rt,t),s(e,ie,t),s(e,ct,t),u(pe,e,t),s(e,ht,t),s(e,Me,t),s(e,ft,t),u(me,e,t),s(e,yt,t),s(e,y,t),s(e,Ut,t),u(ue,e,t),s(e,gt,t),s(e,be,t),s(e,Tt,t),u(de,e,t),s(e,wt,t),s(e,re,t),s(e,Jt,t),u(ce,e,t),s(e,jt,t),s(e,Te,t),Ct=!0},p:ul,i(e){Ct||(b(U.$$.fragment,e),b(g.$$.fragment,e),b(T.$$.fragment,e),b(j.$$.fragment,e),b(B.$$.fragment,e),b(W.$$.fragment,e),b(R.$$.fragment,e),b(N.$$.fragment,e),b(z.$$.fragment,e),b(X.$$.fragment,e),b(K.$$.fragment,e),b(O.$$.fragment,e),b(te.$$.fragment,e),b(ne.$$.fragment,e),b(oe.$$.fragment,e),b(pe.$$.fragment,e),b(me.$$.fragment,e),b(ue.$$.fragment,e),b(de.$$.fragment,e),b(ce.$$.fragment,e),Ct=!0)},o(e){d(U.$$.fragment,e),d(g.$$.fragment,e),d(T.$$.fragment,e),d(j.$$.fragment,e),d(B.$$.fragment,e),d(W.$$.fragment,e),d(R.$$.fragment,e),d(N.$$.fragment,e),d(z.$$.fragment,e),d(X.$$.fragment,e),d(K.$$.fragment,e),d(O.$$.fragment,e),d(te.$$.fragment,e),d(ne.$$.fragment,e),d(oe.$$.fragment,e),d(pe.$$.fragment,e),d(me.$$.fragment,e),d(ue.$$.fragment,e),d(de.$$.fragment,e),d(ce.$$.fragment,e),Ct=!1},d(e){e&&(l(we),l(ge),l(Je),l(je),l(Ce),l(ve),l(w),l(_e),l(f),l(Ie),l(J),l($e),l(Be),l(C),l(Ze),l(v),l(Ge),l(_),l(He),l(I),l(xe),l($),l(Ee),l(We),l(Z),l(ke),l(G),l(Re),l(H),l(Qe),l(x),l(Ae),l(E),l(Ve),l(Se),l(k),l(Le),l(Ne),l(Q),l(ze),l(A),l(qe),l(V),l(Fe),l(S),l(Ye),l(L),l(Xe),l(Pe),l(De),l(q),l(Ke),l(F),l(Oe),l(Y),l(et),l(tt),l(P),l(lt),l(fe),l(st),l(D),l(nt),l(ot),l(at),l(ye),l(it),l(ee),l(pt),l(Mt),l(le),l(mt),l(se),l(ut),l(bt),l(dt),l(ae),l(rt),l(ie),l(ct),l(ht),l(Me),l(ft),l(yt),l(y),l(Ut),l(gt),l(be),l(Tt),l(wt),l(re),l(Jt),l(jt),l(Te)),l(h),r(U,e),r(g,e),r(T,e),r(j,e),r(B,e),r(W,e),r(R,e),r(N,e),r(z,e),r(X,e),r(K,e),r(O,e),r(te,e),r(ne,e),r(oe,e),r(pe,e),r(me,e),r(ue,e),r(de,e),r(ce,e)}}}const Tl='{"title":"工具","local":"工具","sections":[{"title":"什么是工具，如何构建一个工具？","local":"什么是工具如何构建一个工具","sections":[],"depth":3},{"title":"将你的工具分享到 Hub","local":"将你的工具分享到-hub","sections":[],"depth":3},{"title":"将 Space 导入为工具","local":"将-space-导入为工具","sections":[],"depth":3},{"title":"使用 LangChain 工具","local":"使用-langchain-工具","sections":[],"depth":3},{"title":"管理你的 agent 工具箱","local":"管理你的-agent-工具箱","sections":[],"depth":3},{"title":"使用工具集合","local":"使用工具集合","sections":[],"depth":3}],"depth":1}';function wl(vt){return bl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Il extends dl{constructor(h){super(),rl(this,h,wl,gl,ml,{})}}export{Il as component};
