import{s as gt,o as $t,n as Y}from"../chunks/scheduler.ddeee2a5.js";import{S as At,i as Vt,e as J,s as i,c as w,h as Et,a as j,d as n,b as y,f as et,g as m,j as d,k as lt,l as at,m as p,n as T,t as U,o as h,p as I}from"../chunks/index.10b70568.js";import{C as St}from"../chunks/CopyLLMTxtMenu.68696f97.js";import{C as G}from"../chunks/CodeBlock.7ca4c11d.js";import{H as X,E as Xt}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.d66d689f.js";import{H as tt,a as Q}from"../chunks/HfOption.1e773499.js";function Qt(b){let e,r="Install the Hugging Face Hub python package:",M,o,t,s,u='Initialize the <code>InferenceClient</code> with an Inference Provider (check this <a href="https://huggingface.co/docs/inference-providers/index#partners" rel="nofollow">list</a> for all available providers) and your Hugging Face token.',B,f,Z;return o=new G({props:{code:"cGlwJTIwaW5zdGFsbCUyMGh1Z2dpbmdmYWNlX2h1Yg==",highlighted:"pip install huggingface_hub",wrap:!1}}),f=new G({props:{code:"aW1wb3J0JTIwb3MlMEFmcm9tJTIwaHVnZ2luZ2ZhY2VfaHViJTIwaW1wb3J0JTIwSW5mZXJlbmNlQ2xpZW50JTBBJTBBJTIzJTIwSW5pdGlhbGl6ZSUyMHRoZSUyMGNsaWVudCUwQWNsaWVudCUyMCUzRCUyMEluZmVyZW5jZUNsaWVudCglMEElMjAlMjAlMjAlMjBwcm92aWRlciUzRCUyMmNlcmVicmFzJTIyJTJDJTIwJTIwJTIzJTIwb3IlMjB1c2UlMjAlMjJhdXRvJTIyJTIwZm9yJTIwYXV0b21hdGljJTIwc2VsZWN0aW9uJTBBJTIwJTIwJTIwJTIwYXBpX2tleSUzRG9zLmVudmlyb24lNUIlMjJIRl9UT0tFTiUyMiU1RCUyQyUwQSklMEE=",highlighted:`<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> InferenceClient

<span class="hljs-comment"># Initialize the client</span>
client = InferenceClient(
    provider=<span class="hljs-string">&quot;cerebras&quot;</span>,  <span class="hljs-comment"># or use &quot;auto&quot; for automatic selection</span>
    api_key=os.environ[<span class="hljs-string">&quot;HF_TOKEN&quot;</span>],
)
`,wrap:!1}}),{c(){e=J("p"),e.textContent=r,M=i(),w(o.$$.fragment),t=i(),s=J("p"),s.innerHTML=u,B=i(),w(f.$$.fragment)},l(c){e=j(c,"P",{"data-svelte-h":!0}),d(e)!=="svelte-hjeavp"&&(e.textContent=r),M=y(c),m(o.$$.fragment,c),t=y(c),s=j(c,"P",{"data-svelte-h":!0}),d(s)!=="svelte-7krcui"&&(s.innerHTML=u),B=y(c),m(f.$$.fragment,c)},m(c,C){p(c,e,C),p(c,M,C),T(o,c,C),p(c,t,C),p(c,s,C),p(c,B,C),T(f,c,C),Z=!0},p:Y,i(c){Z||(U(o.$$.fragment,c),U(f.$$.fragment,c),Z=!0)},o(c){h(o.$$.fragment,c),h(f.$$.fragment,c),Z=!1},d(c){c&&(n(e),n(M),n(t),n(s),n(B)),I(o,c),I(f,c)}}}function Yt(b){let e,r="Install the OpenAI python package:",M,o,t,s,u="Initialize an <code>OpenAI</code> client with the <code>base_url</code> and your Hugging Face token.",B,f,Z;return o=new G({props:{code:"cGlwJTIwaW5zdGFsbCUyMG9wZW5haQ==",highlighted:"pip install openai",wrap:!1}}),f=new G({props:{code:"aW1wb3J0JTIwb3MlMEFmcm9tJTIwb3BlbmFpJTIwaW1wb3J0JTIwT3BlbkFJJTBBZnJvbSUyMHB5ZGFudGljJTIwaW1wb3J0JTIwQmFzZU1vZGVsJTBBZnJvbSUyMHR5cGluZyUyMGltcG9ydCUyMExpc3QlMEElMEElMjMlMjBJbml0aWFsaXplJTIwdGhlJTIwT3BlbkFJJTIwY2xpZW50JTIwKHdvcmtzJTIwd2l0aCUyMEluZmVyZW5jZSUyMFByb3ZpZGVycyklMEFjbGllbnQlMjAlM0QlMjBPcGVuQUkoJTBBJTIwJTIwJTIwJTIwYmFzZV91cmwlM0QlMjJodHRwcyUzQSUyRiUyRnJvdXRlci5odWdnaW5nZmFjZS5jbyUyRmNlcmVicmFzJTJGdjElMjIlMkMlMEElMjAlMjAlMjAlMjBhcGlfa2V5JTNEb3MuZW52aXJvbiU1QiUyMkhGX1RPS0VOJTIyJTVEJTBBKSUwQQ==",highlighted:`<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">from</span> openai <span class="hljs-keyword">import</span> OpenAI
<span class="hljs-keyword">from</span> pydantic <span class="hljs-keyword">import</span> BaseModel
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">List</span>

