import{s as en,o as an,n as Mn}from"../chunks/scheduler.65852ee5.js";import{S as pn,i as on,g as M,s as e,r as o,A as cn,h as p,f as t,c as a,j as tn,u as c,x as i,k as jt,l as nn,y as yn,a as n,v as y,d as j,t as J,w as m}from"../chunks/index.aa74147d.js";import{T as jn}from"../chunks/Tip.bb8ccac8.js";import{D as Jn,C as T}from"../chunks/DocNotebookDropdown.1a7e6a42.js";import{H as h,E as mn}from"../chunks/getInferenceSnippets.a1cbc7e2.js";function Tn(Sl){let U,I=`<br/>
对于 VLM，图像代表一定数量的 tokens。例如，对于 Idefics2，一张低分辨率的图像代表 64 个 tokens，而高分辨率图像则代表 5*64=320 个 tokens。高分辨率是 TGI 中的默认设置（详情请参见 <a href="https://huggingface.co/HuggingFaceM4/idefics2-8b-chatty" rel="nofollow">模型卡</a> 中的 <code>do_image_splitting</code>）。这意味着一张图像消耗 320 个 tokens。`;return{c(){U=M("p"),U.innerHTML=I},l(w){U=p(w,"P",{"data-svelte-h":!0}),i(U)!=="svelte-kdv1hn"&&(U.innerHTML=I)},m(w,vl){n(w,U,vl)},p:Mn,d(w){w&&t(U)}}}function Un(Sl){let U,I,w,vl,b,Nl,g,zl,C,Jt='<em>作者：<a href="https://huggingface.co/MoritzLaurer" rel="nofollow">Moritz Laurer</a></em>',$l,f,mt='你是否曾想过创建自己的机器学习 API？在这篇教程中，我们将使用 <a href="https://huggingface.co/docs/inference-endpoints/index" rel="nofollow">HF 专用推理端点</a> 来实现这一目标。推理端点允许你选择 HF Hub 上成千上万的模型，创建你自己的 API，并将其部署在你控制的平台和你选择的硬件上。',Fl,Z,Tt='<a href="link-to-recipe">无服务器推理 API</a> 非常适合初步测试，但它们仅限于一组预配置的流行模型，并且有速率限制，因为无服务器 API 的硬件同时被多个用户共享。使用专用推理端点，你可以自定义模型的部署，并且硬件仅为你独享。',xl,B,Ut="在本教程中，我们将：",Ll,G,wt="<li>通过一个简单的 UI 创建推理端点，并向该端点发送标准的 HTTP 请求</li> <li>使用 <code>huggingface_hub</code> 库编程方式创建和管理不同的推理端点</li> <li>涵盖三个用例：使用大型语言模型（LLM）进行文本生成、使用 Stable Diffusion 进行图像生成、以及使用 Idefics2 进行图像推理</li>",Pl,W,Dl,A,ht='如果你还没有 Hugging Face 账号，可以 <a href="https://huggingface.co/join" rel="nofollow">在这里</a> 创建一个账号。如果你在一个较大的团队中工作，也可以创建一个 <a href="https://huggingface.co/organizations" rel="nofollow">HF 组织</a>，通过该组织管理所有模型、数据集和推理端点。专用推理端点是付费服务，因此你需要在个人 HF 账户或 HF 组织的 <a href="https://huggingface.co/settings/billing" rel="nofollow">计费设置</a> 中添加信用卡信息。',Kl,V,ut='接下来，你可以在 <a href="https://huggingface.co/docs/hub/security-tokens" rel="nofollow">这里</a> 创建一个用户访问令牌。对于本教程，带有 <code>read</code> 或 <code>write</code> 权限的令牌即可使用，但我们建议使用更细粒度的令牌以提高安全性。对于本笔记本，你需要一个细粒度令牌，具备以下权限：',Ol,k,dt="<li><code>用户权限 &gt; 推理 &gt; 调用推理端点与管理推理端点</code></li> <li><code>仓库权限 &gt; google/gemma-1.1-2b-it 和 HuggingFaceM4/idefics2-8b-chatty</code></li>",ls,E,ss,R,ts,Q,ns,H,rt='完成初步设置后，我们可以开始创建第一个推理端点。请访问 <a href="https://ui.endpoints.huggingface.co/" rel="nofollow">https://ui.endpoints.huggingface.co/</a> 并点击 <code>+ New</code>，位于 <code>Dedicated Endpoints</code> 旁边。然后，你将看到一个用于创建新端点的界面，提供以下选项（见下图）：',es,_,It='<li><strong>模型仓库</strong>：在这里，你可以输入 HF Hub 上任何模型的标识符。为了本次演示，我们使用 <a href="https://huggingface.co/google/gemma-1.1-2b-it" rel="nofollow">google/gemma-1.1-2b-it</a>，这是一个小型生成式大型语言模型（2.5B 参数）。</li> <li><strong>端点名称</strong>：端点名称会根据模型标识符自动生成，但你可以修改它。有效的端点名称只能包含小写字母、数字或连字符（”-”），并且长度必须在 4 到 32 个字符之间。</li> <li><strong>实例配置</strong>：在这里，你可以选择来自主要云平台的一系列 CPU 或 GPU 配置。你还可以调整区域设置，例如，如果你需要将端点托管在欧盟地区。</li> <li><strong>自动缩放到零</strong>：你可以将端点配置为在一段时间后缩放为零 GPU/CPU。缩放到零的端点将不再计费。请注意，重新启动端点时需要将模型重新加载到内存中（并可能重新下载），这对于大型模型可能需要几分钟时间。</li> <li><strong>端点安全级别</strong>：默认的安全级别是 <code>Protected</code>，需要授权的 HF 令牌才能访问该端点。<code>Public</code> 端点任何人都可以访问，无需令牌认证。<code>Private</code> 端点仅通过跨区域的安全 AWS 或 Azure PrivateLink 连接可用。</li> <li><strong>高级配置</strong>：在这里，你可以选择一些高级选项，例如 Docker 容器类型。由于 Gemma 与 <a href="https://huggingface.co/docs/text-generation-inference/index" rel="nofollow">文本生成推理（TGI）</a> 容器兼容，系统会自动选择 TGI 作为容器类型，并提供其他默认设置。</li>',as,X,bt="按照下图中的选项进行选择，并点击 <code>Create Endpoint</code>。",Ms,u,gt='<img src="https://huggingface.co/datasets/huggingface/cookbook-images/resolve/main/enterprise-endpoints-creation.png"/>',ps,q,Ct="大约一分钟后，你的推理端点将被创建，你将看到类似下图的页面。",is,v,ft="在端点的 <code>概览</code> 页面上，你可以找到用于查询该端点的 URL，一个用于测试模型的 Playground，以及其他标签页，包括 <code>分析</code>、<code>使用情况与费用</code>、<code>日志</code> 和 <code>设置</code>。",os,d,Zt='<img src="https://huggingface.co/datasets/huggingface/cookbook-images/resolve/main/enterprise-endpoint-overviewpage.png"/>',cs,Y,ys,S,Bt='在进入生产环境时，你不一定希望手动启动、停止和修改推理端点。<code>huggingface_hub</code> 库提供了很好的功能，用于编程方式管理推理端点。可以在 <a href="https://huggingface.co/docs/huggingface_hub/guides/inference_endpoints" rel="nofollow">这里</a> 查看文档，以及在 <a href="https://huggingface.co/docs/huggingface_hub/en/package_reference/inference_endpoints" rel="nofollow">这里</a> 获取所有函数的详细信息。以下是一些关键函数：',js,N,Js,z,Gt="你也可以通过编程方式创建推理端点。让我们重新创建与 UI 创建的相同的 <code>gemma</code> LLM 推理端点。",ms,$,Ts,F,Us,x,ws,L,Wt='现在，让我们像查询其他 LLM API 一样查询这个端点。首先，从界面复制端点 URL（或者使用 <code>endpoint.url</code>）并将其赋值给下面的 <code>API_URL</code>。接着，我们使用标准化的消息格式来传递文本输入，即一个包含用户和助手消息的字典，这种格式你可能在其他 LLM API 服务中见过。接下来，我们需要将聊天模板应用到这些消息上，这是像 Gemma、Llama-3 等 LLM 模型已经训练过的格式（详细信息请参见 <a href="https://huggingface.co/docs/transformers/main/en/chat_templating" rel="nofollow">文档</a>）。对于大多数最新的生成式 LLM，应用这个聊天模板是非常重要的，否则模型的表现会退化，且不会抛出错误。',hs,P,us,D,At=`Your text input looks like this, after the chat template has been applied:

<bos><start_of_turn>user
Please write a short poem about open source for me.<end_of_turn>
</end_of_turn></start_of_turn></bos>`,ds,K,rs,O,Vt=`The output from your API/Endpoint call:

[&#123;'generated_text': "Free to use, free to share,\\nA collaborative code, a community's care.\\n\\nCode transparent, bugs readily found,\\nContributions welcome, stories unbound.\\nOpen source, a gift to all,\\nBuilding the future, one line at a call.\\n\\nSo join the movement, embrace the light,\\nOpen source, shining ever so bright."}]
`,Is,ll,kt="就这样，你已经向你的推理端点发出了第一次请求——你自己的 API！",bs,sl,Et='如果你希望端点自动处理聊天模板，并且你的 LLM 运行在 TGI 容器上，你也可以通过在 URL 后追加 <code>/v1/chat/completions</code> 路径来使用 <a href="https://huggingface.co/docs/text-generation-inference/en/messages_api" rel="nofollow">messages API</a>。使用 <code>/v1/chat/completions</code> 路径时，运行在端点上的 <a href="https://huggingface.co/docs/text-generation-inference/index" rel="nofollow">TGI</a> 容器会自动应用聊天模板，并且与 OpenAI 的 API 结构完全兼容，便于互操作性。你可以查看 <a href="https://huggingface.github.io/text-generation-inference/#/Text%20Generation%20Inference/chat_completions" rel="nofollow">TGI Swagger UI</a> 获取所有可用参数。请注意，默认 <code>/</code> 路径和 <code>/v1/chat/completions</code> 路径接受的参数略有不同。以下是使用 messages API 的稍微修改过的代码：',gs,tl,Cs,nl,Rt=`The output from your API/Endpoint call with the OpenAI-compatible messages API route:

&#123;'id': '', 'object': 'text_completion', 'created': 1718283608, 'model': '/repository', 'system_fingerprint': '2.0.5-dev0-sha-90184df', 'choices': [&#123;'index': 0, 'message': &#123;'role': 'assistant', 'content': '**Open Source**\\n\\nA license for the mind,\\nTo share, distribute, and bind,\\nIdeas freely given birth,\\nFor the good of all to sort.\\n\\nCode transparent, eyes open wide,\\nA permission for the wise,\\nTo learn, to build, to use at will,\\nA future bright, we help fill.\\n\\nFrom servers vast to candles low,\\nOpen source, a guiding key,\\nFor progress made, knowledge shared,\\nA future brimming with'}, 'logprobs': None, 'finish_reason': 'length'}], 'usage': &#123;'prompt_tokens': 20, 'completion_tokens': 100, 'total_tokens': 120}}
`,fs,el,Zs,al,Qt='你还可以使用 <a href="https://huggingface.co/docs/huggingface_hub/en/package_reference/inference_client#huggingface_hub.InferenceClient" rel="nofollow"><code>InferenceClient</code></a> 来轻松地向你的端点发送请求。该客户端是 <code>huggingface_hub</code> Python 库中提供的一个便捷工具，允许你轻松调用 <a href="https://huggingface.co/docs/inference-endpoints/index" rel="nofollow">专用推理端点</a> 和 <a href="https://huggingface.co/docs/api-inference/index" rel="nofollow">无服务器推理 API</a>。详细信息请参阅 <a href="https://huggingface.co/docs/huggingface_hub/en/package_reference/inference_client#inference" rel="nofollow">文档</a>。',Bs,Ml,Ht="这是向你的端点发送请求的最简洁方式：",Gs,pl,Ws,il,As,ol,Vs,cl,_t="按照相同的过程，你可以为 HF Hub 上的任何模型创建推理端点。接下来，我们将展示一些其他的使用场景。",ks,yl,Es,jl,Xt="我们可以使用与 LLM 几乎相同的代码来创建一个图像生成推理端点。唯一的区别是，在这种情况下，我们不使用 TGI 容器，因为 TGI 仅为 LLM（以及视觉 LLM）设计。",Rs,Jl,Qs,ml,qt=`Collecting Pillow
  Downloading pillow-10.3.0-cp39-cp39-manylinux_2_28_x86_64.whl (4.5 MB)
\x1B[K     |████████████████████████████████| 4.5 MB 24.7 MB/s eta 0:00:01
\x1B[?25hInstalling collected packages: Pillow
Successfully installed Pillow-10.3.0
`,Hs,Tl,_s,Ul,vt=`Does the endpoint already exist? True
Waiting for endpoint to start
Endpoint ready
`,Xs,wl,qs,hl,Yt=`PROMPT:  A whimsical illustration of a fashionably dressed llama proudly holding a worn, vintage cookbook, with a warm cup of tea and a few freshly baked treats scattered around, set against a cozy background of rustic wood and blooming flowers.
`,vs,ul,St="我们再次暂停端点以停止计费。",Ys,dl,Ss,rl,Ns,Il,Nt='现在，让我们为视觉语言模型（VLM）创建一个推理端点。VLM 与 LLM 非常相似，不同之处在于它们可以同时接受文本和图像作为输入。它们的输出是自回归生成的文本，就像标准的 LLM 一样。VLM 可以处理许多任务，从视觉问答到文档理解。在这个例子中，我们使用 <a href="https://huggingface.co/blog/idefics2" rel="nofollow">Idefics2</a>，一个强大的 8B 参数 VLM。',zs,bl,zt="首先，我们需要将使用 Stable Diffusion 生成的 PIL 图像转换为 <code>base64</code> 编码的字符串，以便通过网络将其发送给模型。",$s,gl,Fs,Cl,$t='由于 VLM 和 LLM 非常相似，我们可以再次使用几乎相同的消息格式和聊天模板，只需添加一些代码以将图像包含在提示中。有关提示格式的具体细节，请参阅 <a href="https://huggingface.co/HuggingFaceM4/idefics2-8b" rel="nofollow">Idefics2 模型卡</a>。',xs,fl,Ls,r,Ps,Zl,Ft='像 Idefics2 这样的多个 VLM 也受到 TGI 支持（请参见 <a href="https://huggingface.co/docs/text-generation-inference/supported_models" rel="nofollow">支持的模型列表</a>），因此在创建端点时，我们再次使用 TGI 容器。',Ds,Bl,Ks,Gl,xt=`Does the endpoint already exist? False
Waiting for endpoint to be created
Endpoint ready
`,Os,Wl,lt,Al,Lt=`In a quaint little café, there lived a llama,
With glasses on his face, he was quite a charm.
He'd sit at the table,
With a book and a mable,
And sip from a cup of warm tea.
`,st,Vl,tt,kl,nt,El,Pt="<li>在创建多个端点时，你可能会收到一个错误消息，提示你的 GPU 配额已满。不要犹豫，直接发送邮件到错误消息中的邮箱地址，我们很可能会增加你的 GPU 配额。</li> <li><code>paused</code> 和 <code>scaled-to-zero</code> 端点有什么区别？<code>scaled-to-zero</code> 端点可以通过用户请求灵活唤醒并扩展，而 <code>paused</code> 端点需要由端点创建者手动解除暂停。此外，<code>scaled-to-zero</code> 端点会占用你的 GPU 配额（按其可能扩展到的最大副本数计算），而 <code>paused</code> 端点则不会。因此，一个简单的释放 GPU 配额的方法是暂停一些端点。</li>",et,Rl,at,Ql,Dt="就是这样，你已经为文本到文本、文本到图像、图像到文本的生成创建了三个不同的端点（你自己的 API！），同样的过程也适用于许多其他模型和任务。",Mt,Hl,Kt='我们鼓励你阅读专用推理端点的 <a href="https://huggingface.co/docs/inference-endpoints/index" rel="nofollow">文档</a>，以了解更多信息。如果你正在使用生成式 LLM 和 VLM，我们还建议阅读 TGI 的 <a href="https://huggingface.co/docs/text-generation-inference/index" rel="nofollow">文档</a>，因为最流行的 LLM 和 VLM 也都支持 TGI，这将使你的端点更加高效。',pt,_l,Ot='例如，你可以通过 <a href="https://huggingface.co/docs/text-generation-inference/basic_tutorials/using_guidance" rel="nofollow">TGI Guidance</a> 使用 <strong>JSON 模式或函数调用</strong> 来与开源模型交互（还可以参考这个 <a href="https://huggingface.co/learn/cookbook/structured_generation" rel="nofollow">食谱</a> 中的结构化生成示例，适用于 RAG）。',it,Xl,ln="当将端点投入生产时，你可能需要进行一些额外的改进，以提高设置的效率。使用 TGI 时，你应通过异步函数调用向端点发送请求批次，以充分利用端点的硬件，并且你可以调整多个容器参数，以优化延迟和吞吐量，针对你的具体用例进行优化。我们将在另一篇指南中介绍这些优化。",ot,ql,ct,Yl,yt;return b=new Jn({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/cookbook/blob/main/notebooks/zh-CN/enterprise_dedicated_endpoints.ipynb"}]}}),g=new h({props:{title:"推理端点（专用）",local:"推理端点专用",headingTag:"h1"}}),W=new h({props:{title:"安装与登录",local:"安装与登录",headingTag:"h2"}}),E=new T({props:{code:"IXBpcCUyMGluc3RhbGwlMjBodWdnaW5nZmFjZV9odWJ+JTNEMC4yMy4zJTBBIXBpcCUyMGluc3RhbGwlMjB0cmFuc2Zvcm1lcnN+JTNENC40MS4y",highlighted:`!pip install huggingface_hub~=<span class="hljs-number">0.23</span><span class="hljs-number">.3</span>
!pip install transformers~=<span class="hljs-number">4.41</span><span class="hljs-number">.2</span>`,wrap:!1}}),R=new T({props:{code:"JTIzJTIwTG9naW4lMjB0byUyMHRoZSUyMEhGJTIwSHViLiUyMFdlJTIwcmVjb21tZW5kJTIwdXNpbmclMjB0aGlzJTIwbG9naW4lMjBtZXRob2QlMEElMjMlMjB0byUyMGF2b2lkJTIwdGhlJTIwbmVlZCUyMGZvciUyMGV4cGxpY2l0bHklMjBzdG9yaW5nJTIweW91ciUyMEhGJTIwdG9rZW4lMjBpbiUyMHZhcmlhYmxlcyUwQWltcG9ydCUyMGh1Z2dpbmdmYWNlX2h1YiUwQSUwQWh1Z2dpbmdmYWNlX2h1Yi5pbnRlcnByZXRlcl9sb2dpbigp",highlighted:`<span class="hljs-comment"># Login to the HF Hub. We recommend using this login method</span>
<span class="hljs-comment"># to avoid the need for explicitly storing your HF token in variables</span>
<span class="hljs-keyword">import</span> huggingface_hub

huggingface_hub.interpreter_login()`,wrap:!1}}),Q=new h({props:{title:"创建你的第一个推理端点",local:"创建你的第一个推理端点",headingTag:"h2"}}),Y=new h({props:{title:"编程方式创建和管理端点",local:"编程方式创建和管理端点",headingTag:"h3"}}),N=new T({props:{code:"JTIzJTIwbGlzdCUyMGFsbCUyMHlvdXIlMjBpbmZlcmVuY2UlMjBlbmRwb2ludHMlMEFodWdnaW5nZmFjZV9odWIubGlzdF9pbmZlcmVuY2VfZW5kcG9pbnRzKCklMEElMEElMjMlMjBnZXQlMjBhbiUyMGV4aXN0aW5nJTIwZW5kcG9pbnQlMjBhbm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IwJTIwJTIwaW5zdGFuY2Vfc2l6ZSUzRCUyMngxJTIyJTJDJTBBJTIzJTIwJTIwJTIwJTIwaW5zdGFuY2VfdHlwZSUzRCUyMm52aWRpYS1hMTAwJTIyJTJDJTIwJTIwJTIzJTIwbnZpZGlhLWExMGclMEElMjMlMjAp",highlighted:`<span class="hljs-comment"># list all your inference endpoints</span>
huggingface_hub.list_inference_endpoints()

<span class="hljs-comment"># get an existing endpoint and check it&#x27;s status</span>
endpoint = huggingface_hub.get_inference_endpoint(
    name=<span class="hljs-string">&quot;gemma-1-1-2b-it-yci&quot;</span>,  <span class="hljs-comment"># the name of the endpoint</span>
    namespace=<span class="hljs-string">&quot;MoritzLaurer&quot;</span>,  <span class="hljs-comment"># your user name or organization name</span>
)
<span class="hljs-built_in">print</span>(endpoint)

<span class="hljs-comment"># Pause endpoint to stop billing</span>
endpoint.pause()

<span class="hljs-comment"># Resume and wait until the endpoint is ready</span>
<span class="hljs-comment"># endpoint.resume()</span>
<span class="hljs-comment"># endpoint.wait()</span>

<span class="hljs-comment"># Update the endpoint to a different GPU</span>
<span class="hljs-comment"># You can find the correct arguments for different hardware types in this table: https://huggingface.co/docs/inference-endpoints/pricing#gpu-instances</span>
<span class="hljs-comment"># endpoint.update(</span>
<span class="hljs-comment">#    instance_size=&quot;x1&quot;,</span>
<span class="hljs-comment">#    instance_type=&quot;nvidia-a100&quot;,  # nvidia-a10g</span>
<span class="hljs-comment"># )</span>`,wrap:!1}}),$=new T({props:{code:" ",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> create_inference_endpoint


model_id = <span class="hljs-string">&quot;google/gemma-1.1-2b-it&quot;</span>
endpoint_name = <span class="hljs-string">&quot;gemma-1-1-2b-it-001&quot;</span>  <span class="hljs-comment"># Valid Endpoint names must only contain lower-case characters, numbers or hyphens (&quot;-&quot;) and are between 4 to 32 characters long.</span>
namespace = <span class="hljs-string">&quot;MoritzLaurer&quot;</span>  <span class="hljs-comment"># your user or organization name</span>


<span class="hljs-comment"># check if endpoint with this name already exists from previous tests</span>
available_endpoints_names = [endpoint.name <span class="hljs-keyword">for</span> endpoint <span class="hljs-keyword">in</span> huggingface_hub.list_inference_endpoints()]
<span class="hljs-keyword">if</span> endpoint_name <span class="hljs-keyword">in</span> available_endpoints_names:
    endpoint_exists = <span class="hljs-literal">True</span>
<span class="hljs-keyword">else</span>:
    endpoint_exists = <span class="hljs-literal">False</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Does the endpoint already exist?&quot;</span>, endpoint_exists)


<span class="hljs-comment"># create new endpoint</span>
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> endpoint_exists:
    endpoint = create_inference_endpoint(
        endpoint_name,
        repository=model_id,
        namespace=namespace,
        framework=<span class="hljs-string">&quot;pytorch&quot;</span>,
        task=<span class="hljs-string">&quot;text-generation&quot;</span>,
        <span class="hljs-comment"># see the available hardware options here: https://huggingface.co/docs/inference-endpoints/pricing#pricing</span>
        accelerator=<span class="hljs-string">&quot;gpu&quot;</span>,
        vendor=<span class="hljs-string">&quot;aws&quot;</span>,
        region=<span class="hljs-string">&quot;us-east-1&quot;</span>,
        instance_size=<span class="hljs-string">&quot;x1&quot;</span>,
        instance_type=<span class="hljs-string">&quot;nvidia-a10g&quot;</span>,
        min_replica=<span class="hljs-number">0</span>,
        max_replica=<span class="hljs-number">1</span>,
        <span class="hljs-built_in">type</span>=<span class="hljs-string">&quot;protected&quot;</span>,
        <span class="hljs-comment"># since the LLM is compatible with TGI, we specify that we want to use the latest TGI image</span>
        custom_image={
            <span class="hljs-string">&quot;health_route&quot;</span>: <span class="hljs-string">&quot;/health&quot;</span>,
            <span class="hljs-string">&quot;env&quot;</span>: {<span class="hljs-string">&quot;MODEL_ID&quot;</span>: <span class="hljs-string">&quot;/repository&quot;</span>},
            <span class="hljs-string">&quot;url&quot;</span>: <span class="hljs-string">&quot;ghcr.io/huggingface/text-generation-inference:latest&quot;</span>,
        },
    )
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Waiting for endpoint to be created&quot;</span>)
    endpoint.wait()
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Endpoint ready&quot;</span>)

