Skip to content

Commit c0110cb

Browse files
authored
Merge pull request Wei-Shaw#941 from CoolCoolTomato/main
fix: 修复gpt-5.2以上模型映射到gpt-5.2以下时verbosity参数引发的报错
2 parents 1f8e114 + eb0b77b commit c0110cb

2 files changed

Lines changed: 32 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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,14 @@ func (s *OpenAIGatewayService) Forward(ctx context.Context, c *gin.Context, acco
17671767
bodyModified = true
17681768
markPatchSet("model", normalizedModel)
17691769
}
1770+
1771+
// 移除 gpt-5.2-codex 以下的版本 verbosity 参数
1772+
// 确保高版本模型向低版本模型映射不报错
1773+
if !SupportsVerbosity(normalizedModel) {
1774+
if text, ok := reqBody["text"].(map[string]any); ok {
1775+
delete(text, "verbosity")
1776+
}
1777+
}
17701778
}
17711779

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

0 commit comments

Comments
 (0)