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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: use live trending GGUFs in agent setup (#9752)
Michael Han0451b8f24d9f
diff --git a/studio/frontend/src/features/settings/lib/agent-hub-model.ts b/studio/frontend/src/features/settings/lib/agent-hub-model.tsnew file mode 100644index 00000000000..ee76824362d--- /dev/null+++ b/studio/frontend/src/features/settings/lib/agent-hub-model.ts@@ -0,0 +1,89 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++type HubModelTaskMetadata = {+ id?: string | null;+ pipelineTag?: string | null;+ tags?: readonly string[] | null;+};++// Coding agents require a chat-completions model. When the Hub declares a+// primary pipeline, admit only pipelines that can consume conversational text;+// a missing pipeline remains eligible because many valid GGUF repos omit it.+const CHAT_GENERATION_TASKS: ReadonlySet<string> = new Set([+ "text-generation",+ "conversational",+ "image-text-to-text",+ "audio-text-to-text",+ "any-to-any",+]);++// These generation tasks belong to the Audio page and cannot serve coding-agent+// chat completions. Keep this narrower than generic audio tags so audio-capable+// chat and vision-language models remain available.+const SPEECH_ONLY_TAGS: ReadonlySet<string> = new Set([+ "text-to-speech",+ "automatic-speech-recognition",+]);++const CLASSIFIER_TASKS: ReadonlySet<string> = new Set([+ "text-classification",+ "token-classification",+ "zero-shot-classification",+]);++const RERANKER_TAGS: ReadonlySet<string> = new Set([+ "reranker",+ "reranking",+ "text-ranking",+ "cross-encoder",+]);++const RERANKER_ID_PATTERN =+ /(?:^|[-_./])(?:rerank(?:er|ing)?|classif(?:ier|ication))(?:$|[-_./])/i;++function normalize(value: string | null | undefined): string | null {+ const normalized = value?.toLowerCase().trim();+ return normalized || null;+}++export function isChatGenerativeHubModel(model: HubModelTaskMetadata): boolean {+ const pipeline = normalize(model.pipelineTag);+ return pipeline == null || CHAT_GENERATION_TASKS.has(pipeline);+}++export function isSpeechOnlyHubModel(model: HubModelTaskMetadata): boolean {+ const pipeline = normalize(model.pipelineTag);+ if (pipeline) {+ return SPEECH_ONLY_TAGS.has(pipeline);+ }+ return (model.tags ?? []).some((tag) => {+ const normalized = normalize(tag);+ return normalized != null && SPEECH_ONLY_TAGS.has(normalized);+ });+}++export function isClassifierOrRerankerHubModel(+ model: HubModelTaskMetadata,+): boolean {+ const pipeline = normalize(model.pipelineTag);+ if (+ pipeline &&+ (CLASSIFIER_TASKS.has(pipeline) || RERANKER_TAGS.has(pipeline))+ ) {+ return true;+ }+ if (RERANKER_ID_PATTERN.test(model.id ?? "")) {+ return true;+ }+ if (pipeline) {+ return false;+ }+ return (model.tags ?? []).some((tag) => {+ const normalized = normalize(tag);+ return (+ normalized != null &&+ (CLASSIFIER_TASKS.has(normalized) || RERANKER_TAGS.has(normalized))+ );+ });+}diff --git a/studio/frontend/src/features/settings/tabs/agents-tab.tsx b/studio/frontend/src/features/settings/tabs/agents-tab.tsxindex aefc12dd833..b865f8d1de6 100644--- a/studio/frontend/src/features/settings/tabs/agents-tab.tsx+++ b/studio/frontend/src/features/settings/tabs/agents-tab.tsx@@ -33,7 +33,15 @@ import {listLocalModels,listModels,} from "@/features/chat";-import { useHfTokenStore } from "@/features/hub";+import {+ EMBEDDING_TAGS,+ type HfModelResult,+ ggufVariantDisplayLabel,+ hfApiToken,+ useHfTokenStore,+ useHubModelSearch,+ useOnlineStatus,+} from "@/features/hub";import type { TranslationKey } from "@/i18n";import { useT } from "@/i18n";import { getApiBase, isTauri } from "@/lib/api-base";@@ -53,12 +61,18 @@ import {} from "../components/agent-command";import { SettingsSection } from "../components/settings-section";import { psSingle, shSingle } from "../components/usage-examples";+import {+ isChatGenerativeHubModel,+ isClassifierOrRerankerHubModel,+ isSpeechOnlyHubModel,+} from "../lib/agent-hub-model.ts";import { useSettingsPanelPrefsStore } from "../stores/settings-panel-prefs-store";-import { ggufVariantDisplayLabel } from "@/features/hub";const DOCS_URL = "https://unsloth.ai/docs/integrations/unsloth-start";-const EXAMPLE_MODEL_REPO = "unsloth/gemma-4-E4B-it-GGUF";+const FLAGS_DOCS_URL = `${DOCS_URL}#flags--options`;+const EXAMPLE_MODEL_REPO = "unsloth/Qwen3.8-27B-GGUF";const EXAMPLE_MODEL_VARIANT = "UD-Q4_K_XL";+const EXAMPLE_MODEL_FLAGS = "--reasoning-effort medium";const MODEL_RESULT_LIMIT = 7;const STATUS_POLL_MS = 5000;const HUGGING_FACE_REPO_PATTERN = /^[^/\\:\s]+\/[^/\\:\s]+$/;@@ -221,10 +235,32 @@ function modelKey(model: string): string {return looksLikePath(model) ? model : model.toLowerCase();}+function mergeModelOrder(primary: string[], fallback: string[]): string[] {+ const ordered: string[] = [];+ const seen = new Set<string>();+ for (const model of [...primary, ...fallback]) {+ const key = modelKey(model);+ if (seen.has(key)) {+ continue;+ }+ seen.add(key);+ ordered.push(model);+ }+ return ordered;+}+function isHuggingFaceRepo(model: string): boolean {return HUGGING_FACE_REPO_PATTERN.test(model);}+function isEmbeddingHubModel(+ model: Pick<HfModelResult, "pipelineTag" | "tags">,+): boolean {+ return [model.pipelineTag, ...(model.tags ?? [])].some(+ (tag) => tag != null && EMBEDDING_TAGS.has(tag.toLowerCase()),+ );+}+function formatBytes(bytes: number): string {if (!Number.isFinite(bytes) || bytes <= 0) {return "";@@ -626,7 +662,17 @@ export function AgentsTab() {const t = useT();const serverUrl = usePlatformStore((s) => s.serverUrl);const hfToken = useHfTokenStore((s) => s.token);+ const hfAccessToken = hfApiToken(hfToken);+ const online = useOnlineStatus();const deviceType = usePlatformStore((s) => s.deviceType);+ const { results: trendingGgufs } = useHubModelSearch("", {+ channel: { owner: "unsloth", tags: ["gguf"] },+ sortBy: "trendingScore",+ sortDirection: "desc",+ accessToken: hfAccessToken,+ keepUnsupportedTags: false,+ enabled: online,+ });// The remote snippet runs on the client, so use the client platform, not deviceType.// Anchor the match: a bare includes("win") would also match "darwin".const [isWindowsClient] = useState(() => {@@ -725,6 +771,24 @@ export function AgentsTab() {const [variantsFailed, setVariantsFailed] = useState(false);const labelFor = (model: string) => modelLabels[model] ?? model;+ const trendingModels = useMemo(+ () =>+ trendingGgufs+ .filter(+ (model) =>+ model.isGguf &&+ isChatGenerativeHubModel(model) &&+ !isEmbeddingHubModel(model) &&+ !isSpeechOnlyHubModel(model) &&+ !isClassifierOrRerankerHubModel(model),+ )+ .map((model) => model.id),+ [trendingGgufs],+ );+ const orderedModels = useMemo(+ () => mergeModelOrder(trendingModels, models),+ [models, trendingModels],+ );const matchingModels = useMemo(() => {const tokens = modelSearch.trim()@@ -733,22 +797,28 @@ export function AgentsTab() {.filter(Boolean);const matches =tokens.length === 0- ? models- : models.filter((model) => {+ ? orderedModels+ : orderedModels.filter((model) => {// Search both, so a scanned model is findable by name and by path.const haystack =`${model} ${modelLabels[model] ?? ""}`.toLowerCase();return tokens.every((token) => haystack.includes(token));});- if (tokens.length === 0 && matches.includes(selectedModel)) {- return [- selectedModel,- ...matches.filter((model) => model !== selectedModel),- ];+ if (tokens.length === 0) {+ const selectedKey = modelKey(selectedModel);+ const selectedIndex = matches.findIndex(+ (model) => modelKey(model) === selectedKey,+ );+ if (selectedIndex > 0) {+ return [+ matches[selectedIndex],+ ...matches.filter((_, index) => index !== selectedIndex),+ ];+ }}return matches;- }, [modelLabels, modelSearch, models, selectedModel]);+ }, [modelLabels, modelSearch, orderedModels, selectedModel]);const visibleModels = matchingModels.slice(0, MODEL_RESULT_LIMIT);const preferredVariant = knownVariants[selectedModel] ?? null;@@ -758,12 +828,14 @@ export function AgentsTab() {// /v1/models advertises for it. The resident model is exempt: it already// loaded by id, and cached-gguf keeps the largest copy across caches, whose// snapshot could switch cache or quant under it.- const cachedLoadId =- selectedModel === activeStatusModel- ? null- : (cachedLoadIds[selectedModel] ??- cachedLoadIds[selectedModel.toLowerCase()] ??- null);+ const selectedModelIsActive =+ activeStatusModel != null &&+ modelKey(selectedModel) === modelKey(activeStatusModel);+ const cachedLoadId = selectedModelIsActive+ ? null+ : (cachedLoadIds[selectedModel] ??+ cachedLoadIds[selectedModel.toLowerCase()] ??+ null);const modelId = cachedLoadId ?? selectedModel;const suffixVariant = isHuggingFaceRepo(modelId);const commandModel =@@ -774,11 +846,17 @@ export function AgentsTab() {// A bare `unsloth start` attaches to whatever is loaded, which is the only way// to reach a native-grant GGUF: naming it would switch the server to another model.const attachOnly = selectedModel === attachOnlyModel;- const modelArgs = attachOnly- ? ""- : selectedVariant && !suffixVariant+ const selectedModelArgs =+ selectedVariant && !suffixVariant? `--model ${commandModelArg} --gguf-variant ${quoteShellArg(selectedVariant, isWindowsShell)}`: `--model ${commandModelArg}`;+ const selectedModelFlags =+ modelKey(selectedModel) === modelKey(EXAMPLE_MODEL_REPO)+ ? EXAMPLE_MODEL_FLAGS+ : "";+ const modelArgs = attachOnly+ ? ""+ : [selectedModelArgs, selectedModelFlags].filter(Boolean).join(" ");// No key is passed: the CLI caches an explicit one per base, overwriting a working// saved key. Omitting it replays the saved key; the remote section covers first setup.const commandOs = isWindowsShell ? "windows" : "unix";@@ -1078,6 +1156,7 @@ export function AgentsTab() {// absence there is not evidence.if (looksLikePath(restored) ||+ isHuggingFaceRepo(restored) ||discoveredKeys.has(modelKey(restored)) ||(active && modelKey(active.model) === modelKey(restored))) {@@ -1404,7 +1483,9 @@ export function AgentsTab() {<CommandItemkey={model}value={model}- data-checked={model === selectedModel}+ data-checked={+ modelKey(model) === modelKey(selectedModel)+ }onSelect={() => {modelSelectionChanged.current = true;restoredModel.current = null;@@ -1533,12 +1614,27 @@ export function AgentsTab() {<span className="text-xs font-medium text-foreground">{t("settings.agents.generatedCommand")}</span>+ <p className="text-ui-11 leading-relaxed text-muted-foreground">+ {t("settings.agents.automaticSettingsNote")}+ </p><CopyableCodevalue={command}copyLabel={t("settings.agents.copyGeneratedCommand")}copied={copied}onCopy={handleCopy}/>+ <p className="text-ui-11 leading-relaxed text-muted-foreground">+ {t("settings.agents.configurationNote")}{" "}+ <a+ href={FLAGS_DOCS_URL}+ target="_blank"+ rel="noopener noreferrer"+ className="rounded text-foreground underline decoration-border decoration-dotted underline-offset-2 transition-colors hover:decoration-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"+ >+ {t("settings.agents.configurationDocs")}+ </a>{" "}+ {t("settings.agents.configurationFlagsSuffix")}+ </p></div><SubagentSectiondiff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.tsindex b4f60442ea8..98da0ec5607 100644--- a/studio/frontend/src/i18n/locales/en.ts+++ b/studio/frontend/src/i18n/locales/en.ts@@ -1214,6 +1214,12 @@ export const en = {docs: "Docs",agentDocs: "Open {agent} setup docs",copyGeneratedCommand: "Copy generated command",+ automaticSettingsNote:+ "Unsloth automatically applies the model’s recommended settings if you have not set any flags.",+ configurationNote:+ "You can also adjust any configuration. See further below or",+ configurationDocs: "docs",+ configurationFlagsSuffix: "for flags.",modelNote:"Codex requires a GGUF model served by llama-server. Other agents can also use transformer-backed models; remove --model to use the model already loaded in Unsloth.",subagent: {diff --git a/studio/frontend/tests/agents-model-picker.test.ts b/studio/frontend/tests/agents-model-picker.test.tsnew file mode 100644index 00000000000..0d9e5a93a05--- /dev/null+++ b/studio/frontend/tests/agents-model-picker.test.ts@@ -0,0 +1,182 @@+// 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 assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";+import { fileURLToPath } from "node:url";+import {+ isChatGenerativeHubModel,+ isClassifierOrRerankerHubModel,+ isSpeechOnlyHubModel,+} from "../src/features/settings/lib/agent-hub-model.ts";+import { en } from "../src/i18n/locales/en.ts";++const TAB = readFileSync(+ fileURLToPath(+ new URL("../src/features/settings/tabs/agents-tab.tsx", import.meta.url),+ ),+ "utf-8",+);++test("the default model demonstrates reasoning effort without sampling flags", () => {+ assert.ok(+ TAB.includes('const EXAMPLE_MODEL_REPO = "unsloth/Qwen3.8-27B-GGUF";'),+ );+ assert.ok(TAB.includes('const EXAMPLE_MODEL_VARIANT = "UD-Q4_K_XL";'));+ const start = TAB.indexOf("const EXAMPLE_MODEL_FLAGS");+ const flags = TAB.slice(start, TAB.indexOf(";", start));+ assert.ok(flags.includes("--reasoning-effort medium"));+ for (const samplingFlag of [+ "--temperature",+ "--top-p",+ "--top-k",+ "--min-p",+ "--presence-penalty",+ ]) {+ assert.ok(!flags.includes(samplingFlag));+ }+ assert.ok(+ TAB.includes("modelKey(selectedModel) === modelKey(EXAMPLE_MODEL_REPO)"),+ );+ assert.equal(+ en.settings.agents.automaticSettingsNote,+ "Unsloth automatically applies the model’s recommended settings if you have not set any flags.",+ );+ assert.equal(+ en.settings.agents.configurationNote,+ "You can also adjust any configuration. See further below or",+ );+ assert.equal(en.settings.agents.configurationDocs, "docs");+ assert.equal(en.settings.agents.configurationFlagsSuffix, "for flags.");+ assert.ok(TAB.includes("href={FLAGS_DOCS_URL}"));+ assert.ok(TAB.includes("#flags--options"));+});++test("the model dropdown loads live trending GGUFs", () => {+ const start = TAB.indexOf('useHubModelSearch("", {');+ const request = TAB.slice(start, TAB.indexOf("});", start));+ assert.ok(request.includes('owner: "unsloth"'));+ assert.ok(request.includes('tags: ["gguf"]'));+ assert.ok(request.includes('sortBy: "trendingScore"'));+ assert.ok(request.includes('sortDirection: "desc"'));+ assert.ok(request.includes("keepUnsupportedTags: false"));+ assert.ok(TAB.includes("isChatGenerativeHubModel(model)"));+ assert.ok(TAB.includes("!isEmbeddingHubModel(model)"));+ assert.ok(TAB.includes("EMBEDDING_TAGS.has(tag.toLowerCase())"));+ assert.ok(TAB.includes("!isSpeechOnlyHubModel(model)"));+ assert.ok(TAB.includes("!isClassifierOrRerankerHubModel(model)"));+ assert.ok(TAB.includes("mergeModelOrder(trendingModels, models)"));+ assert.ok(TAB.includes("[...primary, ...fallback]"));+});++test("the agent feed admits only declared chat-generation pipelines", () => {+ for (const pipelineTag of [+ "text-generation",+ "conversational",+ "image-text-to-text",+ "audio-text-to-text",+ "any-to-any",+ ]) {+ assert.equal(isChatGenerativeHubModel({ pipelineTag }), true);+ }+ for (const pipelineTag of [+ "fill-mask",+ "audio-classification",+ "voice-activity-detection",+ "feature-extraction",+ "question-answering",+ "image-classification",+ "text-to-speech",+ "text-classification",+ ]) {+ assert.equal(isChatGenerativeHubModel({ pipelineTag }), false);+ }+ assert.equal(+ isChatGenerativeHubModel({ pipelineTag: " TEXT-GENERATION " }),+ true,+ );+ assert.equal(isChatGenerativeHubModel({}), true);+});++test("the agent feed excludes speech-only model tasks", () => {+ for (const pipelineTag of [+ "text-to-speech",+ "automatic-speech-recognition",+ ]) {+ assert.equal(isSpeechOnlyHubModel({ pipelineTag }), true);+ }+ assert.equal(+ isSpeechOnlyHubModel({+ tags: ["GGUF", " TEXT-TO-SPEECH "],+ }),+ true,+ );+ assert.equal(+ isSpeechOnlyHubModel({+ pipelineTag: "text-generation",+ tags: ["gguf", "text-to-speech"],+ }),+ false,+ );+ assert.equal(+ isSpeechOnlyHubModel({+ pipelineTag: "audio-text-to-text",+ tags: ["gguf", "automatic-speech-recognition"],+ }),+ false,+ );+ assert.equal(+ isSpeechOnlyHubModel({ pipelineTag: "image-text-to-text" }),+ false,+ );+});++test("the agent feed excludes classifier and reranker models", () => {+ for (const pipelineTag of [+ "text-classification",+ "token-classification",+ "zero-shot-classification",+ "text-ranking",+ ]) {+ assert.equal(isClassifierOrRerankerHubModel({ pipelineTag }), true);+ }+ assert.equal(+ isClassifierOrRerankerHubModel({ id: "unsloth/Qwen3-Reranker-GGUF" }),+ true,+ );+ assert.equal(+ isClassifierOrRerankerHubModel({ tags: ["gguf", "cross-encoder"] }),+ true,+ );+ assert.equal(+ isClassifierOrRerankerHubModel({+ pipelineTag: "text-generation",+ tags: ["text-classification"],+ }),+ false,+ );+ assert.equal(+ isClassifierOrRerankerHubModel({+ id: "unsloth/Qwen3.8-27B-GGUF",+ pipelineTag: "text-generation",+ }),+ false,+ );+});++test("restored Hub selections remain valid while uncached", () => {+ assert.ok(TAB.includes("isHuggingFaceRepo(restored)"));+});++test("model selection matching ignores Hub repository casing", () => {+ assert.ok(TAB.includes("modelKey(model) === selectedKey"));+ assert.ok(TAB.includes("modelKey(model) === modelKey(selectedModel)"));+});++test("an adopted resident model does not use a cached load ID", () => {+ assert.ok(TAB.includes("const selectedModelIsActive"));+ assert.ok(+ TAB.includes("const cachedLoadId = selectedModelIsActive\n ? null"),+ );+});