import{s as Mn,n as pn,o as on}from"../chunks/scheduler.1f027d5a.js";import{S as cn,i as jn,e as M,s as e,c as o,h as yn,a as p,d as t,b as a,f as en,g as c,j as i,k as Jt,q as an,l as Jn,m as n,n as j,t as y,o as J,p as m}from"../chunks/index.6117a65d.js";import{C as mn}from"../chunks/CopyLLMTxtMenu.0ff8411a.js";import{D as Tn,C as T}from"../chunks/DocNotebookDropdown.316c3715.js";import{H as U,E as Un}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.0eecd2bb.js";function wn(mt){let w,Yl,ql,Sl,r,Nl,I,zl,b,Fl,g,Tt='<em>作者：<a href="https://huggingface.co/MoritzLaurer" rel="nofollow">Moritz Laurer</a></em>',$l,f,Ut='你是否曾想过创建自己的机器学习 API？在这篇教程中，我们将使用 <a href="https://huggingface.co/docs/inference-endpoints/index" rel="nofollow">HF 专用推理端点</a> 来实现这一目标。推理端点允许你选择 HF Hub 上成千上万的模型，创建你自己的 API，并将其部署在你控制的平台和你选择的硬件上。',xl,C,wt='<a href="link-to-recipe">无服务器推理 API</a> 非常适合初步测试，但它们仅限于一组预配置的流行模型，并且有速率限制，因为无服务器 API 的硬件同时被多个用户共享。使用专用推理端点，你可以自定义模型的部署，并且硬件仅为你独享。',Ll,Z,ht="在本教程中，我们将：",Pl,B,ut="<li>通过一个简单的 UI 创建推理端点，并向该端点发送标准的 HTTP 请求</li> <li>使用 <code>huggingface_hub</code> 库编程方式创建和管理不同的推理端点</li> <li>涵盖三个用例：使用大型语言模型（LLM）进行文本生成、使用 Stable Diffusion 进行图像生成、以及使用 Idefics2 进行图像推理</li>",Dl,G,Kl,W,dt='如果你还没有 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> 中添加信用卡信息。',Ol,A,rt='接下来，你可以在 <a href="https://huggingface.co/docs/hub/security-tokens" rel="nofollow">这里</a> 创建一个用户访问令牌。对于本教程，带有 <code>read</code> 或 <code>write</code> 权限的令牌即可使用，但我们建议使用更细粒度的令牌以提高安全性。对于本笔记本，你需要一个细粒度令牌，具备以下权限：',ls,V,It="<li><code>用户权限 &gt; 推理 &gt; 调用推理端点与管理推理端点</code></li> <li><code>仓库权限 &gt; google/gemma-1.1-2b-it 和 HuggingFaceM4/idefics2-8b-chatty</code></li>",ss,E,ts,k,ns,R,es,Q,bt='完成初步设置后，我们可以开始创建第一个推理端点。请访问 <a href="https://ui.endpoints.huggingface.co/" rel="nofollow">https://ui.endpoints.huggingface.co/</a> 并点击 <code>+ New</code>，位于 <code>Dedicated Endpoints</code> 旁边。然后，你将看到一个用于创建新端点的界面，提供以下选项（见下图）：',as,H,gt='<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>',Ms,_,ft="按照下图中的选项进行选择，并点击 <code>Create Endpoint</code>。",ps,h,Ct='<img src="https://huggingface.co/datasets/huggingface/cookbook-images/resolve/main/enterprise-endpoints-creation.png"/>',is,X,Zt="大约一分钟后，你的推理端点将被创建，你将看到类似下图的页面。",os,q,Bt="在端点的 <code>概览</code> 页面上，你可以找到用于查询该端点的 URL，一个用于测试模型的 Playground，以及其他标签页，包括 <code>分析</code>、<code>使用情况与费用</code>、<code>日志</code> 和 <code>设置</code>。",cs,u,Gt='<img src="https://huggingface.co/datasets/huggingface/cookbook-images/resolve/main/enterprise-endpoint-overviewpage.png"/>',js,v,ys,Y,Wt='在进入生产环境时，你不一定希望手动启动、停止和修改推理端点。<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,S,ms,N,At="你也可以通过编程方式创建推理端点。让我们重新创建与 UI 创建的相同的 <code>gemma</code> LLM 推理端点。",Ts,z,Us,F,ws,$,hs,x,Vt='现在，让我们像查询其他 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，应用这个聊天模板是非常重要的，否则模型的表现会退化，且不会抛出错误。',us,L,ds,P,Et=`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>`,rs,D,Is,K,kt=`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."}]
`,bs,O,Rt="就这样，你已经向你的推理端点发出了第一次请求——你自己的 API！",gs,ll,Qt='如果你希望端点自动处理聊天模板，并且你的 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 的稍微修改过的代码：',fs,sl,Cs,tl,Ht=`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}}
`,Zs,nl,Bs,el,_t='你还可以使用 <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>。',Gs,al,Xt="这是向你的端点发送请求的最简洁方式：",Ws,Ml,As,pl,Vs,il,Es,ol,qt="按照相同的过程，你可以为 HF Hub 上的任何模型创建推理端点。接下来，我们将展示一些其他的使用场景。",ks,cl,Rs,jl,vt="我们可以使用与 LLM 几乎相同的代码来创建一个图像生成推理端点。唯一的区别是，在这种情况下，我们不使用 TGI 容器，因为 TGI 仅为 LLM（以及视觉 LLM）设计。",Qs,yl,Hs,Jl,Yt=`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
`,_s,ml,Xs,Tl,St=`Does the endpoint already exist? True
Waiting for endpoint to start
Endpoint ready
`,qs,Ul,vs,wl,Nt=`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.
`,Ys,hl,zt="我们再次暂停端点以停止计费。",Ss,ul,Ns,dl,zs,rl,Ft='现在，让我们为视觉语言模型（VLM）创建一个推理端点。VLM 与 LLM 非常相似，不同之处在于它们可以同时接受文本和图像作为输入。它们的输出是自回归生成的文本，就像标准的 LLM 一样。VLM 可以处理许多任务，从视觉问答到文档理解。在这个例子中，我们使用 <a href="https://huggingface.co/blog/idefics2" rel="nofollow">Idefics2</a>，一个强大的 8B 参数 VLM。',Fs,Il,$t="首先，我们需要将使用 Stable Diffusion 生成的 PIL 图像转换为 <code>base64</code> 编码的字符串，以便通过网络将其发送给模型。",$s,bl,xs,gl,xt='由于 VLM 和 LLM 非常相似，我们可以再次使用几乎相同的消息格式和聊天模板，只需添加一些代码以将图像包含在提示中。有关提示格式的具体细节，请参阅 <a href="https://huggingface.co/HuggingFaceM4/idefics2-8b" rel="nofollow">Idefics2 模型卡</a>。',Ls,fl,Ps,d,Lt=`<p><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。</p>`,Ds,Cl,Pt='像 Idefics2 这样的多个 VLM 也受到 TGI 支持（请参见 <a href="https://huggingface.co/docs/text-generation-inference/supported_models" rel="nofollow">支持的模型列表</a>），因此在创建端点时，我们再次使用 TGI 容器。',Ks,Zl,Os,Bl,Dt=`Does the endpoint already exist? False
Waiting for endpoint to be created
Endpoint ready
`,lt,Gl,st,Wl,Kt=`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.
`,tt,Al,nt,Vl,et,El,Ot="<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>",at,kl,Mt,Rl,ln="就是这样，你已经为文本到文本、文本到图像、图像到文本的生成创建了三个不同的端点（你自己的 API！），同样的过程也适用于许多其他模型和任务。",pt,Ql,sn='我们鼓励你阅读专用推理端点的 <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，这将使你的端点更加高效。',it,Hl,tn='例如，你可以通过 <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）。',ot,_l,nn="当将端点投入生产时，你可能需要进行一些额外的改进，以提高设置的效率。使用 TGI 时，你应通过异步函数调用向端点发送请求批次，以充分利用端点的硬件，并且你可以调整多个容器参数，以优化延迟和吞吐量，针对你的具体用例进行优化。我们将在另一篇指南中介绍这些优化。",ct,Xl,jt,vl,yt;return r=new Tn({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"}]}}),I=new mn({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),b=new U({props:{title:"推理端点（专用）",local:"推理端点专用",headingTag:"h1"}}),G=new U({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}}),k=new T({props:{code:"JTIzJTIwTG9naW4lMjB0byUyMHRoZSUyMEhGJTIwSHViLiUyMFdlJTIwcmVjb21tZW5kJTIwdXNpbmclMjB0aGlzJTIwbG9naW4lMjBtZXRob2QlMjAlMEElMjMlMjB0byUyMGF2b2lkJTIwdGhlJTIwbmVlZCUyMGZvciUyMGV4cGxpY2l0bHklMjBzdG9yaW5nJTIweW91ciUyMEhGJTIwdG9rZW4lMjBpbiUyMHZhcmlhYmxlcyUyMCUwQWltcG9ydCUyMGh1Z2dpbmdmYWNlX2h1YiUwQWh1Z2dpbmdmYWNlX2h1Yi5pbnRlcnByZXRlcl9sb2dpbigp",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}}),R=new U({props:{title:"创建你的第一个推理端点",local:"创建你的第一个推理端点",headingTag:"h2"}}),v=new U({props:{title:"编程方式创建和管理端点",local:"编程方式创建和管理端点",headingTag:"h3"}}),S=new T({props:{code:"JTIzJTIwbGlzdCUyMGFsbCUyMHlvdXIlMjBpbmZlcmVuY2UlMjBlbmRwb2ludHMlMEFodWdnaW5nZmFjZV9odWIubGlzdF9pbmZlcmVuY2VfZW5kcG9pbnRzKCklMEElMEElMjMlMjBnZXQlMjBhbiUyMGV4aXN0aW5nJTIwZW5kcG9pbnQlMjBhbmQlMjBjaGVjayUyMGl0J3MlMjBzdGF0dXMlMEFlbmRwb2lud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IwJTIwJTIwJTIwaW5zdGFuY2VfdHlwZSUzRCUyMm52aWRpYS1hMTAwJTIyJTJDJTIwJTIwJTIzJTIwbnZpZGlhLWExMGclMEElMjMp",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}}),z=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}}),$=new U({props:{title:"查询你的推理端点",local:"查询你的推理端点",headingTag:"h2"}}),L=new T({props:{code:"aW1wb3J0JTIwcmVxdWVzdHMlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUwQSUwQSUyMyUyMHBhc3RlJTIweW91ciUyMGVuZHBvaW50JTIwVVJMJTIwaGVyZSUyMG9yJTIwcmV1c2UlMjBlbmRwb2ludC51cmwlMjBpZiUyMHlvdSUyMGNyZWF0ZWQlMjB0aGUlMjBlbmRwb2ludCUyMHByb2dyYW1tYXRpY2FsbHklMEFBUElfVVJMJTIwJTNEJTIwZW5kcG9pbnQudXJsJTIwJTIwJTIzJTIwb3IlMjBwYXN0ZSUyMGxpbmslMjBsaWtlJTIwJTIyaHR0cHMlM0ElMkYlMkZk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yJTJDJTIwJTIyY29udGVudCUyMiUzQSUyMCUyMkklMjBhbSUyMG5vdCUyMGluJTIwdGhlJTIwbW9vZC4lMjIlN0QlMkMlMEElMjAlMjAlMjAlMjAlMjMlN0IlMjJyb2xlJTIyJTNBJTIwJTIydXNlciUyMiUyQyUyMCUyMmNvbnRlbnQlMjIlM0ElMjAlMjJDYW4lMjB5b3UlMjBwbGVhc2UlMjBkbyUyMHRoaXMlMjBmb3IlMjBtZSUzRiUyMiU3RCUyQyUwQSU1RCUwQSUwQSUyMyUyMGFwcGx5JTIwdGhlJTIwY2hhdCUyMHRlbXBsYXRlJTIwZm9yJTIwdGhlJTIwcmVzcGVjdGl2ZSUyMG1vZGVsJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJnb29nbGUlMkZnZW1tYS0xLjEtMmItaXQlMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCklMjAlMEFtZXNzYWdlc193aXRoX3RlbXBsYXRlJTIwJTNEJTIwdG9rZW5pemVyLmFwcGx5X2NoYXRfdGVtcGxhdGUobWVzc2FnZXMlMkMlMjB0b2tlbml6ZSUzREZhbHNlKSUwQXByaW50KCUyMllvdXIlMjB0ZXh0JTIwaW5wdXQlMjBsb29rcyUyMGxpa2UlMjB0aGlzJTJDJTIwYWZ0ZXIlMjB0aGUlMjBjaGF0JTIwdGVtcGxhdGUlMjBoYXMlMjBiZWVuJTIwYXBwbGllZCUzQSU1Q24lMjIpJTBBcHJpbnQobWVzc2FnZXNfd2l0aF90ZW1wbGF0ZSk=",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}}),D=new T({props:{code:"JTIzJTIwc2VuZCUyMHN0YW5kYXJkJTIwaHR0cCUyMHJlcXVlc3QlMjB0byUyMGVuZHBvaW50JTBBb3V0cHV0JTIwJTNEJTIwcXVlcnkoJTBBJTIwJTIwJTIwJTIwcGF5bG9hZCUyMCUzRCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmlucHV0cyUyMiUzQSUyMG1lc3NhZ2VzX3dpdGhfdGVtcGxhdGUlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJwYXJhbWV0ZXJzJTIyJTNBJTIwJTdCJTIydGVtcGVyYXR1cmUlMjIlM0ElMjAwLjIlMkMlMjAlMjJtYXhfbmV3X3Rva2VucyUyMiUzQSUyMDEwMCUyQyUyMCUyMnNlZWQlMjIlM0ElMjA0MiUyQyUyMCUyMnJldHVybl9mdWxsX3RleHQlMjIlM0ElMjBGYWxzZSU3RCUyQyUwQSUyMCUyMCUyMCUyMCU3RCUyQyUwQSUyMCUyMCUyMCUyMGFwaV91cmwlMjAlM0QlMjBBUElfVVJMJTBBKSUwQSUwQXByaW50KCUyMlRoZSUyMG91dHB1dCUyMGZyb20lMjB5b3VyJTIwQVBJJTJGRW5kcG9pbnQlMjBjYWxsJTNBJTVDbiUyMiklMEFwcmludChvdXRwdXQp",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}}),sl=new T({props:{code:"QVBJX1VSTF9DSEFUJTIwJTNEJTIwQVBJX1VSTCUyMCUyQiUyMCUyMiUyRnYxJTJGY2hhdCUyRmNvbXBsZXRpb25zJTIyJTBBJTBBb3V0cHV0JTIwJTNEJTIwcXVlcnkoJTBBJTIwJTIwJTIwJTIwcGF5bG9hZCUyMCUzRCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMm1lc3NhZ2VzJTIyJTNBJTIwbWVzc2FnZXMlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJtb2RlbCUyMiUzQSUyMCUyMnRnaSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnBhcmFtZXRlcnMlMjIlM0ElMjAlN0IlMjJ0ZW1wZXJhdHVyZSUyMiUzQSUyMDAuMiUyQyUyMCUyMm1heF90b2tlbnMlMjIlM0ElMjAxMDAlMkMlMjAlMjJzZWVkJTIyJTNBJTIwNDIlN0QlMkMlMEElMjAlMjAlMjAlMjAlN0QlMkMlMEElMjAlMjAlMjAlMjBhcGlfdXJsJTIwJTNEJTIwQVBJX1VSTF9DSEFUJTBBKSUwQSUwQXByaW50KCUyMlRoZSUyMG91dHB1dCUyMGZyb20lMjB5b3VyJTIwQVBJJTJGRW5kcG9pbnQlMjBjYWxsJTIwd2l0aCUyMHRoZSUyME9wZW5BSS1jb21wYXRpYmxlJTIwbWVzc2FnZXMlMjBBUEklMjByb3V0ZSUzQSU1Q24lMjIpJTBBcHJpbnQob3V0cHV0KQ==",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}}),nl=new U({props:{title:"使用 InferenceClient 简化端点使用",local:"使用-inferenceclient-简化端点使用",headingTag:"h3"}}),Ml=new T({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMEluZmVyZW5jZUNsaWVudCUwQSUwQWNsaWVudCUyMCUzRCUyMEluZmVyZW5jZUNsaWVudCgpJTBBJTBBb3V0cHV0JTIwJTNEJTIwY2xpZW50LmNoYXRfY29tcGxldGlvbiglMEElMjAlMjAlMjAlMjBtZXNzYWdlcyUyQyUyMCUyMCUyMyUyMHRoZSUyMGNoYXQlMjB0ZW1wbGF0ZSUyMGlzJTIwYXBwbGllZCUyMGF1dG9tYXRpY2FsbHklMkMlMjBpZiUyMHlvdXIlMjBlbmRwb2ludCUyMHVzZXMlMjBhJTIwVEdJJTIwY29udGFpbmVyJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0RBUElfVVJMJTJDJTIwJTBBJTIwJTIwJTIwJTIwdGVtcGVyYXR1cmUlM0QwLjIlMkMlMjBtYXhfdG9rZW5zJTNEMTAwJTJDJTIwc2VlZCUzRDQyJTJDJTBBKSUwQSUwQXByaW50KCUyMlRoZSUyMG91dHB1dCUyMGZyb20lMjB5b3VyJTIwQVBJJTJGRW5kcG9pbnQlMjBjYWxsJTIwd2l0aCUyMHRoZSUyMEluZmVyZW5jZUNsaWVudCUzQSU1Q24lMjIpJTBBcHJpbnQob3V0cHV0KQ==",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}}),pl=new T({props:{code:"JTIzJTIwcGF1c2UlMjB0aGUlMjBlbmRwb2ludCUyMHRvJTIwc3RvcCUyMGJpbGxpbmclMEElMjNlbmRwb2ludC5wYXVzZSgp",highlighted:`<span class="hljs-comment"># pause the endpoint to stop billing</span>
<span class="hljs-comment">#endpoint.pause()</span>`,wrap:!1}}),il=new U({props:{title:"为各种模型创建推理端点",local:"为各种模型创建推理端点",headingTag:"h2"}}),cl=new U({props:{title:"使用 Stable Diffusion 进行图像生成",local:"使用-stable-diffusion-进行图像生成",headingTag:"h3"}}),yl=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}}),ml=new T({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGNyZWF0ZV9pbmZlcmVuY2VfZW5kcG9pbnQlMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi14bC1iYXNlLTEuMCUyMiUwQWVuZHBvaW50X25hbWUlMjAlM0QlMjAlMjJzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS0wLTAwMSUyMiUyMCUyMCUyMyUyMFZhbGlkJTIwRW5kcG9pbnQlMjBuYW1lcyUyMG11c3QlMjBvbmx5JTIwY29udGFpbiUyMGxvd2VyLWNhc2UlMjBjaGFyYWN0ZXJzJTJDJTIwbnVtYmVycyUyMG9yJTIwaHlwaGVucyUyMCglMjItJTIyKSUyMGFuZCUyMGFyZSUyMGJldHdlZW4lMjA0JTIwdG8lMjAzMiUyMGNoYXJhY3RlcnMlMjBsb25nLiUwQW5hbWVzcGFjZSUyMCUzRCUyMCUyMk1vcml0ekxhdXJlciUyMiUyMCUyMCUyMyUyMHlvdXIlMjB1c2VyJTIwb3IlMjBvcmdhbml6YXRpb24lMjBuYW1lJTBBdGFzayUyMCUzRCUyMCUyMnRleHQtdG8taW1hZ2UlMjIlMEElMEElMjMlMjBjaGVjayUyMGlmJTIwZW5kcG9pbnQl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G5hbWUlMjBhbHJlYWR5JTIwZXhpc3RzJTJDJTIwZ2V0JTIwZXhpc3RpbmclMjBlbmRwb2ludCUwQWVsc2UlM0ElMEElMjAlMjAlMjAlMjBlbmRwb2ludCUyMCUzRCUyMGh1Z2dpbmdmYWNlX2h1Yi5nZXRfaW5mZXJlbmNlX2VuZHBvaW50KG5hbWUlM0RlbmRwb2ludF9uYW1lJTJDJTIwbmFtZXNwYWNlJTNEbmFtZXNwYWNlKSUwQSUyMCUyMCUyMCUyMGlmJTIwZW5kcG9pbnQuc3RhdHVzJTIwaW4lMjAlNUIlMjJwYXVzZWQlMjIlMkMlMjAlMjJzY2FsZWRUb1plcm8lMjIlNUQlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmludCglMjJSZXN1bWluZyUyMGVuZHBvaW50JTIyKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGVuZHBvaW50LnJlc3VtZSgpJTBBJTIwJTIwJTIwJTIwcHJpbnQoJTIyV2FpdGluZyUyMGZvciUyMGVuZHBvaW50JTIwdG8lMjBzdGFydCUyMiklMEElMjAlMjAlMjAlMjBlbmRwb2ludC53YWl0KCklMEElMjAlMjAlMjAlMjBwcmludCglMjJFbmRwb2ludCUyMHJlYWR5JTIyKQ==",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}}),Ul=new T({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIyQSUyMHdoaW1zaWNhbCUyMGlsbHVzdHJhdGlvbiUyMG9mJTIwYSUyMGZhc2hpb25hYmx5JTIwZHJlc3NlZCUyMGxsYW1hJTIwcHJvdWRseSUyMGhvbGRpbmclMjBhJTIwd29ybiUyQyUyMHZpbnRhZ2UlMjBjb29rYm9vayUyQyUyMHdpdGglMjBhJTIwd2FybSUyMGN1cCUyMG9mJTIwdGVhJTIwYW5kJTIwYSUyMGZldyUyMGZyZXNobHklMjBiYWtlZCUyMHRyZWF0cyUyMHNjYXR0ZXJlZCUyMGFyb3VuZCUyQyUyMHNldCUyMGFnYWluc3QlMjBhJTIwY296eSUyMGJhY2tncm91bmQlMjBvZiUyMHJ1c3RpYyUyMHdvb2QlMjBhbmQlMjBibG9vbWluZyUyMGZsb3dlcnMuJTIyJTBBJTBBaW1hZ2UlMjAlM0QlMjBjbGllbnQudGV4dF90b19pbWFnZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlM0Rwcm9tcHQlMkMlMEElMjAlMjAlMjAlMjBtb2RlbCUzRGVuZHBvaW50LnVybCUyQyUyMCUyMCUyMyUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi14bC1iYXNlLTEuMCUyMiUyQyUwQSUyMCUyMCUyMCUyMGd1aWRhbmNlX3NjYWxlJTNEOCUyQyUwQSklMEElMEFwcmludCglMjJQUk9NUFQlM0ElMjAlMjIlMkMlMjBwcm9tcHQpJTBBZGlzcGxheShpbWFnZS5yZXNpemUoKGltYWdlLndpZHRoJTIwJTJGJTJGJTIwMiUyQyUyMGltYWdlLmhlaWdodCUyMCUyRiUyRiUyMDIpKSk=",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}}),ul=new T({props:{code:"ZW5kcG9pbnQucGF1c2UoKQ==",highlighted:"endpoint.pause()",wrap:!1}}),dl=new U({props:{title:"视觉语言模型：对文本和图像的推理",local:"视觉语言模型对文本和图像的推理",headingTag:"h3"}}),bl=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:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Qcm9jZXNzb3IlMEElMEElMjMlMjBsb2FkJTIwdGhlJTIwcHJvY2Vzc29yJTBBbW9kZWxfaWRfdmxtJTIwJTNEJTIwJTIySHVnZ2luZ0ZhY2VNNCUyRmlkZWZpY3MyLThiLWNoYXR0eSUyMiUwQXByb2Nlc3NvciUyMCUzRCUyMEF1dG9Qcm9jZXNzb3IuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkX3ZsbSklMEElMEElMjMlMjBkZWZpbmUlMjB0aGUlMjB1c2VyJTIwbWVzc2FnZXMlMEFtZXNzYWdlcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMnJvbGUlMjIlM0ElMjAlMjJ1c2VyJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyY29udGVudCUyMiUzQSUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QiUyMnR5cGUlMjIlM0ElMjAlMjJpbWFnZSUyMiU3RCUyQyUyMCUyMCUyMyUyMHRoZSUyMGltYWdlJTIwaXMlMjBwbGFjZWQlMjBoZXJlJTIwaW4lMjB0aGUlMjBwcm9tcHQuJTIwWW91JTIwY2FuJTIwYWRkJTIwbXVsdGlwbGUlMjBpbWFnZXMlMjB0aHJvdWdob3V0JTIwdGhlJTIwY29udmVyc2F0aW9uLiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3QiUyMnR5cGUlMjIlM0ElMjAlMjJ0ZXh0JTIyJTJDJTIwJTIydGV4dCU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21wdC5yZXBsYWNlKCUyMiUzQ2ltYWdlJTNFJTIyJTJDJTIwaW1hZ2VfaW5wdXQp",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}}),Zl=new T({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGNyZWF0ZV9pbmZlcmVuY2VfZW5kcG9pbnQlMEElMEFlbmRwb2ludF9uYW1lJTIwJTNEJTIwJTIyaWRlZ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MjAlN0QlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ1cmwlMjIlM0ElMjAlMjJnaGNyLmlvJTJGaHVnZ2luZ2ZhY2UlMkZ0ZXh0LWdlbmVyYXRpb24taW5mZXJlbmNlJTNBbGF0ZXN0JTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdEJTJDJTBBJTIwJTIwJTIwJTIwKSUwQSUwQSUyMCUyMCUyMCUyMHByaW50KCUyMldhaXRpbmclMjBmb3IlMjBlbmRwb2ludCUyMHRvJTIwYmUlMjBjcmVhdGVkJTIyKSUwQSUyMCUyMCUyMCUyMGVuZHBvaW50LndhaXQoKSUwQSUyMCUyMCUyMCUyMHByaW50KCUyMkVuZHBvaW50JTIwcmVhZHklMjIp",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}}),Gl=new T({props:{code:"b3V0cHV0JTIwJTNEJTIwY2xpZW50LnRleHRfZ2VuZXJhdGlvbiglMEElMjAlMjAlMjAlMjBwcm9tcHQlMkMlMjBtb2RlbCUzRG1vZGVsX2lkX3ZsbSUyQyUyMG1heF9uZXdfdG9rZW5zJTNEMjAwJTJDJTIwc2VlZCUzRDQyJTBBKSUwQSUwQXByaW50KG91dHB1dCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>output = client.text_generation(
<span class="hljs-meta">... </span>    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">... </span>)

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