import{s as xt,n as Bt,o as Ht}from"../chunks/scheduler.505acc25.js";import{S as Vt,i as St,e as i,s as n,c as b,h as Nt,a,d as s,b as M,f as $t,g as _,j as o,k as vt,l as Wt,m as e,n as x,t as B,o as H,p as V}from"../chunks/index.b1175496.js";import{C as Qt,H as bt}from"../chunks/Heading.eda51538.js";import{C as _t}from"../chunks/CodeBlock.9d480d26.js";import{E as zt}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.ea377ea6.js";function Gt(jt){let T,W,S,Q,u,z,J,G,p,It='函数调用是<strong>大语言模型 (LLM) 对其环境采取行动的一种方式</strong>。它最初在 <a href="https://openai.com/index/function-calling-and-other-api-updates/" rel="nofollow">GPT-4中引入</a>，然后被其他模型复制。',P,j,rt="就像智能体 (Agent) 的工具一样，函数调用赋予了模型<strong>对其环境采取行动的能力</strong>。然而，函数调用能力是<strong>由模型学习的</strong>，并且<strong>比其他智能体技术更少依赖提示</strong>。",Z,I,yt="在第1单元中，智能体<strong>没有学习使用工具 (Tools)</strong>，我们只是提供了工具列表，并依赖模型<strong>能够泛化使用这些工具定义计划</strong>的事实。",k,r,wt="而在这里，<strong>通过函数调用，智能体被微调（训练）来使用工具</strong>。",Y,y,R,w,ct="在第1单元中，我们探讨了智能体的一般工作流程。一旦用户向智能体提供了一些工具并用查询提示它，模型将循环执行：",O,c,mt="<li><em>思考(Think)</em>：为了实现目标，我需要采取什么行动。</li> <li><em>行动(Act)</em>：使用正确的参数格式化行动并停止生成。</li> <li><em>观察(Observe)</em>：从执行中获取结果。</li>",F,m,At="在通过 API 与模型进行的”典型”对话中，对话将在用户和助手消息之间交替进行，如下所示：",D,A,X,U,Ut="函数调用为对话带来了<strong>新的角色</strong>！",K,f,ft="<li>一个用于 <strong>行动(Action)</strong> 的新角色</li> <li>一个用于 <strong>观察(Observation)</strong> 的新角色</li>",tt,q,qt='如果我们以 <a href="https://docs.mistral.ai/capabilities/function_calling/" rel="nofollow">Mistral API</a> 为例，它看起来像这样：',lt,g,st,C,gt="<p>…但你说函数调用有一个新角色？</p>",et,h,Ct="<strong>是也不是</strong>，在这种情况下和许多其他API中，模型将要采取的行动格式化为”助手”消息。聊天模板然后将此表示为函数调用的<strong>特殊词元 (special tokens)</strong>。",nt,d,ht="<li><code>[AVAILABLE_TOOLS]</code> – 开始可用工具列表</li> <li><code>[/AVAILABLE_TOOLS]</code> – 结束可用工具列表</li> <li><code>[TOOL_CALLS]</code> – 调用工具（即采取”行动”）</li> <li><code>[TOOL_RESULTS]</code> – “观察”行动的结果</li> <li><code>[/TOOL_RESULTS]</code> – 观察结束（即模型可以再次解码）</li>",Mt,E,dt='我们将在本课程中再次讨论函数调用，但如果你想深入了解，可以查看<a href="https://docs.mistral.ai/capabilities/function_calling/" rel="nofollow">这个优秀的文档部分</a>',it,at,ot,L,Et='现在我们已经了解了什么是函数调用以及它是如何工作的，让我们<strong>为一个尚未具有这些能力的模型添加一些函数调用功能</strong>：通过向模型添加一些新的特殊词元来增强： <a href="https://huggingface.co/google/gemma-2-2b-it" rel="nofollow">google/gemma-2-2b-it</a>。',Tt,$,Lt="要能够做到这一点，<strong>我们首先需要理解微调和LoRA</strong>。",ut,v,Jt,N,pt;return u=new Qt({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),J=new bt({props:{title:"什么是函数调用？(What is Function Calling?)",local:"什么是函数调用what-is-function-calling",headingTag:"h1"}}),y=new bt({props:{title:"模型如何”学习”采取行动？",local:"模型如何学习采取行动",headingTag:"h2"}}),A=new _t({props:{code:"Y29udmVyc2F0aW9uJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTdCJTIycm9sZSUyMiUzQSUyMCUyMnVzZXIlMjIlMkMlMjAlMjJjb250ZW50JTIyJTNBJTIwJTIySSUyMG5lZWQlMjBoZWxwJTIwd2l0aCUyMG15JTIwb3JkZXIlMjIlN0QlMkMlMEElMjAlMjAlMjAlMjAlN0IlMjJyb2xlJTIyJTNBJTIwJTIyYXNzaXN0YW50JTIyJTJDJTIwJTIyY29udGVudCUyMiUzQSUyMCUyMkknZCUyMGJlJTIwaGFwcHklMjB0byUyMGhlbHAuJTIwQ291bGQlMjB5b3UlMjBwcm92aWRlJTIweW91ciUyMG9yZGVyJTIwbnVtYmVyJTNGJTIyJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTdCJTIycm9sZSUyMiUzQSUyMCUyMnVzZXIlMjIlMkMlMjAlMjJjb250ZW50JTIyJTNBJTIwJTIySXQncyUyME9SREVSLTEyMyUyMiU3RCUyQyUwQSU1RA==",highlighted:`conversation = [
    {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;I need help with my order&quot;</span>},
    {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;assistant&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;I&#x27;d be happy to help. Could you provide your order number?&quot;</span>},
    {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;It&#x27;s ORDER-123&quot;</span>},
]`,wrap:!1}}),g=new _t({props:{code:"Y29udmVyc2F0aW9uJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycm9sZSUyMiUzQSUyMCUyMnVzZXIlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJjb250ZW50JTIyJTNBJTIwJTIyV2hhdCdzJTIwdGhlJTIwc3RhdHVzJTIwb2YlMjBteSUyMHRyYW5zYWN0aW9uJTIwVDEwMDElM0YlMjIlMEElMjAlMjAlMjAlMjAlN0QlMkMlMEElMjAlMjAlMjAlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJyb2xlJTIyJTNBJTIwJTI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91ciUyMHRyYW5zYWN0aW9uJTIwVDEwMDElMjBoYXMlMjBiZWVuJTIwc3VjY2Vzc2Z1bGx5JTIwcGFpZC4lMjIlMEElMjAlMjAlMjAlMjAlN0QlMEElNUQ=",highlighted:`conversation = [
    {
        <span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>,
        <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;What&#x27;s the status of my transaction T1001?&quot;</span>
    },
    {
        <span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;assistant&quot;</span>,
        <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;&quot;</span>,
        <span class="hljs-string">&quot;function_call&quot;</span>: {
            <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;retrieve_payment_status&quot;</span>,
            <span class="hljs-string">&quot;arguments&quot;</span>: <span class="hljs-string">&quot;{\\&quot;transaction_id\\&quot;: \\&quot;T1001\\&quot;}&quot;</span>
        }
    },
    {
        <span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;tool&quot;</span>,
        <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;retrieve_payment_status&quot;</span>,
        <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;{\\&quot;status\\&quot;: \\&quot;Paid\\&quot;}&quot;</span>
    },
    {
        <span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;assistant&quot;</span>,
        <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;Your transaction T1001 has been successfully paid.&quot;</span>
    }
]`,wrap:!1}}),v=new zt({props:{source:"https://github.com/huggingface/agents-course/blob/main/units/zh-CN/bonus-unit1/what-is-function-calling.mdx"}}),{c(){T=i("meta"),W=n(),S=i("p"),Q=n(),b(u.$$.fragment),z=n(),b(J.$$.fragment),G=n(),p=i("p"),p.innerHTML=It,P=n(),j=i("p"),j.innerHTML=rt,Z=n(),I=i("p"),I.innerHTML=yt,k=n(),r=i("p"),r.innerHTML=wt,Y=n(),b(y.$$.fragment),R=n(),w=i("p"),w.textContent=ct,O=n(),c=i("ol"),c.innerHTML=mt,F=n(),m=i("p"),m.textContent=At,D=n(),b(A.$$.fragment),X=n(),U=i("p"),U.innerHTML=Ut,K=n(),f=i("ol"),f.innerHTML=ft,tt=n(),q=i("p"),q.innerHTML=qt,lt=n(),b(g.$$.fragment),st=n(),C=i("blockquote"),C.innerHTML=gt,et=n(),h=i("p"),h.innerHTML=Ct,nt=n(),d=i("ul"),d.innerHTML=ht,Mt=n(),E=i("p"),E.innerHTML=dt,it=n(),at=i("hr"),ot=n(),L=i("p"),L.innerHTML=Et,Tt=n(),$=i("p"),$.innerHTML=Lt,ut=n(),b(v.$$.fragment),Jt=n(),N=i("p"),this.h()},l(t){const l=Nt("svelte-u9bgzb",document.head);T=a(l,"META",{name:!0,content:!0}),l.forEach(s),W=M(t),S=a(t,"P",{}),$t(S).forEach(s),Q=M(t),_(u.$$.fragment,t),z=M(t),_(J.$$.fragment,t),G=M(t),p=a(t,"P",{"data-svelte-h":!0}),o(p)!=="svelte-19ebsto"&&(p.innerHTML=It),P=M(t),j=a(t,"P",{"data-svelte-h":!0}),o(j)!=="svelte-gq5voe"&&(j.innerHTML=rt),Z=M(t),I=a(t,"P",{"data-svelte-h":!0}),o(I)!=="svelte-ulxmhv"&&(I.innerHTML=yt),k=M(t),r=a(t,"P",{"data-svelte-h":!0}),o(r)!=="svelte-u9shua"&&(r.innerHTML=wt),Y=M(t),_(y.$$.fragment,t),R=M(t),w=a(t,"P",{"data-svelte-h":!0}),o(w)!=="svelte-z7sy4s"&&(w.textContent=ct),O=M(t),c=a(t,"OL",{"data-svelte-h":!0}),o(c)!=="svelte-12q46c4"&&(c.innerHTML=mt),F=M(t),m=a(t,"P",{"data-svelte-h":!0}),o(m)!=="svelte-d5zh1u"&&(m.textContent=At),D=M(t),_(A.$$.fragment,t),X=M(t),U=a(t,"P",{"data-svelte-h":!0}),o(U)!=="svelte-1olmnld"&&(U.innerHTML=Ut),K=M(t),f=a(t,"OL",{"data-svelte-h":!0}),o(f)!=="svelte-7l5xvn"&&(f.innerHTML=ft),tt=M(t),q=a(t,"P",{"data-svelte-h":!0}),o(q)!=="svelte-6yaj69"&&(q.innerHTML=qt),lt=M(t),_(g.$$.fragment,t),st=M(t),C=a(t,"BLOCKQUOTE",{"data-svelte-h":!0}),o(C)!=="svelte-19xgplh"&&(C.innerHTML=gt),et=M(t),h=a(t,"P",{"data-svelte-h":!0}),o(h)!=="svelte-1c40gde"&&(h.innerHTML=Ct),nt=M(t),d=a(t,"UL",{"data-svelte-h":!0}),o(d)!=="svelte-1peyits"&&(d.innerHTML=ht),Mt=M(t),E=a(t,"P",{"data-svelte-h":!0}),o(E)!=="svelte-uqkf1r"&&(E.innerHTML=dt),it=M(t),at=a(t,"HR",{}),ot=M(t),L=a(t,"P",{"data-svelte-h":!0}),o(L)!=="svelte-1njxg1"&&(L.innerHTML=Et),Tt=M(t),$=a(t,"P",{"data-svelte-h":!0}),o($)!=="svelte-1qsyrf0"&&($.innerHTML=Lt),ut=M(t),_(v.$$.fragment,t),Jt=M(t),N=a(t,"P",{}),$t(N).forEach(s),this.h()},h(){vt(T,"name","hf:doc:metadata"),vt(T,"content",Pt)},m(t,l){Wt(document.head,T),e(t,W,l),e(t,S,l),e(t,Q,l),x(u,t,l),e(t,z,l),x(J,t,l),e(t,G,l),e(t,p,l),e(t,P,l),e(t,j,l),e(t,Z,l),e(t,I,l),e(t,k,l),e(t,r,l),e(t,Y,l),x(y,t,l),e(t,R,l),e(t,w,l),e(t,O,l),e(t,c,l),e(t,F,l),e(t,m,l),e(t,D,l),x(A,t,l),e(t,X,l),e(t,U,l),e(t,K,l),e(t,f,l),e(t,tt,l),e(t,q,l),e(t,lt,l),x(g,t,l),e(t,st,l),e(t,C,l),e(t,et,l),e(t,h,l),e(t,nt,l),e(t,d,l),e(t,Mt,l),e(t,E,l),e(t,it,l),e(t,at,l),e(t,ot,l),e(t,L,l),e(t,Tt,l),e(t,$,l),e(t,ut,l),x(v,t,l),e(t,Jt,l),e(t,N,l),pt=!0},p:Bt,i(t){pt||(B(u.$$.fragment,t),B(J.$$.fragment,t),B(y.$$.fragment,t),B(A.$$.fragment,t),B(g.$$.fragment,t),B(v.$$.fragment,t),pt=!0)},o(t){H(u.$$.fragment,t),H(J.$$.fragment,t),H(y.$$.fragment,t),H(A.$$.fragment,t),H(g.$$.fragment,t),H(v.$$.fragment,t),pt=!1},d(t){t&&(s(W),s(S),s(Q),s(z),s(G),s(p),s(P),s(j),s(Z),s(I),s(k),s(r),s(Y),s(R),s(w),s(O),s(c),s(F),s(m),s(D),s(X),s(U),s(K),s(f),s(tt),s(q),s(lt),s(st),s(C),s(et),s(h),s(nt),s(d),s(Mt),s(E),s(it),s(at),s(ot),s(L),s(Tt),s($),s(ut),s(Jt),s(N)),s(T),V(u,t),V(J,t),V(y,t),V(A,t),V(g,t),V(v,t)}}}const Pt='{"title":"什么是函数调用？(What is Function Calling?)","local":"什么是函数调用what-is-function-calling","sections":[{"title":"模型如何”学习”采取行动？","local":"模型如何学习采取行动","sections":[],"depth":2}],"depth":1}';function Zt(jt){return Ht(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Dt extends Vt{constructor(T){super(),St(this,T,Zt,Gt,xt,{})}}export{Dt as component};
