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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user