<span class="hljs-comment"># Initialize the OpenAI client (works with Inference Providers)</span>
client = OpenAI(
    base_url=<span class="hljs-string">&quot;https://router.huggingface.co/cerebras/v1&quot;</span>,
    api_key=os.environ[<span class="hljs-string">&quot;HF_TOKEN&quot;</span>]
)
`,wrap:!1}}),{c(){e=J("p"),e.textContent=r,M=i(),w(o.$$.fragment),t=i(),s=J("p"),s.innerHTML=u,B=i(),w(f.$$.fragment)},l(c){e=j(c,"P",{"data-svelte-h":!0}),d(e)!=="svelte-o4ok3i"&&(e.textContent=r),M=y(c),m(o.$$.fragment,c),t=y(c),s=j(c,"P",{"data-svelte-h":!0}),d(s)!=="svelte-16x37n"&&(s.innerHTML=u),B=y(c),m(f.$$.fragment,c)},m(c,C){p(c,e,C),p(c,M,C),T(o,c,C),p(c,t,C),p(c,s,C),p(c,B,C),T(f,c,C),Z=!0},p:Y,i(c){Z||(U(o.$$.fragment,c),U(f.$$.fragment,c),Z=!0)},o(c){h(o.$$.fragment,c),h(f.$$.fragment,c),Z=!1},d(c){c&&(n(e),n(M),n(t),n(s),n(B)),I(o,c),I(f,c)}}}function Nt(b){let e,r,M,o;return e=new Q({props:{id:"structured-outputs-implementation",option:"huggingface_hub",$$slots:{default:[Qt]},$$scope:{ctx:b}}}),M=new Q({props:{id:"structured-outputs-implementation",option:"openai",$$slots:{default:[Yt]},$$scope:{ctx:b}}}),{c(){w(e.$$.fragment),r=i(),w(M.$$.fragment)},l(t){m(e.$$.fragment,t),r=y(t),m(M.$$.fragment,t)},m(t,s){T(e,t,s),p(t,r,s),T(M,t,s),o=!0},p(t,s){const u={};s&2&&(u.$$scope={dirty:s,ctx:t}),e.$set(u);const B={};s&2&&(B.$$scope={dirty:s,ctx:t}),M.$set(B)},i(t){o||(U(e.$$.fragment,t),U(M.$$.fragment,t),o=!0)},o(t){h(e.$$.fragment,t),h(M.$$.fragment,t),o=!1},d(t){t&&n(r),I(e,t),I(M,t)}}}function Rt(b){let e,r="Here’s how to generate structured outputs with the Hugging Face Hub client:",M,o,t;return o=new G({props:{code:"ZnJvbSUyMHB5ZGFudGljJTIwaW1wb3J0JTIwQmFzZU1vZGVsJTBBJTBBJTIzJTIwRXhhbXBsZSUyMHBhcGVyJTIwdGV4dCUyMCh0cnVuY2F0ZWQlMjBmb3IlMjBicmV2aXR5KSUwQXBhcGVyX3RleHQlMjAlM0QlMjAlMjIlMjIlMjIlMEFUaXRsZSUzQSUyMEF0dGVudGlvbiUyMElzJTIwQWxsJTIwWW91JTIwTmVlZCUwQSUwQUFic3RyYWN0JTNBJTIwVGhlJTIwZG9taW5hbnQlMjBzZXF1ZW5jZSUyMHRyYW5zZHVjdGlvbiUyMG1vZGVscyUyMGFyZSUyMGJhc2VkJTIwb24lMjBjb21wbGV4JTIwcmVjdXJyZW50JTIwJTBBb3IlMjBjb252b2x1dGlvbmFsJTIwbmV1cmFsJTIwbmV0d29ya3MlMjB0aGF0JTIwaW5jbHVkZSUyMGFuJTIwZW5jb2RlciUyMGFuZCUyMGElMjBkZWNvZGVyLiUyMFRoZSUyMGJlc3QlMjAlMEFwZXJmb3JtaW5nJTIwbW9kZWxzJTIwYWxzbyUyMGNvbm5lY3QlMjB0aGUlMjBlbmNvZGVyJTIwYW5kJTIwZGVjb2RlciUyMHRocm91Z2glMjBhbiUyMGF0dGVudGlvbiUyMG1lY2hhbmlzbS4lMjAlMEFXZSUyMHByb3Bvc2UlMjBhJTIwbmV3JTIwc2ltcGx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iglMEElMjAlMjAlMjAlMjBtZXNzYWdlcyUzRG1lc3NhZ2VzJTJDJTBBJTIwJTIwJTIwJTIwcmVzcG9uc2VfZm9ybWF0JTNEcmVzcG9uc2VfZm9ybWF0JTJDJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0QlMjJRd2VuJTJGUXdlbjMtMzJCJTIyJTJDJTBBKSUwQSUwQSUyMyUyMFRoZSUyMHJlc3BvbnNlJTIwaXMlMjBndWFyYW50ZWVkJTIwdG8lMjBtYXRjaCUyMHlvdXIlMjBzY2hlbWElMEFzdHJ1Y3R1cmVkX2RhdGElMjAlM0QlMjByZXNwb25zZS5jaG9pY2VzJTVCMCU1RC5tZXNzYWdlLmNvbnRlbnQlMEFwcmludChzdHJ1Y3R1cmVkX2RhdGEp",highlighted:`<span class="hljs-keyword">from</span> pydantic <span class="hljs-keyword">import</span> BaseModel

<span class="hljs-comment"># Example paper text (truncated for brevity)</span>
paper_text = <span class="hljs-string">&quot;&quot;&quot;
Title: Attention Is All You Need

Abstract: The dominant sequence transduction models are based on complex recurrent 
or convolutional neural networks that include an encoder and a decoder. The best 
performing models also connect the encoder and decoder through an attention mechanism. 
We propose a new simple network architecture, the Transformer, based solely on 
attention mechanisms, dispensing with recurrence and convolutions entirely...
&quot;&quot;&quot;</span>

<span class="hljs-comment"># Define the response format</span>
<span class="hljs-keyword">class</span> <span class="hljs-title class_">PaperAnalysis</span>(<span class="hljs-title class_ inherited__">BaseModel</span>):
    title: <span class="hljs-built_in">str</span>
    abstract_summary: <span class="hljs-built_in">str</span>

<span class="hljs-comment"># Convert the Pydantic model to a JSON Schema and wrap it in a dictionary</span>
response_format = {
    <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;json_schema&quot;</span>,
    <span class="hljs-string">&quot;json_schema&quot;</span>: {
        <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;PaperAnalysis&quot;</span>,
        <span class="hljs-string">&quot;schema&quot;</span>: PaperAnalysis.model_json_schema(),
        <span class="hljs-string">&quot;strict&quot;</span>: <span class="hljs-literal">True</span>,
    },
}

<span class="hljs-comment"># Define your messages with a system prompt and a user prompt</span>
<span class="hljs-comment"># The system prompt is a description of the task you want the model to perform</span>
<span class="hljs-comment"># The user prompt is the input data you want to process</span>
messages = [
    {
        <span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;system&quot;</span>, 
        <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;Extract paper title and abstract summary.&quot;</span>
    },
    {
        <span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>, 
        <span class="hljs-string">&quot;content&quot;</span>: paper_text
    }
]

<span class="hljs-comment"># Generate structured output using Qwen/Qwen3-32B model</span>
response = client.chat_completion(
    messages=messages,
    response_format=response_format,
    model=<span class="hljs-string">&quot;Qwen/Qwen3-32B&quot;</span>,
)

<span class="hljs-comment"># The response is guaranteed to match your schema</span>
structured_data = response.choices[<span class="hljs-number">0</span>].message.content
<span class="hljs-built_in">print</span>(structured_data)`,wrap:!1}}),{c(){e=J("p"),e.textContent=r,M=i(),w(o.$$.fragment)},l(s){e=j(s,"P",{"data-svelte-h":!0}),d(e)!=="svelte-1qwa2c8"&&(e.textContent=r),M=y(s),m(o.$$.fragment,s)},m(s,u){p(s,e,u),p(s,M,u),T(o,s,u),t=!0},p:Y,i(s){t||(U(o.$$.fragment,s),t=!0)},o(s){h(o.$$.fragment,s),t=!1},d(s){s&&(n(e),n(M)),I(o,s)}}}function Ft(b){let e,r="Here’s how to generate structured outputs with the OpenAI client:",M,o,t;return o=new G({props:{code:"JTIzJTIwRXhhbXBsZSUyMHBhcGVyJTIwdGV4dCUyMCh0cnVuY2F0ZWQlMjBmb3IlMjBicmV2aXR5KSUwQXBhcGVyX3RleHQlMjAlM0QlMjAlMjIlMjIlMjIlMEFUaXRsZSUzQSUyMEF0dGVudGlvbiUyMElzJTIwQWxsJTIwWW91JTIwTmVlZCUwQSUwQUFic3RyYWN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JTVEJTJDJTBBJTIwJTIwJTIwJTIwcmVzcG9uc2VfZm9ybWF0JTNEUGFwZXJBbmFseXNpcyUwQSklMEE=",highlighted:`<span class="hljs-comment"># Example paper text (truncated for brevity)</span>
paper_text = <span class="hljs-string">&quot;&quot;&quot;
Title: Attention Is All You Need

