gateway: a relay's Chinese "未知请求字段:prompt_cache_retention" is read as a refusal of that field, and the request is asked again without it (ldl123292 on X)
基元律动's OpenAI-compatible relay answers a field it doesn't take as "未知请求字段:<name>". refusedOptional only knew the English wordings, so the retry without prompt_cache_retention (and the other optionalFields) never happened and the error went to the client. magpie itself adds none of these fields to a custom provider's request: prompt_cache_retention is the client's own, and optionalFields already drops it on a refusal and remembers the provider. Added the Chinese wordings (未知/未识别/不支持/ 不允许/无效 + 请求 + 字段/参数/属性) to unsupportedOptionalField. Run: gofmt clean; go test -run 'Optional|Refus' ./internal/gateway ok on mote; go vet gateway darwin/windows/linux. chinese-unknown-field and chinese-unsupported-quoted in TestRefusedOptionalNamesOnlyUnsupportedFields fail on the old gateway.go (checked by hand). Not run: full suite before the tag (started after), the relay itself (no account).
This commit is contained in:
@@ -8713,6 +8713,11 @@ func refusedOptional(status int, msg, body []byte) []string {
|
||||
|
||||
var unknownOptionalField = lazyre.New("(?i)\\b(?:unknown (?:name|field|parameter)|unsupported (?:parameter|field|property|argument)|unrecognized (?:request )?(?:argument|parameter)(?: supplied)?):?\\s*['\"\\x60]([a-z_]+)['\"\\x60]")
|
||||
var unquotedUnsupportedOptionalField = lazyre.New("(?i)\\bunsupported (?:parameter|field|property|argument):\\s*([a-z_]+)\\b")
|
||||
|
||||
// chineseRefusedOptionalField is a relay refusing a field in Chinese:
|
||||
// 基元律动's "未知请求字段:prompt_cache_retention" (ldl123292 on X).
|
||||
var chineseRefusedOptionalField = lazyre.New("(?:未知|未识别|不支持|不允许|无效)(?:的)?(?:请求)?(?:字段|参数|属性)\\s*[::]?\\s*['\"\\x60「“]?([a-z_]+)")
|
||||
|
||||
var rejectedOptionalField = lazyre.New("(?i)(?:^|\\b(?:parameter|field|property|argument)\\s+)['\"\\x60]([a-z_]+)['\"\\x60]\\s+(?:is\\s+)?(?:unsupported|not supported)\\b")
|
||||
|
||||
// leadingRejectedOptionalField is a message that starts with the field's
|
||||
@@ -8771,6 +8776,11 @@ func unsupportedOptionalField(fault any, field string) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, match := range chineseRefusedOptionalField.FindAllStringSubmatch(v, -1) {
|
||||
if match[1] == field {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, match := range rejectedOptionalField.FindAllStringSubmatch(v, -1) {
|
||||
if match[1] == field {
|
||||
return true
|
||||
|
||||
@@ -181,6 +181,10 @@ func TestRefusedOptionalNamesOnlyUnsupportedFields(t *testing.T) {
|
||||
{"codex-unquoted-unsupported-parameter", `{"code":null,"message":"Codex: Unsupported parameter: prompt_cache_retention","param":null,"type":"invalid_request_error"}`, 400, []string{"prompt_cache_retention"}},
|
||||
// the ChatGPT backend's, as it gave it on 2026-10-14 (#2154)
|
||||
{"openai-bare-name", `{"error":{"message":"prompt_cache_options is not supported on this model","type":"invalid_request_error","param":"prompt_cache_options","code":"invalid_parameter"}}`, 400, []string{"prompt_cache_options"}},
|
||||
// a relay's Chinese refusal (基元律动, ldl123292 on X)
|
||||
{"chinese-unknown-field", `{"error":{"message":"未知请求字段:prompt_cache_retention","type":"invalid_request_error"}}`, 400, []string{"prompt_cache_retention"}},
|
||||
{"chinese-unsupported-quoted", `{"error":{"message":"不支持的参数: 'prompt_cache_retention'"}}`, 400, []string{"prompt_cache_retention"}},
|
||||
{"chinese-other-field", `{"error":{"message":"未知请求字段:foo_bar"}}`, 400, nil},
|
||||
{"bare-name-not-leading", `{"error":{"message":"The input said metadata is not supported here"}}`, 400, nil},
|
||||
{"bare-name-other-field", `{"error":{"message":"reasoning is not supported on this model"}}`, 400, nil},
|
||||
{"plain-error", `Unknown name "store": Cannot find field.`, 400, []string{"store"}},
|
||||
|
||||
Reference in New Issue
Block a user