74 lines
2.1 KiB
TypeScript
74 lines
2.1 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { parseHuggingFaceRef } from "@/lib/model-ref";
|
|
|
|
export const runtime = "nodejs";
|
|
export const dynamic = "force-dynamic";
|
|
|
|
const controlPlaneUrl = (
|
|
process.env.LUMBRIDGE_CONTROL_PLANE_URL ?? "http://127.0.0.1:8902"
|
|
).replace(/\/+$/, "");
|
|
|
|
/**
|
|
* Record a Hugging Face model suggestion for Karti to review manually.
|
|
*
|
|
* This endpoint only forwards an inert review record to the Lumbridge control
|
|
* plane. Neither service downloads, imports, schedules, or executes a model.
|
|
*/
|
|
|
|
export async function POST(req: Request) {
|
|
let body: { model?: string; notes?: string };
|
|
try {
|
|
body = await req.json();
|
|
} catch {
|
|
return NextResponse.json({ error: "invalid JSON" }, { status: 400 });
|
|
}
|
|
|
|
const ref = parseHuggingFaceRef(body.model ?? "");
|
|
if (!ref) {
|
|
return NextResponse.json(
|
|
{ error: "Expected a Hugging Face model reference like `owner/model`." },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(`${controlPlaneUrl}/api/model-suggestions`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
sourceUrl: `https://huggingface.co/${ref}`,
|
|
reason: "Suggested via Lumbridge Bench for manual model review.",
|
|
notes: (body.notes ?? "").slice(0, 2000) || undefined,
|
|
}),
|
|
cache: "no-store",
|
|
signal: AbortSignal.timeout(5_000),
|
|
});
|
|
if (!response.ok) {
|
|
const result = await response.json().catch(() => null) as {
|
|
error?: string;
|
|
} | null;
|
|
return NextResponse.json(
|
|
{
|
|
error:
|
|
result?.error ??
|
|
"The Lumbridge review inbox could not accept that suggestion.",
|
|
},
|
|
{ status: response.status },
|
|
);
|
|
}
|
|
} catch {
|
|
return NextResponse.json(
|
|
{ error: "The Lumbridge review inbox is temporarily unavailable." },
|
|
{ status: 503 },
|
|
);
|
|
}
|
|
|
|
return NextResponse.json({
|
|
ok: true,
|
|
model: ref,
|
|
message:
|
|
"Suggestion received. Karti reviews every model manually. Nothing is " +
|
|
"downloaded or run automatically; approved results appear on the board later.",
|
|
});
|
|
}
|