Recommended files with a quant; floating selection bar

Picking model weights in Add model or Download more also selects the
files that usually go with them (chat template, MTP head, mmproj, ...),
shown in a strip where each can be unchecked. Variants are matched by
quant, otherwise the best single one; kinds already selected aren't
added twice. Which kinds is set in Settings -> Downloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-05 23:10:53 +02:00
1 parent 145818f149
commit 0247f257fb
16 files changed
+514 -27

No files matched your search

+30 -6
View File
@@ -5,9 +5,11 @@ import { useRouter } from "next/navigation";
import { useMemo, useState } from "react";
import { toast } from "sonner";
import { FileRoleBadge } from "@/components/labels";
import { RecommendedStrip } from "@/components/recommended-strip";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import { Progress } from "@/components/ui/progress";
import { useRecommended } from "@/hooks/use-recommended";
import { groupSplitFiles } from "@/lib/file-groups";
import { formatBytes, percent, shortSha } from "@/lib/format";
import { quantGroup } from "@/lib/selection";
@@ -26,6 +28,7 @@ export function FilesHeader({
localCount,
localBytes,
candidates,
selectedPaths,
freeBytes,
busy,
hubMissing,
@@ -37,6 +40,8 @@ export function FilesHeader({
localCount: number;
localBytes: number;
candidates: Candidate[];
/** Files the model already has selected (no second mmproj/MTP is recommended). */
selectedPaths: string[];
freeBytes: number | null;
/** A download is queued/running; adding files has to wait. */
busy: boolean;
@@ -61,13 +66,18 @@ export function FilesHeader({
return [...m.entries()].sort(([a], [b]) => a.localeCompare(b, undefined, { numeric: true }));
}, [candidates]);
// Companions (template, MTP, mmproj, …) of newly picked model files come along.
const { all: recAll, active: recActive, setOn: setRecommendedOn, reset: resetRecommended } = useRecommended(candidates, picked, { have: selectedPaths });
const chosen = useMemo(() => new Set([...picked, ...recActive]), [picked, recActive]);
// Split files are one entry; its checkbox selects all parts.
const entries = useMemo(() => groupSplitFiles(candidates), [candidates]);
const pickedEntries = entries.filter((e) => e.parts.every((p) => picked.has(p.path))).length;
const pickedBytes = candidates.filter((c) => picked.has(c.path)).reduce((s, c) => s + c.size, 0);
const pickedEntries = entries.filter((e) => e.parts.every((p) => chosen.has(p.path))).length;
const pickedBytes = candidates.filter((c) => chosen.has(c.path)).reduce((s, c) => s + c.size, 0);
const tooBig = freeBytes != null && pickedBytes > freeBytes;
function toggle(paths: string[], on: boolean) {
setRecommendedOn(paths, on);
setPicked((prev) => {
const next = new Set(prev);
for (const p of paths) {
@@ -84,7 +94,7 @@ export function FilesHeader({
const res = await fetch(`/api/models/${modelId}/files`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ add: [...picked] }),
body: JSON.stringify({ add: [...chosen] }),
});
const body = await res.json().catch(() => ({}));
if (!res.ok) {
@@ -94,6 +104,7 @@ export function FilesHeader({
toast.success(`${body.added} file${body.added === 1 ? "" : "s"} added, download queued`);
setOpen(false);
setPicked(new Set());
resetRecommended();
router.refresh();
} finally {
setSubmitting(false);
@@ -165,10 +176,13 @@ export function FilesHeader({
</div>
)}
<RecommendedStrip files={candidates} paths={recAll} active={recActive} onToggle={toggle} className="mx-5 mt-3" />
<ul className="mt-3 max-h-96 divide-y overflow-y-auto border-y bg-card">
{entries.map((e) => {
const paths = e.parts.map((p) => p.path);
const on = paths.every((p) => picked.has(p));
const on = paths.every((p) => chosen.has(p));
const isRecommended = paths.every((p) => recAll.includes(p));
return (
<li key={e.path}>
<label className="grid cursor-pointer grid-cols-[1rem_auto_minmax(0,1fr)_auto] items-center gap-x-3 px-5 py-2 hover:bg-muted/50">
@@ -181,6 +195,11 @@ export function FilesHeader({
{e.totalParts} parts
</span>
)}
{isRecommended && (
<span className="shrink-0 rounded border border-amber-500/30 bg-amber-500/10 px-1 text-[10px] leading-4 text-amber-700 dark:text-amber-300">
recommended
</span>
)}
</span>
<span className="text-right text-sm text-muted-foreground tabular-nums">{formatBytes(e.size)}</span>
</label>
@@ -202,10 +221,15 @@ export function FilesHeader({
)}
</span>
<div className="ml-auto flex gap-2">
<Button variant="ghost" size="sm" onClick={() => setPicked(new Set())} disabled={picked.size === 0}>
<Button variant="ghost" size="sm" onClick={() => {
setPicked(new Set());
resetRecommended();
}}
disabled={chosen.size === 0}
>
Clear
</Button>
<Button size="sm" onClick={submit} disabled={picked.size === 0 || submitting || busy}>
<Button size="sm" onClick={submit} disabled={chosen.size === 0 || submitting || busy}>
{submitting ? "Adding…" : pickedEntries === 0 ? "Download" : `Download ${pickedEntries} file${pickedEntries === 1 ? "" : "s"}`}
</Button>
</div>
+1
View File
@@ -155,6 +155,7 @@ export function FilesTab({
localCount={localEntries.length}
localBytes={localBytes}
candidates={others.map((f) => ({ path: f.path, size: f.size }))}
selectedPaths={selected.map((f) => f.path)}
freeBytes={freeBytes}
busy={busy}
hubMissing={hubMissing}
+41 -11
View File
@@ -2,9 +2,10 @@
import { XIcon } from "lucide-react";
import Link from "next/link";
import { useEffect, useMemo, useRef, useState } from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { toast } from "sonner";
import { FileRoleBadge } from "@/components/labels";
import { RecommendedStrip } from "@/components/recommended-strip";
import { TagBadge } from "@/components/tag-badge";
import { TagPicker } from "@/components/tag-picker";
import { Badge } from "@/components/ui/badge";
@@ -14,6 +15,7 @@ import { Checkbox } from "@/components/ui/checkbox";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { useRecommended } from "@/hooks/use-recommended";
import { groupSplitFiles } from "@/lib/file-groups";
import { formatBytes, shortSha } from "@/lib/format";
import type { LookupResult } from "@/lib/hub/lookup";
@@ -57,6 +59,22 @@ export function AddModelForm({
const [submitting, setSubmitting] = useState(false);
const [tags, setTags] = useState<{ name: string; color?: string | null }[]>([]);
const includePatterns = useMemo(() => parsePatternList(includeText), [includeText]);
const excludePatterns = useMemo(() => parsePatternList(excludeText), [excludeText]);
const repoFiles = useMemo(() => result?.files ?? [], [result]);
const isExcluded = useCallback((path: string) => matchesAny(path, excludePatterns), [excludePatterns]);
// Picked by checkbox or include pattern; recommended companions come on top.
const picked = useMemo(
() => repoFiles.filter((f) => (checked.has(f.path) || matchesAny(f.path, includePatterns)) && !isExcluded(f.path)).map((f) => f.path),
[repoFiles, checked, includePatterns, isExcluded],
);
const { all: recAll, active: recActive, setOn: setRecommendedOn, reset: resetRecommended } = useRecommended(
repoFiles,
picked,
{ isExcluded },
);
// Local files of the imported folder by path.
const onDisk = useMemo(() => new Map((importFolder?.files ?? []).map((f) => [f.path, f.size])), [importFolder]);
@@ -70,6 +88,7 @@ export function AddModelForm({
setRevision(r.revision);
// Import: preselect every repo file that's already in the folder.
setChecked(new Set(r.files.filter((f) => onDisk.has(f.path)).map((f) => f.path)));
resetRecommended();
setIncludeText("");
setExcludeText("");
setTags([]);
@@ -90,23 +109,22 @@ export function AddModelForm({
// eslint-disable-next-line react-hooks/exhaustive-deps -- run once for the folder being imported
}, [importFolder]);
const includePatterns = useMemo(() => parsePatternList(includeText), [includeText]);
const excludePatterns = useMemo(() => parsePatternList(excludeText), [excludeText]);
const files = useMemo(() => {
if (!result) return [];
return result.files.map((f) => {
const pickedSet = new Set(picked);
return repoFiles.map((f) => {
const byPattern = matchesAny(f.path, includePatterns);
const excluded = matchesAny(f.path, excludePatterns);
const excluded = isExcluded(f.path);
return {
...f,
group: quantGroup(f.path),
byPattern,
excluded,
selected: (checked.has(f.path) || byPattern) && !excluded,
recommended: recAll.includes(f.path),
selected: pickedSet.has(f.path) || recActive.has(f.path),
};
});
}, [result, checked, includePatterns, excludePatterns]);
}, [repoFiles, picked, includePatterns, isExcluded, recAll, recActive]);
const groups = useMemo(() => {
const m = new Map<string, { paths: string[]; size: number }>();
@@ -134,6 +152,7 @@ export function AddModelForm({
const notInRepo = importFolder ? importFolder.files.filter((f) => !repoPaths.has(f.path)).length : 0;
function toggle(paths: string[], on: boolean) {
setRecommendedOn(paths, on);
setChecked((prev) => {
const next = new Set(prev);
for (const path of paths) {
@@ -164,7 +183,7 @@ export function AddModelForm({
repoId: result.repoId,
revision: result.revision,
sha: result.sha,
include: [...includePatterns, ...[...checked].sort().map(escapeGlob)],
include: [...includePatterns, ...[...new Set([...checked, ...recActive])].sort().map(escapeGlob)],
exclude: excludePatterns,
tags: tags.map((t) => t.name),
localPath: importFolder?.path,
@@ -300,6 +319,8 @@ export function AddModelForm({
</div>
)}
<RecommendedStrip files={repoFiles} paths={recAll} active={recActive} onToggle={toggle} />
<div className="grid gap-3 sm:grid-cols-2">
<div className="flex flex-col gap-1.5">
<Label htmlFor="include">Include patterns</Label>
@@ -378,6 +399,7 @@ export function AddModelForm({
const some = !all && parts.some((f) => f.selected);
const byPattern = parts.every((f) => f.byPattern);
const excluded = parts.every((f) => f.excluded);
const isRecommended = parts.every((f) => f.recommended);
return (
<TableRow key={e.path} data-state={all ? "selected" : undefined}>
<TableCell>
@@ -400,6 +422,11 @@ export function AddModelForm({
</span>
)}
{excluded && <span className="text-xs text-muted-foreground">(excluded)</span>}
{isRecommended && (
<span className="shrink-0 rounded border border-amber-500/30 bg-amber-500/10 px-1 text-[10px] leading-4 text-amber-700 dark:text-amber-300">
recommended
</span>
)}
{importFolder && <DiskState parts={parts} onDisk={onDisk} />}
</span>
</TableCell>
@@ -414,7 +441,7 @@ export function AddModelForm({
</Table>
</Card>
<div className="sticky bottom-0 -mx-4 border-t bg-background/95 px-4 py-3 backdrop-blur">
<div className="sticky bottom-3 z-10 rounded-xl bg-card/95 px-4 py-3 text-card-foreground shadow-lg ring-1 ring-foreground/10 backdrop-blur">
<div className="flex flex-wrap items-center gap-x-4 gap-y-2">
<div className="text-sm">
<span className="font-medium">
@@ -429,7 +456,10 @@ export function AddModelForm({
)}
</div>
<div className="ml-auto flex gap-2">
<Button type="button" variant="ghost" onClick={() => setChecked(new Set())}>
<Button type="button" variant="ghost" onClick={() => {
setChecked(new Set());
resetRecommended();
}}>
Clear
</Button>
<Button
+7 -3
View File
@@ -5,14 +5,18 @@ import { AppNav } from "@/components/app-nav";
import { LabelSettingsProvider } from "@/components/labels";
import { UserMenu } from "@/components/user-menu";
import { WorkerIndicator } from "@/components/worker-indicator";
import { getFileRoleStyles } from "@/lib/settings";
import { getFileRoleStyles, getRecommendedRoles } from "@/lib/settings";
import { getWorkerStatus } from "@/lib/worker-status";
export default async function AppLayout({ children }: LayoutProps<"/">) {
const session = await auth();
if (!session?.user) redirect("/login");
const [worker, fileRoles] = await Promise.all([getWorkerStatus(), getFileRoleStyles()]);
const [worker, fileRoles, recommendedRoles] = await Promise.all([
getWorkerStatus(),
getFileRoleStyles(),
getRecommendedRoles(),
]);
return (
<div className="flex min-h-screen flex-col overflow-x-clip">
@@ -38,7 +42,7 @@ export default async function AppLayout({ children }: LayoutProps<"/">) {
</div>
</header>
<main className="mx-auto w-full max-w-7xl flex-1 px-4 py-6">
<LabelSettingsProvider fileRoles={fileRoles}>{children}</LabelSettingsProvider>
<LabelSettingsProvider fileRoles={fileRoles} recommendedRoles={recommendedRoles}>{children}</LabelSettingsProvider>
</main>
</div>
);
+10
View File
@@ -0,0 +1,10 @@
import type { Metadata } from "next";
import { getRecommendedRoles } from "@/lib/settings";
import { RecommendedSettings } from "./recommended-settings";
export const dynamic = "force-dynamic";
export const metadata: Metadata = { title: "Downloads · Settings" };
export default async function DownloadSettingsPage() {
return <RecommendedSettings initial={await getRecommendedRoles()} />;
}
@@ -0,0 +1,96 @@
"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import { FileRoleBadge } from "@/components/labels";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Checkbox } from "@/components/ui/checkbox";
import { FILE_ROLES, type FileRole } from "@/lib/file-roles";
import { RECOMMENDABLE_ROLES } from "@/lib/recommend";
/** Example file name per kind, so the badge shows the configured label and color. */
const EXAMPLE: Partial<Record<FileRole, string>> = {
template: "chat_template.jinja",
mtp: "mtp-model.gguf",
vision: "mmproj-F16.gguf",
draft: "model-draft.gguf",
config: "config.json",
tokenizer: "tokenizer.json",
imatrix: "imatrix.dat",
adapter: "adapter_model.safetensors",
docs: "README.md",
};
const HINT: Partial<Record<FileRole, string>> = {
mtp: "The variant with the same quant as your model file, otherwise the closest one.",
vision: "One mmproj file: same quant if there is one, otherwise F16, BF16, Q8_0, F32.",
draft: "One draft model, picked like MTP.",
imatrix: "Only needed to make your own quants.",
config: "GGUF files already contain it; useful for safetensors repos.",
tokenizer: "GGUF files already contain it; useful for safetensors repos.",
};
/** Which file kinds are selected automatically when you pick model weights. Saves on change. */
export function RecommendedSettings({ initial }: { initial: FileRole[] }) {
const router = useRouter();
const [roles, setRoles] = useState(new Set(initial));
const [saving, setSaving] = useState(false);
async function toggle(role: FileRole, on: boolean) {
const before = roles;
const next = new Set(roles);
if (on) next.add(role);
else next.delete(role);
setRoles(next);
setSaving(true);
try {
const res = await fetch("/api/settings/downloads", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ recommendedRoles: [...next] }),
});
if (!res.ok) {
const body = await res.json().catch(() => ({}));
toast.error(body.error?.message ?? `Could not save (${res.status})`);
setRoles(before);
return;
}
router.refresh();
} finally {
setSaving(false);
}
}
return (
<Card>
<CardHeader>
<CardTitle>Recommended files</CardTitle>
<CardDescription>
When you pick model weights (a quant) in Add model or Download more, files of these kinds are selected along
with them. You can still uncheck them before downloading.
</CardDescription>
</CardHeader>
<CardContent>
<div className="divide-y rounded-lg ring-1 ring-foreground/10">
{RECOMMENDABLE_ROLES.map((role) => (
<label key={role} className="flex cursor-pointer items-start gap-3 px-4 py-3 hover:bg-muted/40">
<Checkbox
checked={roles.has(role)}
disabled={saving}
onCheckedChange={(v) => void toggle(role, v === true)}
className="mt-0.5"
aria-label={FILE_ROLES[role].label}
/>
<FileRoleBadge path={EXAMPLE[role] ?? role} />
<span className="flex min-w-0 flex-col">
<span className="text-sm">{FILE_ROLES[role].description}</span>
{HINT[role] && <span className="text-xs text-muted-foreground">{HINT[role]}</span>}
</span>
</label>
))}
</div>
</CardContent>
</Card>
);
}
+2 -1
View File
@@ -1,9 +1,10 @@
import { TagIcon, TagsIcon } from "lucide-react";
import { DownloadIcon, TagIcon, TagsIcon } from "lucide-react";
import { SettingsNav } from "./settings-nav";
const SECTIONS = [
{ href: "/settings/labels", label: "File labels", icon: <TagIcon className="size-4" /> },
{ href: "/settings/tags", label: "Tags", icon: <TagsIcon className="size-4" /> },
{ href: "/settings/downloads", label: "Downloads", icon: <DownloadIcon className="size-4" /> },
];
export default function SettingsLayout({ children }: LayoutProps<"/settings">) {
+22
View File
@@ -0,0 +1,22 @@
import { NextResponse } from "next/server";
import { z } from "zod";
import { withAuth } from "@/lib/api-auth";
import { apiError, handleApiError } from "@/lib/api-errors";
import { getRecommendedRoles, saveRecommendedRoles, SettingsError } from "@/lib/settings";
export const dynamic = "force-dynamic";
/** Download settings: which file kinds are picked along with model weights. */
export const GET = withAuth(async () => NextResponse.json({ recommendedRoles: await getRecommendedRoles() }));
const Body = z.object({ recommendedRoles: z.array(z.string()).max(32) });
export const PUT = withAuth(async (req) => {
try {
const { recommendedRoles } = Body.parse(await req.json());
return NextResponse.json({ recommendedRoles: await saveRecommendedRoles(recommendedRoles) });
} catch (err) {
if (err instanceof SettingsError) return apiError(err.status, err.code, err.message);
return handleApiError(err);
}
});