import{S as yo,i as vo,s as ko,e as o,k as c,w as v,t as i,N as Jo,c as a,d as s,m as u,a as r,x as k,h as p,b as h,P as Be,G as t,g as n,y as J,q as T,o as M,B as j,v as To}from"../chunks/vendor-hf-doc-builder.js";import{T as wo}from"../chunks/Tip-hf-doc-builder.js";import{I as Ae}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as lt}from"../chunks/CodeBlock-hf-doc-builder.js";function Mo(pe){let f,b;return{c(){f=o("p"),b=i("Webhooks are now publicly available!")},l(m){f=a(m,"P",{});var d=r(f);b=p(d,"Webhooks are now publicly available!"),d.forEach(s)},m(m,d){n(m,f,d),t(f,b)},d(m){m&&s(f)}}}function jo(pe){let f;return{c(){f=i('When creating a bot that will interact with other users on the Hub, we ask that you clearly label the account as a "Bot" (see profile screenshot).')},l(b){f=p(b,'When creating a bot that will interact with other users on the Hub, we ask that you clearly label the account as a "Bot" (see profile screenshot).')},m(b,m){n(b,f,m)},d(b){b&&s(f)}}}function Eo(pe){let f,b,m,d,Ce,q,ot,Qe,at,is,N,ps,ce,nt,cs,_,I,Re,G,rt,Pe,it,us,W,pt,H,ct,ut,hs,w,Oe,ht,ft,Ve,mt,bt,Le,dt,wt,De,yt,fs,ue,vt,ms,he,fe,ml,bs,g,B,Ye,X,kt,z,Jt,Ze,Tt,Mt,ds,me,jt,ws,be,de,bl,ys,A,vs,$,C,qe,x,Et,Ge,_t,ks,we,gt,Js,ye,$t,Ts,Q,Ut,F,St,Nt,Ms,R,It,K,Wt,Bt,js,ve,P,At,He,Ct,Qt,ee,Rt,Es,ke,Pt,_s,se,gs,y,Ot,Xe,Vt,Lt,ze,Dt,Yt,xe,Zt,qt,$s,te,Us,Je,Gt,Ss,E,Fe,Ht,Xt,Ke,zt,xt,le,Ft,es,Kt,el,Ns,Te,sl,Is,oe,Ws,O,tl,ss,ll,ol,Bs,Me,al,As,ae,Cs,U,V,ts,ne,nl,ls,rl,Qs,je,il,Rs,Ee,pl,Ps,L,_e,dl,cl,ge,wl,Os,$e,ul,Vs,Ue,Se,yl,Ls,S,D,os,re,hl,as,fl,Ds,Ne,Ie,vl,Ys;return q=new Ae({}),N=new wo({props:{$$slots:{default:[Mo]},$$scope:{ctx:pe}}}),G=new Ae({}),X=new Ae({}),A=new wo({props:{$$slots:{default:[jo]},$$scope:{ctx:pe}}}),x=new Ae({}),se=new lt({props:{code:"YXBwLnBvc3QoJTIyJTJGJTIyJTJDJTIwYXN5bmMlMjAocmVxJTJDJTIwcmVzKSUyMCUzRCUzRSUyMCU3QiUwQSUwOWlmJTIwKHJlcS5oZWFkZXIoJTIyWC1XZWJob29rLVNlY3JldCUyMiklMjAhJTNEJTNEJTIwcHJvY2Vzcy5lbnYuV0VCSE9PS19TRUNSRVQpJTIwJTdCJTBBJTA5JTA5Y29uc29sZS5lcnJvciglMjJpbmNvcnJlY3QlMjBzZWNyZXQlMjIpJTNCJTBBJTA5JTA5cmV0dXJuJTIwcmVzLnN0YXR1cyg0MDApLmpzb24oJTdCJTIwZXJyb3IlM0ElMjAlMjJpbmNvcnJlY3QlMjBzZWNyZXQlMjIlMjAlN0QpJTNCJTBBJTA5JTdEJTBBJTA5Li4u",highlighted:`app.<span class="hljs-title function_">post</span>(<span class="hljs-string">&quot;/&quot;</span>, <span class="hljs-keyword">async</span> (req, res) =&gt; {
	<span class="hljs-keyword">if</span> (req.<span class="hljs-title function_">header</span>(<span class="hljs-string">&quot;X-Webhook-Secret&quot;</span>) !== process.<span class="hljs-property">env</span>.<span class="hljs-property">WEBHOOK_SECRET</span>) {
		<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">&quot;incorrect secret&quot;</span>);
		<span class="hljs-keyword">return</span> res.<span class="hljs-title function_">status</span>(<span class="hljs-number">400</span>).<span class="hljs-title function_">json</span>({ <span class="hljs-attr">error</span>: <span class="hljs-string">&quot;incorrect secret&quot;</span> });
	}
	...`}}),te=new lt({props:{code:"JTA5Y29uc3QlMjBldmVudCUyMCUzRCUyMHJlcS5ib2R5LmV2ZW50JTNCJTBBJTA5aWYlMjAoJTBBJTA5JTA5ZXZlbnQuYWN0aW9uJTIwJTNEJTNEJTNEJTIwJTIyY3JlYXRlJTIyJTIwJTI2JTI2JTBBJTA5JTA5ZXZlbnQuc2NvcGUlMjAlM0QlM0QlM0QlMjAlMjJkaXNjdXNzaW9uLmNvbW1lbnQlMjIlMjAlMjYlMjYlMEElMDklMDlyZXEuYm9keS5jb21tZW50LmNvbnRlbnQuaW5jbHVkZXMoQk9UX1VTRVJOQU1FKSUwQSUwOSklMjAlN0IlMEElMDklMDkuLi4=",highlighted:`	<span class="hljs-keyword">const</span> event = req.<span class="hljs-property">body</span>.<span class="hljs-property">event</span>;
	<span class="hljs-keyword">if</span> (
		event.<span class="hljs-property">action</span> === <span class="hljs-string">&quot;create&quot;</span> &amp;&amp;
		event.<span class="hljs-property">scope</span> === <span class="hljs-string">&quot;discussion.comment&quot;</span> &amp;&amp;
		req.<span class="hljs-property">body</span>.<span class="hljs-property">comment</span>.<span class="hljs-property">content</span>.<span class="hljs-title function_">includes</span>(<span class="hljs-variable constant_">BOT_USERNAME</span>)
	) {
		...`}}),oe=new lt({props:{code:"JTA5Y29uc3QlMjBJTkZFUkVOQ0VfVVJMJTIwJTNEJTBBJTA5JTA5JTIyaHR0cHMlM0ElMkYlMkZhcGktaW5mZXJlbmNlLmh1Z2dpbmdmYWNlLmNvJTJGbW9kZWxzJTJGYmlnc2NpZW5jZSUyRmJsb29tJTIyJTNCJTBBJTA5Y29uc3QlMjBQUk9NUFQlMjAlM0QlMjAlNjBQcmV0ZW5kJTIwdGhhdCUyMHlvdSUyMGFyZSUyMGElMjBib3QlMjB0aGF0JTIwcmVwbGllcyUyMHRvJTIwZGlzY3Vzc2lvbnMlMjBhYm91dCUyMG1hY2hpbmUlMjBsZWFybmluZyUyQyUyMGFuZCUyMHJlcGx5JTIwdG8lMjB0aGUlMjBmb2xsb3dpbmclMjBjb21tZW50JTNBJTVDbiU2MCUzQiUwQSUwQSUwOWNvbnN0JTIwcmVzcG9uc2UlMjAlM0QlMjBhd2FpdCUyMGZldGNoKElORkVSRU5DRV9VUkwlMkMlMjAlN0IlMEElMDklMDltZXRob2QlM0ElMjAlMjJQT1NUJTIyJTJDJTBBJTA5JTA5Ym9keSUzQSUyMEpTT04uc3RyaW5naWZ5KCU3QiUyMGlucHV0cyUzQSUyMFBST01QVCUyMCUyQiUyMHJlcS5ib2R5LmNvbW1lbnQuY29udGVudCUyMCU3RCklMkMlMEElMDklN0QpJTNCJTBBJTA5aWYlMjAocmVzcG9uc2Uub2spJTIwJTdCJTBBJTA5JTA5Y29uc3QlMjBvdXRwdXQlMjAlM0QlMjBhd2FpdCUyMHJlc3BvbnNlLmpzb24oKSUzQiUwQSUwOSUwOWNvbnN0JTIwY29udGludWF0aW9uVGV4dCUyMCUzRCUyMG91dHB1dCU1QjAlNUQuZ2VuZXJhdGVkX3RleHQucmVwbGFjZSglMEElMDklMDklMDlQUk9NUFQlMjAlMkIlMjByZXEuYm9keS5jb21tZW50LmNvbnRlbnQlMkMlMEElMDklMDklMDklMjIlMjIlMEElMDklMDkpJTNCJTBBJTA5JTA5Li4u",highlighted:`	<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">INFERENCE_URL</span> =
		<span class="hljs-string">&quot;https://api-inference.huggingface.co/models/bigscience/bloom&quot;</span>;
	<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">PROMPT</span> = <span class="hljs-string">\`Pretend that you are a bot that replies to discussions about machine learning, and reply to the following comment:\\n\`</span>;

	<span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> <span class="hljs-title function_">fetch</span>(<span class="hljs-variable constant_">INFERENCE_URL</span>, {
		<span class="hljs-attr">method</span>: <span class="hljs-string">&quot;POST&quot;</span>,
		<span class="hljs-attr">body</span>: <span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">stringify</span>({ <span class="hljs-attr">inputs</span>: <span class="hljs-variable constant_">PROMPT</span> + req.<span class="hljs-property">body</span>.<span class="hljs-property">comment</span>.<span class="hljs-property">content</span> }),
	});
	<span class="hljs-keyword">if</span> (response.<span class="hljs-property">ok</span>) {
		<span class="hljs-keyword">const</span> output = <span class="hljs-keyword">await</span> response.<span class="hljs-title function_">json</span>();
		<span class="hljs-keyword">const</span> continuationText = output[<span class="hljs-number">0</span>].<span class="hljs-property">generated_text</span>.<span class="hljs-title function_">replace</span>(
			<span class="hljs-variable constant_">PROMPT</span> + req.<span class="hljs-property">body</span>.<span class="hljs-property">comment</span>.<span class="hljs-property">content</span>,
			<span class="hljs-string">&quot;&quot;</span>
		);
		...`}}),ae=new lt({props:{code:"JTA5Y29uc3QlMjBjb21tZW50VXJsJTIwJTNEJTIwcmVxLmJvZHkuZGlzY3Vzc2lvbi51cmwuYXBpJTIwJTJCJTIwJTIyJTJGY29tbWVudCUyMiUzQiUwQSUwQSUwOWNvbnN0JTIwY29tbWVudEFwaVJlc3BvbnNlJTIwJTNEJTIwYXdhaXQlMjBmZXRjaChjb21tZW50VXJsJTJDJTIwJTdCJTBBJTA5JTA5bWV0aG9kJTNBJTIwJTIyUE9TVCUyMiUyQyUwQSUwOSUwOWhlYWRlcnMlM0ElMjAlN0IlMEElMDklMDklMDlBdXRob3JpemF0aW9uJTNBJTIwJTYwQmVhcmVyJTIwJTI0JTdCcHJvY2Vzcy5lbnYuSEZfVE9LRU4lN0QlNjAlMkMlMEElMDklMDklMDklMjJDb250ZW50LVR5cGUlMjIlM0ElMjAlMjJhcHBsaWNhdGlvbiUyRmpzb24lMjIlMkMlMEElMDklMDklN0QlMkMlMEElMDklMDlib2R5JTNBJTIwSlNPTi5zdHJpbmdpZnkoJTdCJTIwY29tbWVudCUzQSUyMGNvbnRpbnVhdGlvblRleHQlMjAlN0QpJTJDJTBBJTA5JTdEKSUzQiUwQSUwQSUwOWNvbnN0JTIwYXBpT3V0cHV0JTIwJTNEJTIwYXdhaXQlMjBjb21tZW50QXBpUmVzcG9uc2UuanNvbigpJTNC",highlighted:`	<span class="hljs-keyword">const</span> commentUrl = req.<span class="hljs-property">body</span>.<span class="hljs-property">discussion</span>.<span class="hljs-property">url</span>.<span class="hljs-property">api</span> + <span class="hljs-string">&quot;/comment&quot;</span>;

	<span class="hljs-keyword">const</span> commentApiResponse = <span class="hljs-keyword">await</span> <span class="hljs-title function_">fetch</span>(commentUrl, {
		<span class="hljs-attr">method</span>: <span class="hljs-string">&quot;POST&quot;</span>,
		<span class="hljs-attr">headers</span>: {
			<span class="hljs-title class_">Authorization</span>: <span class="hljs-string">\`Bearer <span class="hljs-subst">\${({}).HF_TOKEN}</span>\`</span>,
			<span class="hljs-string">&quot;Content-Type&quot;</span>: <span class="hljs-string">&quot;application/json&quot;</span>,
		},
		<span class="hljs-attr">body</span>: <span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">stringify</span>({ <span class="hljs-attr">comment</span>: continuationText }),
	});

	<span class="hljs-keyword">const</span> apiOutput = <span class="hljs-keyword">await</span> commentApiResponse.<span class="hljs-title function_">json</span>();`}}),ne=new Ae({}),re=new Ae({}),{c(){f=o("meta"),b=c(),m=o("h1"),d=o("a"),Ce=o("span"),v(q.$$.fragment),ot=c(),Qe=o("span"),at=i("Webhook guide: build a Discussion bot based on BLOOM"),is=c(),v(N.$$.fragment),ps=c(),ce=o("p"),nt=i("Here\u2019s a short guide on how to use Hugging Face Webhooks to build a bot that replies to Discussion comments on the Hub with a response generated by BLOOM, a multilingual language model, using the free Inference API."),cs=c(),_=o("h2"),I=o("a"),Re=o("span"),v(G.$$.fragment),rt=c(),Pe=o("span"),it=i("Create your Webhook in your user profile"),us=c(),W=o("p"),pt=i("First, let\u2019s create a Webhook from your "),H=o("a"),ct=i("settings"),ut=i("."),hs=c(),w=o("ul"),Oe=o("li"),ht=i("Input a few target repositories that your Webhook will listen to."),ft=c(),Ve=o("li"),mt=i("You can put a dummy Webhook URL for now, but defining your webhook will let you look at the events that will be sent to it (and you can replay them, which will be useful for debugging)."),bt=c(),Le=o("li"),dt=i("Input a secret as it will be more secure."),wt=c(),De=o("li"),yt=i("Subscribe to Community (PR & discussions) events, as we are building a Discussion bot."),fs=c(),ue=o("p"),vt=i("Your Webhook will look like this:"),ms=c(),he=o("p"),fe=o("img"),bs=c(),g=o("h2"),B=o("a"),Ye=o("span"),v(X.$$.fragment),kt=c(),z=o("span"),Jt=i("Create a new "),Ze=o("code"),Tt=i("Bot"),Mt=i(" user profile"),ds=c(),me=o("p"),jt=i("In this guide, we create a separate user account to host a Space and to post comments:"),ws=c(),be=o("p"),de=o("img"),ys=c(),v(A.$$.fragment),vs=c(),$=o("h2"),C=o("a"),qe=o("span"),v(x.$$.fragment),Et=c(),Ge=o("span"),_t=i("Create a Space that will react to your Webhook"),ks=c(),we=o("p"),gt=i("The third step is actually to listen to the Webhook events."),Js=c(),ye=o("p"),$t=i("An easy way is to use a Space for this. We use the user account we created, but you could do it from your main user account if you wanted to."),Ts=c(),Q=o("p"),Ut=i("The Space\u2019s code is "),F=o("a"),St=i("here"),Nt=i("."),Ms=c(),R=o("p"),It=i("We used NodeJS and Typescript to implement it, but any language or framework would work equally well. Read more about Docker Spaces "),K=o("a"),Wt=i("here"),Bt=i("."),js=c(),ve=o("p"),P=o("strong"),At=i("The main "),He=o("code"),Ct=i("server.ts"),Qt=i(" file is "),ee=o("a"),Rt=i("here"),Es=c(),ke=o("p"),Pt=i("Let\u2019s walk through what happens in this file:"),_s=c(),v(se.$$.fragment),gs=c(),y=o("p"),Ot=i("Here, we listen to POST requests made to "),Xe=o("code"),Vt=i("/"),Lt=i(", and then we check that the "),ze=o("code"),Dt=i("X-Webhook-Secret"),Yt=i(" header is equal to the secret we had previously defined (you need to also set the "),xe=o("code"),Zt=i("WEBHOOK_SECRET"),qt=i(" secret in your Space\u2019s settings to be able to verify it)."),$s=c(),v(te.$$.fragment),Us=c(),Je=o("p"),Gt=i("The event\u2019s payload is encoded as JSON. Here, we specify that we will run our Webhook only when:"),Ss=c(),E=o("ul"),Fe=o("li"),Ht=i("the event concerns a discussion comment"),Xt=c(),Ke=o("li"),zt=i("the event is a creation, i.e. a new comment has been posted"),xt=c(),le=o("li"),Ft=i("the comment\u2019s content contains "),es=o("code"),Kt=i("@discussion-bot"),el=i(", i.e. our bot was just mentioned in a comment."),Ns=c(),Te=o("p"),sl=i("In that case, we will continue to the next step:"),Is=c(),v(oe.$$.fragment),Ws=c(),O=o("p"),tl=i("This is the coolest part: we call the Inference API for the BLOOM model, prompting it with "),ss=o("code"),ll=i("PROMPT"),ol=i(", and we get the continuation text, i.e., the part generated by the model."),Bs=c(),Me=o("p"),al=i("Finally, we will post it as a reply in the same discussion thread:"),As=c(),v(ae.$$.fragment),Cs=c(),U=o("h2"),V=o("a"),ts=o("span"),v(ne.$$.fragment),nl=c(),ls=o("span"),rl=i("Configure your Webhook to send events to your Space"),Qs=c(),je=o("p"),il=i("Last but not least, you\u2019ll need to configure your Webhook to send POST requests to your Space."),Rs=c(),Ee=o("p"),pl=i("Let\u2019s first grab our Space\u2019s \u201Cdirect URL\u201D from the contextual menu. Click on \u201CEmbed this Space\u201D and copy the \u201CDirect URL\u201D."),Ps=c(),L=o("p"),_e=o("img"),cl=c(),ge=o("img"),Os=c(),$e=o("p"),ul=i("Update your webhook to send requests to that URL:"),Vs=c(),Ue=o("p"),Se=o("img"),Ls=c(),S=o("h2"),D=o("a"),os=o("span"),v(re.$$.fragment),hl=c(),as=o("span"),fl=i("Result"),Ds=c(),Ne=o("p"),Ie=o("img"),this.h()},l(e){const l=Jo('[data-svelte="svelte-1phssyn"]',document.head);f=a(l,"META",{name:!0,content:!0}),l.forEach(s),b=u(e),m=a(e,"H1",{class:!0});var ie=r(m);d=a(ie,"A",{id:!0,class:!0,href:!0});var ns=r(d);Ce=a(ns,"SPAN",{});var kl=r(Ce);k(q.$$.fragment,kl),kl.forEach(s),ns.forEach(s),ot=u(ie),Qe=a(ie,"SPAN",{});var Jl=r(Qe);at=p(Jl,"Webhook guide: build a Discussion bot based on BLOOM"),Jl.forEach(s),ie.forEach(s),is=u(e),k(N.$$.fragment,e),ps=u(e),ce=a(e,"P",{});var Tl=r(ce);nt=p(Tl,"Here\u2019s a short guide on how to use Hugging Face Webhooks to build a bot that replies to Discussion comments on the Hub with a response generated by BLOOM, a multilingual language model, using the free Inference API."),Tl.forEach(s),cs=u(e),_=a(e,"H2",{class:!0});var Zs=r(_);I=a(Zs,"A",{id:!0,class:!0,href:!0});var Ml=r(I);Re=a(Ml,"SPAN",{});var jl=r(Re);k(G.$$.fragment,jl),jl.forEach(s),Ml.forEach(s),rt=u(Zs),Pe=a(Zs,"SPAN",{});var El=r(Pe);it=p(El,"Create your Webhook in your user profile"),El.forEach(s),Zs.forEach(s),us=u(e),W=a(e,"P",{});var qs=r(W);pt=p(qs,"First, let\u2019s create a Webhook from your "),H=a(qs,"A",{href:!0,rel:!0});var _l=r(H);ct=p(_l,"settings"),_l.forEach(s),ut=p(qs,"."),qs.forEach(s),hs=u(e),w=a(e,"UL",{});var Y=r(w);Oe=a(Y,"LI",{});var gl=r(Oe);ht=p(gl,"Input a few target repositories that your Webhook will listen to."),gl.forEach(s),ft=u(Y),Ve=a(Y,"LI",{});var $l=r(Ve);mt=p($l,"You can put a dummy Webhook URL for now, but defining your webhook will let you look at the events that will be sent to it (and you can replay them, which will be useful for debugging)."),$l.forEach(s),bt=u(Y),Le=a(Y,"LI",{});var Ul=r(Le);dt=p(Ul,"Input a secret as it will be more secure."),Ul.forEach(s),wt=u(Y),De=a(Y,"LI",{});var Sl=r(De);yt=p(Sl,"Subscribe to Community (PR & discussions) events, as we are building a Discussion bot."),Sl.forEach(s),Y.forEach(s),fs=u(e),ue=a(e,"P",{});var Nl=r(ue);vt=p(Nl,"Your Webhook will look like this:"),Nl.forEach(s),ms=u(e),he=a(e,"P",{});var Il=r(he);fe=a(Il,"IMG",{src:!0,alt:!0}),Il.forEach(s),bs=u(e),g=a(e,"H2",{class:!0});var Gs=r(g);B=a(Gs,"A",{id:!0,class:!0,href:!0});var Wl=r(B);Ye=a(Wl,"SPAN",{});var Bl=r(Ye);k(X.$$.fragment,Bl),Bl.forEach(s),Wl.forEach(s),kt=u(Gs),z=a(Gs,"SPAN",{});var Hs=r(z);Jt=p(Hs,"Create a new "),Ze=a(Hs,"CODE",{});var Al=r(Ze);Tt=p(Al,"Bot"),Al.forEach(s),Mt=p(Hs," user profile"),Hs.forEach(s),Gs.forEach(s),ds=u(e),me=a(e,"P",{});var Cl=r(me);jt=p(Cl,"In this guide, we create a separate user account to host a Space and to post comments:"),Cl.forEach(s),ws=u(e),be=a(e,"P",{});var Ql=r(be);de=a(Ql,"IMG",{src:!0,alt:!0}),Ql.forEach(s),ys=u(e),k(A.$$.fragment,e),vs=u(e),$=a(e,"H2",{class:!0});var Xs=r($);C=a(Xs,"A",{id:!0,class:!0,href:!0});var Rl=r(C);qe=a(Rl,"SPAN",{});var Pl=r(qe);k(x.$$.fragment,Pl),Pl.forEach(s),Rl.forEach(s),Et=u(Xs),Ge=a(Xs,"SPAN",{});var Ol=r(Ge);_t=p(Ol,"Create a Space that will react to your Webhook"),Ol.forEach(s),Xs.forEach(s),ks=u(e),we=a(e,"P",{});var Vl=r(we);gt=p(Vl,"The third step is actually to listen to the Webhook events."),Vl.forEach(s),Js=u(e),ye=a(e,"P",{});var Ll=r(ye);$t=p(Ll,"An easy way is to use a Space for this. We use the user account we created, but you could do it from your main user account if you wanted to."),Ll.forEach(s),Ts=u(e),Q=a(e,"P",{});var zs=r(Q);Ut=p(zs,"The Space\u2019s code is "),F=a(zs,"A",{href:!0,rel:!0});var Dl=r(F);St=p(Dl,"here"),Dl.forEach(s),Nt=p(zs,"."),zs.forEach(s),Ms=u(e),R=a(e,"P",{});var xs=r(R);It=p(xs,"We used NodeJS and Typescript to implement it, but any language or framework would work equally well. Read more about Docker Spaces "),K=a(xs,"A",{href:!0,rel:!0});var Yl=r(K);Wt=p(Yl,"here"),Yl.forEach(s),Bt=p(xs,"."),xs.forEach(s),js=u(e),ve=a(e,"P",{});var Zl=r(ve);P=a(Zl,"STRONG",{});var rs=r(P);At=p(rs,"The main "),He=a(rs,"CODE",{});var ql=r(He);Ct=p(ql,"server.ts"),ql.forEach(s),Qt=p(rs," file is "),ee=a(rs,"A",{href:!0,rel:!0});var Gl=r(ee);Rt=p(Gl,"here"),Gl.forEach(s),rs.forEach(s),Zl.forEach(s),Es=u(e),ke=a(e,"P",{});var Hl=r(ke);Pt=p(Hl,"Let\u2019s walk through what happens in this file:"),Hl.forEach(s),_s=u(e),k(se.$$.fragment,e),gs=u(e),y=a(e,"P",{});var Z=r(y);Ot=p(Z,"Here, we listen to POST requests made to "),Xe=a(Z,"CODE",{});var Xl=r(Xe);Vt=p(Xl,"/"),Xl.forEach(s),Lt=p(Z,", and then we check that the "),ze=a(Z,"CODE",{});var zl=r(ze);Dt=p(zl,"X-Webhook-Secret"),zl.forEach(s),Yt=p(Z," header is equal to the secret we had previously defined (you need to also set the "),xe=a(Z,"CODE",{});var xl=r(xe);Zt=p(xl,"WEBHOOK_SECRET"),xl.forEach(s),qt=p(Z," secret in your Space\u2019s settings to be able to verify it)."),Z.forEach(s),$s=u(e),k(te.$$.fragment,e),Us=u(e),Je=a(e,"P",{});var Fl=r(Je);Gt=p(Fl,"The event\u2019s payload is encoded as JSON. Here, we specify that we will run our Webhook only when:"),Fl.forEach(s),Ss=u(e),E=a(e,"UL",{});var We=r(E);Fe=a(We,"LI",{});var Kl=r(Fe);Ht=p(Kl,"the event concerns a discussion comment"),Kl.forEach(s),Xt=u(We),Ke=a(We,"LI",{});var eo=r(Ke);zt=p(eo,"the event is a creation, i.e. a new comment has been posted"),eo.forEach(s),xt=u(We),le=a(We,"LI",{});var Fs=r(le);Ft=p(Fs,"the comment\u2019s content contains "),es=a(Fs,"CODE",{});var so=r(es);Kt=p(so,"@discussion-bot"),so.forEach(s),el=p(Fs,", i.e. our bot was just mentioned in a comment."),Fs.forEach(s),We.forEach(s),Ns=u(e),Te=a(e,"P",{});var to=r(Te);sl=p(to,"In that case, we will continue to the next step:"),to.forEach(s),Is=u(e),k(oe.$$.fragment,e),Ws=u(e),O=a(e,"P",{});var Ks=r(O);tl=p(Ks,"This is the coolest part: we call the Inference API for the BLOOM model, prompting it with "),ss=a(Ks,"CODE",{});var lo=r(ss);ll=p(lo,"PROMPT"),lo.forEach(s),ol=p(Ks,", and we get the continuation text, i.e., the part generated by the model."),Ks.forEach(s),Bs=u(e),Me=a(e,"P",{});var oo=r(Me);al=p(oo,"Finally, we will post it as a reply in the same discussion thread:"),oo.forEach(s),As=u(e),k(ae.$$.fragment,e),Cs=u(e),U=a(e,"H2",{class:!0});var et=r(U);V=a(et,"A",{id:!0,class:!0,href:!0});var ao=r(V);ts=a(ao,"SPAN",{});var no=r(ts);k(ne.$$.fragment,no),no.forEach(s),ao.forEach(s),nl=u(et),ls=a(et,"SPAN",{});var ro=r(ls);rl=p(ro,"Configure your Webhook to send events to your Space"),ro.forEach(s),et.forEach(s),Qs=u(e),je=a(e,"P",{});var io=r(je);il=p(io,"Last but not least, you\u2019ll need to configure your Webhook to send POST requests to your Space."),io.forEach(s),Rs=u(e),Ee=a(e,"P",{});var po=r(Ee);pl=p(po,"Let\u2019s first grab our Space\u2019s \u201Cdirect URL\u201D from the contextual menu. Click on \u201CEmbed this Space\u201D and copy the \u201CDirect URL\u201D."),po.forEach(s),Ps=u(e),L=a(e,"P",{});var st=r(L);_e=a(st,"IMG",{src:!0,alt:!0}),cl=u(st),ge=a(st,"IMG",{src:!0,alt:!0}),st.forEach(s),Os=u(e),$e=a(e,"P",{});var co=r($e);ul=p(co,"Update your webhook to send requests to that URL:"),co.forEach(s),Vs=u(e),Ue=a(e,"P",{});var uo=r(Ue);Se=a(uo,"IMG",{src:!0,alt:!0}),uo.forEach(s),Ls=u(e),S=a(e,"H2",{class:!0});var tt=r(S);D=a(tt,"A",{id:!0,class:!0,href:!0});var ho=r(D);os=a(ho,"SPAN",{});var fo=r(os);k(re.$$.fragment,fo),fo.forEach(s),ho.forEach(s),hl=u(tt),as=a(tt,"SPAN",{});var mo=r(as);fl=p(mo,"Result"),mo.forEach(s),tt.forEach(s),Ds=u(e),Ne=a(e,"P",{});var bo=r(Ne);Ie=a(bo,"IMG",{src:!0,alt:!0}),bo.forEach(s),this.h()},h(){h(f,"name","hf:doc:metadata"),h(f,"content",JSON.stringify(_o)),h(d,"id","webhook-guide-build-a-discussion-bot-based-on-bloom"),h(d,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(d,"href","#webhook-guide-build-a-discussion-bot-based-on-bloom"),h(m,"class","relative group"),h(I,"id","create-your-webhook-in-your-user-profile"),h(I,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(I,"href","#create-your-webhook-in-your-user-profile"),h(_,"class","relative group"),h(H,"href","https://huggingface.co/settings/webhooks"),h(H,"rel","nofollow"),Be(fe.src,ml="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/webhooks-guides/001-discussion-bot/webhook-creation.png")||h(fe,"src",ml),h(fe,"alt","webhook-creation"),h(B,"id","create-a-new-bot-user-profile"),h(B,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(B,"href","#create-a-new-bot-user-profile"),h(g,"class","relative group"),Be(de.src,bl="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/webhooks-guides/001-discussion-bot/discussion-bot-profile.png")||h(de,"src",bl),h(de,"alt","discussion-bot-profile"),h(C,"id","create-a-space-that-will-react-to-your-webhook"),h(C,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(C,"href","#create-a-space-that-will-react-to-your-webhook"),h($,"class","relative group"),h(F,"href","https://huggingface.co/spaces/discussion-bot/webhook/tree/main"),h(F,"rel","nofollow"),h(K,"href","https://huggingface.co/docs/hub/spaces-sdks-docker"),h(K,"rel","nofollow"),h(ee,"href","https://huggingface.co/spaces/discussion-bot/webhook/blob/main/server.ts"),h(ee,"rel","nofollow"),h(V,"id","configure-your-webhook-to-send-events-to-your-space"),h(V,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(V,"href","#configure-your-webhook-to-send-events-to-your-space"),h(U,"class","relative group"),Be(_e.src,dl="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/webhooks-guides/001-discussion-bot/embed-space.png")||h(_e,"src",dl),h(_e,"alt","embed this Space"),Be(ge.src,wl="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/webhooks-guides/001-discussion-bot/direct-url.png")||h(ge,"src",wl),h(ge,"alt","direct URL"),Be(Se.src,yl="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/webhooks-guides/001-discussion-bot/webhook-creation.png")||h(Se,"src",yl),h(Se,"alt","webhook settings"),h(D,"id","result"),h(D,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(D,"href","#result"),h(S,"class","relative group"),Be(Ie.src,vl="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/webhooks-guides/001-discussion-bot/discussion-result.png")||h(Ie,"src",vl),h(Ie,"alt","discussion-result")},m(e,l){t(document.head,f),n(e,b,l),n(e,m,l),t(m,d),t(d,Ce),J(q,Ce,null),t(m,ot),t(m,Qe),t(Qe,at),n(e,is,l),J(N,e,l),n(e,ps,l),n(e,ce,l),t(ce,nt),n(e,cs,l),n(e,_,l),t(_,I),t(I,Re),J(G,Re,null),t(_,rt),t(_,Pe),t(Pe,it),n(e,us,l),n(e,W,l),t(W,pt),t(W,H),t(H,ct),t(W,ut),n(e,hs,l),n(e,w,l),t(w,Oe),t(Oe,ht),t(w,ft),t(w,Ve),t(Ve,mt),t(w,bt),t(w,Le),t(Le,dt),t(w,wt),t(w,De),t(De,yt),n(e,fs,l),n(e,ue,l),t(ue,vt),n(e,ms,l),n(e,he,l),t(he,fe),n(e,bs,l),n(e,g,l),t(g,B),t(B,Ye),J(X,Ye,null),t(g,kt),t(g,z),t(z,Jt),t(z,Ze),t(Ze,Tt),t(z,Mt),n(e,ds,l),n(e,me,l),t(me,jt),n(e,ws,l),n(e,be,l),t(be,de),n(e,ys,l),J(A,e,l),n(e,vs,l),n(e,$,l),t($,C),t(C,qe),J(x,qe,null),t($,Et),t($,Ge),t(Ge,_t),n(e,ks,l),n(e,we,l),t(we,gt),n(e,Js,l),n(e,ye,l),t(ye,$t),n(e,Ts,l),n(e,Q,l),t(Q,Ut),t(Q,F),t(F,St),t(Q,Nt),n(e,Ms,l),n(e,R,l),t(R,It),t(R,K),t(K,Wt),t(R,Bt),n(e,js,l),n(e,ve,l),t(ve,P),t(P,At),t(P,He),t(He,Ct),t(P,Qt),t(P,ee),t(ee,Rt),n(e,Es,l),n(e,ke,l),t(ke,Pt),n(e,_s,l),J(se,e,l),n(e,gs,l),n(e,y,l),t(y,Ot),t(y,Xe),t(Xe,Vt),t(y,Lt),t(y,ze),t(ze,Dt),t(y,Yt),t(y,xe),t(xe,Zt),t(y,qt),n(e,$s,l),J(te,e,l),n(e,Us,l),n(e,Je,l),t(Je,Gt),n(e,Ss,l),n(e,E,l),t(E,Fe),t(Fe,Ht),t(E,Xt),t(E,Ke),t(Ke,zt),t(E,xt),t(E,le),t(le,Ft),t(le,es),t(es,Kt),t(le,el),n(e,Ns,l),n(e,Te,l),t(Te,sl),n(e,Is,l),J(oe,e,l),n(e,Ws,l),n(e,O,l),t(O,tl),t(O,ss),t(ss,ll),t(O,ol),n(e,Bs,l),n(e,Me,l),t(Me,al),n(e,As,l),J(ae,e,l),n(e,Cs,l),n(e,U,l),t(U,V),t(V,ts),J(ne,ts,null),t(U,nl),t(U,ls),t(ls,rl),n(e,Qs,l),n(e,je,l),t(je,il),n(e,Rs,l),n(e,Ee,l),t(Ee,pl),n(e,Ps,l),n(e,L,l),t(L,_e),t(L,cl),t(L,ge),n(e,Os,l),n(e,$e,l),t($e,ul),n(e,Vs,l),n(e,Ue,l),t(Ue,Se),n(e,Ls,l),n(e,S,l),t(S,D),t(D,os),J(re,os,null),t(S,hl),t(S,as),t(as,fl),n(e,Ds,l),n(e,Ne,l),t(Ne,Ie),Ys=!0},p(e,[l]){const ie={};l&2&&(ie.$$scope={dirty:l,ctx:e}),N.$set(ie);const ns={};l&2&&(ns.$$scope={dirty:l,ctx:e}),A.$set(ns)},i(e){Ys||(T(q.$$.fragment,e),T(N.$$.fragment,e),T(G.$$.fragment,e),T(X.$$.fragment,e),T(A.$$.fragment,e),T(x.$$.fragment,e),T(se.$$.fragment,e),T(te.$$.fragment,e),T(oe.$$.fragment,e),T(ae.$$.fragment,e),T(ne.$$.fragment,e),T(re.$$.fragment,e),Ys=!0)},o(e){M(q.$$.fragment,e),M(N.$$.fragment,e),M(G.$$.fragment,e),M(X.$$.fragment,e),M(A.$$.fragment,e),M(x.$$.fragment,e),M(se.$$.fragment,e),M(te.$$.fragment,e),M(oe.$$.fragment,e),M(ae.$$.fragment,e),M(ne.$$.fragment,e),M(re.$$.fragment,e),Ys=!1},d(e){s(f),e&&s(b),e&&s(m),j(q),e&&s(is),j(N,e),e&&s(ps),e&&s(ce),e&&s(cs),e&&s(_),j(G),e&&s(us),e&&s(W),e&&s(hs),e&&s(w),e&&s(fs),e&&s(ue),e&&s(ms),e&&s(he),e&&s(bs),e&&s(g),j(X),e&&s(ds),e&&s(me),e&&s(ws),e&&s(be),e&&s(ys),j(A,e),e&&s(vs),e&&s($),j(x),e&&s(ks),e&&s(we),e&&s(Js),e&&s(ye),e&&s(Ts),e&&s(Q),e&&s(Ms),e&&s(R),e&&s(js),e&&s(ve),e&&s(Es),e&&s(ke),e&&s(_s),j(se,e),e&&s(gs),e&&s(y),e&&s($s),j(te,e),e&&s(Us),e&&s(Je),e&&s(Ss),e&&s(E),e&&s(Ns),e&&s(Te),e&&s(Is),j(oe,e),e&&s(Ws),e&&s(O),e&&s(Bs),e&&s(Me),e&&s(As),j(ae,e),e&&s(Cs),e&&s(U),j(ne),e&&s(Qs),e&&s(je),e&&s(Rs),e&&s(Ee),e&&s(Ps),e&&s(L),e&&s(Os),e&&s($e),e&&s(Vs),e&&s(Ue),e&&s(Ls),e&&s(S),j(re),e&&s(Ds),e&&s(Ne)}}}const _o={local:"webhook-guide-build-a-discussion-bot-based-on-bloom",sections:[{local:"create-your-webhook-in-your-user-profile",title:"Create your Webhook in your user profile"},{local:"create-a-new-bot-user-profile",title:"Create a new `Bot` user profile"},{local:"create-a-space-that-will-react-to-your-webhook",title:"Create a Space that will react to your Webhook"},{local:"configure-your-webhook-to-send-events-to-your-space",title:"Configure your Webhook to send events to your Space"},{local:"result",title:"Result"}],title:"Webhook guide: build a Discussion bot based on BLOOM"};function go(pe){return To(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Io extends yo{constructor(f){super();vo(this,f,go,Eo,ko,{})}}export{Io as default,_o as metadata};