Abstract: The dominant sequence transduction models are based on complex recurrent 
or convolutional neural networks that include an encoder and a decoder...
&quot;&quot;&quot;</span>

<span class="hljs-comment"># Generate structured output using Qwen/Qwen3-32B model</span>
<span class="hljs-comment"># With the OpenAI client, you can use the \`response_format\` as a pydantic model</span>
completion = client.beta.chat.completions.parse(
    model=<span class="hljs-string">&quot;qwen-3-32b&quot;</span>,
    messages=[
        {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;system&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;Extract paper title and abstract summary.&quot;</span>},
        {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: paper_text}
    ],
    response_format=PaperAnalysis
)
`,wrap:!1}}),{c(){e=J("p"),e.textContent=r,M=i(),w(o.$$.fragment)},l(s){e=j(s,"P",{"data-svelte-h":!0}),d(e)!=="svelte-843mud"&&(e.textContent=r),M=y(s),m(o.$$.fragment,s)},m(s,u){p(s,e,u),p(s,M,u),T(o,s,u),t=!0},p:Y,i(s){t||(U(o.$$.fragment,s),t=!0)},o(s){h(o.$$.fragment,s),t=!1},d(s){s&&(n(e),n(M)),I(o,s)}}}function vt(b){let e,r,M,o;return e=new Q({props:{id:"structured-outputs-implementation",option:"huggingface_hub",$$slots:{default:[Rt]},$$scope:{ctx:b}}}),M=new Q({props:{id:"structured-outputs-implementation",option:"openai",$$slots:{default:[Ft]},$$scope:{ctx:b}}}),{c(){w(e.$$.fragment),r=i(),w(M.$$.fragment)},l(t){m(e.$$.fragment,t),r=y(t),m(M.$$.fragment,t)},m(t,s){T(e,t,s),p(t,r,s),T(M,t,s),o=!0},p(t,s){const u={};s&2&&(u.$$scope={dirty:s,ctx:t}),e.$set(u);const B={};s&2&&(B.$$scope={dirty:s,ctx:t}),M.$set(B)},i(t){o||(U(e.$$.fragment,t),U(M.$$.fragment,t),o=!0)},o(t){h(e.$$.fragment,t),h(M.$$.fragment,t),o=!1},d(t){t&&n(r),I(e,t),I(M,t)}}}function zt(b){let e,r="The Hugging Face Hub client returns a <code>ChatCompletion</code> object, which contains the response from the model as a string. Use the <code>json.loads</code> function to parse the response and get the structured data.",M,o,t;return o=new G({props:{code:"JTIzJTIwVGhlJTIwcmVzcG9uc2UlMjBpcyUyMGd1YXJhbnRlZWQlMjB0byUyMG1hdGNoJTIweW91ciUyMHNjaGVtYSUwQXN0cnVjdHVyZWRfZGF0YSUyMCUzRCUyMHJlc3BvbnNlLmNob2ljZXMlNUIwJTVELm1lc3NhZ2UuY29udGVudCUwQXByaW50KCUyMlBhcGVyJTIwQW5hbHlzaXMlMjBSZXN1bHRzJTNBJTIyKSUwQXByaW50KHN0cnVjdHVyZWRfZGF0YSklMEElMEElMjMlMjBQYXJzZSUyMHRoZSUyMEpTT04lMjB0byUyMHdvcmslMjB3aXRoJTIwaW5kaXZpZHVhbCUyMGZpZWxkcyUwQWltcG9ydCUyMGpzb24lMEFhbmFseXNpcyUyMCUzRCUyMGpzb24ubG9hZHMoc3RydWN0dXJlZF9kYXRhKSUwQXByaW50KGYlMjJUaXRsZSUzQSUyMCU3QmFuYWx5c2lzJTVCJ3RpdGxlJyU1RCU3RCUyMiUwQXByaW50KGYlMjJBYnN0cmFjdCUyMFN1bW1hcnklM0ElMjAlN0JhbmFseXNpcyU1QidhYnN0cmFjdF9zdW1tYXJ5JyU1RCU3RCUyMik=",highlighted:`<span class="hljs-comment"># The response is guaranteed to match your schema</span>
structured_data = response.choices[<span class="hljs-number">0</span>].message.content
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Paper Analysis Results:&quot;</span>)
<span class="hljs-built_in">print</span>(structured_data)

