fix: classify budget errors in error envelopes
This commit is contained in:
1 parent
e0c926104e
commit
88c55cc6a9
2 files changed
+11
No files matched your search
+3
@@ -215,6 +215,9 @@ public class OpenAiCompatibleProvider {
|
|||||||
*/
|
*/
|
||||||
static ApiException classifyUpstreamError(int status, String body) {
|
static ApiException classifyUpstreamError(int status, String body) {
|
||||||
String details = body == null ? "" : body.toLowerCase(java.util.Locale.ROOT);
|
String details = body == null ? "" : body.toLowerCase(java.util.Locale.ROOT);
|
||||||
|
if (requiresLargerOutputBudget(details)) {
|
||||||
|
return new ApiException("INVALID_MAX_TOKENS", "上游模型要求 max_tokens 大于 1024,请提高输出 Token 上限后重试", 400);
|
||||||
|
}
|
||||||
if (status == 408 || status == 504 || details.matches(".*(request|gateway|upstream).{0,12}(timed out|timeout|超时).*")) {
|
if (status == 408 || status == 504 || details.matches(".*(request|gateway|upstream).{0,12}(timed out|timeout|超时).*")) {
|
||||||
return new ApiException("UPSTREAM_PROVIDER_TIMEOUT", "上游模型供应商响应超时", 504);
|
return new ApiException("UPSTREAM_PROVIDER_TIMEOUT", "上游模型供应商响应超时", 504);
|
||||||
}
|
}
|
||||||
|
|||||||
+8
@@ -94,4 +94,12 @@ class ProviderErrorClassificationTest {
|
|||||||
assertTrue(OpenAiCompatibleProvider.requiresLargerOutputBudget(
|
assertTrue(OpenAiCompatibleProvider.requiresLargerOutputBudget(
|
||||||
"max_tokens must be greater than 1024 for manual Claude thinking"));
|
"max_tokens must be greater than 1024 for manual Claude thinking"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void classifiesMinimumBudgetErrorsEvenWhenRelayUsesHttp200Envelope() {
|
||||||
|
var error = OpenAiCompatibleProvider.classifyUpstreamError(200,
|
||||||
|
"{\"error\":{\"message\":\"max_tokens must be greater than 1024\"}}");
|
||||||
|
assertEquals("INVALID_MAX_TOKENS", error.getCode());
|
||||||
|
assertEquals(400, error.getStatus());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user