feat(experiments): integrate freeform analysis path
This commit is contained in:
+77
-16
@@ -80,23 +80,40 @@ export async function analyseScenario(scenario, opts = {}) {
|
|||||||
let providerApiPath;
|
let providerApiPath;
|
||||||
let providerExecution;
|
let providerExecution;
|
||||||
try {
|
try {
|
||||||
const providerResult = await provider.generateReconstruction(
|
// Condition D freeform mode: call without schema enforcement → genuine raw text.
|
||||||
promptObj.prompt,
|
if (opts.freeform) {
|
||||||
reconstructionModelName,
|
const providerResult = await provider.generateReconstruction(
|
||||||
opts.generationSchema ?? reconstructionGenerationJsonSchema,
|
promptObj.prompt,
|
||||||
{ outputZodSchema: reconstructionGenerationSchema },
|
reconstructionModelName,
|
||||||
);
|
null, // no JSON schema
|
||||||
if (
|
{ outputZodSchema: reconstructionGenerationSchema },
|
||||||
providerResult &&
|
);
|
||||||
typeof providerResult === "object" &&
|
if (providerResult && typeof providerResult === "object" && "response" in providerResult) {
|
||||||
"response" in providerResult &&
|
rawResponse = providerResult.response;
|
||||||
"providerApiPath" in providerResult
|
providerApiPath = providerResult.providerApiPath ?? null;
|
||||||
) {
|
providerExecution = providerResult.providerExecution ?? null;
|
||||||
rawResponse = providerResult.response;
|
} else {
|
||||||
providerApiPath = providerResult.providerApiPath;
|
rawResponse = typeof providerResult === "string" ? providerResult : JSON.stringify(providerResult);
|
||||||
providerExecution = providerResult.providerExecution;
|
}
|
||||||
} else {
|
} else {
|
||||||
rawResponse = providerResult;
|
const providerResult = await provider.generateReconstruction(
|
||||||
|
promptObj.prompt,
|
||||||
|
reconstructionModelName,
|
||||||
|
opts.generationSchema ?? reconstructionGenerationJsonSchema,
|
||||||
|
{ outputZodSchema: reconstructionGenerationSchema },
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
providerResult &&
|
||||||
|
typeof providerResult === "object" &&
|
||||||
|
"response" in providerResult &&
|
||||||
|
"providerApiPath" in providerResult
|
||||||
|
) {
|
||||||
|
rawResponse = providerResult.response;
|
||||||
|
providerApiPath = providerResult.providerApiPath;
|
||||||
|
providerExecution = providerResult.providerExecution;
|
||||||
|
} else {
|
||||||
|
rawResponse = providerResult;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return buildErrorResponse(
|
return buildErrorResponse(
|
||||||
@@ -111,6 +128,22 @@ export async function analyseScenario(scenario, opts = {}) {
|
|||||||
|
|
||||||
const duration = Date.now() - startTime;
|
const duration = Date.now() - startTime;
|
||||||
|
|
||||||
|
// ── Condition D freeform: return raw text without parsing ──
|
||||||
|
if (opts.freeform) {
|
||||||
|
const text = typeof rawResponse === "string"
|
||||||
|
? rawResponse
|
||||||
|
: JSON.stringify(rawResponse);
|
||||||
|
return buildSuccessResultFreeform(
|
||||||
|
text,
|
||||||
|
reconstructionModelName,
|
||||||
|
duration,
|
||||||
|
promptVersion,
|
||||||
|
null, // no compatibility for freeform
|
||||||
|
providerApiPath,
|
||||||
|
providerExecution,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Try to capture raw response for diagnostics
|
// Try to capture raw response for diagnostics
|
||||||
let rawResponseStr;
|
let rawResponseStr;
|
||||||
try {
|
try {
|
||||||
@@ -228,6 +261,34 @@ function buildSuccessResultV2(data, model, duration, version, compatibility) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Build a success result for Condition D freeform output — no schema validation. */
|
||||||
|
function buildSuccessResultFreeform(
|
||||||
|
text,
|
||||||
|
model,
|
||||||
|
duration,
|
||||||
|
version,
|
||||||
|
compatibility,
|
||||||
|
providerApiPath,
|
||||||
|
providerExecution,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
validationStatus: "freeform",
|
||||||
|
modelName: model,
|
||||||
|
responseDurationMs: duration,
|
||||||
|
rawResponse: text.slice(0, 3000),
|
||||||
|
promptVersion: version,
|
||||||
|
inputClassification: null,
|
||||||
|
reconstruction: text, // genuine freeform text — not JSON-structured output
|
||||||
|
evidence: undefined,
|
||||||
|
nextQuestion: undefined,
|
||||||
|
errors: undefined,
|
||||||
|
presentationValidationStatus: "valid",
|
||||||
|
presentationValidationIssues: [],
|
||||||
|
...(compatibility ? buildCompatibilityDiagnostics(compatibility) : {}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function buildSuccessResultV1(data, model, duration, version, compatibility) {
|
function buildSuccessResultV1(data, model, duration, version, compatibility) {
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@@ -373,6 +373,9 @@ export async function startCase(body, dependencies = {}) {
|
|||||||
if (dependencies.generationSchema) {
|
if (dependencies.generationSchema) {
|
||||||
analysisOptions.generationSchema = dependencies.generationSchema;
|
analysisOptions.generationSchema = dependencies.generationSchema;
|
||||||
}
|
}
|
||||||
|
if (dependencies.freeform) {
|
||||||
|
analysisOptions.freeform = dependencies.freeform;
|
||||||
|
}
|
||||||
const analysis = await analyseScenario(scenario, analysisOptions);
|
const analysis = await analyseScenario(scenario, analysisOptions);
|
||||||
|
|
||||||
if (!analysis.success) {
|
if (!analysis.success) {
|
||||||
@@ -394,6 +397,23 @@ export async function startCase(body, dependencies = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Condition D freeform + reconstruction-only: skip structured graph pipeline.
|
||||||
|
if (dependencies.reconstructionOnly && dependencies.freeform) {
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
summary: analysis.summary ?? null,
|
||||||
|
reconstruction: analysis.reconstruction, // genuine freeform text
|
||||||
|
situationGraph: null,
|
||||||
|
selectedQuestion: null,
|
||||||
|
diagnostics: buildDiagnostics({
|
||||||
|
analysis,
|
||||||
|
graph: null,
|
||||||
|
graphReferenceValidation: null,
|
||||||
|
}),
|
||||||
|
statusCode: 200,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const initialGraph = buildInitialGraph({
|
const initialGraph = buildInitialGraph({
|
||||||
reconstruction: analysis.reconstruction,
|
reconstruction: analysis.reconstruction,
|
||||||
evidence: analysis.evidence,
|
evidence: analysis.evidence,
|
||||||
|
|||||||
Reference in New Issue
Block a user