Files
human-archive/src/app/api/questions/route.ts
MrSphay f29339cf12
Some checks failed
Build and publish Docker image / docker (push) Failing after 2m33s
Initial human archive app
2026-06-26 21:31:46 +02:00

26 lines
780 B
TypeScript

import { NextResponse } from "next/server";
import { z } from "zod";
import { answerQuestion } from "@/lib/questions";
const questionSchema = z.object({
question: z.string().min(4).max(1200),
language: z.enum(["DE", "EN"]).default("DE"),
});
export async function POST(request: Request) {
const parsed = questionSchema.safeParse(await request.json());
if (!parsed.success) {
return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
}
try {
const answer = await answerQuestion(parsed.data.question, parsed.data.language);
return NextResponse.json({ answer });
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Question answering failed" },
{ status: 500 },
);
}
}