- Rename the app to Kaname - Hub metadata per model (base models, architecture, license, Hub tags), backfilled by the worker for existing models - Library search across repo/author/family/quant/tags and multi-select facet filters (author, family, quant, tag, status) kept in the URL - Custom tags (model page editor, on add, click-to-filter) - README rewritten around a quick install, with banner and screenshots - deploy/compose.yaml: models in a host folder (KANAME_MODELS_DIR) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2167ea0950
commit
67191b3e16
37 files changed
+2028
-206
No files matched your search
@@ -2,6 +2,7 @@
|
||||
// Server-side only: it reads HF_TOKEN from the environment. Never import from client components.
|
||||
|
||||
import { coreEnv } from "@/lib/env";
|
||||
import { parseRepoMetadata, type RepoMetadata } from "./metadata";
|
||||
|
||||
const HUB = "https://huggingface.co";
|
||||
const TIMEOUT_MS = 20_000;
|
||||
@@ -48,6 +49,7 @@ export type RepoInfo = {
|
||||
gated: false | "auto" | "manual";
|
||||
private: boolean;
|
||||
lastModified: string | null;
|
||||
metadata: RepoMetadata;
|
||||
};
|
||||
|
||||
function headers(): HeadersInit {
|
||||
@@ -138,13 +140,14 @@ export async function getRepoInfo(repoId: string, revision: string): Promise<Rep
|
||||
gated?: false | "auto" | "manual";
|
||||
private?: boolean;
|
||||
lastModified?: string;
|
||||
};
|
||||
} & Parameters<typeof parseRepoMetadata>[0];
|
||||
return {
|
||||
repoId: j.id ?? repoId,
|
||||
sha: j.sha,
|
||||
gated: j.gated ?? false,
|
||||
private: j.private ?? false,
|
||||
lastModified: j.lastModified ?? null,
|
||||
metadata: parseRepoMetadata(j),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// Pure helpers that turn Hub model info into searchable metadata. Shared by web and worker.
|
||||
|
||||
export type RepoMetadata = {
|
||||
author: string | null;
|
||||
baseModels: string[];
|
||||
architecture: string | null;
|
||||
pipelineTag: string | null;
|
||||
license: string | null;
|
||||
hubTags: string[];
|
||||
};
|
||||
|
||||
type HubModelInfo = {
|
||||
id?: string;
|
||||
author?: string;
|
||||
pipeline_tag?: string;
|
||||
tags?: string[];
|
||||
cardData?: { base_model?: string | string[]; license?: string | string[] } | null;
|
||||
gguf?: { architecture?: string } | null;
|
||||
config?: { model_type?: string } | null;
|
||||
};
|
||||
|
||||
/** Hub tags that carry no useful search signal (or are stored separately). */
|
||||
const NOISE_TAG = /^(arxiv|region|deploy|base_model|license|doi|dataset):|^(endpoints_compatible|autotrain_compatible|eval-results|text-generation-inference|conversational)$/;
|
||||
|
||||
const asArray = (v: string | string[] | undefined | null): string[] =>
|
||||
v == null ? [] : (Array.isArray(v) ? v : [v]).filter((x): x is string => typeof x === "string" && x.length > 0);
|
||||
|
||||
export function parseRepoMetadata(info: HubModelInfo): RepoMetadata {
|
||||
const tags = info.tags ?? [];
|
||||
|
||||
// Prefer the model card; fall back to "base_model:<relation>:<id>" / "base_model:<id>" tags.
|
||||
let baseModels = asArray(info.cardData?.base_model);
|
||||
if (baseModels.length === 0) {
|
||||
baseModels = tags
|
||||
.filter((t) => t.startsWith("base_model:"))
|
||||
.map((t) => t.split(":").at(-1)!)
|
||||
.filter((id) => id.includes("/"));
|
||||
}
|
||||
|
||||
const license = asArray(info.cardData?.license)[0] ?? tags.find((t) => t.startsWith("license:"))?.slice(8) ?? null;
|
||||
|
||||
return {
|
||||
author: info.author ?? info.id?.split("/")[0] ?? null,
|
||||
baseModels: [...new Set(baseModels)],
|
||||
architecture: info.gguf?.architecture ?? info.config?.model_type ?? null,
|
||||
pipelineTag: info.pipeline_tag ?? null,
|
||||
license,
|
||||
hubTags: [...new Set(tags.filter((t) => !NOISE_TAG.test(t)))],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The model "family" for filtering: the org of the base model(s) (unsloth/Qwen3-8B-GGUF → "Qwen"),
|
||||
* or the repo's own org for original models without a base model.
|
||||
*/
|
||||
export function modelFamilies(repoId: string, baseModels: string[] | null | undefined): string[] {
|
||||
const orgs = (baseModels ?? []).map((b) => b.split("/")[0]).filter(Boolean);
|
||||
return orgs.length > 0 ? [...new Set(orgs)] : [repoId.split("/")[0]];
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { eq, isNull } from "drizzle-orm";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { models } from "@/lib/db/schema";
|
||||
import { getRepoInfo } from "./client";
|
||||
import type { RepoMetadata } from "./metadata";
|
||||
|
||||
/** Columns to write on `models` for fetched Hub metadata. */
|
||||
export function metadataColumns(meta: RepoMetadata) {
|
||||
return {
|
||||
baseModels: meta.baseModels,
|
||||
architecture: meta.architecture,
|
||||
pipelineTag: meta.pipelineTag,
|
||||
license: meta.license,
|
||||
hubTags: meta.hubTags,
|
||||
metadataFetchedAt: new Date(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch Hub metadata for models that don't have it yet (added before metadata existed).
|
||||
* Returns how many were updated; failures are reported but don't stop the others.
|
||||
*/
|
||||
export async function backfillMetadata(onError: (repoId: string, err: unknown) => void): Promise<number> {
|
||||
const missing = await db()
|
||||
.select({ id: models.id, repoId: models.repoId, pinnedSha: models.pinnedSha })
|
||||
.from(models)
|
||||
.where(isNull(models.metadataFetchedAt));
|
||||
let updated = 0;
|
||||
for (const m of missing) {
|
||||
try {
|
||||
const info = await getRepoInfo(m.repoId, m.pinnedSha);
|
||||
await db().update(models).set(metadataColumns(info.metadata)).where(eq(models.id, m.id));
|
||||
updated++;
|
||||
} catch (err) {
|
||||
onError(m.repoId, err);
|
||||
}
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
Reference in new issue
Block a user