Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 650x 650x 650x 650x 1x 114x 114x 114x 14x 114x 6x 6x 8x 8x 1x 108x 108x 108x 108x 6x 6x 6x 6x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 114x 114x 114x 114x 114x 6x 108x 104x 27x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x | import type { Tier } from "../models/user";
/** Invalid model setting → the handler returns 500 SERVICE_ERROR (contracts/model-config.md). */
export class ModelConfigError extends Error {}
export const REASONING_EFFORTS = ["none", "low", "medium", "high", "xhigh"] as const;
export type ReasoningEffort = (typeof REASONING_EFFORTS)[number];
export interface ModelConfig {
deployment: string;
apiVersion: string;
/** Omitted from the request when undefined. */
temperature?: number;
/** Omitted from the request when undefined. */
reasoningEffort?: ReasoningEffort;
}
// Fixed by the PR1 live probe (specs/006-profile-match-ux/eval-models.md).
export const DEFAULT_API_VERSION = "2024-12-01-preview";
/** Empty strings count as unset, matching the Premium-deployment convention. */
function setting(env: NodeJS.ProcessEnv, name: string): string | undefined {
const value = env[name];
return value === undefined || value === "" ? undefined : value;
}
function parseTemperature(env: NodeJS.ProcessEnv, name: string): number | undefined {
const raw = setting(env, name);
if (raw === undefined) return undefined;
const value = Number(raw);
if (!Number.isFinite(value) || value < 0 || value > 2) {
throw new ModelConfigError(`${name} must be a number in [0, 2], got "${raw}".`);
}
return value;
}
function parseReasoningEffort(env: NodeJS.ProcessEnv, name: string): ReasoningEffort | undefined {
const raw = setting(env, name);
if (raw === undefined) return undefined;
if (!(REASONING_EFFORTS as readonly string[]).includes(raw)) {
throw new ModelConfigError(
`${name} must be one of ${REASONING_EFFORTS.join("|")}, got "${raw}".`
);
}
return raw as ReasoningEffort;
}
/**
* Per-deployment request settings (research R1). Pure: reads only `env`.
* Premium uses its own `_PREMIUM` settings only when its own deployment is
* set; otherwise it falls back to the free deployment AND the free settings,
* because settings belong to the deployment, not the tier.
*/
export function resolveModelConfig(tier: Tier, env: NodeJS.ProcessEnv): ModelConfig {
const premiumDeployment = setting(env, "AZURE_OPENAI_JOB_DEPLOYMENT_PREMIUM");
const usePremium = tier === "premium" && premiumDeployment !== undefined;
const suffix = usePremium ? "_PREMIUM" : "";
const deployment = usePremium
? premiumDeployment
: setting(env, "AZURE_OPENAI_JOB_DEPLOYMENT") ??
setting(env, "AZURE_OPENAI_DEPLOYMENT") ??
"gpt-4o-mini";
const temperature = parseTemperature(env, `AZURE_OPENAI_JOB_TEMPERATURE${suffix}`);
const reasoningEffort = parseReasoningEffort(env, `AZURE_OPENAI_JOB_REASONING_EFFORT${suffix}`);
return {
deployment,
apiVersion: setting(env, "AZURE_OPENAI_API_VERSION") ?? DEFAULT_API_VERSION,
...(temperature !== undefined ? { temperature } : {}),
...(reasoningEffort !== undefined ? { reasoningEffort } : {}),
};
}
|