import{S as Ft,i as Wt,s as Xt,e as o,k as h,w as M,t as l,M as Dt,c as n,d as t,m as f,a as r,x as G,h as i,b as p,T as Ot,G as s,g as c,y as N,q as A,o as C,B as I,v as Lt}from"../../chunks/vendor-hf-doc-builder.js";import{T as Yt}from"../../chunks/Tip-hf-doc-builder.js";import{I as _t}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as He}from"../../chunks/CodeBlock-hf-doc-builder.js";function Kt(he){let u,_;return{c(){u=o("p"),_=l("Due to the possibility of leaking access tokens to users of your website or web application, we only support accessing private/gated models from server-side environments (e.g., Node.js) that have access to the process\u2019 environment variables.")},l(m){u=n(m,"P",{});var v=r(u);_=i(v,"Due to the possibility of leaking access tokens to users of your website or web application, we only support accessing private/gated models from server-side environments (e.g., Node.js) that have access to the process\u2019 environment variables."),v.forEach(t)},m(m,v){c(m,u,v),s(u,_)},d(m){m&&t(u)}}}function qt(he){let u,_,m,v,Y,x,Pe,K,Qe,fe,T,ue,w,b,q,Z,Re,ee,ze,me,H,P,Be,Ve,de,d,Oe,Q,Fe,We,te,Xe,De,se,Le,Ye,ae,Ke,qe,ve,g,W,Tt,et,X,bt,ye,$,tt,oe,st,at,we,k,E,ne,R,ot,re,nt,ge,J,rt,le,lt,it,ke,U,ct,ie,pt,ht,_e,z,Te,j,ft,ce,ut,mt,be,B,$e,S,dt,pe,vt,yt,Ee,D,wt,Je,V,Ue,L,gt,je,O,Se;return x=new _t({}),T=new Yt({props:{$$slots:{default:[Kt]},$$scope:{ctx:he}}}),Z=new _t({}),R=new _t({}),z=new He({props:{code:"aW1wb3J0JTIwJTdCJTIwQXV0b1Rva2VuaXplciUyMCU3RCUyMGZyb20lMjAnJTQweGVub3ZhJTJGdHJhbnNmb3JtZXJzJyUzQiUwQSUwQSUyRiUyRiUyMExvYWQlMjB0b2tlbml6ZXIlMjBmb3IlMjBhJTIwZ2F0ZWQlMjByZXBvc2l0b3J5LiUwQWNvbnN0JTIwdG9rZW5pemVyJTIwJTNEJTIwYXdhaXQlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCgnbWV0YS1sbGFtYSUyRkxsYW1hLTItN2ItaGYnKSUzQiUwQSUwQSUyRiUyRiUyMEVuY29kZSUyMHRleHQuJTBBY29uc3QlMjB0ZXh0JTIwJTNEJTIwJ0hlbGxvJTIwd29ybGQhJyUzQiUwQWNvbnN0JTIwZW5jb2RlZCUyMCUzRCUyMHRva2VuaXplci5lbmNvZGUodGV4dCklM0IlMEFjb25zb2xlLmxvZyhlbmNvZGVkKSUzQg==",highlighted:`<span class="hljs-keyword">import</span> { <span class="hljs-title class_">AutoTokenizer</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@xenova/transformers&#x27;</span>;

<span class="hljs-comment">// Load tokenizer for a gated repository.</span>
<span class="hljs-keyword">const</span> tokenizer = <span class="hljs-keyword">await</span> <span class="hljs-title class_">AutoTokenizer</span>.<span class="hljs-title function_">from_pretrained</span>(<span class="hljs-string">&#x27;meta-llama/Llama-2-7b-hf&#x27;</span>);

<span class="hljs-comment">// Encode text.</span>
<span class="hljs-keyword">const</span> text = <span class="hljs-string">&#x27;Hello world!&#x27;</span>;
<span class="hljs-keyword">const</span> encoded = tokenizer.<span class="hljs-title function_">encode</span>(text);
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(encoded);`}}),B=new He({props:{code:"SEZfQUNDRVNTX1RPS0VOJTNEaGZfLi4uJTIwbm9kZSUyMHRlc3RzJTJGbGxhbWEuanM=",highlighted:"HF_ACCESS_TOKEN=hf_... node tests/llama.js"}}),V=new He({props:{code:"JTVCJTIwMSUyQyUyMDE1MDQzJTJDJTIwMzE4NiUyQyUyMDI5OTkxJTIwJTVE",highlighted:"[ 1, 15043, 3186, 29991 ]"}}),O=new He({props:{code:"JTJGJTJGJTIwU2V0JTIwYWNjZXNzJTIwdG9rZW4lMjAoTkIlM0ElMjBLZWVwJTIwdGhpcyUyMHByaXZhdGUhKSUwQXByb2Nlc3MuZW52LkhGX0FDQ0VTU19UT0tFTiUyMCUzRCUyMCdoZl8uLi4nJTNCJTBBJTBBJTJGJTJGJTIwLi4uJTIwcmVzdCUyMG9mJTIweW91ciUyMGNvZGU=",highlighted:`<span class="hljs-comment">// Set access token (NB: Keep this private!)</span>
process.<span class="hljs-property">env</span>.<span class="hljs-property">HF_ACCESS_TOKEN</span> = <span class="hljs-string">&#x27;hf_...&#x27;</span>;

<span class="hljs-comment">// ... rest of your code</span>`}}),{c(){u=o("meta"),_=h(),m=o("h1"),v=o("a"),Y=o("span"),M(x.$$.fragment),Pe=h(),K=o("span"),Qe=l("Accessing Private/Gated Models"),fe=h(),M(T.$$.fragment),ue=h(),w=o("h2"),b=o("a"),q=o("span"),M(Z.$$.fragment),Re=h(),ee=o("span"),ze=l("Step 1: Generating a User Access Token"),me=h(),H=o("p"),P=o("a"),Be=l("User Access Tokens"),Ve=l(" are the preferred way to authenticate an application to Hugging Face services."),de=h(),d=o("p"),Oe=l("To generate an access token, navigate to the "),Q=o("a"),Fe=l("Access Tokens tab"),We=l(" in your settings and click on the "),te=o("strong"),Xe=l("New token"),De=l(" button. Choose a name for your token and click "),se=o("strong"),Le=l("Generate a token"),Ye=l(" (we recommend keeping the \u201CRole\u201D as read-only). You can then click the "),ae=o("strong"),Ke=l("Copy"),qe=l(" button next to your newly-created token to copy it to your clipboard."),ve=h(),g=o("div"),W=o("img"),et=h(),X=o("img"),ye=h(),$=o("p"),tt=l("To delete or refresh User Access Tokens, you can click the "),oe=o("strong"),st=l("Manage"),at=l(" button."),we=h(),k=o("h2"),E=o("a"),ne=o("span"),M(R.$$.fragment),ot=h(),re=o("span"),nt=l("Step 2: Using the access token in Transformers.js"),ge=h(),J=o("p"),rt=l("Transformers.js will attach an Authorization header to requests made to the Hugging Face Hub when the "),le=o("code"),lt=l("HF_ACCESS_TOKEN"),it=l(" environment variable is set and visible to the process."),ke=h(),U=o("p"),ct=l("One way to do this is to call your program with the environment variable set. For example, let\u2019s say you have a file called "),ie=o("code"),pt=l("llama.js"),ht=l(" with the following code:"),_e=h(),M(z.$$.fragment),Te=h(),j=o("p"),ft=l("You can then use the following command to set the "),ce=o("code"),ut=l("HF_ACCESS_TOKEN"),mt=l(" environment variable and run the file:"),be=h(),M(B.$$.fragment),$e=h(),S=o("p"),dt=l("(remember to replace "),pe=o("code"),vt=l("hf_..."),yt=l(" with your actual access token)."),Ee=h(),D=o("p"),wt=l("If done correctly, you should see the following output:"),Je=h(),M(V.$$.fragment),Ue=h(),L=o("p"),gt=l("Alternatively, you can set the environment variable directly in your code:"),je=h(),M(O.$$.fragment),this.h()},l(e){const a=Dt('[data-svelte="svelte-1phssyn"]',document.head);u=n(a,"META",{name:!0,content:!0}),a.forEach(t),_=f(e),m=n(e,"H1",{class:!0});var F=r(m);v=n(F,"A",{id:!0,class:!0,href:!0});var $t=r(v);Y=n($t,"SPAN",{});var Et=r(Y);G(x.$$.fragment,Et),Et.forEach(t),$t.forEach(t),Pe=f(F),K=n(F,"SPAN",{});var Jt=r(K);Qe=i(Jt,"Accessing Private/Gated Models"),Jt.forEach(t),F.forEach(t),fe=f(e),G(T.$$.fragment,e),ue=f(e),w=n(e,"H2",{class:!0});var Me=r(w);b=n(Me,"A",{id:!0,class:!0,href:!0});var Ut=r(b);q=n(Ut,"SPAN",{});var jt=r(q);G(Z.$$.fragment,jt),jt.forEach(t),Ut.forEach(t),Re=f(Me),ee=n(Me,"SPAN",{});var St=r(ee);ze=i(St,"Step 1: Generating a User Access Token"),St.forEach(t),Me.forEach(t),me=f(e),H=n(e,"P",{});var kt=r(H);P=n(kt,"A",{href:!0,rel:!0});var Mt=r(P);Be=i(Mt,"User Access Tokens"),Mt.forEach(t),Ve=i(kt," are the preferred way to authenticate an application to Hugging Face services."),kt.forEach(t),de=f(e),d=n(e,"P",{});var y=r(d);Oe=i(y,"To generate an access token, navigate to the "),Q=n(y,"A",{href:!0,rel:!0});var Gt=r(Q);Fe=i(Gt,"Access Tokens tab"),Gt.forEach(t),We=i(y," in your settings and click on the "),te=n(y,"STRONG",{});var Nt=r(te);Xe=i(Nt,"New token"),Nt.forEach(t),De=i(y," button. Choose a name for your token and click "),se=n(y,"STRONG",{});var At=r(se);Le=i(At,"Generate a token"),At.forEach(t),Ye=i(y," (we recommend keeping the \u201CRole\u201D as read-only). You can then click the "),ae=n(y,"STRONG",{});var Ct=r(ae);Ke=i(Ct,"Copy"),Ct.forEach(t),qe=i(y," button next to your newly-created token to copy it to your clipboard."),y.forEach(t),ve=f(e),g=n(e,"DIV",{class:!0});var Ge=r(g);W=n(Ge,"IMG",{class:!0,src:!0}),et=f(Ge),X=n(Ge,"IMG",{class:!0,src:!0}),Ge.forEach(t),ye=f(e),$=n(e,"P",{});var Ne=r($);tt=i(Ne,"To delete or refresh User Access Tokens, you can click the "),oe=n(Ne,"STRONG",{});var It=r(oe);st=i(It,"Manage"),It.forEach(t),at=i(Ne," button."),Ne.forEach(t),we=f(e),k=n(e,"H2",{class:!0});var Ae=r(k);E=n(Ae,"A",{id:!0,class:!0,href:!0});var xt=r(E);ne=n(xt,"SPAN",{});var Zt=r(ne);G(R.$$.fragment,Zt),Zt.forEach(t),xt.forEach(t),ot=f(Ae),re=n(Ae,"SPAN",{});var Ht=r(re);nt=i(Ht,"Step 2: Using the access token in Transformers.js"),Ht.forEach(t),Ae.forEach(t),ge=f(e),J=n(e,"P",{});var Ce=r(J);rt=i(Ce,"Transformers.js will attach an Authorization header to requests made to the Hugging Face Hub when the "),le=n(Ce,"CODE",{});var Pt=r(le);lt=i(Pt,"HF_ACCESS_TOKEN"),Pt.forEach(t),it=i(Ce," environment variable is set and visible to the process."),Ce.forEach(t),ke=f(e),U=n(e,"P",{});var Ie=r(U);ct=i(Ie,"One way to do this is to call your program with the environment variable set. For example, let\u2019s say you have a file called "),ie=n(Ie,"CODE",{});var Qt=r(ie);pt=i(Qt,"llama.js"),Qt.forEach(t),ht=i(Ie," with the following code:"),Ie.forEach(t),_e=f(e),G(z.$$.fragment,e),Te=f(e),j=n(e,"P",{});var xe=r(j);ft=i(xe,"You can then use the following command to set the "),ce=n(xe,"CODE",{});var Rt=r(ce);ut=i(Rt,"HF_ACCESS_TOKEN"),Rt.forEach(t),mt=i(xe," environment variable and run the file:"),xe.forEach(t),be=f(e),G(B.$$.fragment,e),$e=f(e),S=n(e,"P",{});var Ze=r(S);dt=i(Ze,"(remember to replace "),pe=n(Ze,"CODE",{});var zt=r(pe);vt=i(zt,"hf_..."),zt.forEach(t),yt=i(Ze," with your actual access token)."),Ze.forEach(t),Ee=f(e),D=n(e,"P",{});var Bt=r(D);wt=i(Bt,"If done correctly, you should see the following output:"),Bt.forEach(t),Je=f(e),G(V.$$.fragment,e),Ue=f(e),L=n(e,"P",{});var Vt=r(L);gt=i(Vt,"Alternatively, you can set the environment variable directly in your code:"),Vt.forEach(t),je=f(e),G(O.$$.fragment,e),this.h()},h(){p(u,"name","hf:doc:metadata"),p(u,"content",JSON.stringify(es)),p(v,"id","accessing-privategated-models"),p(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"),p(v,"href","#accessing-privategated-models"),p(m,"class","relative group"),p(b,"id","step-1-generating-a-user-access-token"),p(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"),p(b,"href","#step-1-generating-a-user-access-token"),p(w,"class","relative group"),p(P,"href","https://huggingface.co/docs/hub/security-tokens"),p(P,"rel","nofollow"),p(Q,"href","https://huggingface.co/settings/tokens"),p(Q,"rel","nofollow"),p(W,"class","block dark:hidden"),Ot(W.src,Tt="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/new-token.png")||p(W,"src",Tt),p(X,"class","hidden dark:block"),Ot(X.src,bt="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/new-token-dark.png")||p(X,"src",bt),p(g,"class","flex justify-center"),p(E,"id","step-2-using-the-access-token-in-transformersjs"),p(E,"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"),p(E,"href","#step-2-using-the-access-token-in-transformersjs"),p(k,"class","relative group")},m(e,a){s(document.head,u),c(e,_,a),c(e,m,a),s(m,v),s(v,Y),N(x,Y,null),s(m,Pe),s(m,K),s(K,Qe),c(e,fe,a),N(T,e,a),c(e,ue,a),c(e,w,a),s(w,b),s(b,q),N(Z,q,null),s(w,Re),s(w,ee),s(ee,ze),c(e,me,a),c(e,H,a),s(H,P),s(P,Be),s(H,Ve),c(e,de,a),c(e,d,a),s(d,Oe),s(d,Q),s(Q,Fe),s(d,We),s(d,te),s(te,Xe),s(d,De),s(d,se),s(se,Le),s(d,Ye),s(d,ae),s(ae,Ke),s(d,qe),c(e,ve,a),c(e,g,a),s(g,W),s(g,et),s(g,X),c(e,ye,a),c(e,$,a),s($,tt),s($,oe),s(oe,st),s($,at),c(e,we,a),c(e,k,a),s(k,E),s(E,ne),N(R,ne,null),s(k,ot),s(k,re),s(re,nt),c(e,ge,a),c(e,J,a),s(J,rt),s(J,le),s(le,lt),s(J,it),c(e,ke,a),c(e,U,a),s(U,ct),s(U,ie),s(ie,pt),s(U,ht),c(e,_e,a),N(z,e,a),c(e,Te,a),c(e,j,a),s(j,ft),s(j,ce),s(ce,ut),s(j,mt),c(e,be,a),N(B,e,a),c(e,$e,a),c(e,S,a),s(S,dt),s(S,pe),s(pe,vt),s(S,yt),c(e,Ee,a),c(e,D,a),s(D,wt),c(e,Je,a),N(V,e,a),c(e,Ue,a),c(e,L,a),s(L,gt),c(e,je,a),N(O,e,a),Se=!0},p(e,[a]){const F={};a&2&&(F.$$scope={dirty:a,ctx:e}),T.$set(F)},i(e){Se||(A(x.$$.fragment,e),A(T.$$.fragment,e),A(Z.$$.fragment,e),A(R.$$.fragment,e),A(z.$$.fragment,e),A(B.$$.fragment,e),A(V.$$.fragment,e),A(O.$$.fragment,e),Se=!0)},o(e){C(x.$$.fragment,e),C(T.$$.fragment,e),C(Z.$$.fragment,e),C(R.$$.fragment,e),C(z.$$.fragment,e),C(B.$$.fragment,e),C(V.$$.fragment,e),C(O.$$.fragment,e),Se=!1},d(e){t(u),e&&t(_),e&&t(m),I(x),e&&t(fe),I(T,e),e&&t(ue),e&&t(w),I(Z),e&&t(me),e&&t(H),e&&t(de),e&&t(d),e&&t(ve),e&&t(g),e&&t(ye),e&&t($),e&&t(we),e&&t(k),I(R),e&&t(ge),e&&t(J),e&&t(ke),e&&t(U),e&&t(_e),I(z,e),e&&t(Te),e&&t(j),e&&t(be),I(B,e),e&&t($e),e&&t(S),e&&t(Ee),e&&t(D),e&&t(Je),I(V,e),e&&t(Ue),e&&t(L),e&&t(je),I(O,e)}}}const es={local:"accessing-privategated-models",sections:[{local:"step-1-generating-a-user-access-token",title:"Step 1: Generating a User Access Token"},{local:"step-2-using-the-access-token-in-transformersjs",title:"Step 2: Using the access token in Transformers.js"}],title:"Accessing Private/Gated Models"};function ts(he){return Lt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class rs extends Ft{constructor(u){super();Wt(this,u,ts,qt,Xt,{})}}export{rs as default,es as metadata};
