Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: language and platform tabs for the API page code examples (#15084)

Michael Handb76346db77e
diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.ts
index 7a8af3576bd..2da8659fa43 100644
--- a/studio/frontend/scripts/check-bundle-budget.ts
+++ b/studio/frontend/scripts/check-bundle-budget.ts
@@ -412,8 +412,11 @@ export const BUDGET = {
// Skill ZIP import/export (#14181) adds 2,721 B raw / 758 B transfer to the eager Skills dialog
// and locale strings (6,929,934 -> 6,932,655 B raw, 2,087,782 -> 2,088,540 B transfer against
// fb104d2b57, one machine and build, Node 22.23.2, unchanged at 99 chunks). Raised by that growth.
- transferBytes: 2_088_648,
- rawBytes: 6_932_971,
+ // Language and platform tabs on the API page examples (#15084) add 138 B raw / 53 B transfer: Vite's preload map
+ // in the entry and settings chunks naming the example box, now a lazy chunk shared by the API page and Settings
+ // (6,932,829 -> 6,932,967 B raw, 2,088,616 -> 2,088,669 B transfer against cfc593f0bd, Node 26, 99 chunks).
+ transferBytes: 2_088_701,
+ rawBytes: 6_933_109,
};
// The chunk count is reported but not budgeted. Splitting a page out of the entry raises it while lowering the
diff --git a/studio/frontend/src/features/api-monitor/api-monitor-page.tsx b/studio/frontend/src/features/api-monitor/api-monitor-page.tsx
index 49d0f8fa5ab..df92be21bd4 100644
--- a/studio/frontend/src/features/api-monitor/api-monitor-page.tsx
+++ b/studio/frontend/src/features/api-monitor/api-monitor-page.tsx
@@ -71,6 +71,11 @@ import {
useRef,
useState,
} from "react";
+import { buildApiExample } from "./api-sampling-example";
+import {
+ ApiExampleBox,
+ useApiExampleChoices,
+} from "./components/api-example-box";
import { ApiExampleDialog } from "./components/api-example-dialog";
import { ApiModelLoadControls } from "./components/api-model-load-controls";
import { SavedModelSettingsPanel } from "./components/saved-model-settings";
@@ -211,17 +216,6 @@ function compactEndpoint(endpoint: string): string {
.replace(V1_PREFIX_RE, "/");
}
-function quickStartSnippet(baseUrl: string, model: string): string {
- const body = JSON.stringify({
- model,
- messages: [{ role: "user", content: "Hello!" }],
- }).replace(/'/g, "'\\''");
- return `curl ${baseUrl}/chat/completions \\
- -H "Authorization: Bearer $UNSLOTH_API_KEY" \\
- -H "Content-Type: application/json" \\
- -d '${body}'`;
-}
-
function statusDotClass(status: ApiMonitorEntry["status"]): string {
switch (status) {
case "running":
@@ -840,7 +834,7 @@ function QuickStart({
baseUrl: string;
model: string | null;
}): ReactElement {
- const snippet = quickStartSnippet(baseUrl, model ?? "MODEL_ID");
+ const choices = useApiExampleChoices(baseUrl, "curl");
return (
<div className="flex flex-col items-center gap-4 px-6 py-12 text-center">
<span
@@ -865,18 +859,17 @@ function QuickStart({
: "Load a model, then send a request to the base URL. It appears here as it streams."}
</p>
</div>
- <div className="relative w-full max-w-2xl text-left">
- <pre
- className={cn(
- "overflow-x-auto scroll-rounded rounded-lg py-3 pr-11 pl-3.5 font-mono text-ui-11 leading-[1.6] text-foreground",
- INSET,
- )}
- >
- {snippet}
- </pre>
- <div className="absolute top-1.5 right-1.5">
- <CopyButton value={snippet} label="Copy example request" />
- </div>
+ <div className="w-full max-w-2xl text-left">
+ <ApiExampleBox
+ choices={choices}
+ code={buildApiExample({
+ baseUrl,
+ model: model ?? "MODEL_ID",
+ sampling: {},
+ language: choices.language,
+ os: choices.os,
+ })}
+ />
</div>
<Button
type="button"
@@ -1245,7 +1238,7 @@ export function ApiMonitorPage(): ReactElement {
<HugeiconsIcon
icon={CodeIcon}
strokeWidth={1.75}
- className="size-3.5"
+ className="size-4"
/>
</Button>
</ToolbarTooltip>
diff --git a/studio/frontend/src/features/api-monitor/api-sampling-example.ts b/studio/frontend/src/features/api-monitor/api-sampling-example.ts
index 2558aa1e82e..a823912920f 100644
--- a/studio/frontend/src/features/api-monitor/api-sampling-example.ts
+++ b/studio/frontend/src/features/api-monitor/api-sampling-example.ts
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+import { psSingle, shSingle } from "../settings/components/agent-command.ts";
+
export type ApiSamplingDefaults = Partial<{
temperature: number;
top_p: number;
@@ -10,9 +12,25 @@ export type ApiSamplingDefaults = Partial<{
presence_penalty: number;
}>;
+export type ApiExampleLanguage = "curl" | "python" | "javascript";
+export type ApiExampleOs = "unix" | "windows";
+
+export const API_EXAMPLE_LANGUAGES: {
+ id: ApiExampleLanguage;
+ label: string;
+}[] = [
+ { id: "curl", label: "curl" },
+ { id: "python", label: "Python" },
+ { id: "javascript", label: "JavaScript" },
+];
+
+export const API_EXAMPLE_KEY = "sk-unsloth-YOUR_KEY";
+const PROMPT = "Hello!";
+
// The OpenAI client takes these as kwargs; the Unsloth extensions only go through extra_body.
const CLIENT_FIELDS = ["temperature", "top_p", "presence_penalty"] as const;
const EXTRA_FIELDS = ["top_k", "min_p", "repetition_penalty"] as const;
+const ALL_FIELDS = [...CLIENT_FIELDS, ...EXTRA_FIELDS];
export function apiExampleModelName(
id: string,
@@ -21,15 +39,40 @@ export function apiExampleModelName(
return ggufVariant && !id.includes(":") ? `${id}:${ggufVariant}` : id;
}
+/** The language prefix of the API tab's stored pick ("pythonTools" -> "python"). */
+export const LANGUAGE_PREFIX_RE = /^(curl|python|javascript)/;
+
+export function apiExampleLanguage(
+ stored: string | null | undefined,
+ fallback: ApiExampleLanguage,
+): ApiExampleLanguage {
+ const match = stored?.match(LANGUAGE_PREFIX_RE);
+ return match ? (match[1] as ApiExampleLanguage) : fallback;
+}
+
+interface ApiExampleInput {
+ /** Ends in /v1, as the OpenAI clients take it. */
+ baseUrl: string;
+ model: string;
+ sampling: ApiSamplingDefaults;
+ apiKey?: string;
+}
+
+function samplingBody(sampling: ApiSamplingDefaults): Record<string, number> {
+ const body: Record<string, number> = {};
+ for (const field of ALL_FIELDS) {
+ const value = sampling[field];
+ if (value != null) body[field] = value;
+ }
+ return body;
+}
+
export function buildApiSamplingExample({
baseUrl,
model,
sampling,
-}: {
- baseUrl: string;
- model: string;
- sampling: ApiSamplingDefaults;
-}): string {
+ apiKey = API_EXAMPLE_KEY,
+}: ApiExampleInput): string {
const args = CLIENT_FIELDS.filter((field) => sampling[field] != null).map(
(field) => ` ${field}=${sampling[field]},`,
);
@@ -41,15 +84,94 @@ export function buildApiSamplingExample({
"",
"client = OpenAI(",
` base_url=${JSON.stringify(baseUrl)},`,
- ' api_key="sk-unsloth-YOUR_KEY",',
+ ` api_key=${JSON.stringify(apiKey)},`,
")",
"",
"response = client.chat.completions.create(",
` model=${JSON.stringify(model)},`,
- ' messages=[{"role": "user", "content": "Hello!"}],',
+ ` messages=[{"role": "user", "content": ${JSON.stringify(PROMPT)}}],`,
...args,
...(extras.length > 0 ? [" extra_body={", ...extras, " },"] : []),
")",
"print(response.choices[0].message.content)",
].join("\n");
}
+
+function javascriptExample({
+ baseUrl,
+ model,
+ sampling,
+ apiKey = API_EXAMPLE_KEY,
+}: ApiExampleInput): string {
+ // The JS SDK forwards unknown options into the body, so the Unsloth fields sit at the top level.
+ const options = Object.entries(samplingBody(sampling)).map(
+ ([field, value]) => ` ${field}: ${value},`,
+ );
+ return [
+ 'import OpenAI from "openai";',
+ "",
+ "const client = new OpenAI({",
+ ` baseURL: ${JSON.stringify(baseUrl)},`,
+ ` apiKey: ${JSON.stringify(apiKey)},`,
+ "});",
+ "",
+ "const response = await client.chat.completions.create({",
+ ` model: ${JSON.stringify(model)},`,
+ ` messages: [{ role: "user", content: ${JSON.stringify(PROMPT)} }],`,
+ ...options,
+ "});",
+ "console.log(response.choices[0].message.content);",
+ ].join("\n");
+}
+
+/** One field per line, the messages kept on one, as the API tab's curl prints them. */
+function requestBody(
+ model: string,
+ sampling: ApiSamplingDefaults,
+ indent: string,
+): string {
+ const fields = [
+ `"model": ${JSON.stringify(model)}`,
+ `"messages": [{"role": "user", "content": ${JSON.stringify(PROMPT)}}]`,
+ ...Object.entries(samplingBody(sampling)).map(
+ ([field, value]) => `"${field}": ${value}`,
+ ),
+ ];
+ return `{\n${fields.map((f) => `${indent} ${f}`).join(",\n")}\n${indent}}`;
+}
+
+function curlExample(
+ { baseUrl, model, sampling, apiKey = API_EXAMPLE_KEY }: ApiExampleInput,
+ os: ApiExampleOs,
+): string {
+ if (os === "windows") {
+ // PowerShell mangles inline JSON quotes on the way to curl.exe, so the body goes through a file.
+ return `$body = '${psSingle(requestBody(model, sampling, ""))}'
+Set-Content -Path body.json -Value $body -Encoding ascii
+curl.exe ${baseUrl}/chat/completions \`
+ -H "Authorization: Bearer ${apiKey}" \`
+ -H "Content-Type: application/json" \`
+ -d "@body.json"`;
+ }
+ return `curl ${baseUrl}/chat/completions \\
+ -H "Authorization: Bearer ${apiKey}" \\
+ -H "Content-Type: application/json" \\
+ -d '${shSingle(requestBody(model, sampling, " "))}'`;
+}
+
+export function buildApiExample(
+ input: ApiExampleInput & { language: ApiExampleLanguage; os: ApiExampleOs },
+): string {
+ if (input.language === "python") return buildApiSamplingExample(input);
+ if (input.language === "javascript") return javascriptExample(input);
+ return curlExample(input, input.os);
+}
+
+/** Shiki's name for each example language. */
+export function apiExampleShikiLanguage(
+ language: ApiExampleLanguage,
+ os: ApiExampleOs,
+): string {
+ if (language === "curl") return os === "windows" ? "powershell" : "bash";
+ return language;
+}
diff --git a/studio/frontend/src/features/api-monitor/components/api-example-box.tsx b/studio/frontend/src/features/api-monitor/components/api-example-box.tsx
new file mode 100644
index 00000000000..bf379ecf5dd
--- /dev/null
+++ b/studio/frontend/src/features/api-monitor/components/api-example-box.tsx
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import {
+ ExampleCodeBox,
+ type ExampleOs,
+ ExampleToggle,
+ useExampleOs,
+} from "@/features/settings/components/api-example-parts";
+import { useSettingsPanelPrefsStore } from "@/features/settings/stores/settings-panel-prefs-store";
+import {
+ API_EXAMPLE_LANGUAGES,
+ type ApiExampleLanguage,
+ LANGUAGE_PREFIX_RE,
+ apiExampleLanguage,
+ apiExampleShikiLanguage,
+} from "../api-sampling-example";
+
+export interface ApiExampleChoices {
+ language: ApiExampleLanguage;
+ setLanguage: (language: ApiExampleLanguage) => void;
+ os: ExampleOs;
+ setOs: (os: ExampleOs) => void;
+}
+
+/** Language and platform, shared with the API settings tab's examples. */
+export function useApiExampleChoices(
+ baseUrl: string,
+ fallback: ApiExampleLanguage,
+): ApiExampleChoices {
+ // Read from the store on every render, not copied at mount: the API page keeps the quick start and the
+ // (closed) example dialog mounted together, and a pick in one must show in the other.
+ const [detectedOs, setOs] = useExampleOs(baseUrl);
+ const storedOs = useSettingsPanelPrefsStore((s) => s.apiExampleOs);
+ const os = storedOs ?? detectedOs;
+ const storedLang = useSettingsPanelPrefsStore((s) => s.apiExampleLang);
+ const setStoredLang = useSettingsPanelPrefsStore((s) => s.setApiExampleLang);
+ const language = apiExampleLanguage(storedLang, fallback);
+ const setLanguage = (next: ApiExampleLanguage) => {
+ // Swap only the language, so the settings tab keeps its request kind (e.g. "pythonTools").
+ const stored = useSettingsPanelPrefsStore.getState().apiExampleLang;
+ setStoredLang(
+ stored && LANGUAGE_PREFIX_RE.test(stored)
+ ? stored.replace(LANGUAGE_PREFIX_RE, next)
+ : next,
+ );
+ };
+ return { language, setLanguage, os, setOs };
+}
+
+export function ApiExampleBox({
+ choices,
+ code,
+ fitContent,
+}: {
+ choices: ApiExampleChoices;
+ code: string;
+ fitContent?: boolean;
+}) {
+ return (
+ <ExampleCodeBox
+ code={code}
+ language={apiExampleShikiLanguage(choices.language, choices.os)}
+ label="Example request"
+ redactFromReload={false}
+ pills={
+ <ExampleToggle
+ label="Language"
+ value={choices.language}
+ options={API_EXAMPLE_LANGUAGES}
+ onChange={choices.setLanguage}
+ />
+ }
+ os={choices.os}
+ onOsChange={choices.setOs}
+ fitContent={fitContent}
+ />
+ );
+}
diff --git a/studio/frontend/src/features/api-monitor/components/api-example-dialog.tsx b/studio/frontend/src/features/api-monitor/components/api-example-dialog.tsx
index 95f6bf11ad0..1f571c759a8 100644
--- a/studio/frontend/src/features/api-monitor/components/api-example-dialog.tsx
+++ b/studio/frontend/src/features/api-monitor/components/api-example-dialog.tsx
@@ -1,12 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-import { createCodePlugin } from "@/components/assistant-ui/code-plugin";
-import {
- unslothDarkTheme,
- unslothLightTheme,
-} from "@/components/assistant-ui/code-themes";
-import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
@@ -15,22 +9,12 @@ import {
DialogTitle,
} from "@/components/ui/dialog";
import { authFetch } from "@/features/auth";
-import { copyToClipboard } from "@/lib/copy-to-clipboard";
-import { Tick02Icon } from "@/lib/tick-icon";
-import { Copy01Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
-import { type ReactElement, useEffect, useMemo, useRef, useState } from "react";
-import { Streamdown } from "streamdown";
+import { type ReactElement, useEffect, useState } from "react";
import {
type ApiSamplingDefaults,
- buildApiSamplingExample,
+ buildApiExample,
} from "../api-sampling-example";
-
-const SHIKI_THEMES = [unslothLightTheme, unslothDarkTheme] as [
- typeof unslothLightTheme,
- typeof unslothDarkTheme,
-];
-const codePlugin = createCodePlugin({ themes: SHIKI_THEMES });
+import { ApiExampleBox, useApiExampleChoices } from "./api-example-box";
export function ApiExampleDialog({
open,
@@ -46,8 +30,7 @@ export function ApiExampleDialog({
samplingModelId: string;
}): ReactElement {
const [sampling, setSampling] = useState<ApiSamplingDefaults | null>(null);
- const [copied, setCopied] = useState(false);
- const timer = useRef<number | undefined>(undefined);
+ const choices = useApiExampleChoices(baseUrl, "python");
useEffect(() => {
if (!open) return;
@@ -69,15 +52,6 @@ export function ApiExampleDialog({
};
}, [open, samplingModelId]);
- useEffect(() => () => window.clearTimeout(timer.current), []);
-
- const snippet = buildApiSamplingExample({
- baseUrl,
- model,
- sampling: sampling ?? {},
- });
- const markdown = useMemo(() => `\`\`\`python\n${snippet}\n\`\`\``, [snippet]);
-
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="corner-squircle dialog-soft-surface gap-5 sm:max-w-3xl">
@@ -89,44 +63,23 @@ export function ApiExampleDialog({
values to override them.
</DialogDescription>
</DialogHeader>
- <div className="relative min-w-0">
- <div className="corner-squircle max-h-[60dvh] overflow-auto scroll-rounded rounded-lg bg-[color-mix(in_oklab,var(--foreground)_calc(5%*var(--contrast-wash-gain,1)),transparent)] py-3 pr-11 pl-3 text-ui-12 leading-[1.6] dark:bg-[rgb(255_255_255_/_calc(0.05*var(--contrast-wash-gain,1)))] [&_[data-streamdown=code-block-header]]:hidden [&_[data-streamdown=code-block]]:!my-0 [&_[data-streamdown=code-block]]:!border-0 [&_[data-streamdown=code-block]]:!bg-transparent [&_[data-streamdown=code-block]]:!p-0 [&_code]:!text-ui-12 [&_pre]:!m-0 [&_pre]:!border-0 [&_pre]:!bg-transparent [&_pre]:!p-0 [&_pre]:!text-ui-12 [&_pre]:!leading-[1.6]">
- {sampling ? (
- <Streamdown
- mode="static"
- plugins={{ code: codePlugin }}
- controls={{ code: false }}
- shikiTheme={SHIKI_THEMES}
- >
- {markdown}
- </Streamdown>
- ) : (
- <span className="font-mono text-muted-foreground">Loading…</span>
- )}
- </div>
- <Button
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Copy example request"
- title={copied ? "Copied" : "Copy example request"}
- disabled={!sampling}
- onClick={async () => {
- if (await copyToClipboard(snippet)) {
- setCopied(true);
- window.clearTimeout(timer.current);
- timer.current = window.setTimeout(() => setCopied(false), 1800);
- }
- }}
- className="absolute top-2 right-2 size-7 rounded-full p-0"
- >
- <HugeiconsIcon
- icon={copied ? Tick02Icon : Copy01Icon}
- strokeWidth={1.75}
- className="size-3.5"
- />
- </Button>
- </div>
+ {sampling ? (
+ <ApiExampleBox
+ fitContent={true}
+ choices={choices}
+ code={buildApiExample({
+ baseUrl,
+ model,
+ sampling,
+ language: choices.language,
+ os: choices.os,
+ })}
+ />
+ ) : (
+ <span className="font-mono text-ui-12 text-muted-foreground">
+ Loading…
+ </span>
+ )}
</DialogContent>
</Dialog>
);
diff --git a/studio/frontend/src/features/settings/components/api-example-parts.tsx b/studio/frontend/src/features/settings/components/api-example-parts.tsx
index e7637636a4b..83e8bfb25ad 100644
--- a/studio/frontend/src/features/settings/components/api-example-parts.tsx
+++ b/studio/frontend/src/features/settings/components/api-example-parts.tsx
@@ -38,6 +38,10 @@ const OS_OPTIONS: { id: ExampleOs; labelKey: TranslationKey }[] = [
{ id: "windows", labelKey: "settings.apiKeys.osWindows" },
];
+// The btn-fill grey (index.css), so a selected pill matches a standard filled button.
+const LIGHT_FILL_PILL =
+ "[html:not(.dark)_&]:bg-[color-mix(in_srgb,var(--foreground)_calc(5%*var(--contrast-wash-gain,1)),transparent)] [html:not(.dark)_&]:shadow-none";
+
// Lines that fit the example box's starting height (h-46); longer ones start there and scroll.
const START_LINES = 8;
@@ -142,7 +146,14 @@ export function ExampleToggle<T extends string>({
: "text-muted-foreground hover:text-foreground",
)}
>
- {value === option.id && <SegmentedPill group={pillId} />}
+ {value === option.id && (
+ <SegmentedPill
+ group={pillId}
+ // With no track behind them, the pills take a filled button's grey in light mode, not a
+ // white lifted pill.
+ className={toggle ? undefined : LIGHT_FILL_PILL}
+ />
+ )}
<span className="relative truncate">{option.label}</span>
</button>
))}
@@ -223,6 +234,7 @@ export function ExampleCodeBox({
pills,
os,
onOsChange,
+ fitContent = false,
}: {
code: string;
language: string;
@@ -231,6 +243,8 @@ export function ExampleCodeBox({
pills: ReactNode;
os: ExampleOs;
onOsChange: (os: ExampleOs) => void;
+ /** Show the whole example up to most of the viewport instead of starting eight lines tall. */
+ fitContent?: boolean;
}) {
const t = useT();
const [copied, setCopied] = useState(false);
@@ -289,7 +303,9 @@ export function ExampleCodeBox({
className={cn(
"relative [&>section]:max-h-none [&>section]:min-h-24 [&>section]:pr-8 [&_[data-streamdown=code-block-header]]:hidden",
height === null
- ? tall && "[&>section]:h-46"
+ ? fitContent
+ ? "[&>section]:max-h-[60dvh]"
+ : tall && "[&>section]:h-46"
: "[&>section]:h-(--example-h)",
)}
>
diff --git a/studio/frontend/tests/agent-docs-links.test.ts b/studio/frontend/tests/agent-docs-links.test.ts
index edf2bb3cb47..7a7a4f2e16f 100644
--- a/studio/frontend/tests/agent-docs-links.test.ts
+++ b/studio/frontend/tests/agent-docs-links.test.ts
@@ -127,7 +127,7 @@ test("the example code box starts short, drags taller, and its copy button is ic
// the cap is lifted so a drag can grow it; a height is set, from the drag once there is one
assert.match(
src,
- /"relative \[&>section\]:max-h-none \[&>section\]:min-h-24 \[&>section\]:pr-8 \[&_\[data-streamdown=code-block-header\]\]:hidden",\s*height === null\s*\? tall && "\[&>section\]:h-46"\s*: "\[&>section\]:h-\(--example-h\)"/,
+ /"relative \[&>section\]:max-h-none \[&>section\]:min-h-24 \[&>section\]:pr-8 \[&_\[data-streamdown=code-block-header\]\]:hidden",\s*height === null\s*\? fitContent\s*\? "\[&>section\]:max-h-\[60dvh\]"\s*: tall && "\[&>section\]:h-46"\s*: "\[&>section\]:h-\(--example-h\)"/,
);
// our own handle: CSS resize draws a native grabber the rounded corner clips into an arc
assert.doesNotMatch(src, /resize-y|webkit-resizer/);
diff --git a/studio/frontend/tests/api-sampling-example.test.ts b/studio/frontend/tests/api-sampling-example.test.ts
index 6e4be75ad38..bdd3be83b61 100644
--- a/studio/frontend/tests/api-sampling-example.test.ts
+++ b/studio/frontend/tests/api-sampling-example.test.ts
@@ -6,7 +6,9 @@ import assert from "node:assert/strict";
import test from "node:test";
import {
+ apiExampleLanguage,
apiExampleModelName,
+ buildApiExample,
buildApiSamplingExample,
} from "../src/features/api-monitor/api-sampling-example.ts";
@@ -44,3 +46,52 @@ test("the quant is pinned once", () => {
assert.equal(apiExampleModelName("unsloth/x-GGUF:Q8_0", "Q4_K_M"), "unsloth/x-GGUF:Q8_0");
assert.equal(apiExampleModelName("unsloth/x", null), "unsloth/x");
});
+
+const SAMPLING = { temperature: 1, top_p: 0.95, top_k: -1, min_p: 0.01 };
+
+test("curl and JavaScript put every sampling field at the top level of the body", () => {
+ const curl = buildApiExample({ baseUrl: "http://h/v1", model: "m", sampling: SAMPLING, language: "curl", os: "unix" });
+ assert.match(curl, /^curl http:\/\/h\/v1\/chat\/completions \\/);
+ const body = JSON.parse(curl.slice(curl.indexOf("-d '") + 4, curl.lastIndexOf("'")));
+ assert.deepEqual(body, { model: "m", messages: [{ role: "user", content: "Hello!" }], ...SAMPLING });
+
+ const js = buildApiExample({ baseUrl: "http://h/v1", model: "m", sampling: SAMPLING, language: "javascript", os: "unix" });
+ assert.match(js, /baseURL: "http:\/\/h\/v1"/);
+ assert.match(js, /\n {2}top_k: -1,\n {2}min_p: 0\.01,/);
+ assert.doesNotMatch(js, /extra_body/);
+});
+
+test("Windows curl sends the body through a file PowerShell cannot mangle", () => {
+ const win = buildApiExample({ baseUrl: "http://h/v1", model: "it's", sampling: {}, language: "curl", os: "windows" });
+ assert.match(win, /^\$body = '/);
+ assert.match(win, /"model": "it''s"/);
+ assert.match(win, /curl\.exe http:\/\/h\/v1\/chat\/completions `/);
+ assert.match(win, /-d "@body\.json"$/);
+ // Python and JavaScript read the same on every platform.
+ const args = { baseUrl: "http://h/v1", model: "m", sampling: SAMPLING } as const;
+ for (const language of ["python", "javascript"] as const) {
+ assert.equal(
+ buildApiExample({ ...args, language, os: "windows" }),
+ buildApiExample({ ...args, language, os: "unix" }),
+ );
+ }
+});
+
+test("the stored settings pick names the language", () => {
+ assert.equal(apiExampleLanguage("pythonTools", "curl"), "python");
+ assert.equal(apiExampleLanguage("javascriptAdvanced", "curl"), "javascript");
+ assert.equal(apiExampleLanguage(null, "python"), "python");
+ assert.equal(apiExampleLanguage("ruby", "curl"), "curl");
+});
+
+test("every example box follows the stored language and platform, not a copy taken at mount", async () => {
+ const { readFileSync } = await import("node:fs");
+ const box = readFileSync(
+ new URL("../src/features/api-monitor/components/api-example-box.tsx", import.meta.url),
+ "utf8",
+ );
+ // The quick start and the closed dialog are mounted together; local state would let them drift apart.
+ assert.doesNotMatch(box, /useState/);
+ assert.match(box, /useSettingsPanelPrefsStore\(\(s\) => s\.apiExampleLang\)/);
+ assert.match(box, /useSettingsPanelPrefsStore\(\(s\) => s\.apiExampleOs\)/);
+});
diff --git a/studio/frontend/tests/dialog-scrollbar-corners.test.ts b/studio/frontend/tests/dialog-scrollbar-corners.test.ts
index b0e94ef7b0a..cc6f155249e 100644
--- a/studio/frontend/tests/dialog-scrollbar-corners.test.ts
+++ b/studio/frontend/tests/dialog-scrollbar-corners.test.ts
@@ -47,7 +47,7 @@ test("dialogs and inline rounded scrollers use it", () => {
["components/ui/dialog.tsx", "overflow-y-auto scroll-rounded rounded-3xl"],
["components/ui/alert-dialog.tsx", "overflow-y-auto scroll-rounded rounded-3xl"],
["features/settings/tabs/debugging-tab.tsx", "scroll-rounded rounded-md"],
- ["features/api-monitor/api-monitor-page.tsx", "scroll-rounded rounded-lg"],
+ ["features/api-monitor/api-monitor-page.tsx", "break-words scroll-rounded"],
["features/export/components/export-run-panel.tsx", "scroll-rounded rounded-lg"],
["features/chat/components/research-activity-panel.tsx", "scroll-rounded rounded-xl"],
["features/rag/components/knowledge-base-dialog.tsx", "scroll-rounded rounded-xl border"],