<span class="hljs-comment"># if endpoint with this name already exists, get and resume existing endpoint</span>
<span class="hljs-keyword">else</span>:
    endpoint = huggingface_hub.get_inference_endpoint(name=endpoint_name, namespace=namespace)
    <span class="hljs-keyword">if</span> endpoint.status <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;paused&quot;</span>, <span class="hljs-string">&quot;scaledToZero&quot;</span>]:
        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Resuming endpoint&quot;</span>)
        endpoint.resume()
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Waiting for endpoint to start&quot;</span>)
    endpoint.wait()
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Endpoint ready&quot;</span>)`,wrap:!1}}),F=new T({props:{code:"JTIzJTIwYWNjZXNzJTIwdGhlJTIwZW5kcG9pbnQlMjB1cmwlMjBmb3IlMjBBUEklMjBjYWxscyUwQXByaW50KGVuZHBvaW50LnVybCk=",highlighted:`<span class="hljs-comment"># access the endpoint url for API calls</span>
<span class="hljs-built_in">print</span>(endpoint.url)`,wrap:!1}}),x=new h({props:{title:"查询你的推理端点",local:"查询你的推理端点",headingTag:"h2"}}),P=new T({props:{code:"aW1wb3J0JTIwcmVxdWVzdHMlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUwQSUwQSUyMyUyMHBhc3RlJTIweW91ciUyMGVuZHBvaW50JTIwVVJMJTIwaGVyZSUyMG9yJTIwcmV1c2UlMjBlbmRwb2ludC51cmwlMjBpZiUyMHlvdSUyMGNyZWF0ZWQlMjB0aGUlMjBlbmRwb2ludCUyMHByb2dyYW1tYXRpY2FsbHklMEFBUElfVVJMJTIwJTNEJTIwZW5kcG9pbnQudXJsJTIwJTIwJTIzJTIwb3IlM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lMjAlMjAlMjMlMjAlN0IlMjJyb2xlJTIyJTNBJTIwJTIyYXNzaXN0YW50JTIyJTJDJTIwJTIyY29udGVudCUyMiUzQSUyMCUyMkklMjBhbSUyMG5vdCUyMGluJTIwdGhlJTIwbW9vZC4lMjIlN0QlMkMlMEElMjAlMjAlMjAlMjAlMjMlMjAlN0IlMjJyb2xlJTIyJTNBJTIwJTIydXNlciUyMiUyQyUyMCUyMmNvbnRlbnQlMjIlM0ElMjAlMjJDYW4lMjB5b3UlMjBwbGVhc2UlMjBkbyUyMHRoaXMlMjBmb3IlMjBtZSUzRiUyMiU3RCUyQyUwQSU1RCUwQSUwQSUyMyUyMGFwcGx5JTIwdGhlJTIwY2hhdCUyMHRlbXBsYXRlJTIwZm9yJTIwdGhlJTIwcmVzcGVjdGl2ZSUyMG1vZGVsJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJnb29nbGUlMkZnZW1tYS0xLjEtMmItaXQlMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCklMEFtZXNzYWdlc193aXRoX3RlbXBsYXRlJTIwJTNEJTIwdG9rZW5pemVyLmFwcGx5X2NoYXRfdGVtcGxhdGUobWVzc2FnZXMlMkMlMjB0b2tlbml6ZSUzREZhbHNlKSUwQXByaW50KCUyMllvdXIlMjB0ZXh0JTIwaW5wdXQlMjBsb29rcyUyMGxpa2UlMjB0aGlzJTJDJTIwYWZ0ZXIlMjB0aGUlMjBjaGF0JTIwdGVtcGxhdGUlMjBoYXMlMjBiZWVuJTIwYXBwbGllZCUzQSU1Q24lMjIpJTBBcHJpbnQobWVzc2FnZXNfd2l0aF90ZW1wbGF0ZSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># paste your endpoint URL here or reuse endpoint.url if you created the endpoint programmatically</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>API_URL = endpoint.url  <span class="hljs-comment"># or paste link like &quot;https://dz07884a53qjqb98.us-east-1.aws.endpoints.huggingface.cloud&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>HEADERS = {<span class="hljs-string">&quot;Authorization&quot;</span>: <span class="hljs-string">f&quot;Bearer <span class="hljs-subst">{huggingface_hub.get_token()}</span>&quot;</span>}


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># function for standard http requests</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">query</span>(<span class="hljs-params">payload=<span class="hljs-literal">None</span>, api_url=<span class="hljs-literal">None</span></span>):
<span class="hljs-meta">... </span>    response = requests.post(api_url, headers=HEADERS, json=payload)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> response.json()


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># define conversation input in messages format</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># you can also provide multiple turns between user and assistant</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>messages = [
<span class="hljs-meta">... </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;Please write a short poem about open source for me.&quot;</span>},
<span class="hljs-meta">... </span>    <span class="hljs-comment"># {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;I am not in the mood.&quot;},</span>
<span class="hljs-meta">... </span>    <span class="hljs-comment"># {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Can you please do this for me?&quot;},</span>
<span class="hljs-meta">... </span>]

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># apply the chat template for the respective model</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model_id = <span class="hljs-string">&quot;google/gemma-1.1-2b-it&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(model_id)
<span class="hljs-meta">&gt;&gt;&gt; </span>messages_with_template = tokenizer.apply_chat_template(messages, tokenize=<span class="hljs-literal">False</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Your text input looks like this, after the chat template has been applied:\\n&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(messages_with_template)`,wrap:!1}}),K=new T({props:{code:"JTIzJTIwc2VuZCUyMHN0YW5kYXJkJTIwaHR0cCUyMHJlcXVlc3QlMjB0byUyMGVuZHBvaW50JTBBb3V0cHV0JTIwJTNEJTIwcXVlcnkoJTBBJTIwJTIwJTIwJTIwcGF5bG9hZCUzRCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmlucHV0cyUyMiUzQSUyMG1lc3NhZ2VzX3dpdGhfdGVtcGxhdGUlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJwYXJhbWV0ZXJzJTIyJTNBJTIwJTdCJTIydGVtcGVyYXR1cmUlMjIlM0ElMjAwLjIlMkMlMjAlMjJtYXhfbmV3X3Rva2VucyUyMiUzQSUyMDEwMCUyQyUyMCUyMnNlZWQlMjIlM0ElMjA0MiUyQyUyMCUyMnJldHVybl9mdWxsX3RleHQlMjIlM0ElMjBGYWxzZSU3RCUyQyUwQSUyMCUyMCUyMCUyMCU3RCUyQyUwQSUyMCUyMCUyMCUyMGFwaV91cmwlM0RBUElfVVJMJTJDJTBBKSUwQSUwQXByaW50KCUyMlRoZSUyMG91dHB1dCUyMGZyb20lMjB5b3VyJTIwQVBJJTJGRW5kcG9pbnQlMjBjYWxsJTNBJTVDbiUyMiklMEFwcmludChvdXRwdXQp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># send standard http request to endpoint</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>output = query(
<span class="hljs-meta">... </span>    payload={
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;inputs&quot;</span>: messages_with_template,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;parameters&quot;</span>: {<span class="hljs-string">&quot;temperature&quot;</span>: <span class="hljs-number">0.2</span>, <span class="hljs-string">&quot;max_new_tokens&quot;</span>: <span class="hljs-number">100</span>, <span class="hljs-string">&quot;seed&quot;</span>: <span class="hljs-number">42</span>, <span class="hljs-string">&quot;return_full_text&quot;</span>: <span class="hljs-literal">False</span>},
<span class="hljs-meta">... </span>    },
<span class="hljs-meta">... </span>    api_url=API_URL,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;The output from your API/Endpoint call:\\n&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(output)`,wrap:!1}}),tl=new T({props:{code:"QVBJX1VSTF9DSEFUJTIwJTNEJTIwQVBJX1VSTCUyMCUyQiUyMCUyMiUyRnYxJTJGY2hhdCUyRmNvbXBsZXRpb25zJTIyJTBBJTBBb3V0cHV0JTIwJTNEJTIwcXVlcnkoJTBBJTIwJTIwJTIwJTIwcGF5bG9hZCUzRCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMm1lc3NhZ2VzJTIyJTNBJTIwbWVzc2FnZXMlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJtb2RlbCUyMiUzQSUyMCUyMnRnaSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnBhcmFtZXRlcnMlMjIlM0ElMjAlN0IlMjJ0ZW1wZXJhdHVyZSUyMiUzQSUyMDAuMiUyQyUyMCUyMm1heF90b2tlbnMlMjIlM0ElMjAxMDAlMkMlMjAlMjJzZWVkJTIyJTNBJTIwNDIlN0QlMkMlMEElMjAlMjAlMjAlMjAlN0QlMkMlMEElMjAlMjAlMjAlMjBhcGlfdXJsJTNEQVBJX1VSTF9DSEFUJTJDJTBBKSUwQSUwQXByaW50KCUyMlRoZSUyMG91dHB1dCUyMGZyb20lMjB5b3VyJTIwQVBJJTJGRW5kcG9pbnQlMjBjYWxsJTIwd2l0aCUyMHRoZSUyME9wZW5BSS1jb21wYXRpYmxlJTIwbWVzc2FnZXMlMjBBUEklMjByb3V0ZSUzQSU1Q24lMjIpJTBBcHJpbnQob3V0cHV0KQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>API_URL_CHAT = API_URL + <span class="hljs-string">&quot;/v1/chat/completions&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>output = query(
<span class="hljs-meta">... </span>    payload={
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;messages&quot;</span>: messages,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;model&quot;</span>: <span class="hljs-string">&quot;tgi&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;parameters&quot;</span>: {<span class="hljs-string">&quot;temperature&quot;</span>: <span class="hljs-number">0.2</span>, <span class="hljs-string">&quot;max_tokens&quot;</span>: <span class="hljs-number">100</span>, <span class="hljs-string">&quot;seed&quot;</span>: <span class="hljs-number">42</span>},
<span class="hljs-meta">... </span>    },
<span class="hljs-meta">... </span>    api_url=API_URL_CHAT,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;The output from your API/Endpoint call with the OpenAI-compatible messages API route:\\n&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(output)`,wrap:!1}}),el=new h({props:{title:"使用 InferenceClient 简化端点使用",local:"使用-inferenceclient-简化端点使用",headingTag:"h3"}}),pl=new T({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMEluZmVyZW5jZUNsaWVudCUwQSUwQWNsaWVudCUyMCUzRCUyMEluZmVyZW5jZUNsaWVudCgpJTBBJTBBb3V0cHV0JTIwJTNEJTIwY2xpZW50LmNoYXRfY29tcGxldGlvbiglMEElMjAlMjAlMjAlMjBtZXNzYWdlcyUyQyUyMCUyMCUyMyUyMHRoZSUyMGNoYXQlMjB0ZW1wbGF0ZSUyMGlzJTIwYXBwbGllZCUyMGF1dG9tYXRpY2FsbHklMkMlMjBpZiUyMHlvdXIlMjBlbmRwb2ludCUyMHVzZXMlMjBhJTIwVEdJJTIwY29udGFpbmVyJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0RBUElfVVJMJTJDJTBBJTIwJTIwJTIwJTIwdGVtcGVyYXR1cmUlM0QwLjIlMkMlMEElMjAlMjAlMjAlMjBtYXhfdG9rZW5zJTNEMTAwJTJDJTBBJTIwJTIwJTIwJTIwc2VlZCUzRDQyJTJDJTBBKSUwQSUwQXByaW50KCUyMlRoZSUyMG91dHB1dCUyMGZyb20lMjB5b3VyJTIwQVBJJTJGRW5kcG9pbnQlMjBjYWxsJTIwd2l0aCUyMHRoZSUyMEluZmVyZW5jZUNsaWVudCUzQSU1Q24lMjIpJTBBcHJpbnQob3V0cHV0KQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> InferenceClient

client = InferenceClient()

output = client.chat_completion(
    messages,  <span class="hljs-comment"># the chat template is applied automatically, if your endpoint uses a TGI container</span>
    model=API_URL,
    temperature=<span class="hljs-number">0.2</span>,
    max_tokens=<span class="hljs-number">100</span>,
    seed=<span class="hljs-number">42</span>,
)

<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;The output from your API/Endpoint call with the InferenceClient:\\n&quot;</span>)
<span class="hljs-built_in">print</span>(output)`,wrap:!1}}),il=new T({props:{code:"JTIzJTIwcGF1c2UlMjB0aGUlMjBlbmRwb2ludCUyMHRvJTIwc3RvcCUyMGJpbGxpbmclMEElMjMlMjBlbmRwb2ludC5wYXVzZSgp",highlighted:`<span class="hljs-comment"># pause the endpoint to stop billing</span>
<span class="hljs-comment"># endpoint.pause()</span>`,wrap:!1}}),ol=new h({props:{title:"为各种模型创建推理端点",local:"为各种模型创建推理端点",headingTag:"h2"}}),yl=new h({props:{title:"使用 Stable Diffusion 进行图像生成",local:"使用-stable-diffusion-进行图像生成",headingTag:"h3"}}),Jl=new T({props:{code:"IXBpcCUyMGluc3RhbGwlMjBQaWxsb3clMjAlMjAlMjMlMjBmb3IlMjBpbWFnZSUyMHByb2Nlc3Npbmc=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>!pip install Pillow  <span class="hljs-comment"># for image processing</span>',wrap:!1}}),Tl=new T({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGNyZWF0ZV9pbmZlcmVuY2VfZW5kcG9pbnQlMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi14bC1iYXNlLTEuMCUyMiUwQWVuZHBvaW50X25hbWUlMjAlM0QlMjAlMjJzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS0wLTAwMSUyMiUyMCUyMCUyMyUyMFZhbGlkJTIwRW5kcG9pbnQlMjBuYW1lcyUyMG11c3QlMjBvbmx5JTIwY29udGFpbiUyMGxvd2VyLWNhc2UlMjBjaGFyYWN0ZXJzJTJDJTIwbnVtYmVycyUyMG9yJTIwaHlwaGVucyUyMCglMjItJTIyKSUyMGFuZCUyMGFyZSUyMGJldHdlZW4lMjA0JTIwdG8lMjAzMiUyMGNoYXJhY3RlcnMlMjBsb25nLiUwQW5hbWVzcGFjZSUyMCUzRCUyMCUyMk1vcml0ekxhdXJlciUyMiUyMCUyMCUyMyUyMHlvdXIlMjB1c2VyJTIwb3IlMjBvcmdhbml6YXRpb24lMjBuYW1lJTBBdGFzayUyMCUzRCUy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HJlYWR5JTIyKSUwQSUwQSUyMyUyMGlmJTIwZW5kcG9pbnQlMjB3aXRoJTIwdGhpcyUyMG5hbWUlMjBhbHJlYWR5JTIwZXhpc3RzJTJDJTIwZ2V0JTIwZXhpc3RpbmclMjBlbmRwb2ludCUwQWVsc2UlM0ElMEElMjAlMjAlMjAlMjBlbmRwb2ludCUyMCUzRCUyMGh1Z2dpbmdmYWNlX2h1Yi5nZXRfaW5mZXJlbmNlX2VuZHBvaW50KG5hbWUlM0RlbmRwb2ludF9uYW1lJTJDJTIwbmFtZXNwYWNlJTNEbmFtZXNwYWNlKSUwQSUyMCUyMCUyMCUyMGlmJTIwZW5kcG9pbnQuc3RhdHVzJTIwaW4lMjAlNUIlMjJwYXVzZWQlMjIlMkMlMjAlMjJzY2FsZWRUb1plcm8lMjIlNUQlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmludCglMjJSZXN1bWluZyUyMGVuZHBvaW50JTIyKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGVuZHBvaW50LnJlc3VtZSgpJTBBJTIwJTIwJTIwJTIwcHJpbnQoJTIyV2FpdGluZyUyMGZvciUyMGVuZHBvaW50JTIwdG8lMjBzdGFydCUyMiklMEElMjAlMjAlMjAlMjBlbmRwb2ludC53YWl0KCklMEElMjAlMjAlMjAlMjBwcmludCglMjJFbmRwb2ludCUyMHJlYWR5JTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> create_inference_endpoint

<span class="hljs-meta">&gt;&gt;&gt; </span>model_id = <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>endpoint_name = <span class="hljs-string">&quot;stable-diffusion-xl-base-1-0-001&quot;</span>  <span class="hljs-comment"># Valid Endpoint names must only contain lower-case characters, numbers or hyphens (&quot;-&quot;) and are between 4 to 32 characters long.</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>namespace = <span class="hljs-string">&quot;MoritzLaurer&quot;</span>  <span class="hljs-comment"># your user or organization name</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>task = <span class="hljs-string">&quot;text-to-image&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># check if endpoint with this name already exists from previous tests</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>available_endpoints_names = [endpoint.name <span class="hljs-keyword">for</span> endpoint <span class="hljs-keyword">in</span> huggingface_hub.list_inference_endpoints()]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">if</span> endpoint_name <span class="hljs-keyword">in</span> available_endpoints_names:
<span class="hljs-meta">... </span>    endpoint_exists = <span class="hljs-literal">True</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>    endpoint_exists = <span class="hljs-literal">False</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Does the endpoint already exist?&quot;</span>, endpoint_exists)


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># create new endpoint</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> endpoint_exists:
<span class="hljs-meta">... </span>    endpoint = create_inference_endpoint(
<span class="hljs-meta">... </span>        endpoint_name,
<span class="hljs-meta">... </span>        repository=model_id,
<span class="hljs-meta">... </span>        namespace=namespace,
<span class="hljs-meta">... </span>        framework=<span class="hljs-string">&quot;pytorch&quot;</span>,
<span class="hljs-meta">... </span>        task=task,
<span class="hljs-meta">... </span>        <span class="hljs-comment"># see the available hardware options here: https://huggingface.co/docs/inference-endpoints/pricing#pricing</span>
<span class="hljs-meta">... </span>        accelerator=<span class="hljs-string">&quot;gpu&quot;</span>,
<span class="hljs-meta">... </span>        vendor=<span class="hljs-string">&quot;aws&quot;</span>,
<span class="hljs-meta">... </span>        region=<span class="hljs-string">&quot;us-east-1&quot;</span>,
<span class="hljs-meta">... </span>        instance_size=<span class="hljs-string">&quot;x1&quot;</span>,
<span class="hljs-meta">... </span>        instance_type=<span class="hljs-string">&quot;nvidia-a100&quot;</span>,
<span class="hljs-meta">... </span>        min_replica=<span class="hljs-number">0</span>,
<span class="hljs-meta">... </span>        max_replica=<span class="hljs-number">1</span>,
<span class="hljs-meta">... </span>        <span class="hljs-built_in">type</span>=<span class="hljs-string">&quot;protected&quot;</span>,
<span class="hljs-meta">... </span>    )
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Waiting for endpoint to be created&quot;</span>)
<span class="hljs-meta">... </span>    endpoint.wait()
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Endpoint ready&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># if endpoint with this name already exists, get existing endpoint</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>    endpoint = huggingface_hub.get_inference_endpoint(name=endpoint_name, namespace=namespace)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> endpoint.status <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;paused&quot;</span>, <span class="hljs-string">&quot;scaledToZero&quot;</span>]:
<span class="hljs-meta">... </span>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Resuming endpoint&quot;</span>)
<span class="hljs-meta">... </span>        endpoint.resume()
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Waiting for endpoint to start&quot;</span>)
<span class="hljs-meta">... </span>    endpoint.wait()
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Endpoint ready&quot;</span>)`,wrap:!1}}),wl=new T({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIyQSUyMHdoaW1zaWNhbCUyMGlsbHVzdHJhdGlvbiUyMG9mJTIwYSUyMGZhc2hpb25hYmx5JTIwZHJlc3NlZCUyMGxsYW1hJTIwcHJvdWRseSUyMGhvbGRpbmclMjBhJTIwd29ybiUyQyUyMHZpbnRhZ2UlMjBjb29rYm9vayUyQyUyMHdpdGglMjBhJTIwd2FybSUyMGN1cCUyMG9mJTIwdGVhJTIwYW5kJTIwYSUyMGZldyUyMGZyZXNobHklMjBiYWtlZCUyMHRyZWF0cyUyMHNjYXR0ZXJlZCUyMGFyb3VuZCUyQyUyMHNldCUyMGFnYWluc3QlMjBhJTIwY296eSUyMGJhY2tncm91bmQlMjBvZiUyMHJ1c3RpYyUyMHdvb2QlMjBhbmQlMjBibG9vbWluZyUyMGZsb3dlcnMuJTIyJTBBJTBBaW1hZ2UlMjAlM0QlMjBjbGllbnQudGV4dF90b19pbWFnZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlM0Rwcm9tcHQlMkMlMEElMjAlMjAlMjAlMjBtb2RlbCUzRGVuZHBvaW50LnVybCUyQyUyMCUyMCUyMyUyMCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi14bC1iYXNlLTEuMCUyMiUyQyUwQSUyMCUyMCUyMCUyMGd1aWRhbmNlX3NjYWxlJTNEOCUyQyUwQSklMEElMEFwcmludCglMjJQUk9NUFQlM0ElMjAlMjIlMkMlMjBwcm9tcHQpJTBBZGlzcGxheShpbWFnZS5yZXNpemUoKGltYWdlLndpZHRoJTIwJTJGJTJGJTIwMiUyQyUyMGltYWdlLmhlaWdodCUyMCUyRiUyRiUyMDIpKSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;A whimsical illustration of a fashionably dressed llama proudly holding a worn, vintage cookbook, with a warm cup of tea and a few freshly baked treats scattered around, set against a cozy background of rustic wood and blooming flowers.&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>image = client.text_to_image(
<span class="hljs-meta">... </span>    prompt=prompt,
<span class="hljs-meta">... </span>    model=endpoint.url,  <span class="hljs-comment"># &quot;stabilityai/stable-diffusion-xl-base-1.0&quot;,</span>
<span class="hljs-meta">... </span>    guidance_scale=<span class="hljs-number">8</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;PROMPT: &quot;</span>, prompt)
<span class="hljs-meta">&gt;&gt;&gt; </span>display(image.resize((image.width // <span class="hljs-number">2</span>, image.height // <span class="hljs-number">2</span>)))`,wrap:!1}}),dl=new T({props:{code:"ZW5kcG9pbnQucGF1c2UoKQ==",highlighted:"endpoint.pause()",wrap:!1}}),rl=new h({props:{title:"视觉语言模型：对文本和图像的推理",local:"视觉语言模型对文本和图像的推理",headingTag:"h3"}}),gl=new T({props:{code:"aW1wb3J0JTIwYmFzZTY0JTBBZnJvbSUyMGlvJTIwaW1wb3J0JTIwQnl0ZXNJTyUwQSUwQSUwQWRlZiUyMHBpbF9pbWFnZV90b19iYXNlNjQoaW1hZ2UpJTNBJTBBJTIwJTIwJTIwJTIwYnVmZmVyZWQlMjAlM0QlMjBCeXRlc0lPKCklMEElMjAlMjAlMjAlMjBpbWFnZS5zYXZlKGJ1ZmZlcmVkJTJDJTIwZm9ybWF0JTNEJTIySlBFRyUyMiklMEElMjAlMjAlMjAlMjBpbWdfc3RyJTIwJTNEJTIwYmFzZTY0LmI2NGVuY29kZShidWZmZXJlZC5nZXR2YWx1ZSgpKS5kZWNvZGUoJTIydXRmLTglMjIpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwaW1nX3N0ciUwQSUwQSUwQWltYWdlX2I2NCUyMCUzRCUyMHBpbF9pbWFnZV90b19iYXNlNjQoaW1hZ2Up",highlighted:`<span class="hljs-keyword">import</span> base64
<span class="hljs-keyword">from</span> io <span class="hljs-keyword">import</span> BytesIO


<span class="hljs-keyword">def</span> <span class="hljs-title function_">pil_image_to_base64</span>(<span class="hljs-params">image</span>):
    buffered = BytesIO()
    image.save(buffered, <span class="hljs-built_in">format</span>=<span class="hljs-string">&quot;JPEG&quot;</span>)
    img_str = base64.b64encode(buffered.getvalue()).decode(<span class="hljs-string">&quot;utf-8&quot;</span>)
    <span class="hljs-keyword">return</span> img_str


image_b64 = pil_image_to_base64(image)`,wrap:!1}}),fl=new T({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Qcm9jZXNzb3IlMEElMEElMjMlMjBsb2FkJTIwdGhlJTIwcHJvY2Vzc29yJTBBbW9kZWxfaWRfdmxtJTIwJTNEJTIwJTIySHVnZ2luZ0ZhY2VNNCUyRmlkZWZpY3MyLThiLWNoYXR0eSUyMiUwQXByb2Nlc3NvciUyMCUzRCUyMEF1dG9Qcm9jZXNzb3IuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkX3ZsbSklMEElMEElMjMlMjBkZWZpbmUlMjB0aGUlMjB1c2VyJTIwbWVzc2FnZXMlMEFtZXNzYWdlcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnJvbGUlMjIlM0ElMjAlMjJ1c2VyJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyY29udGVudCUyMiUzQSUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnR5cGUlMjIlM0ElMjAlMjJpbWFnZSUyMiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3RCUyQyUyMCUyMCUyMyUyMHRoZSUyMGltYWdlJTIwaXMlMjBwbGFjZWQlMjBoZXJlJTIwaW4lMjB0aGUlMjBwcm9tcHQuJTIwWW91JTIwY2FuJ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WdlX2lucHV0JTIwJTNEJTIwZiUyMmRhdGElM0FpbWFnZSUyRmpwZWclM0JiYXNlNjQlMkMlN0JpbWFnZV9iNjQlN0QlMjIlMEFpbWFnZV9pbnB1dCUyMCUzRCUyMGYlMjIhJTVCJTVEKCU3QmltYWdlX2lucHV0JTdEKSUyMiUwQXByb21wdCUyMCUzRCUyMHByb21wdC5yZXBsYWNlKCUyMiUzQ2ltYWdlJTNFJTIyJTJDJTIwaW1hZ2VfaW5wdXQp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoProcessor

<span class="hljs-comment"># load the processor</span>
model_id_vlm = <span class="hljs-string">&quot;HuggingFaceM4/idefics2-8b-chatty&quot;</span>
processor = AutoProcessor.from_pretrained(model_id_vlm)

<span class="hljs-comment"># define the user messages</span>
messages = [
    {
        <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;type&quot;</span>: <span class="hljs-string">&quot;image&quot;</span>
            },  <span class="hljs-comment"># the image is placed here in the prompt. You can add multiple images throughout the conversation.</span>
            {<span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;text&quot;</span>, <span class="hljs-string">&quot;text&quot;</span>: <span class="hljs-string">&quot;Write a short limerick about this image.&quot;</span>},
        ],
    },
]

