feat(confidence-engine): constrain reconstruction chat output
This commit is contained in:
+6
-2
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user