АДРЕСНЫЙ РЕЖИМ - ADDRESS: стабилизация интерпретации сленга и mixed RU/EN, расширение intent/mode-роутинга, регресс-тесты и live stress 102/102
This commit is contained in:
@@ -132,6 +132,9 @@ function shouldFallbackToChatCompletions(error: unknown): boolean {
|
||||
if (!(error instanceof ApiError)) {
|
||||
return false;
|
||||
}
|
||||
if (error.code === "OPENAI_OUTPUT_PARSE_FAILED" || error.code === "OPENAI_NON_JSON_RESPONSE") {
|
||||
return true;
|
||||
}
|
||||
if (error.code !== "OPENAI_REQUEST_FAILED") {
|
||||
return false;
|
||||
}
|
||||
@@ -144,6 +147,35 @@ function shouldFallbackToChatCompletions(error: unknown): boolean {
|
||||
return message.includes("/responses") || message.includes("responses");
|
||||
}
|
||||
|
||||
function extractModelErrorMessage(data: Record<string, unknown>): string | null {
|
||||
const rawError = data.error;
|
||||
if (typeof rawError === "string" && rawError.trim().length > 0) {
|
||||
return rawError.trim();
|
||||
}
|
||||
if (rawError && typeof rawError === "object") {
|
||||
const errorObj = rawError as Record<string, unknown>;
|
||||
const message = errorObj.message;
|
||||
if (typeof message === "string" && message.trim().length > 0) {
|
||||
return message.trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isRouteMismatchErrorMessage(message: string): boolean {
|
||||
const source = String(message ?? "").toLowerCase();
|
||||
if (!source) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
/unexpected endpoint|unexpected route|unknown endpoint|unknown route|unsupported endpoint|unsupported route/.test(source) ||
|
||||
(/endpoint/.test(source) && /method/.test(source)) ||
|
||||
(/endpoint/.test(source) && /not found/.test(source)) ||
|
||||
(/route/.test(source) && /not found/.test(source)) ||
|
||||
(/path/.test(source) && /not found/.test(source))
|
||||
);
|
||||
}
|
||||
|
||||
function loadSchemaForTransport(schemaVersion: "v1" | "v2" | "v2_0_1" | "v2_0_2"): Record<string, unknown> {
|
||||
const schemaFile =
|
||||
schemaVersion === "v1"
|
||||
@@ -398,11 +430,16 @@ export class OpenAIResponsesClient {
|
||||
}
|
||||
}
|
||||
|
||||
const modelErrorMessage = extractModelErrorMessage(data);
|
||||
if (modelErrorMessage && canFallbackToAlternativeBase && !isLastCandidate && isRouteMismatchErrorMessage(modelErrorMessage)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const errorObj = (data.error ?? {}) as Record<string, unknown>;
|
||||
throw new ApiError(
|
||||
"OPENAI_REQUEST_FAILED",
|
||||
String(errorObj.message ?? `Model endpoint failed: ${response.status}`),
|
||||
modelErrorMessage ?? String(errorObj.message ?? `Model endpoint failed: ${response.status}`),
|
||||
response.status,
|
||||
{
|
||||
route: routePath,
|
||||
@@ -414,6 +451,14 @@ export class OpenAIResponsesClient {
|
||||
);
|
||||
}
|
||||
|
||||
if (modelErrorMessage) {
|
||||
throw new ApiError("OPENAI_REQUEST_FAILED", modelErrorMessage, 502, {
|
||||
route: routePath,
|
||||
url,
|
||||
status: response.status
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user