Include only the working reconstruction prototype with Ollama integration: - double-wrapping fix (lib/llm/provider.js) - explicit v0.2 JSON output schema (prompts/reconstruct-v0.2.md) - Zod validation layer (lib/reconstruction/schema.js) - shared core analysis path (lib/analysis.js) - prompt versioning infrastructure (lib/reconstruction/prompt.js) - provider abstraction - functioning Ollama provider path - updated API route with centralized analysis - UI components displaying v0.2 data and validation errors - .gitignore rules for generated evaluation artifacts Exclude: evaluator experiments, diagnostic tests, debug scripts, generated artifacts, comparison findings, test data tied to evaluator.
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
import {
|
|
analyseScenario,
|
|
PROMPT_VERSIONS,
|
|
DEFAULT_PROMPT_VERSION,
|
|
} from "@/lib/analysis";
|
|
|
|
export async function POST(request) {
|
|
try {
|
|
const body = await request.json();
|
|
|
|
if (!body.scenario || typeof body.scenario !== "string") {
|
|
return Response.json(
|
|
{ error: "Request must include a 'scenario' string field" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
// Optional prompt version override
|
|
let promptVersion = DEFAULT_PROMPT_VERSION;
|
|
if (body.promptVersion && PROMPT_VERSIONS.includes(body.promptVersion)) {
|
|
promptVersion = body.promptVersion;
|
|
}
|
|
|
|
const result = await analyseScenario(body.scenario, { promptVersion });
|
|
|
|
if (!result.success) {
|
|
return Response.json(
|
|
{ ...result, reconstruction: result.reconstruction || null },
|
|
{ status: Number(result.statusCode) || 500 },
|
|
);
|
|
}
|
|
|
|
return Response.json({
|
|
inputClassification: result.inputClassification,
|
|
reconstruction: result.reconstruction,
|
|
evidence: result.evidence,
|
|
nextQuestion: result.nextQuestion,
|
|
modelName: result.modelName,
|
|
responseDurationMs: result.responseDurationMs,
|
|
validationStatus: result.validationStatus,
|
|
promptVersion: result.promptVersion,
|
|
});
|
|
} catch (e) {
|
|
return Response.json(
|
|
{ error: e.message || "Unknown server error", responseDurationMs: 0 },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|