<span class="hljs-comment"># Parse the JSON to work with individual fields</span>
<span class="hljs-keyword">import</span> json
analysis = json.loads(structured_data)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Title: <span class="hljs-subst">{analysis[<span class="hljs-string">&#x27;title&#x27;</span>]}</span>&quot;</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Abstract Summary: <span class="hljs-subst">{analysis[<span class="hljs-string">&#x27;abstract_summary&#x27;</span>]}</span>&quot;</span>)`,wrap:!1}}),{c(){e=J("p"),e.innerHTML=r,M=i(),w(o.$$.fragment)},l(s){e=j(s,"P",{"data-svelte-h":!0}),d(e)!=="svelte-htjbf8"&&(e.innerHTML=r),M=y(s),m(o.$$.fragment,s)},m(s,u){p(s,e,u),p(s,M,u),T(o,s,u),t=!0},p:Y,i(s){t||(U(o.$$.fragment,s),t=!0)},o(s){h(o.$$.fragment,s),t=!1},d(s){s&&(n(e),n(M)),I(o,s)}}}function Ht(b){let e,r="The OpenAI client returns a <code>ChatCompletion</code> object, which contains the response from the model as a Python object. Access the structured data using the <code>title</code> and <code>abstract_summary</code> attributes of the <code>PaperAnalysis</code> class.",M,o,t;return o=new G({props:{code:"JTIzJTIwR2V0JTIwdGhlJTIwcGFyc2VkJTIwcmVzcG9uc2UlMjBhcyUyMGElMjBQeXRob24lMjBvYmplY3QlMEFhbmFseXNpcyUyMCUzRCUyMGNvbXBsZXRpb24uY2hvaWNlcyU1QjAlNUQubWVzc2FnZS5wYXJzZWQlMEFwcmludChmJTIyVGl0bGUlM0ElMjAlN0JhbmFseXNpcy50aXRsZSU3RCUyMiklMEFwcmludChmJTIyQWJzdHJhY3QlMjBTdW1tYXJ5JTNBJTIwJTdCYW5hbHlzaXMuYWJzdHJhY3Rfc3VtbWFyeSU3RCUyMiklMEElMEElMjMlMjBUaGUlMjBkYXRhJTIwaXMlMjBhbHJlYWR5JTIwdHlwZS1zYWZlJTIwYW5kJTIwdmFsaWRhdGVkJTBBcHJpbnQoZiUyMlRpdGxlJTIwdHlwZSUzQSUyMCU3QnR5cGUoYW5hbHlzaXMudGl0bGUpJTdEJTIyKSUwQXByaW50KGYlMjJTdW1tYXJ5JTIwdHlwZSUzQSUyMCU3QnR5cGUoYW5hbHlzaXMuYWJzdHJhY3Rfc3VtbWFyeSklN0QlMjIp",highlighted:`<span class="hljs-comment"># Get the parsed response as a Python object</span>
analysis = completion.choices[<span class="hljs-number">0</span>].message.parsed
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Title: <span class="hljs-subst">{analysis.title}</span>&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Abstract Summary: <span class="hljs-subst">{analysis.abstract_summary}</span>&quot;</span>)

<span class="hljs-comment"># The data is already type-safe and validated</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Title type: <span class="hljs-subst">{<span class="hljs-built_in">type</span>(analysis.title)}</span>&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Summary type: <span class="hljs-subst">{<span class="hljs-built_in">type</span>(analysis.abstract_summary)}</span>&quot;</span>)`,wrap:!1}}),{c(){e=J("p"),e.innerHTML=r,M=i(),w(o.$$.fragment)},l(s){e=j(s,"P",{"data-svelte-h":!0}),d(e)!=="svelte-t2139z"&&(e.innerHTML=r),M=y(s),m(o.$$.fragment,s)},m(s,u){p(s,e,u),p(s,M,u),T(o,s,u),t=!0},p:Y,i(s){t||(U(o.$$.fragment,s),t=!0)},o(s){h(o.$$.fragment,s),t=!1},d(s){s&&(n(e),n(M)),I(o,s)}}}function kt(b){let e,r,M,o;return e=new Q({props:{id:"structured-outputs-implementation",option:"huggingface_hub",$$slots:{default:[zt]},$$scope:{ctx:b}}}),M=new Q({props:{id:"structured-outputs-implementation",option:"openai",$$slots:{default:[Ht]},$$scope:{ctx:b}}}),{c(){w(e.$$.fragment),r=i(),w(M.$$.fragment)},l(t){m(e.$$.fragment,t),r=y(t),m(M.$$.fragment,t)},m(t,s){T(e,t,s),p(t,r,s),T(M,t,s),o=!0},p(t,s){const u={};s&2&&(u.$$scope={dirty:s,ctx:t}),e.$set(u);const B={};s&2&&(B.$$scope={dirty:s,ctx:t}),M.$set(B)},i(t){o||(U(e.$$.fragment,t),U(M.$$.fragment,t),o=!0)},o(t){h(e.$$.fragment,t),h(M.$$.fragment,t),o=!1},d(t){t&&n(r),I(e,t),I(M,t)}}}function qt(b){let e,r;return e=new G({props:{code:" ",highlighted:`<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">import</span> json

<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> InferenceClient
<span class="hljs-keyword">from</span> pydantic <span class="hljs-keyword">import</span> BaseModel
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">List</span>

<span class="hljs-comment"># Set your Hugging Face token</span>
<span class="hljs-comment"># export HF_TOKEN=&quot;your_token_here&quot;</span>

<span class="hljs-keyword">def</span> <span class="hljs-title function_">analyze_paper_structured</span>():
    <span class="hljs-string">&quot;&quot;&quot;Complete example of structured output for research paper analysis.&quot;&quot;&quot;</span>
    
    <span class="hljs-comment"># Initialize the client</span>
    client = InferenceClient(
        provider=<span class="hljs-string">&quot;cerebras&quot;</span>,  <span class="hljs-comment"># or use &quot;auto&quot; for automatic selection</span>
        api_key=os.environ[<span class="hljs-string">&quot;HF_TOKEN&quot;</span>],
    )
    
    <span class="hljs-comment"># Example paper text (you can replace this with any research paper)</span>
    paper_text = <span class="hljs-string">&quot;&quot;&quot;
    Title: Attention Is All You Need
    
    Abstract: The dominant sequence transduction models are based on complex recurrent 
    or convolutional neural networks that include an encoder and a decoder. The best 
    performing models also connect the encoder and decoder through an attention mechanism. 
    We propose a new simple network architecture, the Transformer, based solely on 
    attention mechanisms, dispensing with recurrence and convolutions entirely. 
    Experiments on two machine translation tasks show these models to be superior 
    in quality while being more parallelizable and requiring significantly less time to train.
    
    Introduction: Recurrent neural networks, long short-term memory and gated recurrent 
    neural networks in particular, have been firmly established as state of the art approaches 
    in sequence modeling and transduction problems such as language modeling and machine translation.
    &quot;&quot;&quot;</span>
    
    <span class="hljs-comment"># Define the response format (JSON Schema)</span>
    <span class="hljs-keyword">class</span> <span class="hljs-title class_">PaperAnalysis</span>(<span class="hljs-title class_ inherited__">BaseModel</span>):
        title: <span class="hljs-built_in">str</span>
        abstract_summary: <span class="hljs-built_in">str</span>

    response_format = {
        <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;json_schema&quot;</span>,
        <span class="hljs-string">&quot;json_schema&quot;</span>: {
            <span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;PaperAnalysis&quot;</span>,
            <span class="hljs-string">&quot;schema&quot;</span>: PaperAnalysis.model_json_schema(),
            <span class="hljs-string">&quot;strict&quot;</span>: <span class="hljs-literal">True</span>,
        },
    }
    
    <span class="hljs-comment"># Define your messages</span>
    messages = [
        {
            <span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;system&quot;</span>, 
            <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;Extract paper title and abstract summary.&quot;</span>
        },
        {
            <span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>, 
            <span class="hljs-string">&quot;content&quot;</span>: paper_text
        }
    ]
    
    <span class="hljs-comment"># Generate structured output</span>
    response = client.chat_completion(
        messages=messages,
        response_format=response_format,
        model=<span class="hljs-string">&quot;Qwen/Qwen3-32B&quot;</span>,
    )
    
    <span class="hljs-comment"># The response is guaranteed to match your schema</span>
    structured_data = response.choices[<span class="hljs-number">0</span>].message.content
    
    <span class="hljs-comment"># Parse and display results</span>
    analysis = json.loads(structured_data)
    
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Title: <span class="hljs-subst">{analysis[<span class="hljs-string">&#x27;title&#x27;</span>]}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Abstract Summary: <span class="hljs-subst">{analysis[<span class="hljs-string">&#x27;abstract_summary&#x27;</span>]}</span>&quot;</span>)

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&quot;__main__&quot;</span>:
    <span class="hljs-comment"># Make sure you have set your HF_TOKEN environment variable</span>
    analyze_paper_structured()`,wrap:!1}}),{c(){w(e.$$.fragment)},l(M){m(e.$$.fragment,M)},m(M,o){T(e,M,o),r=!0},p:Y,i(M){r||(U(e.$$.fragment,M),r=!0)},o(M){h(e.$$.fragment,M),r=!1},d(M){I(e,M)}}}function _t(b){let e,r;return e=new G({props:{code:" ",highlighted:`<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">from</span> openai <span class="hljs-keyword">import</span> OpenAI
<span class="hljs-keyword">from</span> pydantic <span class="hljs-keyword">import</span> BaseModel, Field
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">List</span>

<span class="hljs-comment"># Set your Hugging Face token</span>
<span class="hljs-comment"># export HF_TOKEN=&quot;your_token_here&quot;</span>

<span class="hljs-keyword">class</span> <span class="hljs-title class_">PaperAnalysis</span>(<span class="hljs-title class_ inherited__">BaseModel</span>):
    <span class="hljs-string">&quot;&quot;&quot;Structured model for research paper analysis.&quot;&quot;&quot;</span>
    title: <span class="hljs-built_in">str</span>
    abstract_summary: <span class="hljs-built_in">str</span>

<span class="hljs-keyword">def</span> <span class="hljs-title function_">analyze_paper_structured</span>():
    <span class="hljs-string">&quot;&quot;&quot;Complete example of structured output for research paper analysis.&quot;&quot;&quot;</span>
    
    <span class="hljs-comment"># Initialize the OpenAI client (works with Inference Providers)</span>
    client = OpenAI(
        base_url=<span class="hljs-string">&quot;https://router.huggingface.co/cerebras/v1&quot;</span>,
        api_key=os.environ[<span class="hljs-string">&quot;HF_TOKEN&quot;</span>]
    )
    
    <span class="hljs-comment"># Example paper text (you can replace this with any research paper)</span>
    paper_text = <span class="hljs-string">&quot;&quot;&quot;
    Title: Attention Is All You Need
    
    Abstract: The dominant sequence transduction models are based on complex recurrent 
    or convolutional neural networks that include an encoder and a decoder. The best 
    performing models also connect the encoder and decoder through an attention mechanism. 
    We propose a new simple network architecture, the Transformer, based solely on 
    attention mechanisms, dispensing with recurrence and convolutions entirely. 
    Experiments on two machine translation tasks show these models to be superior 
    in quality while being more parallelizable and requiring significantly less time to train.
    
    Introduction: Recurrent neural networks, long short-term memory and gated recurrent 
    neural networks in particular, have been firmly established as state of the art approaches 
    in sequence modeling and transduction problems such as language modeling and machine translation.
    &quot;&quot;&quot;</span>
    
    <span class="hljs-comment"># Define the response format (JSON Schema)</span>
    <span class="hljs-comment"># Generate structured output</span>
    messages = [
        {
            <span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;system&quot;</span>,
            <span class="hljs-string">&quot;content&quot;</span>: <span class="hljs-string">&quot;Extract paper title and abstract summary.&quot;</span>,
        },
        {
            <span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>,
            <span class="hljs-string">&quot;content&quot;</span>: paper_text,
        },
    ]
    
    completion = client.beta.chat.completions.parse(
        model=<span class="hljs-string">&quot;qwen-3-32b&quot;</span>,
        messages=messages,
        response_format=PaperAnalysis,
    )
    
    <span class="hljs-comment"># Get the parsed response as a Python object</span>
    analysis = completion.choices[<span class="hljs-number">0</span>].message.parsed
    
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Title: <span class="hljs-subst">{analysis.title}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Abstract Summary: <span class="hljs-subst">{analysis.abstract_summary}</span>&quot;</span>)`,wrap:!1}}),{c(){w(e.$$.fragment)},l(M){m(e.$$.fragment,M)},m(M,o){T(e,M,o),r=!0},p:Y,i(M){r||(U(e.$$.fragment,M),r=!0)},o(M){h(e.$$.fragment,M),r=!1},d(M){I(e,M)}}}function xt(b){let e,r,M,o;return e=new Q({props:{id:"complete-script",option:"huggingface_hub",$$slots:{default:[qt]},$$scope:{ctx:b}}}),M=new Q({props:{id:"complete-script",option:"openai",$$slots:{default:[_t]},$$scope:{ctx:b}}}),{c(){w(e.$$.fragment),r=i(),w(M.$$.fragment)},l(t){m(e.$$.fragment,t),r=y(t),m(M.$$.fragment,t)},m(t,s){T(e,t,s),p(t,r,s),T(M,t,s),o=!0},p(t,s){const u={};s&2&&(u.$$scope={dirty:s,ctx:t}),e.$set(u);const B={};s&2&&(B.$$scope={dirty:s,ctx:t}),M.$set(B)},i(t){o||(U(e.$$.fragment,t),U(M.$$.fragment,t),o=!0)},o(t){h(e.$$.fragment,t),h(M.$$.fragment,t),o=!1},d(t){t&&n(r),I(e,t),I(M,t)}}}function Pt(b){let e,r,M,o,t,s,u,B,f,Z="In this guide, we’ll show you how to use Inference Providers to generate structured outputs that follow a specific JSON schema. This is incredibly useful for building reliable AI applications that need predictable, parsable responses.",c,C,nt="Structured outputs guarantee a model returns a response that matches your exact schema every time. This eliminates the need for complex parsing logic and makes your applications more robust.",ml,W,Mt='<p>This guide assumes you have a Hugging Face account. If you don’t have one, you can create one for free at <a href="https://huggingface.co" rel="nofollow">huggingface.co</a>.</p>',Tl,N,Ul,R,pt="Structured outputs make sure model responses always follow a specific structure, typically a JSON Schema. This means you get predictable, type-safe data that integrates easily with your systems. The model follows a strict template so you always get the data in the format you expect.",hl,F,ot="Traditionally, getting structured data from LLMs required prompt engineering (asking the model to “respond in JSON format”), post-processing and parsing the response, and sometimes retrying when parsing failed. This approach is unreliable and can lead to brittle applications.",Il,v,ct="With structured outputs, you get:",dl,z,it="<li>Guaranteed compliance with your defined schema</li> <li>Fewer errors from malformed or unparsable JSON</li> <li>Easier integration with downstream systems</li> <li>No need for retry logic or complex error handling</li> <li>More efficient use of tokens (less verbose instructions)</li>",bl,H,yt="In short, structured outputs make your applications more robust and reliable by ensuring every response matches your schema, with built-in validation and type safety.",Bl,k,fl,q,rt="Before making any API calls, you need to define the structure you want. Let’s build a practical example: extracting structured information from research papers. This is a common real-world use case where you need to parse academic papers and extract key details like title, authors, contributions, and methodology.",Cl,_,ut="We’ll create a simple schema that captures the most essential elements: the paper’s title and a summary of its abstract. The easiest way to do this is to use Pydantic, a library that allows you to define Python classes that represent JSON schemas (among other things).",Gl,x,Zl,P,Jt="Using <code>model_json_schema</code> we can convert the Pydantic model to a JSON Schema which is what the model will receive as a response format instruction. This is the schema that the model will use to generate the response.",Wl,L,gl,O,jt="This simple schema ensures we’ll always get the paper’s title and a concise summary of its abstract. Notice how we mark both fields as required - this guarantees they’ll always be present in the response, making our application more reliable.",$l,K,Al,D,wt="Now that we have our schema defined, let’s set up the client to communicate with the inference providers. We’ll show you two approaches: the Hugging Face Hub client (which gives you direct access to all Inference Providers) and the OpenAI client (which works through OpenAI-compatible endpoints).",Vl,g,El,$,mt="<p>Structured outputs are a good use case for selecting a specific provider and model because you want to avoid incompatibility issues between the model, provider and the schema.</p>",Sl,ll,Xl,tl,Tt="Now let’s extract structured information from a research paper. We’ll send the paper content to the model along with our schema, and get back perfectly structured data.",Ql,sl,Ut="For this example, we’ll analyze a famous AI research paper. The model will read the paper and extract the key information according to our predefined schema.",Yl,A,Nl,el,Rl,al,ht="Both approaches guarantee that your response will match the specified schema. Here’s how to access and use the structured data:",Fl,V,vl,nl,It="The structured output might look like this:",zl,Ml,Hl,pl,dt="You can now confidently process this data without worrying about parsing errors or missing fields. The schema validation ensures that required fields are always present and data types are correct.",kl,ol,ql,cl,bt="Here’s a complete script that you can run immediately to see structured outputs in action:",_l,E,jl,Bt="Click to expand complete script",st,S,xl,il,Pl,yl,ft="Now that you understand structured outputs, you probably want to build an application that uses them. Here are some ideas for fun things you can try out:",Ll,rl,Ct="<li><strong>Different models</strong>: Experiment with different models. The biggest models are not always the best for structured outputs!</li> <li><strong>Multi-turn conversations</strong>: Maintaining structured format across conversation turns.</li> <li><strong>Complex schemas</strong>: Building domain-specific schemas for your use case.</li> <li><strong>Performance optimization</strong>: Choosing the right provider for your structured output needs.</li>",Ol,ul,Kl,wl,Dl;return t=new St({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),u=new X({props:{title:"Structured Outputs with Inference Providers",local:"structured-outputs-with-inference-providers",headingTag:"h1"}}),N=new X({props:{title:"What Are Structured Outputs?",local:"what-are-structured-outputs",headingTag:"h2"}}),k=new X({props:{title:"Step 1: Define Your Schema",local:"step-1-define-your-schema",headingTag:"h2"}}),x=new G({props:{code:"ZnJvbSUyMHB5ZGFudGljJTIwaW1wb3J0JTIwQmFzZU1vZGVsJTBBJTBBY2xhc3MlMjBQYXBlckFuYWx5c2lzKEJhc2VNb2RlbCklM0ElMEElMjAlMjAlMjAlMjB0aXRsZSUzQSUyMHN0ciUwQSUyMCUyMCUyMCUyMGFic3RyYWN0X3N1bW1hcnklM0ElMjBzdHI=",highlighted:`<span class="hljs-keyword">from</span> pydantic <span class="hljs-keyword">import</span> BaseModel

<span class="hljs-keyword">class</span> <span class="hljs-title class_">PaperAnalysis</span>(<span class="hljs-title class_ inherited__">BaseModel</span>):
    title: <span class="hljs-built_in">str</span>
    abstract_summary: <span class="hljs-built_in">str</span>`,wrap:!1}}),L=new G({props:{code:"JTdCJTBBJTIwJTIwJTIydHlwZSUyMiUzQSUyMCUyMm9iamVjdCUyMiUyQyUwQSUyMCUyMCUyMnByb3BlcnRpZXMlMjIlM0ElMjAlN0IlMEElMjAlMjAlMjAlMjAlMjJ0aXRsZSUyMiUzQSUyMCU3QiUyMnR5cGUlMjIlM0ElMjAlMjJzdHJpbmclMjIlN0QlMkMlMEElMjAlMjAlMjAlMjAlMjJhYnN0cmFjdF9zdW1tYXJ5JTIyJTNBJTIwJTdCJTIydHlwZSUyMiUzQSUyMCUyMnN0cmluZyUyMiU3RCUwQSUyMCUyMCU3RCUyQyUwQSUyMCUyMCUyMnJlcXVpcmVkJTIyJTNBJTIwJTVCJTIydGl0bGUlMjIlMkMlMjAlMjJhYnN0cmFjdF9zdW1tYXJ5JTIyJTVEJTBBJTdE",highlighted:`<span class="hljs-punctuation">{</span>
  <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;object&quot;</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;properties&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
    <span class="hljs-attr">&quot;title&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span><span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;string&quot;</span><span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>
    <span class="hljs-attr">&quot;abstract_summary&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span><span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;string&quot;</span><span class="hljs-punctuation">}</span>
  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;required&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">&quot;title&quot;</span><span class="hljs-punctuation">,</span> <span class="hljs-string">&quot;abstract_summary&quot;</span><span class="hljs-punctuation">]</span>
<span class="hljs-punctuation">}</span>`,wrap:!1}}),K=new X({props:{title:"Step 2: Set up your inference client",local:"step-2-set-up-your-inference-client",headingTag:"h2"}}),g=new tt({props:{id:"structured-outputs-implementation",options:["huggingface_hub","openai"],$$slots:{default:[Nt]},$$scope:{ctx:b}}}),ll=new X({props:{title:"Step 3: Generate structured output",local:"step-3-generate-structured-output",headingTag:"h2"}}),A=new tt({props:{id:"structured-outputs-implementation",options:["huggingface_hub","openai"],$$slots:{default:[vt]},$$scope:{ctx:b}}}),el=new X({props:{title:"Step 4: Handle the Response",local:"step-4-handle-the-response",headingTag:"h2"}}),V=new tt({props:{id:"structured-outputs-implementation",options:["huggingface_hub","openai"],$$slots:{default:[kt]},$$scope:{ctx:b}}}),Ml=new G({props:{code:"JTdCJTBBJTIwJTIwJTIydGl0bGUlMjIlM0ElMjAlMjJBdHRlbnRpb24lMjBJcyUyMEFsbCUyMFlvdSUyME5lZWQlMjIlMkMlMEElMjAlMjAlMjJhYnN0cmFjdF9zdW1tYXJ5JTIyJTNBJTIwJTIySW50cm9kdWNlcyUyMHRoZSUyMFRyYW5zZm9ybWVyJTIwYXJjaGl0ZWN0dXJlJTIwYmFzZWQlMjBzb2xlbHklMjBvbiUyMGF0dGVudGlvbiUyMG1lY2hhbmlzbXMlMkMlMjBlbGltaW5hdGluZyUyMHJlY3VycmVuY2UlMjBhbmQlMjBjb252b2x1dGlvbnMlMjBmb3IlMjBzZXF1ZW5jZSUyMHRyYW5zZHVjdGlvbiUyMHRhc2tzLiUyMFNob3dzJTIwc3VwZXJpb3IlMjBxdWFsaXR5JTIwaW4lMjBtYWNoaW5lJTIwdHJhbnNsYXRpb24lMjB3aGlsZSUyMGJlaW5nJTIwbW9yZSUyMHBhcmFsbGVsaXphYmxlJTIwYW5kJTIwcmVxdWlyaW5nJTIwbGVzcyUyMHRyYWluaW5nJTIwdGltZS4lMjIlMEElN0Q=",highlighted:`<span class="hljs-punctuation">{</span>
  <span class="hljs-attr">&quot;title&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Attention Is All You Need&quot;</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;abstract_summary&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Introduces the Transformer architecture based solely on attention mechanisms, eliminating recurrence and convolutions for sequence transduction tasks. Shows superior quality in machine translation while being more parallelizable and requiring less training time.&quot;</span>
<span class="hljs-punctuation">}</span>`,wrap:!1}}),ol=new X({props:{title:"Complete Working Example",local:"complete-working-example",headingTag:"h2"}}),S=new tt({props:{id:"complete-script",options:["huggingface_hub","openai"],$$slots:{default:[xt]},$$scope:{ctx:b}}}),il=new X({props:{title:"Next Steps",local:"next-steps",headingTag:"h2"}}),ul=new Xt({props:{source:"https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/guides/structured-output.md"}}),{c(){e=J("meta"),r=i(),M=J("p"),o=i(),w(t.$$.fragment),s=i(),w(u.$$.fragment),B=i(),f=J("p"),f.textContent=Z,c=i(),C=J("p"),C.textContent=nt,ml=i(),W=J("blockquote"),W.innerHTML=Mt,Tl=i(),w(N.$$.fragment),Ul=i(),R=J("p"),R.textContent=pt,hl=i(),F=J("p"),F.textContent=ot,Il=i(),v=J("p"),v.textContent=ct,dl=i(),z=J("ul"),z.innerHTML=it,bl=i(),H=J("p"),H.textContent=yt,Bl=i(),w(k.$$.fragment),fl=i(),q=J("p"),q.textContent=rt,Cl=i(),_=J("p"),_.textContent=ut,Gl=i(),w(x.$$.fragment),Zl=i(),P=J("p"),P.innerHTML=Jt,Wl=i(),w(L.$$.fragment),gl=i(),O=J("p"),O.textContent=jt,$l=i(),w(K.$$.fragment),Al=i(),D=J("p"),D.textContent=wt,Vl=i(),w(g.$$.fragment),El=i(),$=J("blockquote"),$.innerHTML=mt,Sl=i(),w(ll.$$.fragment),Xl=i(),tl=J("p"),tl.textContent=Tt,Ql=i(),sl=J("p"),sl.textContent=Ut,Yl=i(),w(A.$$.fragment),Nl=i(),w(el.$$.fragment),Rl=i(),al=J("p"),al.textContent=ht,Fl=i(),w(V.$$.fragment),vl=i(),nl=J("p"),nl.textContent=It,zl=i(),w(Ml.$$.fragment),Hl=i(),pl=J("p"),pl.textContent=dt,kl=i(),w(ol.$$.fragment),ql=i(),cl=J("p"),cl.textContent=bt,_l=i(),E=J("details"),jl=J("summary"),jl.textContent=Bt,st=i(),w(S.$$.fragment),xl=i(),w(il.$$.fragment),Pl=i(),yl=J("p"),yl.textContent=ft,Ll=i(),rl=J("ul"),rl.innerHTML=Ct,Ol=i(),w(ul.$$.fragment),Kl=i(),wl=J("p"),this.h()},l(l){const a=Et("svelte-u9bgzb",document.head);e=j(a,"META",{name:!0,content:!0}),a.forEach(n),r=y(l),M=j(l,"P",{}),et(M).forEach(n),o=y(l),m(t.$$.fragment,l),s=y(l),m(u.$$.fragment,l),B=y(l),f=j(l,"P",{"data-svelte-h":!0}),d(f)!=="svelte-9ttvlb"&&(f.textContent=Z),c=y(l),C=j(l,"P",{"data-svelte-h":!0}),d(C)!=="svelte-12uc8sg"&&(C.textContent=nt),ml=y(l),W=j(l,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),d(W)!=="svelte-122ax3a"&&(W.innerHTML=Mt),Tl=y(l),m(N.$$.fragment,l),Ul=y(l),R=j(l,"P",{"data-svelte-h":!0}),d(R)!=="svelte-169s15r"&&(R.textContent=pt),hl=y(l),F=j(l,"P",{"data-svelte-h":!0}),d(F)!=="svelte-1x5j4n7"&&(F.textContent=ot),Il=y(l),v=j(l,"P",{"data-svelte-h":!0}),d(v)!=="svelte-wyd5lm"&&(v.textContent=ct),dl=y(l),z=j(l,"UL",{"data-svelte-h":!0}),d(z)!=="svelte-1li1ouk"&&(z.innerHTML=it),bl=y(l),H=j(l,"P",{"data-svelte-h":!0}),d(H)!=="svelte-ox35fg"&&(H.textContent=yt),Bl=y(l),m(k.$$.fragment,l),fl=y(l),q=j(l,"P",{"data-svelte-h":!0}),d(q)!=="svelte-3xfnuh"&&(q.textContent=rt),Cl=y(l),_=j(l,"P",{"data-svelte-h":!0}),d(_)!=="svelte-dxem51"&&(_.textContent=ut),Gl=y(l),m(x.$$.fragment,l),Zl=y(l),P=j(l,"P",{"data-svelte-h":!0}),d(P)!=="svelte-10hxzx2"&&(P.innerHTML=Jt),Wl=y(l),m(L.$$.fragment,l),gl=y(l),O=j(l,"P",{"data-svelte-h":!0}),d(O)!=="svelte-bj4kz5"&&(O.textContent=jt),$l=y(l),m(K.$$.fragment,l),Al=y(l),D=j(l,"P",{"data-svelte-h":!0}),d(D)!=="svelte-1im08zr"&&(D.textContent=wt),Vl=y(l),m(g.$$.fragment,l),El=y(l),$=j(l,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),d($)!=="svelte-zbg8ko"&&($.innerHTML=mt),Sl=y(l),m(ll.$$.fragment,l),Xl=y(l),tl=j(l,"P",{"data-svelte-h":!0}),d(tl)!=="svelte-hy98jo"&&(tl.textContent=Tt),Ql=y(l),sl=j(l,"P",{"data-svelte-h":!0}),d(sl)!=="svelte-8cc4y2"&&(sl.textContent=Ut),Yl=y(l),m(A.$$.fragment,l),Nl=y(l),m(el.$$.fragment,l),Rl=y(l),al=j(l,"P",{"data-svelte-h":!0}),d(al)!=="svelte-1muepgs"&&(al.textContent=ht),Fl=y(l),m(V.$$.fragment,l),vl=y(l),nl=j(l,"P",{"data-svelte-h":!0}),d(nl)!=="svelte-1mdpka4"&&(nl.textContent=It),zl=y(l),m(Ml.$$.fragment,l),Hl=y(l),pl=j(l,"P",{"data-svelte-h":!0}),d(pl)!=="svelte-137s0j"&&(pl.textContent=dt),kl=y(l),m(ol.$$.fragment,l),ql=y(l),cl=j(l,"P",{"data-svelte-h":!0}),d(cl)!=="svelte-4dji3g"&&(cl.textContent=bt),_l=y(l),E=j(l,"DETAILS",{});var Jl=et(E);jl=j(Jl,"SUMMARY",{"data-svelte-h":!0}),d(jl)!=="svelte-11h62ax"&&(jl.textContent=Bt),st=y(Jl),m(S.$$.fragment,Jl),Jl.forEach(n),xl=y(l),m(il.$$.fragment,l),Pl=y(l),yl=j(l,"P",{"data-svelte-h":!0}),d(yl)!=="svelte-17jdnjl"&&(yl.textContent=ft),Ll=y(l),rl=j(l,"UL",{"data-svelte-h":!0}),d(rl)!=="svelte-1ib0qrf"&&(rl.innerHTML=Ct),Ol=y(l),m(ul.$$.fragment,l),Kl=y(l),wl=j(l,"P",{}),et(wl).forEach(n),this.h()},h(){lt(e,"name","hf:doc:metadata"),lt(e,"content",Lt),lt(W,"class","tip"),lt($,"class","tip")},m(l,a){at(document.head,e),p(l,r,a),p(l,M,a),p(l,o,a),T(t,l,a),p(l,s,a),T(u,l,a),p(l,B,a),p(l,f,a),p(l,c,a),p(l,C,a),p(l,ml,a),p(l,W,a),p(l,Tl,a),T(N,l,a),p(l,Ul,a),p(l,R,a),p(l,hl,a),p(l,F,a),p(l,Il,a),p(l,v,a),p(l,dl,a),p(l,z,a),p(l,bl,a),p(l,H,a),p(l,Bl,a),T(k,l,a),p(l,fl,a),p(l,q,a),p(l,Cl,a),p(l,_,a),p(l,Gl,a),T(x,l,a),p(l,Zl,a),p(l,P,a),p(l,Wl,a),T(L,l,a),p(l,gl,a),p(l,O,a),p(l,$l,a),T(K,l,a),p(l,Al,a),p(l,D,a),p(l,Vl,a),T(g,l,a),p(l,El,a),p(l,$,a),p(l,Sl,a),T(ll,l,a),p(l,Xl,a),p(l,tl,a),p(l,Ql,a),p(l,sl,a),p(l,Yl,a),T(A,l,a),p(l,Nl,a),T(el,l,a),p(l,Rl,a),p(l,al,a),p(l,Fl,a),T(V,l,a),p(l,vl,a),p(l,nl,a),p(l,zl,a),T(Ml,l,a),p(l,Hl,a),p(l,pl,a),p(l,kl,a),T(ol,l,a),p(l,ql,a),p(l,cl,a),p(l,_l,a),p(l,E,a),at(E,jl),at(E,st),T(S,E,null),p(l,xl,a),T(il,l,a),p(l,Pl,a),p(l,yl,a),p(l,Ll,a),p(l,rl,a),p(l,Ol,a),T(ul,l,a),p(l,Kl,a),p(l,wl,a),Dl=!0},p(l,[a]){const Jl={};a&2&&(Jl.$$scope={dirty:a,ctx:l}),g.$set(Jl);const Gt={};a&2&&(Gt.$$scope={dirty:a,ctx:l}),A.$set(Gt);const Zt={};a&2&&(Zt.$$scope={dirty:a,ctx:l}),V.$set(Zt);const Wt={};a&2&&(Wt.$$scope={dirty:a,ctx:l}),S.$set(Wt)},i(l){Dl||(U(t.$$.fragment,l),U(u.$$.fragment,l),U(N.$$.fragment,l),U(k.$$.fragment,l),U(x.$$.fragment,l),U(L.$$.fragment,l),U(K.$$.fragment,l),U(g.$$.fragment,l),U(ll.$$.fragment,l),U(A.$$.fragment,l),U(el.$$.fragment,l),U(V.$$.fragment,l),U(Ml.$$.fragment,l),U(ol.$$.fragment,l),U(S.$$.fragment,l),U(il.$$.fragment,l),U(ul.$$.fragment,l),Dl=!0)},o(l){h(t.$$.fragment,l),h(u.$$.fragment,l),h(N.$$.fragment,l),h(k.$$.fragment,l),h(x.$$.fragment,l),h(L.$$.fragment,l),h(K.$$.fragment,l),h(g.$$.fragment,l),h(ll.$$.fragment,l),h(A.$$.fragment,l),h(el.$$.fragment,l),h(V.$$.fragment,l),h(Ml.$$.fragment,l),h(ol.$$.fragment,l),h(S.$$.fragment,l),h(il.$$.fragment,l),h(ul.$$.fragment,l),Dl=!1},d(l){l&&(n(r),n(M),n(o),n(s),n(B),n(f),n(c),n(C),n(ml),n(W),n(Tl),n(Ul),n(R),n(hl),n(F),n(Il),n(v),n(dl),n(z),n(bl),n(H),n(Bl),n(fl),n(q),n(Cl),n(_),n(Gl),n(Zl),n(P),n(Wl),n(gl),n(O),n($l),n(Al),n(D),n(Vl),n(El),n($),n(Sl),n(Xl),n(tl),n(Ql),n(sl),n(Yl),n(Nl),n(Rl),n(al),n(Fl),n(vl),n(nl),n(zl),n(Hl),n(pl),n(kl),n(ql),n(cl),n(_l),n(E),n(xl),n(Pl),n(yl),n(Ll),n(rl),n(Ol),n(Kl),n(wl)),n(e),I(t,l),I(u,l),I(N,l),I(k,l),I(x,l),I(L,l),I(K,l),I(g,l),I(ll,l),I(A,l),I(el,l),I(V,l),I(Ml,l),I(ol,l),I(S),I(il,l),I(ul,l)}}}const Lt='{"title":"Structured Outputs with Inference Providers","local":"structured-outputs-with-inference-providers","sections":[{"title":"What Are Structured Outputs?","local":"what-are-structured-outputs","sections":[],"depth":2},{"title":"Step 1: Define Your Schema","local":"step-1-define-your-schema","sections":[],"depth":2},{"title":"Step 2: Set up your inference client","local":"step-2-set-up-your-inference-client","sections":[],"depth":2},{"title":"Step 3: Generate structured output","local":"step-3-generate-structured-output","sections":[],"depth":2},{"title":"Step 4: Handle the Response","local":"step-4-handle-the-response","sections":[],"depth":2},{"title":"Complete Working Example","local":"complete-working-example","sections":[],"depth":2},{"title":"Next Steps","local":"next-steps","sections":[],"depth":2}],"depth":1}';function Ot(b){return $t(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class as extends At{constructor(e){super(),Vt(this,e,Ot,Pt,gt,{})}}export{as as component};
