experiment(confidence-engine): route UI journey provider centrally
This commit is contained in:
+2
-3
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { getConfig } from "../lib/config.js";
|
||||
import { getProvider } from "../lib/llm/provider.js";
|
||||
import { getProvider, getProviderModelName } from "../lib/llm/provider.js";
|
||||
import {
|
||||
buildPrompt,
|
||||
PROMPT_VERSIONS,
|
||||
@@ -52,7 +52,6 @@ export async function analyseScenario(scenario, opts = {}) {
|
||||
return buildErrorResponse("Invalid server configuration", startTime, "500");
|
||||
}
|
||||
|
||||
const { OLLAMA_BASE_URL: _ignored, OLLAMA_MODEL } = configResult.config;
|
||||
const promptVersion = opts.promptVersion || DEFAULT_PROMPT_VERSION;
|
||||
|
||||
// ── Build prompt (experiment seam via env var bridge) ──
|
||||
@@ -73,7 +72,7 @@ export async function analyseScenario(scenario, opts = {}) {
|
||||
|
||||
// ── Call provider ──────────────────────────────────
|
||||
const provider = opts.reconstructionProvider ?? getProvider();
|
||||
const reconstructionModelName = opts.reconstructionModelName ?? OLLAMA_MODEL;
|
||||
const reconstructionModelName = opts.reconstructionModelName ?? getProviderModelName();
|
||||
let rawResponse;
|
||||
let providerApiPath;
|
||||
let providerExecution;
|
||||
|
||||
+23
-1
@@ -5,7 +5,29 @@ const envSchema = z.object({
|
||||
OLLAMA_MODEL: z.string().min(1),
|
||||
});
|
||||
|
||||
const openAIExperimentEnvSchema = z.object({
|
||||
OPENAI_API_KEY: z.string().min(1),
|
||||
});
|
||||
|
||||
export const OPENAI_UI_JOURNEY_EXPERIMENT_PROVIDER = "openai";
|
||||
export const OPENAI_TERRA_MODEL = "gpt-5.6-terra";
|
||||
|
||||
export function isOpenAIUiJourneyExperiment() {
|
||||
return process.env.CONFIDENCE_ENGINE_EXPERIMENT_PROVIDER === OPENAI_UI_JOURNEY_EXPERIMENT_PROVIDER;
|
||||
}
|
||||
|
||||
export function getConfig() {
|
||||
if (isOpenAIUiJourneyExperiment()) {
|
||||
const parsed = openAIExperimentEnvSchema.safeParse({
|
||||
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
|
||||
});
|
||||
if (!parsed.success) return { ok: false, error: parsed.error.flatten().fieldErrors };
|
||||
return {
|
||||
ok: true,
|
||||
config: { provider: OPENAI_UI_JOURNEY_EXPERIMENT_PROVIDER, modelName: OPENAI_TERRA_MODEL },
|
||||
};
|
||||
}
|
||||
|
||||
const parsed = envSchema.safeParse({
|
||||
OLLAMA_BASE_URL: process.env.OLLAMA_BASE_URL,
|
||||
OLLAMA_MODEL: process.env.OLLAMA_MODEL,
|
||||
@@ -15,7 +37,7 @@ export function getConfig() {
|
||||
return { ok: false, error: parsed.error.flatten().fieldErrors };
|
||||
}
|
||||
|
||||
return { ok: true, config: parsed.data };
|
||||
return { ok: true, config: { ...parsed.data, provider: "ollama", modelName: parsed.data.OLLAMA_MODEL } };
|
||||
}
|
||||
|
||||
export function assertConfig() {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { analyseScenario } from "../analysis.js";
|
||||
import { assertConfig } from "../config.js";
|
||||
import { getProvider } from "../llm/provider.js";
|
||||
import { getProvider, getProviderModelName } from "@/lib/llm/provider.js";
|
||||
import {
|
||||
makeGraph,
|
||||
startCaseRequestSchema,
|
||||
@@ -666,8 +666,8 @@ async function updateCaseWithDependencies(body, dependencies = {}) {
|
||||
const startedAt = Date.now();
|
||||
|
||||
try {
|
||||
const config = dependencies.config ?? assertConfig();
|
||||
modelName = config.OLLAMA_MODEL;
|
||||
if (!dependencies.config) assertConfig();
|
||||
modelName = dependencies.modelName ?? dependencies.config?.modelName ?? dependencies.config?.OLLAMA_MODEL ?? getProviderModelName();
|
||||
|
||||
const prompt = buildPrompt({
|
||||
situationGraph,
|
||||
@@ -1185,7 +1185,7 @@ export async function reconsiderCompletedEpisode(epiParams, deps = {}) {
|
||||
try {
|
||||
// Preserve original priority (deps.modelName > deps.config.OLLAMA_MODEL > getModelName) with assertConfig fallback only when no deps provide a model
|
||||
let resolvedConfig = undefined;
|
||||
if (deps.modelName == null && deps.config?.OLLAMA_MODEL == null && deps.config !== null) {
|
||||
if (deps.modelName == null && deps.config?.OLLAMA_MODEL == null && deps.config?.modelName == null && deps.config !== null) {
|
||||
const hasOtherDeps = Object.keys(deps).some((k) => k !== "config" && k !== "modelName");
|
||||
if (hasOtherDeps) {
|
||||
resolvedConfig = undefined; // don't call assertConfig when deps is non-empty with other keys
|
||||
@@ -1196,8 +1196,9 @@ export async function reconsiderCompletedEpisode(epiParams, deps = {}) {
|
||||
const config = deps.config ?? resolvedConfig;
|
||||
modelName =
|
||||
deps.modelName ??
|
||||
(config != null ? config.OLLAMA_MODEL : undefined) ??
|
||||
(config != null ? (config.modelName ?? config.OLLAMA_MODEL) : undefined) ??
|
||||
getModelName?.() ??
|
||||
getProviderModelName() ??
|
||||
null;
|
||||
|
||||
const promptBuilder = buildEpisodePrompt ?? buildEpisodeAwareGraphPrompt;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { reconstructionV2Schema } from "../reconstruction/schema.js";
|
||||
import { isOpenAIUiJourneyExperiment, OPENAI_TERRA_MODEL } from "../config.js";
|
||||
|
||||
/**
|
||||
* Provider abstraction — the app calls getProvider() which returns an object
|
||||
@@ -9,9 +10,15 @@ import { reconstructionV2Schema } from "../reconstruction/schema.js";
|
||||
*/
|
||||
|
||||
export function getProvider() {
|
||||
if (isOpenAIUiJourneyExperiment()) return createOpenAIReconstructionProvider();
|
||||
return new OllamaLlmProvider();
|
||||
}
|
||||
|
||||
/** Server-owned model resolution for the configured application provider. */
|
||||
export function getProviderModelName() {
|
||||
return isOpenAIUiJourneyExperiment() ? OPENAI_TERRA_MODEL : process.env.OLLAMA_MODEL ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Experiment-only construction seam. Production provider selection remains Ollama.
|
||||
* @param {{ apiKey?: string, fetchImpl?: typeof fetch }} [options]
|
||||
|
||||
Reference in New Issue
Block a user