feat(confidence-engine): constrain reconstruction chat output

This commit is contained in:
2026-09-05 18:44:47 +01:00
parent 8c5b47bcf5
commit c7a0a79d0f
3 changed files with 20 additions and 3 deletions
+6 -2
View File
@@ -1,3 +1,6 @@
import { z } from "zod";
import { reconstructionV2Schema } from "../reconstruction/schema.js";
/**
* Provider abstraction — the app calls getProvider() which returns an object
* with a generateReconstruction(scenario, modelName) method.
@@ -59,6 +62,7 @@ function recoverJson(raw) {
}
let _chatSupported = null;
const reconstructionJsonSchema = z.toJSONSchema(reconstructionV2Schema);
async function detectChatSupport(baseUrl, modelName) {
if (_chatSupported !== null) return _chatSupported;
@@ -113,7 +117,7 @@ class OllamaLlmProvider {
} catch { /* failed silently — defaults to false */ }
// ================================================================
// Step 2: Try /api/chat if supported and format:json works
// Step 2: Try /api/chat if supported with the reconstruction schema
// ================================================================
if (chatSupported) {
try {
@@ -128,7 +132,7 @@ class OllamaLlmProvider {
model: modelName,
messages: [{ role: "user", content: prompt }],
stream: false,
format: "json",
format: reconstructionJsonSchema,
}),
signal: controller.signal,
});