"use client"; import { useEffect, useMemo, useState } from "react"; import { api, errorText } from "@/lib/api"; import { formatDate } from "@/lib/astro"; import type { CatalogModel, ModelFunction } from "@/lib/types"; import { RunningJobs } from "./RunningJobs"; const LABELS: Record = { summary: { title: "Tömör összefoglaló", about: "Ingyenes, minden új képlethez magától elkészül. Olcsó, gyors modell elég." }, analysis: { title: "Elemzések és éves előrejelzés", about: "Fizetős szövegek: részletes képletelemzés, kapcsolati elemzés és éves előrejelzés.", }, question: { title: "Kérdés-válasz", about: "A kész elemzésekre és előrejelzésekre feltett kérdések válasza (legfeljebb 250 szó)." }, }; /** How many models the picker lists at once (narrow it with the search). */ const SHOWN = 60; const usd = (x: number) => (x < 0.01 ? `$${x.toFixed(4)}` : `$${x.toFixed(3)}`); const perMillion = (x: number) => `$${x < 1 ? x.toFixed(2) : x.toFixed(x % 1 === 0 ? 0 : 2)}`; /** Estimated cost of one analysis of this kind with this model, from the average size of the latest ones. */ function estimate(f: ModelFunction, m: CatalogModel | undefined): number | null { if (!m || f.avg_input_tokens === null || f.avg_output_tokens === null) return null; return (f.avg_input_tokens * m.input_per_million + f.avg_output_tokens * m.output_per_million) / 1e6; } export function AdminModels() { const [functions, setFunctions] = useState(null); const [catalog, setCatalog] = useState(null); const [catalogError, setCatalogError] = useState(null); const [error, setError] = useState(null); useEffect(() => { api<{ functions: ModelFunction[] }>("/admin/models") .then((d) => setFunctions(d.functions)) .catch((e) => setError(errorText(e))); api<{ models: CatalogModel[] }>("/admin/models/catalog") .then((d) => setCatalog(d.models)) .catch((e) => setCatalogError(errorText(e))); }, []); if (error) { return (

{error}

); } if (!functions) return

Betöltés…

; const replace = (next: ModelFunction) => setFunctions((all) => all?.map((f) => (f.kind === next.kind ? next : f)) ?? null); return (
{catalogError && (

{catalogError}

)}

Tartalék: ha a választott modell kétszer hibára fut (vagy egyszer végleges hibával), az alapértelmezett modell írja meg a szöveget. Csak ha az is elbukik, kapja vissza a felhasználó az egységét.

{functions.map((f) => ( ))}
); } function FunctionModel({ fn, catalog, onSaved, }: { fn: ModelFunction; catalog: CatalogModel[] | null; onSaved: (f: ModelFunction) => void; }) { const [open, setOpen] = useState(false); const [query, setQuery] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const current = catalog?.find((m) => m.id === fn.model); const cost = estimate(fn, current); const label = LABELS[fn.kind]; const searchId = `model-search-${fn.kind}`; const matches = useMemo(() => { const words = query.toLowerCase().split(/\s+/).filter(Boolean); return (catalog ?? []).filter((m) => { const text = `${m.name} ${m.id}`.toLowerCase(); return words.every((w) => text.includes(w)); }); }, [catalog, query]); async function save(model: string | null) { setBusy(true); setError(null); try { onSaved(await api(`/admin/models/${fn.kind}`, { method: "PUT", body: { model } })); setOpen(false); setQuery(""); } catch (e) { setError(errorText(e)); } finally { setBusy(false); } } return (

{label.title}

{label.about}

{current?.name ?? fn.model} {fn.model} {current ? `${perMillion(current.input_per_million)} be / ${perMillion(current.output_per_million)} ki, millió tokenenként` : catalog ? "nincs az OpenRouter listájában" : ""} {cost !== null ? `Becsült költség: kb. ${usd(cost)} elemzésenként (az utolsó ${fn.samples} alapján)` : "Költségbecslés az első elkészült elemzések után."} {fn.custom ? `Módosítva: ${fn.updated_at ? formatDate(fn.updated_at, true) : ""}${fn.updated_by ? `, ${fn.updated_by}` : ""}` : "Alapértelmezett"} {fn.custom && ( 0 ? "hint warn" : "hint"}> Tartalék: {fn.default} · az elmúlt 30 napban {fn.fallbacks_30d} / {fn.finished_30d} szövegnél kellett )}
{fn.custom && ( )}
{error && (

{error}

)} {open && (
setQuery(e.target.value)} />
{!catalog ? (

A lista betöltése…

) : ( <>

{matches.length} modell (csak azok, amelyek kötött JSON-választ tudnak adni). Ár: dollár millió tokenenként, bemenet / kimenet{fn.avg_input_tokens !== null ? "; jobb oldalt a becsült költség elemzésenként" : ""}.

    {matches.slice(0, SHOWN).map((m) => { const each = estimate(fn, m); return (
  • ); })}
{matches.length > SHOWN &&

Szűkítsd a keresést a többi találathoz.

} )}
)}
); }