// What a file in a model repo is for, guessed from its path. Shared by UI and server. import type { LabelColor } from "./colors"; export type FileRole = | "model" | "mtp" | "vision" | "draft" | "adapter" | "imatrix" | "config" | "tokenizer" | "template" | "docs" | "image" | "git" | "other"; /** Defaults; label and color can be changed in Settings. */ export const FILE_ROLES: Record = { model: { label: "Model", color: "indigo", description: "Model weights" }, mtp: { label: "MTP", color: "amber", description: "Multi-token prediction head (speculative decoding draft)" }, vision: { label: "Vision", color: "fuchsia", description: "Multimodal projector (mmproj) for image input" }, draft: { label: "Draft", color: "orange", description: "Draft model for speculative decoding" }, adapter: { label: "Adapter", color: "violet", description: "LoRA / adapter weights" }, imatrix: { label: "imatrix", color: "gray", description: "Importance matrix used to make the quants; not needed to run the model" }, config: { label: "Config", color: "sky", description: "Model or generation config" }, tokenizer: { label: "Tokenizer", color: "teal", description: "Tokenizer / vocabulary" }, template: { label: "Template", color: "cyan", description: "Chat template" }, docs: { label: "Docs", color: "gray", description: "Documentation or license" }, image: { label: "Image", color: "pink", description: "Image (e.g. for the model card)" }, git: { label: "Git", color: "gray", description: "Git metadata" }, other: { label: "Other", color: "gray", description: "Other file" }, }; export const FILE_ROLE_ORDER = Object.keys(FILE_ROLES) as FileRole[]; export type FileRoleStyle = { label: string; color: LabelColor }; export type FileRoleStyles = Record; const WEIGHTS = /\.(gguf|safetensors|bin|pt|pth|ckpt|onnx|ggml|mlmodel|npz|h5)$/i; export function fileRole(path: string): FileRole { const lower = path.toLowerCase(); const name = lower.slice(lower.lastIndexOf("/") + 1); const dirs = lower.split("/").slice(0, -1); if (name.startsWith(".git")) return "git"; if (name.includes("imatrix")) return "imatrix"; if (name.includes("mmproj") || dirs.includes("mmproj")) return "vision"; if (name.startsWith("mtp-") || name.startsWith("mtp_") || dirs.includes("mtp")) return "mtp"; if (WEIGHTS.test(name)) { if (name.includes("adapter")) return "adapter"; if (/(^|[-_.])draft([-_.]|$)/.test(name)) return "draft"; return "model"; } if (/^tokenizer|^vocab|^merges\.txt$|^special_tokens_map\.json$|^added_tokens\.json$|\.tiktoken$|^tokenizer\.model$/.test(name)) { return "tokenizer"; } if (name.endsWith(".jinja") || name.includes("chat_template") || name === "template") return "template"; if (name.endsWith(".json") || name === "params" || name.endsWith(".yaml") || name.endsWith(".yml")) return "config"; if (/\.(md|txt|rst)$/.test(name) || name.startsWith("license") || name.startsWith("notice")) return "docs"; if (/\.(png|jpe?g|gif|webp|svg)$/.test(name)) return "image"; return "other"; }