mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-16 20:22:21 +03:00
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.
37 lines
943 B
TypeScript
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;
|
|
}
|