test(confidence-engine): expose reconstruction experiment seam
This commit is contained in:
+7
-2
@@ -53,10 +53,15 @@ export async function analyseScenario(scenario, opts = {}) {
|
||||
const { OLLAMA_BASE_URL: _ignored, OLLAMA_MODEL } = configResult.config;
|
||||
const promptVersion = opts.promptVersion || DEFAULT_PROMPT_VERSION;
|
||||
|
||||
// ── Build prompt ───────────────────────────────────
|
||||
// ── Build prompt (experiment seam via env var bridge) ──
|
||||
let promptObj;
|
||||
try {
|
||||
promptObj = await buildPrompt(trimmed, promptVersion);
|
||||
const experimentInstruction = process.env.RECONSTRUCTION_EXPERIMENT_INSTRUCTION;
|
||||
const buildOpts = {};
|
||||
if (experimentInstruction) {
|
||||
buildOpts.experimentInstruction = experimentInstruction;
|
||||
}
|
||||
promptObj = await buildPrompt(trimmed, promptVersion, buildOpts);
|
||||
} catch (e) {
|
||||
return buildErrorResponse(
|
||||
`Failed to build prompt: ${e.message}`,
|
||||
|
||||
@@ -79,10 +79,13 @@ async function buildV3Prompt(scenario) {
|
||||
|
||||
/**
|
||||
* Build an analysis prompt for the given version.
|
||||
* @param {"v0.1" | "v0.2" | "v0.3"} [version="v0.3"]
|
||||
* @param {string} scenario - The scenario text
|
||||
* @param {"v0.1" | "v0.2" | "v0.3"} [version="v0.3"] - Prompt version
|
||||
* @param {object} [opts] - Optional experimental parameters
|
||||
* @param {string} [opts.experimentInstruction] - Bounded experimental instruction block appended to the base prompt (production prompt is never replaced)
|
||||
* @returns {Promise<{prompt: string, version: string}>}
|
||||
*/
|
||||
export async function buildPrompt(scenario, version = "v0.3") {
|
||||
export async function buildPrompt(scenario, version = "v0.3", opts = {}) {
|
||||
let prompt;
|
||||
switch (version) {
|
||||
case "v0.1":
|
||||
@@ -98,5 +101,15 @@ export async function buildPrompt(scenario, version = "v0.3") {
|
||||
|
||||
const strongJsonHint =
|
||||
"\n\nReturn ONLY a valid JSON object starting with { and ending with }. Do NOT include any text before the opening brace or after the closing brace. Do NOT wrap in markdown backticks.";
|
||||
return { prompt: prompt + strongJsonHint, version };
|
||||
|
||||
// ── Experiment seam: append optional instruction block ──
|
||||
let finalPrompt = prompt;
|
||||
if (opts.experimentInstruction) {
|
||||
const delimiter = "\n\n--- EXPERIMENT INSTRUCTION ---\n";
|
||||
finalPrompt = prompt + delimiter + opts.experimentInstruction + strongJsonHint;
|
||||
} else {
|
||||
finalPrompt = prompt + strongJsonHint;
|
||||
}
|
||||
|
||||
return { prompt: finalPrompt, version };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user