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>
97 lines
3.5 KiB
TypeScript
97 lines
3.5 KiB
TypeScript
"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>
|
|
);
|
|
}
|