import{s as kt,n as _t,o as $t}from"../chunks/scheduler.37c15a92.js";import{S as Ht,i as xt,g as o,s,r as _,A as Bt,h as i,f as l,c as a,j as bt,u as $,x as M,k as vt,y as Vt,a as n,v as H,d as x,t as B,w as V}from"../chunks/index.2bf4358c.js";import{C as Et}from"../chunks/CodeBlock.4f5fc1ad.js";import{H as Lt}from"../chunks/Heading.8ada512a.js";import{E as Wt}from"../chunks/EditOnGithub.9958bcdc.js";function St(Tt){let u,W,L,S,r,N,T,pt='Function-calling is a <strong>way for an LLM to take actions on its environment</strong>. It was first <a href="https://openai.com/index/function-calling-and-other-api-updates/" rel="nofollow">introduced in GPT-4</a>, and was later reproduced in other models.',Q,p,ct="Just like the tools of an Agent, function-calling gives the model the capacity to <strong>take an action on its environment</strong>. However, the function calling capacity <strong>is learned by the model</strong>, and relies <strong>less on prompting than other agents techniques</strong>.",G,c,Jt="During Unit 1, the Agent <strong>didn’t learn to use the Tools</strong>, we just provided the list, and we relied on the fact that the model <strong>was able to generalize on defining a plan using these Tools</strong>.",z,J,jt="While here, <strong>with function-calling, the Agent is fine-tuned (trained) to use Tools</strong>.",P,j,Z,h,ht="In Unit 1, we explored the general workflow of an agent. Once the user has given some tools to the agent and prompted it with a query, the model will cycle through:",O,w,wt="<li><em>Think</em> : What action(s) do I need to take in order to fulfill the objective.</li> <li><em>Act</em> : Format the action with the correct parameter and stop the generation.</li> <li><em>Observe</em> : Get back the result from the execution.</li>",Y,I,It="In a “typical” conversation with a model through an API, the conversation will alternate between user and assistant messages like this:",R,y,F,m,yt="Function-calling brings <strong>new roles to the conversation</strong>!",D,d,mt="<li>One new role for an <strong>Action</strong></li> <li>One new role for an <strong>Observation</strong></li>",X,f,dt='If we take the <a href="https://docs.mistral.ai/capabilities/function_calling/" rel="nofollow">Mistral API</a> as an example, it would look like this:',K,g,tt,A,ft="<p>… But you said there’s a new role for function calls?</p>",et,U,gt="<strong>Yes and no</strong>, in this case and in a lot of other APIs, the model formats the action to take as an “assistant” message. The chat template will then represent this as <strong>special tokens</strong> for function-calling.",lt,q,At="<li><code>[AVAILABLE_TOOLS]</code> – Start the list of available tools</li> <li><code>[/AVAILABLE_TOOLS]</code> – End the list of available tools</li> <li><code>[TOOL_CALLS]</code> – Make a call to a tool (i.e., take an “Action”)</li> <li><code>[TOOL_RESULTS]</code> – “Observe” the result of the action</li> <li><code>[/TOOL_RESULTS]</code> – End of the observation (i.e., the model can decode again)</li>",nt,C,Ut='We’ll talk again about function-calling in this course, but if you want to dive deeper you can check <a href="https://docs.mistral.ai/capabilities/function_calling/" rel="nofollow">this excellent documentation section</a>.',st,at,ot,b,qt='Now that we learned what function-calling is and how it works, let’s <strong>add some function-calling capabilities to a model that does not have those capacities yet</strong>: <a href="https://huggingface.co/google/gemma-2-2b-it" rel="nofollow">google/gemma-2-2b-it</a>, by appending some new special tokens to the model.',it,v,Ct="To be able to do that, <strong>we need first to understand fine-tuning and LoRA</strong>.",Mt,E,ut,k,rt;return r=new Lt({props:{title:"What is Function Calling?",local:"what-is-function-calling",headingTag:"h1"}}),j=new Lt({props:{title:"How does the model “learn” to take an action?",local:"how-does-the-model-learn-to-take-an-action",headingTag:"h2"}}),y=new Et({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 Et({props:{code:"Y29udmVyc2F0aW9uJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycm9sZSUyMiUzQSUyMCUyMnVzZXIlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJjb250ZW50JTIyJTNBJTIwJTIyV2hhdCdzJTIwdGhlJTIwc3RhdHVzJTIwb2YlMjBteSUyMHRyYW5zYWN0aW9uJTIwVDEwMDElM0YlMjIlMEElMjAlMjAlMjAlMjAlN0QlMkMlMEElMjAlMjAlMjAlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJyb2xlJTIyJTNBJTIwJTIyYXNzaXN0YW50JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyY29udGVudCUyMiUzQSUyMCUyMiUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmZ1bmN0aW9uX2NhbGwlMjIlM0ElMjAlN0IlMEElMjAlM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ot;</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}}),E=new Wt({props:{source:"https://github.com/huggingface/agents-course/blob/main/units/en/bonus-unit1/what-is-function-calling.mdx"}}),{c(){u=o("meta"),W=s(),L=o("p"),S=s(),_(r.$$.fragment),N=s(),T=o("p"),T.innerHTML=pt,Q=s(),p=o("p"),p.innerHTML=ct,G=s(),c=o("p"),c.innerHTML=Jt,z=s(),J=o("p"),J.innerHTML=jt,P=s(),_(j.$$.fragment),Z=s(),h=o("p"),h.textContent=ht,O=s(),w=o("ol"),w.innerHTML=wt,Y=s(),I=o("p"),I.textContent=It,R=s(),_(y.$$.fragment),F=s(),m=o("p"),m.innerHTML=yt,D=s(),d=o("ol"),d.innerHTML=mt,X=s(),f=o("p"),f.innerHTML=dt,K=s(),_(g.$$.fragment),tt=s(),A=o("blockquote"),A.innerHTML=ft,et=s(),U=o("p"),U.innerHTML=gt,lt=s(),q=o("ul"),q.innerHTML=At,nt=s(),C=o("p"),C.innerHTML=Ut,st=s(),at=o("hr"),ot=s(),b=o("p"),b.innerHTML=qt,it=s(),v=o("p"),v.innerHTML=Ct,Mt=s(),_(E.$$.fragment),ut=s(),k=o("p"),this.h()},l(t){const e=Bt("svelte-u9bgzb",document.head);u=i(e,"META",{name:!0,content:!0}),e.forEach(l),W=a(t),L=i(t,"P",{}),bt(L).forEach(l),S=a(t),$(r.$$.fragment,t),N=a(t),T=i(t,"P",{"data-svelte-h":!0}),M(T)!=="svelte-pk3h6c"&&(T.innerHTML=pt),Q=a(t),p=i(t,"P",{"data-svelte-h":!0}),M(p)!=="svelte-hycf5a"&&(p.innerHTML=ct),G=a(t),c=i(t,"P",{"data-svelte-h":!0}),M(c)!=="svelte-1i26jpw"&&(c.innerHTML=Jt),z=a(t),J=i(t,"P",{"data-svelte-h":!0}),M(J)!=="svelte-1mmqpap"&&(J.innerHTML=jt),P=a(t),$(j.$$.fragment,t),Z=a(t),h=i(t,"P",{"data-svelte-h":!0}),M(h)!=="svelte-qairlh"&&(h.textContent=ht),O=a(t),w=i(t,"OL",{"data-svelte-h":!0}),M(w)!=="svelte-1kl2016"&&(w.innerHTML=wt),Y=a(t),I=i(t,"P",{"data-svelte-h":!0}),M(I)!=="svelte-8qa297"&&(I.textContent=It),R=a(t),$(y.$$.fragment,t),F=a(t),m=i(t,"P",{"data-svelte-h":!0}),M(m)!=="svelte-1khjwbm"&&(m.innerHTML=yt),D=a(t),d=i(t,"OL",{"data-svelte-h":!0}),M(d)!=="svelte-1g71ln6"&&(d.innerHTML=mt),X=a(t),f=i(t,"P",{"data-svelte-h":!0}),M(f)!=="svelte-4i97j7"&&(f.innerHTML=dt),K=a(t),$(g.$$.fragment,t),tt=a(t),A=i(t,"BLOCKQUOTE",{"data-svelte-h":!0}),M(A)!=="svelte-1ti28mk"&&(A.innerHTML=ft),et=a(t),U=i(t,"P",{"data-svelte-h":!0}),M(U)!=="svelte-avxmc3"&&(U.innerHTML=gt),lt=a(t),q=i(t,"UL",{"data-svelte-h":!0}),M(q)!=="svelte-1yz4fi6"&&(q.innerHTML=At),nt=a(t),C=i(t,"P",{"data-svelte-h":!0}),M(C)!=="svelte-grdf5"&&(C.innerHTML=Ut),st=a(t),at=i(t,"HR",{}),ot=a(t),b=i(t,"P",{"data-svelte-h":!0}),M(b)!=="svelte-pjg6sa"&&(b.innerHTML=qt),it=a(t),v=i(t,"P",{"data-svelte-h":!0}),M(v)!=="svelte-m1lnb4"&&(v.innerHTML=Ct),Mt=a(t),$(E.$$.fragment,t),ut=a(t),k=i(t,"P",{}),bt(k).forEach(l),this.h()},h(){vt(u,"name","hf:doc:metadata"),vt(u,"content",Nt)},m(t,e){Vt(document.head,u),n(t,W,e),n(t,L,e),n(t,S,e),H(r,t,e),n(t,N,e),n(t,T,e),n(t,Q,e),n(t,p,e),n(t,G,e),n(t,c,e),n(t,z,e),n(t,J,e),n(t,P,e),H(j,t,e),n(t,Z,e),n(t,h,e),n(t,O,e),n(t,w,e),n(t,Y,e),n(t,I,e),n(t,R,e),H(y,t,e),n(t,F,e),n(t,m,e),n(t,D,e),n(t,d,e),n(t,X,e),n(t,f,e),n(t,K,e),H(g,t,e),n(t,tt,e),n(t,A,e),n(t,et,e),n(t,U,e),n(t,lt,e),n(t,q,e),n(t,nt,e),n(t,C,e),n(t,st,e),n(t,at,e),n(t,ot,e),n(t,b,e),n(t,it,e),n(t,v,e),n(t,Mt,e),H(E,t,e),n(t,ut,e),n(t,k,e),rt=!0},p:_t,i(t){rt||(x(r.$$.fragment,t),x(j.$$.fragment,t),x(y.$$.fragment,t),x(g.$$.fragment,t),x(E.$$.fragment,t),rt=!0)},o(t){B(r.$$.fragment,t),B(j.$$.fragment,t),B(y.$$.fragment,t),B(g.$$.fragment,t),B(E.$$.fragment,t),rt=!1},d(t){t&&(l(W),l(L),l(S),l(N),l(T),l(Q),l(p),l(G),l(c),l(z),l(J),l(P),l(Z),l(h),l(O),l(w),l(Y),l(I),l(R),l(F),l(m),l(D),l(d),l(X),l(f),l(K),l(tt),l(A),l(et),l(U),l(lt),l(q),l(nt),l(C),l(st),l(at),l(ot),l(b),l(it),l(v),l(Mt),l(ut),l(k)),l(u),V(r,t),V(j,t),V(y,t),V(g,t),V(E,t)}}}const Nt='{"title":"What is Function Calling?","local":"what-is-function-calling","sections":[{"title":"How does the model “learn” to take an action?","local":"how-does-the-model-learn-to-take-an-action","sections":[],"depth":2}],"depth":1}';function Qt(Tt){return $t(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Yt extends Ht{constructor(u){super(),xt(this,u,Qt,St,kt,{})}}export{Yt as component};