<span class="hljs-comment"># apply the chat template to the messages</span>
prompt = processor.apply_chat_template(messages, add_generation_prompt=<span class="hljs-literal">True</span>)

<span class="hljs-comment"># the chat template places a special &quot;&lt;image&gt;&quot; token at the position where the image should go</span>
<span class="hljs-comment"># here we replace the &quot;&lt;image&gt;&quot; token with the base64 encoded image string in the prompt</span>
<span class="hljs-comment"># to be able to send the image via an API request</span>
image_input = <span class="hljs-string">f&quot;data:image/jpeg;base64,<span class="hljs-subst">{image_b64}</span>&quot;</span>
image_input = <span class="hljs-string">f&quot;![](<span class="hljs-subst">{image_input}</span>)&quot;</span>
prompt = prompt.replace(<span class="hljs-string">&quot;&lt;image&gt;&quot;</span>, image_input)`,wrap:!1}}),r=new jn({props:{warning:!1,$$slots:{default:[Tn]},$$scope:{ctx:Sl}}}),Bl=new T({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGNyZWF0ZV9pbmZlcmVuY2VfZW5kcG9pbnQlMEElMEFlbmRwb2ludF9uYW1lJTIwJTNEJTIwJTIyaWRlZmljczItOGItY2hhdHR5LTAwMSUyMiUwQW5hbWVzcGFjZSUyMCUzRCUyMCUyMk1vcml0ekxhdXJlciUyMiUwQXRhc2slMjAlM0QlMjAlMjJ0ZXh0LWdlbmVyYXRpb24lMjIlMEElMEElMjMlMjBjaGVjayUyMGlmJTIwZW5kcG9pbnQlMjB3aXRoJTIwdGhpcyUyMG5hbWUlMjBhbHJlYWR5JTIwZXhpc3RzJTIwZnJvbSUyMHByZXZpb3VzJTIwdGVzdHMlMEFhdmFpbGFibGVfZW5kcG9pbnRzX25hbWVzJTIwJTNEJTIwJTVCZW5kcG9pbnQubmFtZSUyMGZvciUyMGVuZHBvaW50JTIwaW4lMjBodWdnaW5nZmFjZV9odWIubGlzdF9pbmZlcmVuY2VfZW5kcG9pbnRzKCklNUQlMEFpZiUyMGVuZHBvaW50X25hbWUlMjBpbiUyMGF2YWlsYWJsZV9lbmRwb2ludHNfbmFtZXMlM0ElMEElMjAlMjAlMjAlMjBlbmRwb2ludF9leGlzdHMlMjAlM0QlMjBUcnVlJTBBZWxzZSUzQSUwQSUyMCUyMCUyMCUyMGVuZHBvaW50X2V4aXN0cyUyMCUzRCUyMEZhbHNlJTBBcHJpbnQoJTIyRG9lcyUyMHRoZSUyMGVuZHBvaW50JTIwYWxyZWFkeSUyMGV4aXN0JTNGJTIyJTJDJTIwZW5kcG9pbnRfZXhpc3RzKSUwQSUwQSUwQWlmJTIwZW5kcG9pbnRfZXhpc3RzJTNBJTBBJTIwJTIwJTIwJTIwZW5kcG9pbnQlMj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wJTIwJTIwJTIwJTIwJTIyTUFYX1RPVEFMX1RPS0VOUyUyMiUzQSUyMCUyMjE1MzYlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJNT0RFTF9JRCUyMiUzQSUyMCUyMiUyRnJlcG9zaXRvcnklMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0QlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ1cmwlMjIlM0ElMjAlMjJnaGNyLmlvJTJGaHVnZ2luZ2ZhY2UlMkZ0ZXh0LWdlbmVyYXRpb24taW5mZXJlbmNlJTNBbGF0ZXN0JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdEJTJDJTBBJTIwJTIwJTIwJTIwKSUwQSUwQSUyMCUyMCUyMCUyMHByaW50KCUyMldhaXRpbmclMjBmb3IlMjBlbmRwb2ludCUyMHRvJTIwYmUlMjBjcmVhdGVkJTIyKSUwQSUyMCUyMCUyMCUyMGVuZHBvaW50LndhaXQoKSUwQSUyMCUyMCUyMCUyMHByaW50KCUyMkVuZHBvaW50JTIwcmVhZHklMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> create_inference_endpoint

<span class="hljs-meta">&gt;&gt;&gt; </span>endpoint_name = <span class="hljs-string">&quot;idefics2-8b-chatty-001&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>namespace = <span class="hljs-string">&quot;MoritzLaurer&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>task = <span class="hljs-string">&quot;text-generation&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># check if endpoint with this name already exists from previous tests</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>available_endpoints_names = [endpoint.name <span class="hljs-keyword">for</span> endpoint <span class="hljs-keyword">in</span> huggingface_hub.list_inference_endpoints()]
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">if</span> endpoint_name <span class="hljs-keyword">in</span> available_endpoints_names:
<span class="hljs-meta">... </span>    endpoint_exists = <span class="hljs-literal">True</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>    endpoint_exists = <span class="hljs-literal">False</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Does the endpoint already exist?&quot;</span>, endpoint_exists)


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">if</span> endpoint_exists:
<span class="hljs-meta">... </span>    endpoint = huggingface_hub.get_inference_endpoint(name=endpoint_name, namespace=namespace)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> endpoint.status <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;paused&quot;</span>, <span class="hljs-string">&quot;scaledToZero&quot;</span>]:
<span class="hljs-meta">... </span>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Resuming endpoint&quot;</span>)
<span class="hljs-meta">... </span>        endpoint.resume()
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Waiting for endpoint to start&quot;</span>)
<span class="hljs-meta">... </span>    endpoint.wait()
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Endpoint ready&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>    endpoint = create_inference_endpoint(
<span class="hljs-meta">... </span>        endpoint_name,
<span class="hljs-meta">... </span>        repository=model_id_vlm,
<span class="hljs-meta">... </span>        namespace=namespace,
<span class="hljs-meta">... </span>        framework=<span class="hljs-string">&quot;pytorch&quot;</span>,
<span class="hljs-meta">... </span>        task=task,
<span class="hljs-meta">... </span>        accelerator=<span class="hljs-string">&quot;gpu&quot;</span>,
<span class="hljs-meta">... </span>        vendor=<span class="hljs-string">&quot;aws&quot;</span>,
<span class="hljs-meta">... </span>        region=<span class="hljs-string">&quot;us-east-1&quot;</span>,
<span class="hljs-meta">... </span>        <span class="hljs-built_in">type</span>=<span class="hljs-string">&quot;protected&quot;</span>,
<span class="hljs-meta">... </span>        instance_size=<span class="hljs-string">&quot;x1&quot;</span>,
<span class="hljs-meta">... </span>        instance_type=<span class="hljs-string">&quot;nvidia-a100&quot;</span>,
<span class="hljs-meta">... </span>        min_replica=<span class="hljs-number">0</span>,
<span class="hljs-meta">... </span>        max_replica=<span class="hljs-number">1</span>,
<span class="hljs-meta">... </span>        custom_image={
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;health_route&quot;</span>: <span class="hljs-string">&quot;/health&quot;</span>,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;env&quot;</span>: {
<span class="hljs-meta">... </span>                <span class="hljs-string">&quot;MAX_BATCH_PREFILL_TOKENS&quot;</span>: <span class="hljs-string">&quot;2048&quot;</span>,
<span class="hljs-meta">... </span>                <span class="hljs-string">&quot;MAX_INPUT_LENGTH&quot;</span>: <span class="hljs-string">&quot;1024&quot;</span>,
<span class="hljs-meta">... </span>                <span class="hljs-string">&quot;MAX_TOTAL_TOKENS&quot;</span>: <span class="hljs-string">&quot;1536&quot;</span>,
<span class="hljs-meta">... </span>                <span class="hljs-string">&quot;MODEL_ID&quot;</span>: <span class="hljs-string">&quot;/repository&quot;</span>,
<span class="hljs-meta">... </span>            },
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;url&quot;</span>: <span class="hljs-string">&quot;ghcr.io/huggingface/text-generation-inference:latest&quot;</span>,
<span class="hljs-meta">... </span>        },
<span class="hljs-meta">... </span>    )

<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Waiting for endpoint to be created&quot;</span>)
<span class="hljs-meta">... </span>    endpoint.wait()
<span class="hljs-meta">... </span>    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Endpoint ready&quot;</span>)`,wrap:!1}}),Wl=new T({props:{code:"b3V0cHV0JTIwJTNEJTIwY2xpZW50LnRleHRfZ2VuZXJhdGlvbihwcm9tcHQlMkMlMjBtb2RlbCUzRG1vZGVsX2lkX3ZsbSUyQyUyMG1heF9uZXdfdG9rZW5zJTNEMjAwJTJDJTIwc2VlZCUzRDQyKSUwQSUwQXByaW50KG91dHB1dCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>output = client.text_generation(prompt, model=model_id_vlm, max_new_tokens=<span class="hljs-number">200</span>, seed=<span class="hljs-number">42</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(output)`,wrap:!1}}),Vl=new T({props:{code:"ZW5kcG9pbnQucGF1c2UoKQ==",highlighted:"endpoint.pause()",wrap:!1}}),kl=new h({props:{title:"额外信息",local:"额外信息",headingTag:"h2"}}),Rl=new h({props:{title:"结论与下一步",local:"结论与下一步",headingTag:"h2"}}),ql=new mn({props:{source:"https://github.com/huggingface/cookbook/blob/main/notebooks/zh-CN/enterprise_dedicated_endpoints.md"}}),{c(){U=M("meta"),I=e(),w=M("p"),vl=e(),o(b.$$.fragment),Nl=e(),o(g.$$.fragment),zl=e(),C=M("p"),C.innerHTML=Jt,$l=e(),f=M("p"),f.innerHTML=mt,Fl=e(),Z=M("p"),Z.innerHTML=Tt,xl=e(),B=M("p"),B.textContent=Ut,Ll=e(),G=M("ul"),G.innerHTML=wt,Pl=e(),o(W.$$.fragment),Dl=e(),A=M("p"),A.innerHTML=ht,Kl=e(),V=M("p"),V.innerHTML=ut,Ol=e(),k=M("ul"),k.innerHTML=dt,ls=e(),o(E.$$.fragment),ss=e(),o(R.$$.fragment),ts=e(),o(Q.$$.fragment),ns=e(),H=M("p"),H.innerHTML=rt,es=e(),_=M("ul"),_.innerHTML=It,as=e(),X=M("p"),X.innerHTML=bt,Ms=e(),u=M("div"),u.innerHTML=gt,ps=e(),q=M("p"),q.textContent=Ct,is=e(),v=M("p"),v.innerHTML=ft,os=e(),d=M("div"),d.innerHTML=Zt,cs=e(),o(Y.$$.fragment),ys=e(),S=M("p"),S.innerHTML=Bt,js=e(),o(N.$$.fragment),Js=e(),z=M("p"),z.innerHTML=Gt,ms=e(),o($.$$.fragment),Ts=e(),o(F.$$.fragment),Us=e(),o(x.$$.fragment),ws=e(),L=M("p"),L.innerHTML=Wt,hs=e(),o(P.$$.fragment),us=e(),D=M("pre"),D.innerHTML=At,ds=e(),o(K.$$.fragment),rs=e(),O=M("pre"),O.textContent=Vt,Is=e(),ll=M("p"),ll.textContent=kt,bs=e(),sl=M("p"),sl.innerHTML=Et,gs=e(),o(tl.$$.fragment),Cs=e(),nl=M("pre"),nl.textContent=Rt,fs=e(),o(el.$$.fragment),Zs=e(),al=M("p"),al.innerHTML=Qt,Bs=e(),Ml=M("p"),Ml.textContent=Ht,Gs=e(),o(pl.$$.fragment),Ws=e(),o(il.$$.fragment),As=e(),o(ol.$$.fragment),Vs=e(),cl=M("p"),cl.textContent=_t,ks=e(),o(yl.$$.fragment),Es=e(),jl=M("p"),jl.textContent=Xt,Rs=e(),o(Jl.$$.fragment),Qs=e(),ml=M("pre"),ml.textContent=qt,Hs=e(),o(Tl.$$.fragment),_s=e(),Ul=M("pre"),Ul.textContent=vt,Xs=e(),o(wl.$$.fragment),qs=e(),hl=M("pre"),hl.textContent=Yt,vs=e(),ul=M("p"),ul.textContent=St,Ys=e(),o(dl.$$.fragment),Ss=e(),o(rl.$$.fragment),Ns=e(),Il=M("p"),Il.innerHTML=Nt,zs=e(),bl=M("p"),bl.innerHTML=zt,$s=e(),o(gl.$$.fragment),Fs=e(),Cl=M("p"),Cl.innerHTML=$t,xs=e(),o(fl.$$.fragment),Ls=e(),o(r.$$.fragment),Ps=e(),Zl=M("p"),Zl.innerHTML=Ft,Ds=e(),o(Bl.$$.fragment),Ks=e(),Gl=M("pre"),Gl.textContent=xt,Os=e(),o(Wl.$$.fragment),lt=e(),Al=M("pre"),Al.textContent=Lt,st=e(),o(Vl.$$.fragment),tt=e(),o(kl.$$.fragment),nt=e(),El=M("ul"),El.innerHTML=Pt,et=e(),o(Rl.$$.fragment),at=e(),Ql=M("p"),Ql.textContent=Dt,Mt=e(),Hl=M("p"),Hl.innerHTML=Kt,pt=e(),_l=M("p"),_l.innerHTML=Ot,it=e(),Xl=M("p"),Xl.textContent=ln,ot=e(),o(ql.$$.fragment),ct=e(),Yl=M("p"),this.h()},l(l){const s=cn("svelte-u9bgzb",document.head);U=p(s,"META",{name:!0,content:!0}),s.forEach(t),I=a(l),w=p(l,"P",{}),tn(w).forEach(t),vl=a(l),c(b.$$.fragment,l),Nl=a(l),c(g.$$.fragment,l),zl=a(l),C=p(l,"P",{"data-svelte-h":!0}),i(C)!=="svelte-11k54vh"&&(C.innerHTML=Jt),$l=a(l),f=p(l,"P",{"data-svelte-h":!0}),i(f)!=="svelte-9ss3up"&&(f.innerHTML=mt),Fl=a(l),Z=p(l,"P",{"data-svelte-h":!0}),i(Z)!=="svelte-c516pg"&&(Z.innerHTML=Tt),xl=a(l),B=p(l,"P",{"data-svelte-h":!0}),i(B)!=="svelte-1qdkdqc"&&(B.textContent=Ut),Ll=a(l),G=p(l,"UL",{"data-svelte-h":!0}),i(G)!=="svelte-10z2bl0"&&(G.innerHTML=wt),Pl=a(l),c(W.$$.fragment,l),Dl=a(l),A=p(l,"P",{"data-svelte-h":!0}),i(A)!=="svelte-1knx79m"&&(A.innerHTML=ht),Kl=a(l),V=p(l,"P",{"data-svelte-h":!0}),i(V)!=="svelte-1oo71hg"&&(V.innerHTML=ut),Ol=a(l),k=p(l,"UL",{"data-svelte-h":!0}),i(k)!=="svelte-19nrg04"&&(k.innerHTML=dt),ls=a(l),c(E.$$.fragment,l),ss=a(l),c(R.$$.fragment,l),ts=a(l),c(Q.$$.fragment,l),ns=a(l),H=p(l,"P",{"data-svelte-h":!0}),i(H)!=="svelte-c01oir"&&(H.innerHTML=rt),es=a(l),_=p(l,"UL",{"data-svelte-h":!0}),i(_)!=="svelte-1pyonng"&&(_.innerHTML=It),as=a(l),X=p(l,"P",{"data-svelte-h":!0}),i(X)!=="svelte-s10q1t"&&(X.innerHTML=bt),Ms=a(l),u=p(l,"DIV",{style:!0,"data-svelte-h":!0}),i(u)!=="svelte-y2vyyr"&&(u.innerHTML=gt),ps=a(l),q=p(l,"P",{"data-svelte-h":!0}),i(q)!=="svelte-6l41wa"&&(q.textContent=Ct),is=a(l),v=p(l,"P",{"data-svelte-h":!0}),i(v)!=="svelte-1190x9g"&&(v.innerHTML=ft),os=a(l),d=p(l,"DIV",{style:!0,"data-svelte-h":!0}),i(d)!=="svelte-a4voxj"&&(d.innerHTML=Zt),cs=a(l),c(Y.$$.fragment,l),ys=a(l),S=p(l,"P",{"data-svelte-h":!0}),i(S)!=="svelte-19h4ojp"&&(S.innerHTML=Bt),js=a(l),c(N.$$.fragment,l),Js=a(l),z=p(l,"P",{"data-svelte-h":!0}),i(z)!=="svelte-15zu242"&&(z.innerHTML=Gt),ms=a(l),c($.$$.fragment,l),Ts=a(l),c(F.$$.fragment,l),Us=a(l),c(x.$$.fragment,l),ws=a(l),L=p(l,"P",{"data-svelte-h":!0}),i(L)!=="svelte-1ljukhn"&&(L.innerHTML=Wt),hs=a(l),c(P.$$.fragment,l),us=a(l),D=p(l,"PRE",{"data-svelte-h":!0}),i(D)!=="svelte-1ge2cq1"&&(D.innerHTML=At),ds=a(l),c(K.$$.fragment,l),rs=a(l),O=p(l,"PRE",{"data-svelte-h":!0}),i(O)!=="svelte-eapgg6"&&(O.textContent=Vt),Is=a(l),ll=p(l,"P",{"data-svelte-h":!0}),i(ll)!=="svelte-1cgqd4k"&&(ll.textContent=kt),bs=a(l),sl=p(l,"P",{"data-svelte-h":!0}),i(sl)!=="svelte-1yhn6qo"&&(sl.innerHTML=Et),gs=a(l),c(tl.$$.fragment,l),Cs=a(l),nl=p(l,"PRE",{"data-svelte-h":!0}),i(nl)!=="svelte-ylq8xh"&&(nl.textContent=Rt),fs=a(l),c(el.$$.fragment,l),Zs=a(l),al=p(l,"P",{"data-svelte-h":!0}),i(al)!=="svelte-1wihcpf"&&(al.innerHTML=Qt),Bs=a(l),Ml=p(l,"P",{"data-svelte-h":!0}),i(Ml)!=="svelte-dxfw3d"&&(Ml.textContent=Ht),Gs=a(l),c(pl.$$.fragment,l),Ws=a(l),c(il.$$.fragment,l),As=a(l),c(ol.$$.fragment,l),Vs=a(l),cl=p(l,"P",{"data-svelte-h":!0}),i(cl)!=="svelte-1azqnoq"&&(cl.textContent=_t),ks=a(l),c(yl.$$.fragment,l),Es=a(l),jl=p(l,"P",{"data-svelte-h":!0}),i(jl)!=="svelte-t8eiz4"&&(jl.textContent=Xt),Rs=a(l),c(Jl.$$.fragment,l),Qs=a(l),ml=p(l,"PRE",{"data-svelte-h":!0}),i(ml)!=="svelte-155ymre"&&(ml.textContent=qt),Hs=a(l),c(Tl.$$.fragment,l),_s=a(l),Ul=p(l,"PRE",{"data-svelte-h":!0}),i(Ul)!=="svelte-1y8n5ov"&&(Ul.textContent=vt),Xs=a(l),c(wl.$$.fragment,l),qs=a(l),hl=p(l,"PRE",{"data-svelte-h":!0}),i(hl)!=="svelte-1cx6d48"&&(hl.textContent=Yt),vs=a(l),ul=p(l,"P",{"data-svelte-h":!0}),i(ul)!=="svelte-sfxj2q"&&(ul.textContent=St),Ys=a(l),c(dl.$$.fragment,l),Ss=a(l),c(rl.$$.fragment,l),Ns=a(l),Il=p(l,"P",{"data-svelte-h":!0}),i(Il)!=="svelte-1qbnxlo"&&(Il.innerHTML=Nt),zs=a(l),bl=p(l,"P",{"data-svelte-h":!0}),i(bl)!=="svelte-8nnv5d"&&(bl.innerHTML=zt),$s=a(l),c(gl.$$.fragment,l),Fs=a(l),Cl=p(l,"P",{"data-svelte-h":!0}),i(Cl)!=="svelte-15w7yiz"&&(Cl.innerHTML=$t),xs=a(l),c(fl.$$.fragment,l),Ls=a(l),c(r.$$.fragment,l),Ps=a(l),Zl=p(l,"P",{"data-svelte-h":!0}),i(Zl)!=="svelte-1ntw2le"&&(Zl.innerHTML=Ft),Ds=a(l),c(Bl.$$.fragment,l),Ks=a(l),Gl=p(l,"PRE",{"data-svelte-h":!0}),i(Gl)!=="svelte-rvo07b"&&(Gl.textContent=xt),Os=a(l),c(Wl.$$.fragment,l),lt=a(l),Al=p(l,"PRE",{"data-svelte-h":!0}),i(Al)!=="svelte-vodlno"&&(Al.textContent=Lt),st=a(l),c(Vl.$$.fragment,l),tt=a(l),c(kl.$$.fragment,l),nt=a(l),El=p(l,"UL",{"data-svelte-h":!0}),i(El)!=="svelte-10t0gg8"&&(El.innerHTML=Pt),et=a(l),c(Rl.$$.fragment,l),at=a(l),Ql=p(l,"P",{"data-svelte-h":!0}),i(Ql)!=="svelte-12ddamu"&&(Ql.textContent=Dt),Mt=a(l),Hl=p(l,"P",{"data-svelte-h":!0}),i(Hl)!=="svelte-su5adi"&&(Hl.innerHTML=Kt),pt=a(l),_l=p(l,"P",{"data-svelte-h":!0}),i(_l)!=="svelte-1s2t7ek"&&(_l.innerHTML=Ot),it=a(l),Xl=p(l,"P",{"data-svelte-h":!0}),i(Xl)!=="svelte-1q2ene4"&&(Xl.textContent=ln),ot=a(l),c(ql.$$.fragment,l),ct=a(l),Yl=p(l,"P",{}),tn(Yl).forEach(t),this.h()},h(){jt(U,"name","hf:doc:metadata"),jt(U,"content",wn),nn(u,"display","flex"),nn(u,"justify-content","center",1),jt(d,"style","flex justify-center")},m(l,s){yn(document.head,U),n(l,I,s),n(l,w,s),n(l,vl,s),y(b,l,s),n(l,Nl,s),y(g,l,s),n(l,zl,s),n(l,C,s),n(l,$l,s),n(l,f,s),n(l,Fl,s),n(l,Z,s),n(l,xl,s),n(l,B,s),n(l,Ll,s),n(l,G,s),n(l,Pl,s),y(W,l,s),n(l,Dl,s),n(l,A,s),n(l,Kl,s),n(l,V,s),n(l,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,s),y(kl,l,s),n(l,nt,s),n(l,El,s),n(l,et,s),y(Rl,l,s),n(l,at,s),n(l,Ql,s),n(l,Mt,s),n(l,Hl,s),n(l,pt,s),n(l,_l,s),n(l,it,s),n(l,Xl,s),n(l,ot,s),y(ql,l,s),n(l,ct,s),n(l,Yl,s),yt=!0},p(l,[s]){const sn={};s&2&&(sn.$$scope={dirty:s,ctx:l}),r.$set(sn)},i(l){yt||(j(b.$$.fragment,l),j(g.$$.fragment,l),j(W.$$.fragment,l),j(E.$$.fragment,l),j(R.$$.fragment,l),j(Q.$$.fragment,l),j(Y.$$.fragment,l),j(N.$$.fragment,l),j($.$$.fragment,l),j(F.$$.fragment,l),j(x.$$.fragment,l),j(P.$$.fragment,l),j(K.$$.fragment,l),j(tl.$$.fragment,l),j(el.$$.fragment,l),j(pl.$$.fragment,l),j(il.$$.fragment,l),j(ol.$$.fragment,l),j(yl.$$.fragment,l),j(Jl.$$.fragment,l),j(Tl.$$.fragment,l),j(wl.$$.fragment,l),j(dl.$$.fragment,l),j(rl.$$.fragment,l),j(gl.$$.fragment,l),j(fl.$$.fragment,l),j(r.$$.fragment,l),j(Bl.$$.fragment,l),j(Wl.$$.fragment,l),j(Vl.$$.fragment,l),j(kl.$$.fragment,l),j(Rl.$$.fragment,l),j(ql.$$.fragment,l),yt=!0)},o(l){J(b.$$.fragment,l),J(g.$$.fragment,l),J(W.$$.fragment,l),J(E.$$.fragment,l),J(R.$$.fragment,l),J(Q.$$.fragment,l),J(Y.$$.fragment,l),J(N.$$.fragment,l),J($.$$.fragment,l),J(F.$$.fragment,l),J(x.$$.fragment,l),J(P.$$.fragment,l),J(K.$$.fragment,l),J(tl.$$.fragment,l),J(el.$$.fragment,l),J(pl.$$.fragment,l),J(il.$$.fragment,l),J(ol.$$.fragment,l),J(yl.$$.fragment,l),J(Jl.$$.fragment,l),J(Tl.$$.fragment,l),J(wl.$$.fragment,l),J(dl.$$.fragment,l),J(rl.$$.fragment,l),J(gl.$$.fragment,l),J(fl.$$.fragment,l),J(r.$$.fragment,l),J(Bl.$$.fragment,l),J(Wl.$$.fragment,l),J(Vl.$$.fragment,l),J(kl.$$.fragment,l),J(Rl.$$.fragment,l),J(ql.$$.fragment,l),yt=!1},d(l){l&&(t(I),t(w),t(vl),t(Nl),t(zl),t(C),t($l),t(f),t(Fl),t(Z),t(xl),t(B),t(Ll),t(G),t(Pl),t(Dl),t(A),t(Kl),t(V),t(Ol),t(k),t(ls),t(ss),t(ts),t(ns),t(H),t(es),t(_),t(as),t(X),t(Ms),t(u),t(ps),t(q),t(is),t(v),t(os),t(d),t(cs),t(ys),t(S),t(js),t(Js),t(z),t(ms),t(Ts),t(Us),t(ws),t(L),t(hs),t(us),t(D),t(ds),t(rs),t(O),t(Is),t(ll),t(bs),t(sl),t(gs),t(Cs),t(nl),t(fs),t(Zs),t(al),t(Bs),t(Ml),t(Gs),t(Ws),t(As),t(Vs),t(cl),t(ks),t(Es),t(jl),t(Rs),t(Qs),t(ml),t(Hs),t(_s),t(Ul),t(Xs),t(qs),t(hl),t(vs),t(ul),t(Ys),t(Ss),t(Ns),t(Il),t(zs),t(bl),t($s),t(Fs),t(Cl),t(xs),t(Ls),t(Ps),t(Zl),t(Ds),t(Ks),t(Gl),t(Os),t(lt),t(Al),t(st),t(tt),t(nt),t(El),t(et),t(at),t(Ql),t(Mt),t(Hl),t(pt),t(_l),t(it),t(Xl),t(ot),t(ct),t(Yl)),t(U),m(b,l),m(g,l),m(W,l),m(E,l),m(R,l),m(Q,l),m(Y,l),m(N,l),m($,l),m(F,l),m(x,l),m(P,l),m(K,l),m(tl,l),m(el,l),m(pl,l),m(il,l),m(ol,l),m(yl,l),m(Jl,l),m(Tl,l),m(wl,l),m(dl,l),m(rl,l),m(gl,l),m(fl,l),m(r,l),m(Bl,l),m(Wl,l),m(Vl,l),m(kl,l),m(Rl,l),m(ql,l)}}}const wn='{"title":"推理端点（专用）","local":"推理端点专用","sections":[{"title":"安装与登录","local":"安装与登录","sections":[],"depth":2},{"title":"创建你的第一个推理端点","local":"创建你的第一个推理端点","sections":[{"title":"编程方式创建和管理端点","local":"编程方式创建和管理端点","sections":[],"depth":3}],"depth":2},{"title":"查询你的推理端点","local":"查询你的推理端点","sections":[{"title":"使用 InferenceClient 简化端点使用","local":"使用-inferenceclient-简化端点使用","sections":[],"depth":3}],"depth":2},{"title":"为各种模型创建推理端点","local":"为各种模型创建推理端点","sections":[{"title":"使用 Stable Diffusion 进行图像生成","local":"使用-stable-diffusion-进行图像生成","sections":[],"depth":3},{"title":"视觉语言模型：对文本和图像的推理","local":"视觉语言模型对文本和图像的推理","sections":[],"depth":3}],"depth":2},{"title":"额外信息","local":"额外信息","sections":[],"depth":2},{"title":"结论与下一步","local":"结论与下一步","sections":[],"depth":2}],"depth":1}';function hn(Sl){return an(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gn extends pn{constructor(U){super(),on(this,U,hn,Un,en,{})}}export{gn as component};
