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.

1.6 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

export interface DiffusionRoutePick {
  repoId: string;
  opts: { kind: "gguf" | "single_file" | "pipeline"; filename?: string };
}

export function diffusionFileKind(filename?: string | null): DiffusionRoutePick["opts"]["kind"] {
  if (!filename) return "pipeline";
  return filename.toLowerCase().endsWith(".safetensors") ? "single_file" : "gguf";
}

/** Chat-routed picks carry only search params, so recognise bare local single files here (a pipeline
 * load would evict the resident model and fail). `spec` covers curated single-file artifacts. */
export function diffusionRoutePick(
  model: string,
  quant?: string | null,
  spec?: { kind: "gguf" | "single_file" | "pipeline"; filename?: string } | null,
): DiffusionRoutePick {
  if (quant) {
    return { repoId: model, opts: { kind: diffusionFileKind(quant), filename: quant } };
  }
  // A spec exists only for catalog repo ids, so it beats extension sniffing.
  if (spec) return { repoId: model, opts: { kind: spec.kind, filename: spec.filename } };
  const norm = model.replace(/\\/g, "/");
  const slash = norm.lastIndexOf("/");
  const filename = slash >= 0 ? norm.slice(slash + 1) : norm;
  const dir = slash >= 0 ? norm.slice(0, slash) : ".";
  const lower = filename.toLowerCase();
  if (lower.endsWith(".gguf")) {
    return { repoId: dir, opts: { kind: "gguf", filename } };
  }
  if (lower.endsWith(".safetensors")) {
    return { repoId: dir, opts: { kind: "single_file", filename } };
  }
  return { repoId: model, opts: { kind: "pipeline" } };
}