Initial human archive app
Some checks failed
Build and publish Docker image / docker (push) Failing after 2m33s
Some checks failed
Build and publish Docker image / docker (push) Failing after 2m33s
This commit is contained in:
25
src/app/api/questions/route.ts
Normal file
25
src/app/api/questions/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
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 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user