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
Tag the compat endpoint's Ollama rows with their real source (#9988)
Shubhankar Tripathyd37e98ec59d3
diff --git a/studio/backend/models/models.py b/studio/backend/models/models.pyindex efd01db2d0b..9a40c364fba 100644--- a/studio/backend/models/models.py+++ b/studio/backend/models/models.py@@ -220,7 +220,7 @@ class LocalModelInfo(BaseModel):id: str = Field(..., description = "Identifier to use for loading/training")display_name: str = Field(..., description = "Display label")path: str = Field(..., description = "Local path where model data was discovered")- source: Literal["models_dir", "hf_cache", "lmstudio", "custom"] = Field(+ source: Literal["models_dir", "hf_cache", "lmstudio", "ollama", "custom"] = Field(...,description = "Discovery source",)diff --git a/studio/backend/routes/models.py b/studio/backend/routes/models.pyindex 2e058e921c6..06b01bfbd3d 100644--- a/studio/backend/routes/models.py+++ b/studio/backend/routes/models.py@@ -985,7 +985,10 @@ def _scan_ollama_dir(ollama_dir: Path, limit: Optional[int] = None) -> List[Locamodel_id = f"ollama/{repo_name}:{tag}",display_name = display + suffix,path = gguf_link_path,- source = "custom",+ # The frontend groups and labels these rows by this value+ # (local-model-options.ts, pickers.tsx); "custom" hid them+ # in the generic folder section (#9986).+ source = "ollama",updated_at = updated_at,),)@@ -1151,7 +1154,14 @@ def collect_local_models(record_scan_failure(str(folder.get("path", folder_path)), e)continuenote_scan_folder_scanned(str(folder.get("path", folder_path)), found = bool(custom_models))- local_models += [m.model_copy(update = {"source": "custom"}) for m in custom_models]+ # Keep an already-attributed source: a registered ~/.ollama/models (or a+ # folder shadowing the HF cache) must not re-stamp its rows as generic+ # custom entries. Mirrors _promote_to_custom_source() in+ # hub/services/models/local_inventory.py.+ local_models += [+ m if m.source in ("hf_cache", "ollama") else m.model_copy(update = {"source": "custom"})+ for m in custom_models+ ]# Deduplicate, but always keep custom folder entries (keyed by (id, source)) so they show# in the "Custom Folders" UI section even when the model is also in the HF cache.diff --git a/studio/backend/tests/test_legacy_ollama_source.py b/studio/backend/tests/test_legacy_ollama_source.pynew file mode 100644index 00000000000..5cfcbb1c0b6--- /dev/null+++ b/studio/backend/tests/test_legacy_ollama_source.py@@ -0,0 +1,87 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""The compat /api/models/local path tags Ollama rows with their real source.++The chat and training pickers group and label rows by ``source``, and the+frontend branches on ``"ollama"`` explicitly. The legacy scanner in+routes/models.py stamped its rows ``"custom"`` — and the legacy LocalModelInfo+schema did not even admit ``"ollama"``, so correcting the stamp alone 500'd the+route. The custom-folder merge then re-stamped every row from a registered+folder, so a user who registered ``~/.ollama/models`` (Studio's own recommended+folder) lost the attribution a second way. (#9986)+"""++from __future__ import annotations++import json+from pathlib import Path++import pytest++from models.models import LocalModelInfo+++def _write_ollama_store(root: Path) -> None:+ digest_value = "b" * 64+ blob = root / "blobs" / f"sha256-{digest_value}"+ blob.parent.mkdir(parents = True)+ blob.write_bytes(b"GGUF-not-really")+ tag_file = root / "manifests" / "registry.ollama.ai" / "library" / "llama3" / "latest"+ tag_file.parent.mkdir(parents = True)+ tag_file.write_text(+ json.dumps(+ {+ "config": {},+ "layers": [+ {+ "mediaType": "application/vnd.ollama.image.model",+ "digest": f"sha256:{digest_value}",+ }+ ],+ }+ ),+ encoding = "utf-8",+ )+++def test_legacy_schema_admits_the_ollama_source():+ row = LocalModelInfo(+ id = "/links/llama3.gguf",+ display_name = "llama3:latest",+ path = "/links/llama3.gguf",+ source = "ollama",+ )+ assert row.source == "ollama"+++def test_legacy_scanner_tags_rows_ollama(tmp_path):+ from routes import models as models_route++ root = tmp_path / "ollama"+ _write_ollama_store(root)+ found = models_route._scan_ollama_dir(root)+ assert len(found) == 1+ assert found[0].source == "ollama"+ assert found[0].model_id == "ollama/llama3:latest"++[email protected]("source", ["hf_cache", "ollama"])+def test_custom_folder_merge_keeps_real_sources(source):+ # The merge step mirrors _promote_to_custom_source() in+ # hub/services/models/local_inventory.py: only unattributed rows become+ # "custom"; a registered ~/.ollama/models or HF-cache shadow keeps its label.+ src = (Path(__file__).resolve().parent.parent / "routes" / "models.py").read_text(+ encoding = "utf-8"+ )+ assert 'm if m.source in ("hf_cache", "ollama") else' in src+ row = LocalModelInfo(+ id = "/x",+ display_name = "x",+ path = "/x",+ source = source,+ )+ kept = (+ row if row.source in ("hf_cache", "ollama") else row.model_copy(update = {"source": "custom"})+ )+ assert kept.source == sourcediff --git a/studio/frontend/src/features/recipe-studio/dialogs/models/local-recipe-model-selector.tsx b/studio/frontend/src/features/recipe-studio/dialogs/models/local-recipe-model-selector.tsxindex 92f6da47951..68e9f71d84c 100644--- a/studio/frontend/src/features/recipe-studio/dialogs/models/local-recipe-model-selector.tsx+++ b/studio/frontend/src/features/recipe-studio/dialogs/models/local-recipe-model-selector.tsx@@ -75,6 +75,8 @@ function sourceLabel(model: LocalModelInfo): string {return "HF cache";case "lmstudio":return "LM Studio";+ case "ollama":+ return "Ollama";case "custom":return "Custom folder";default:diff --git a/studio/frontend/src/features/training/api/models-api.ts b/studio/frontend/src/features/training/api/models-api.tsindex 8d1c38684bd..4d77d010e48 100644--- a/studio/frontend/src/features/training/api/models-api.ts+++ b/studio/frontend/src/features/training/api/models-api.ts@@ -93,7 +93,7 @@ export interface LocalModelInfo {id: string;display_name: string;path: string;- source: "models_dir" | "hf_cache" | "lmstudio" | "custom";+ source: "models_dir" | "hf_cache" | "lmstudio" | "ollama" | "custom";model_id?: string | null;updated_at?: number | null;}diff --git a/studio/frontend/tests/recipe-selector-source-label.test.ts b/studio/frontend/tests/recipe-selector-source-label.test.tsnew file mode 100644index 00000000000..af1403e3bf7--- /dev/null+++ b/studio/frontend/tests/recipe-selector-source-label.test.ts@@ -0,0 +1,77 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++// The compat endpoint now stamps Ollama rows "ollama" (#9986 bug 1), so every+// consumer of LocalModelInfo.source must name that source rather than fall to+// its generic default. The recipe selector's sourceLabel switch lives inside a+// component, so its ollama case is pinned via the AST, and its label text is+// held in parity with the hub inventory's label for the same source.++import assert from "node:assert/strict";+import { readFileSync } from "node:fs";+import test from "node:test";++import ts from "typescript";++import { registerBundlerResolver } from "./helpers/kit.ts";++registerBundlerResolver();++const { localSourceLabel } = await import(+ "../src/features/hub/inventory/view-models.ts"+);++const SELECTOR = new URL(+ "../src/features/recipe-studio/dialogs/models/local-recipe-model-selector.tsx",+ import.meta.url,+);+const source = ts.createSourceFile(+ "local-recipe-model-selector.tsx",+ readFileSync(SELECTOR, "utf8"),+ ts.ScriptTarget.ESNext,+ true,+ ts.ScriptKind.TSX,+);++/** The string literal returned by sourceLabel's `case "ollama"` clause, if any. */+function ollamaCaseLabel(): string | null {+ let label: string | null = null;+ const visit = (node: ts.Node): void => {+ if (+ ts.isFunctionDeclaration(node) &&+ node.name?.text === "sourceLabel" &&+ node.body+ ) {+ const visitCase = (inner: ts.Node): void => {+ if (+ ts.isCaseClause(inner) &&+ ts.isStringLiteral(inner.expression) &&+ inner.expression.text === "ollama"+ ) {+ for (const statement of inner.statements) {+ if (+ ts.isReturnStatement(statement) &&+ statement.expression &&+ ts.isStringLiteral(statement.expression)+ ) {+ label = statement.expression.text;+ }+ }+ }+ ts.forEachChild(inner, visitCase);+ };+ ts.forEachChild(node.body, visitCase);+ }+ ts.forEachChild(node, visit);+ };+ ts.forEachChild(source, visit);+ return label;+}++test("the recipe selector names the ollama source instead of falling to Local", () => {+ assert.equal(ollamaCaseLabel(), "Ollama");+});++test("the recipe selector and hub inventory agree on the ollama label", () => {+ assert.equal(ollamaCaseLabel(), localSourceLabel("ollama"));+});