Skip to content

Commit fd8ccaf

Browse files
fix: 修复gpt-5.2以上模型映射到gpt-5.2以下时verbosity参数引发的报错
1 parent 8dd38f4 commit fd8ccaf

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

backend/internal/service/openai_codex_transform.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package service
22

33
import (
4+
"fmt"
45
"strings"
56
)
67

@@ -226,6 +227,29 @@ func normalizeCodexModel(model string) string {
226227
return "gpt-5.1"
227228
}
228229

230+
func SupportsVerbosity(model string) bool {
231+
if !strings.HasPrefix(model, "gpt-") {
232+
return true
233+
}
234+
235+
var major, minor int
236+
n, _ := fmt.Sscanf(model, "gpt-%d.%d", &major, &minor)
237+
238+
if major > 5 {
239+
return true
240+
}
241+
if major < 5 {
242+
return false
243+
}
244+
245+
// gpt-5
246+
if n == 1 {
247+
return true
248+
}
249+
250+
return minor >= 3
251+
}
252+
229253
func getNormalizedCodexModel(modelID string) string {
230254
if modelID == "" {
231255
return ""

backend/internal/service/openai_gateway_service.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,16 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
17581758
bodyModified = true
17591759
markPatchSet("model", normalizedModel)
17601760
}
1761+
1762+
// 移除 gpt-5.2-codex 以下的版本 verbosity 参数
1763+
// 确保高版本模型向低版本模型映射不报错
1764+
if !SupportsVerbosity(reqBody["model"].(string)) {
1765+
if text, ok := reqBody["text"].(map[string]any); ok {
1766+
if _, ok := text["verbosity"].(string); ok {
1767+
delete(text, "verbosity")
1768+
}
1769+
}
1770+
}
17611771
}
17621772

17631773
// 规范化 reasoning.effort 参数(minimal -> none),与上游允许值对齐。

0 commit comments

Comments
 (0)