Hungarian prompts in Hungarian, model choice per analysis kind, admin regenerate
- The built-in Hungarian system prompts and the user message frame are written in Hungarian - Admin page Modellek: the model of each analysis kind, chosen from the OpenRouter list (structured-output models only) with prices and a cost estimate per analysis - Admin: regenerate any analysis in place with the current prompt and model (no charge) - Fix: a failed forecast analysis refunds a forecast unit, not a natal one Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,205 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { formatDate } from "@/lib/astro";
|
||||
import type { CatalogModel, ModelFunction, PromptKind } from "@/lib/types";
|
||||
|
||||
const LABELS: Record<PromptKind, { title: string; about: string }> = {
|
||||
summary: { title: "Tömör összefoglaló", about: "Ingyenes, minden új képlethez magától elkészül. Olcsó, gyors modell elég." },
|
||||
natal: { title: "Részletes képletelemzés", about: "Fizetős, hat fejezet." },
|
||||
synastry: { title: "Kapcsolati elemzés", about: "Fizetős, öt fejezet két képletről." },
|
||||
forecast: { title: "Éves előrejelzés", about: "Fizetős, öt fejezet, a leghosszabb adatsorral." },
|
||||
};
|
||||
|
||||
/** 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<ModelFunction[] | null>(null);
|
||||
const [catalog, setCatalog] = useState<CatalogModel[] | null>(null);
|
||||
const [catalogError, setCatalogError] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(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 (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
if (!functions) return <p className="muted">Betöltés…</p>;
|
||||
const replace = (next: ModelFunction) => setFunctions((all) => all?.map((f) => (f.kind === next.kind ? next : f)) ?? null);
|
||||
|
||||
return (
|
||||
<div className="model-list">
|
||||
{catalogError && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{catalogError}
|
||||
</p>
|
||||
)}
|
||||
{functions.map((f) => (
|
||||
<FunctionModel key={f.kind} fn={f} catalog={catalog} onSaved={replace} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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<string | null>(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<ModelFunction>(`/admin/models/${fn.kind}`, { method: "PUT", body: { model } }));
|
||||
setOpen(false);
|
||||
setQuery("");
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="card model-card" aria-labelledby={`model-${fn.kind}`}>
|
||||
<div className="model-head">
|
||||
<div>
|
||||
<h2 id={`model-${fn.kind}`}>{label.title}</h2>
|
||||
<p className="hint">{label.about}</p>
|
||||
</div>
|
||||
<div className="model-current">
|
||||
<strong>{current?.name ?? fn.model}</strong>
|
||||
<code>{fn.model}</code>
|
||||
<span className="hint">
|
||||
{current
|
||||
? `${perMillion(current.input_per_million)} be / ${perMillion(current.output_per_million)} ki, millió tokenenként`
|
||||
: catalog
|
||||
? "nincs az OpenRouter listájában"
|
||||
: ""}
|
||||
</span>
|
||||
<span className="hint">
|
||||
{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."}
|
||||
</span>
|
||||
<span className="hint">
|
||||
{fn.custom
|
||||
? `Módosítva: ${fn.updated_at ? formatDate(fn.updated_at, true) : ""}${fn.updated_by ? `, ${fn.updated_by}` : ""}`
|
||||
: "Alapértelmezett"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-sm" onClick={() => setOpen((o) => !o)} aria-expanded={open}>
|
||||
{open ? "Mégse" : "Másik modell"}
|
||||
</button>
|
||||
{fn.custom && (
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => save(null)} disabled={busy}>
|
||||
Vissza az alapértelmezettre ({fn.default})
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{open && (
|
||||
<div className="model-picker">
|
||||
<div className="field">
|
||||
<label htmlFor={searchId}>Keresés név vagy azonosító szerint</label>
|
||||
<input
|
||||
id={searchId}
|
||||
className="inp"
|
||||
type="search"
|
||||
value={query}
|
||||
autoFocus
|
||||
placeholder="pl. claude, gpt, gemini"
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{!catalog ? (
|
||||
<p className="muted">A lista betöltése…</p>
|
||||
) : (
|
||||
<>
|
||||
<p className="hint">
|
||||
{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" : ""}.
|
||||
</p>
|
||||
<ul className="model-options">
|
||||
{matches.slice(0, SHOWN).map((m) => {
|
||||
const each = estimate(fn, m);
|
||||
return (
|
||||
<li key={m.id}>
|
||||
<button
|
||||
type="button"
|
||||
className="model-option"
|
||||
aria-current={m.id === fn.model ? "true" : undefined}
|
||||
onClick={() => save(m.id)}
|
||||
disabled={busy}
|
||||
>
|
||||
<span>
|
||||
<strong>{m.name}</strong>
|
||||
<code>{m.id}</code>
|
||||
</span>
|
||||
<span className="model-price">
|
||||
{perMillion(m.input_per_million)} / {perMillion(m.output_per_million)}
|
||||
{each !== null && <strong>{usd(each)}</strong>}
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
{matches.length > SHOWN && <p className="hint">Szűkítsd a keresést a többi találathoz.</p>}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { AdminNav } from "@/components/AdminNav";
|
||||
import { requireMe } from "@/lib/server";
|
||||
|
||||
import { AdminModels } from "./AdminModels";
|
||||
|
||||
export const metadata: Metadata = { title: "Modellek" };
|
||||
|
||||
export default async function AdminModelsPage() {
|
||||
const me = await requireMe("/admin/modellek");
|
||||
if (!me.user.roles.includes("admin")) notFound();
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<AdminNav current="/admin/modellek" />
|
||||
<div className="page-head">
|
||||
<h1>Modellek</h1>
|
||||
<p className="muted">
|
||||
Melyik modell írja az egyes elemzéseket. A változás az ezután kért és az újragenerált elemzésekre hat; a már
|
||||
elkészültek változatlanok maradnak. A felhasználók a modell nevét sehol nem látják.
|
||||
</p>
|
||||
</div>
|
||||
<AdminModels />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -610,3 +610,26 @@ a.pair-row:hover strong { color: var(--gold); }
|
||||
.timeline-item { grid-template-columns: 52px 1fr; }
|
||||
.timeline-glyph { display: none; }
|
||||
}
|
||||
|
||||
/* admin: models */
|
||||
.model-list { display: flex; flex-direction: column; gap: 16px; }
|
||||
.model-card { gap: 12px; }
|
||||
.model-head { display: flex; gap: 12px 24px; justify-content: space-between; flex-wrap: wrap; }
|
||||
.model-head h2 { margin: 0 0 4px; font-size: 20px; }
|
||||
.model-current { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; text-align: right; min-width: 0; }
|
||||
.model-current code, .model-option code { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
|
||||
.model-picker { display: flex; flex-direction: column; gap: 8px; }
|
||||
.model-options { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 420px; overflow-y: auto; }
|
||||
.model-option {
|
||||
width: 100%; display: flex; gap: 12px; justify-content: space-between; align-items: center; text-align: left;
|
||||
padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: inherit; cursor: pointer; font: inherit;
|
||||
}
|
||||
.model-option > span:first-child { display: flex; flex-direction: column; min-width: 0; }
|
||||
.model-option:hover { border-color: var(--gold); }
|
||||
.model-option[aria-current="true"] { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 10%, transparent); }
|
||||
.model-price { display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; color: var(--muted); white-space: nowrap; }
|
||||
.model-price strong { color: var(--ink); font-size: 14px; }
|
||||
@media (max-width: 640px) {
|
||||
.model-current { align-items: flex-start; text-align: left; }
|
||||
}
|
||||
.regenerate { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
|
||||
|
||||
@@ -72,7 +72,12 @@ export default async function ChartPage({ params }: { params: Promise<{ id: stri
|
||||
<WheelLegend />
|
||||
</div>
|
||||
<div className="field chart-side">
|
||||
<ChartSummary chartId={chart.id} initial={summary} detailedDone={detailed?.status === "done"} />
|
||||
<ChartSummary
|
||||
chartId={chart.id}
|
||||
initial={summary}
|
||||
detailedDone={detailed?.status === "done"}
|
||||
isAdmin={me.user.roles.includes("admin")}
|
||||
/>
|
||||
<BigThree chart={chart} />
|
||||
{(elements || modalities || phase) && (
|
||||
<div className="card" style={{ gap: 12 }}>
|
||||
|
||||
@@ -4,6 +4,7 @@ const PAGES = [
|
||||
{ href: "/admin", label: "Felhasználók" },
|
||||
{ href: "/admin/meghivok", label: "Meghívók" },
|
||||
{ href: "/admin/promptok", label: "Promptok" },
|
||||
{ href: "/admin/modellek", label: "Modellek" },
|
||||
];
|
||||
|
||||
/** Switches between the admin pages. */
|
||||
|
||||
@@ -6,6 +6,7 @@ import { api } from "@/lib/api";
|
||||
import type { Analysis } from "@/lib/types";
|
||||
|
||||
import { AnalysisLoading } from "./AnalysisLoading";
|
||||
import { RegenerateButton } from "./RegenerateButton";
|
||||
import { Rich } from "./Rich";
|
||||
import { openTab } from "./Tabs";
|
||||
|
||||
@@ -21,11 +22,14 @@ export function ChartSummary({
|
||||
chartId,
|
||||
initial,
|
||||
detailedDone = false,
|
||||
isAdmin = false,
|
||||
}: {
|
||||
chartId: string;
|
||||
initial: Analysis | null;
|
||||
/** The detailed analysis is ready: the link says so instead of offering it. */
|
||||
detailedDone?: boolean;
|
||||
/** Admins can write the summary again. */
|
||||
isAdmin?: boolean;
|
||||
}) {
|
||||
const [summary, setSummary] = useState<Analysis | null>(initial);
|
||||
const [gaveUp, setGaveUp] = useState(false);
|
||||
@@ -61,6 +65,15 @@ export function ChartSummary({
|
||||
<span className="eyebrow">Röviden</span>
|
||||
{content ? (
|
||||
<>
|
||||
{isAdmin && summary && (
|
||||
<RegenerateButton
|
||||
analysisId={summary.id}
|
||||
onStarted={(a) => {
|
||||
setGaveUp(false);
|
||||
setSummary(a);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<h2 id="summary-title" className="summary-title">
|
||||
{content.title}
|
||||
</h2>
|
||||
|
||||
@@ -9,6 +9,7 @@ import type { Analysis } from "@/lib/types";
|
||||
import { AI_SHORT } from "./AiNote";
|
||||
import { AnalysisLoading } from "./AnalysisLoading";
|
||||
import { PackageChooser } from "./PackageCards";
|
||||
import { RegenerateButton } from "./RegenerateButton";
|
||||
import { AnalysisView } from "./AnalysisView";
|
||||
|
||||
const POLL_MS = 5000;
|
||||
@@ -145,6 +146,7 @@ export function DetailedAnalysis({
|
||||
return (
|
||||
<section className="analysis-card" aria-label={t.eyebrow}>
|
||||
<span className="eyebrow">{t.eyebrow}</span>
|
||||
{isAdmin && <RegenerateButton analysisId={analysis.id} onStarted={setAnalysis} />}
|
||||
{note && <p className="hint">{note}</p>}
|
||||
<AnalysisView content={analysis.content} kind={target.kind} />
|
||||
</section>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import type { Analysis } from "@/lib/types";
|
||||
|
||||
/**
|
||||
* Admin only: writes the analysis again in place with the current prompt and
|
||||
* model (nobody is charged). Asks once before it starts.
|
||||
*/
|
||||
export function RegenerateButton({ analysisId, onStarted }: { analysisId: string; onStarted: (a: Analysis) => void }) {
|
||||
const [asking, setAsking] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
async function regenerate() {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
onStarted(await api<Analysis>(`/admin/analyses/${analysisId}/regenerate`, { method: "POST" }));
|
||||
setAsking(false);
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="regenerate">
|
||||
{asking ? (
|
||||
<>
|
||||
<span className="hint">A mostani szöveg helyett újat ír a jelenlegi prompttal és modellel.</span>
|
||||
<button type="button" className="btn btn-sm" onClick={regenerate} disabled={busy}>
|
||||
{busy ? "Indítás…" : "Igen, újragenerálás"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => setAsking(false)} disabled={busy}>
|
||||
Mégse
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<button type="button" className="btn btn-sm btn-ghost" onClick={() => setAsking(true)} title="Admin: újragenerálás">
|
||||
↻ Újragenerálás
|
||||
</button>
|
||||
)}
|
||||
{error && (
|
||||
<span className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -231,6 +231,30 @@ export interface AdminUser {
|
||||
|
||||
export type PromptKind = "summary" | "natal" | "synastry" | "forecast";
|
||||
|
||||
/** Admin: the model writing one kind of analysis. */
|
||||
export interface ModelFunction {
|
||||
kind: PromptKind;
|
||||
model: string;
|
||||
/** The configured default (environment). */
|
||||
default: string;
|
||||
custom: boolean;
|
||||
updated_at: string | null;
|
||||
updated_by: string | null;
|
||||
/** Average size of the latest analyses of this kind, for the cost estimate. */
|
||||
avg_input_tokens: number | null;
|
||||
avg_output_tokens: number | null;
|
||||
samples: number;
|
||||
}
|
||||
|
||||
/** A model OpenRouter offers; prices in USD per million tokens. */
|
||||
export interface CatalogModel {
|
||||
id: string;
|
||||
name: string;
|
||||
input_per_million: number;
|
||||
output_per_million: number;
|
||||
context_length: number | null;
|
||||
}
|
||||
|
||||
export interface PromptRevision {
|
||||
id: number;
|
||||
custom: boolean;
|
||||
|
||||
Reference in New Issue
Block a user