feat: enhance remote model search to use dynamic catalog
Replace hardcoded list of popular models with dynamic catalog from getCatalogModels(). Enable searching by model name or description and include model descriptions in results. Improves discoverability and maintains up-to-date model list without manual updates. Database files updated accordingly.
This commit is contained in:
1 parent
7b2386876a
commit
30290ae87a
10 files changed
+2003
-50
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
type CatalogModel = {
|
||||
name: string;
|
||||
description?: string;
|
||||
capabilities?: string[];
|
||||
parameter_sizes?: string[];
|
||||
pulls?: string;
|
||||
tags_count?: number;
|
||||
last_updated?: string;
|
||||
url?: string;
|
||||
};
|
||||
|
||||
type CatalogFile = {
|
||||
models?: CatalogModel[];
|
||||
};
|
||||
|
||||
let cachedModels: CatalogModel[] | null = null;
|
||||
let cachedMtimeMs: number | null = null;
|
||||
|
||||
function resolveCatalogPath(): string {
|
||||
// Arquivo fica em data/models.json na raiz do projeto
|
||||
return path.join(process.cwd(), "data", "models.json");
|
||||
}
|
||||
|
||||
export async function getCatalogModels(): Promise<CatalogModel[]> {
|
||||
try {
|
||||
const catalogPath = resolveCatalogPath();
|
||||
const stat = await fs.stat(catalogPath);
|
||||
|
||||
// Cache simples por mtime
|
||||
if (cachedModels && cachedMtimeMs && stat.mtimeMs === cachedMtimeMs) {
|
||||
return cachedModels;
|
||||
}
|
||||
|
||||
const raw = await fs.readFile(catalogPath, "utf-8");
|
||||
const json = JSON.parse(raw) as CatalogFile;
|
||||
const models = Array.isArray(json.models) ? json.models : [];
|
||||
|
||||
cachedModels = models;
|
||||
cachedMtimeMs = stat.mtimeMs;
|
||||
return models;
|
||||
} catch (error) {
|
||||
// Em caso de erro, retorne array vazio para não quebrar a UI
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user