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:
1 parent
145818f149
commit
0247f257fb
16 files changed
+514
-27
No files matched your search
@@ -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>
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in new issue
Block a user