mirror of
https://github.com/vercel-labs/json-render.git
synced 2026-10-20 06:19:57 +08:00
* no-ai * pdf * pdf example * fixes * ai gateway * fixes * fixes * fixes * shadcn * 3 panes * fixes * fixes * fixes * fixes * fix CI * fix
36 lines
910 B
TypeScript
36 lines
910 B
TypeScript
import { streamText } from "ai";
|
|
import { gateway } from "@ai-sdk/gateway";
|
|
import { buildUserPrompt, type Spec } from "@json-render/core";
|
|
import { pdfCatalog } from "@/lib/catalog";
|
|
|
|
export const maxDuration = 60;
|
|
|
|
const SYSTEM_PROMPT = pdfCatalog.prompt();
|
|
|
|
const DEFAULT_MODEL = "anthropic/claude-haiku-4.5";
|
|
|
|
export async function POST(req: Request) {
|
|
const { prompt, startingSpec } = (await req.json()) as {
|
|
prompt: string;
|
|
startingSpec?: Spec | null;
|
|
};
|
|
|
|
if (!prompt || typeof prompt !== "string") {
|
|
return Response.json({ error: "prompt is required" }, { status: 400 });
|
|
}
|
|
|
|
const userPrompt = buildUserPrompt({
|
|
prompt,
|
|
currentSpec: startingSpec,
|
|
});
|
|
|
|
const result = streamText({
|
|
model: gateway(process.env.AI_GATEWAY_MODEL ?? DEFAULT_MODEL),
|
|
system: SYSTEM_PROMPT,
|
|
prompt: userPrompt,
|
|
temperature: 0.7,
|
|
});
|
|
|
|
return result.toTextStreamResponse();
|
|
}
|