From 95a46783408c57e9930f188795356845c402a3a7 Mon Sep 17 00:00:00 2001 From: admin <572701190@qq.com> Date: Sat, 9 May 2026 03:35:55 +0800 Subject: [PATCH] Handle overloaded AI provider responses - Preserve upstream AI provider HTTP status codes and expose AI-specific error codes for overload, rate limit, unavailable, and generic provider failures. - Add short retries for transient AI provider 429/5xx chat completion responses, with configurable retry delays. - Show friendly AI busy/unavailable messages in the report editor instead of raw provider JSON. - Preserve custom backend error codes in the shared API exception filter. - Add AI service tests for retry behavior and overload error mapping. - Update API, feature, and testing documentation for AI proxy retry and error handling. --- docs/api-contract.md | 1 + docs/features.md | 2 +- docs/testing.md | 3 +- server/src/ai/ai.service.test.ts | 82 +++++++++++++++++++++++ server/src/ai/ai.service.ts | 65 ++++++++++++++++-- server/src/common/api-exception.filter.ts | 13 +++- src/pages/ReportEditor.tsx | 17 ++++- 7 files changed, 174 insertions(+), 9 deletions(-) create mode 100644 server/src/ai/ai.service.test.ts diff --git a/docs/api-contract.md b/docs/api-contract.md index 8d9df62..a36f583 100644 --- a/docs/api-contract.md +++ b/docs/api-contract.md @@ -541,6 +541,7 @@ pageSize?: number - 请求上下文只能包含当前报告内容和当前报告内用户有权访问的图片/关键帧。 - 不允许跨部门检索报告作为上下文。 - 当前实现接收 OpenAI 兼容 `messages`、温度等参数,后端会用全局 Provider 的 `modelName` 覆盖请求中的 `model`,所有用户共用同一套 key。 +- 上游模型返回 `429/5xx` 等临时错误时,后端会对 `/chat/completions` 做短暂重试;重试后仍失败时保留上游 HTTP 状态码,并通过错误码区分 `AI_PROVIDER_OVERLOADED`、`AI_PROVIDER_RATE_LIMITED`、`AI_PROVIDER_UNAVAILABLE` 或 `AI_PROVIDER_ERROR`。 ## Speech API diff --git a/docs/features.md b/docs/features.md index 21130d9..b350c45 100644 --- a/docs/features.md +++ b/docs/features.md @@ -41,7 +41,7 @@ | 视频上传 | 真实集成 | 使用浏览器 File API 和对象 URL即时预览,并优先通过 `/api/files` 以 `kind = VIDEO` 写入后端文件资源。 | | 自动抽帧 | 真实集成 | 使用 `