Files
OmniRoute/open-sse/utils/finishReason.ts
Markus Hartung f237c07def Fix/5976 continued (#6216)
fix(combo): 5 streaming-path fixes (#5976) — locked-stream 500, error-frame-only-if-no-content, Gemini MALFORMED_RESPONSE→content_filter failover, correlationId substring, per-model-500 lockout skip + request-logger UI. Merged — thank you, @hartmark! Maintainer follow-up: releaseQualityClone cancels the abandoned quality-check tee branch (per-request memory) + regression test. All 41 combo/streaming quality tests green. Base-reds only. Integrated into release/v3.8.45.
2026-07-05 08:37:49 -03:00

37 lines
943 B
TypeScript

const OPENAI_FINISH_REASONS = new Set([
"stop",
"length",
"tool_calls",
"content_filter",
"function_call",
]);
const SAFETY_FINISH_REASONS = new Set([
"safety",
"recitation",
"blocklist",
"prohibited_content",
"content_filtered",
"policy_violation",
"malformed_response",
]);
export function normalizeOpenAICompatibleFinishReason(value: unknown): unknown {
if (typeof value !== "string") return value;
const normalized = value.toLowerCase();
if (OPENAI_FINISH_REASONS.has(normalized)) return normalized;
if (normalized === "max_tokens") return "length";
if (SAFETY_FINISH_REASONS.has(normalized)) return "content_filter";
return normalized;
}
export function normalizeOpenAICompatibleFinishReasonString(
value: unknown,
fallback = "stop"
): string {
const normalized = normalizeOpenAICompatibleFinishReason(value);
return typeof normalized === "string" && normalized ? normalized : fallback;
}