From 75b57bc1124f5712003db66dded76d820ed398ce Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Thu, 13 Nov 2025 17:42:19 +0800 Subject: [PATCH] Fixed: #246 feat(runtime): add support for GPT-5.1 models and variants Introduce GPT-5.1 model family, including minimal, low, medium, high, Codex, and Codex Mini variants. Update tokenization and reasoning effort handling to accommodate new models in executor and registry. --- internal/registry/model_definitions.go | 156 ++++++++++++++++++++ internal/runtime/executor/codex_executor.go | 32 ++++ internal/runtime/executor/token_helpers.go | 2 + 3 files changed, 190 insertions(+) diff --git a/internal/registry/model_definitions.go b/internal/registry/model_definitions.go index bbc49dc8..d66adeb5 100644 --- a/internal/registry/model_definitions.go +++ b/internal/registry/model_definitions.go @@ -417,6 +417,162 @@ func GetOpenAIModels() []*ModelInfo { MaxCompletionTokens: 128000, SupportedParameters: []string{"tools"}, }, + { + ID: "gpt-5.1", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5", + Description: "Stable version of GPT 5, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, + { + ID: "gpt-5.1-minimal", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5 Minimal", + Description: "Stable version of GPT 5, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, + { + ID: "gpt-5.1-low", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5 Low", + Description: "Stable version of GPT 5, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, + { + ID: "gpt-5.1-medium", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5 Medium", + Description: "Stable version of GPT 5, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, + { + ID: "gpt-5.1-high", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5 High", + Description: "Stable version of GPT 5, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, + { + ID: "gpt-5.1-codex", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5 Codex", + Description: "Stable version of GPT 5 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, + { + ID: "gpt-5.1-codex-low", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5 Codex Low", + Description: "Stable version of GPT 5 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, + { + ID: "gpt-5.1-codex-medium", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5 Codex Medium", + Description: "Stable version of GPT 5 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, + { + ID: "gpt-5.1-codex-high", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5 Codex High", + Description: "Stable version of GPT 5 Codex, The best model for coding and agentic tasks across domains.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, + { + ID: "gpt-5.1-codex-mini", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5 Codex Mini", + Description: "Stable version of GPT 5 Codex Mini: cheaper, faster, but less capable version of GPT 5 Codex.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, + { + ID: "gpt-5.1-codex-mini-medium", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5 Codex Mini Medium", + Description: "Stable version of GPT 5 Codex Mini: cheaper, faster, but less capable version of GPT 5 Codex.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, + { + ID: "gpt-5.1-codex-mini-high", + Object: "model", + Created: time.Now().Unix(), + OwnedBy: "openai", + Type: "openai", + Version: "gpt-5.1-2025-11-12", + DisplayName: "GPT 5 Codex Mini High", + Description: "Stable version of GPT 5 Codex Mini: cheaper, faster, but less capable version of GPT 5 Codex.", + ContextLength: 400000, + MaxCompletionTokens: 128000, + SupportedParameters: []string{"tools"}, + }, } } diff --git a/internal/runtime/executor/codex_executor.go b/internal/runtime/executor/codex_executor.go index 947bff88..34c17724 100644 --- a/internal/runtime/executor/codex_executor.go +++ b/internal/runtime/executor/codex_executor.go @@ -85,6 +85,38 @@ func (e *CodexExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, re default: body, _ = sjson.SetBytes(body, "reasoning.effort", "medium") } + } else if util.InArray([]string{"gpt-5.1", "gpt-5.1-minimal", "gpt-5.1-low", "gpt-5.1-medium", "gpt-5.1-high"}, req.Model) { + body, _ = sjson.SetBytes(body, "model", "gpt-5.1") + switch req.Model { + case "gpt-5.1-minimal": + body, _ = sjson.SetBytes(body, "reasoning.effort", "minimal") + case "gpt-5.1-low": + body, _ = sjson.SetBytes(body, "reasoning.effort", "low") + case "gpt-5.1-medium": + body, _ = sjson.SetBytes(body, "reasoning.effort", "medium") + case "gpt-5.1-high": + body, _ = sjson.SetBytes(body, "reasoning.effort", "high") + } + } else if util.InArray([]string{"gpt-5.1-codex", "gpt-5.1-codex-low", "gpt-5.1-codex-medium", "gpt-5.1-codex-high"}, req.Model) { + body, _ = sjson.SetBytes(body, "model", "gpt-5.1-codex") + switch req.Model { + case "gpt-5.1-codex-low": + body, _ = sjson.SetBytes(body, "reasoning.effort", "low") + case "gpt-5.1-codex-medium": + body, _ = sjson.SetBytes(body, "reasoning.effort", "medium") + case "gpt-5.1-codex-high": + body, _ = sjson.SetBytes(body, "reasoning.effort", "high") + } + } else if util.InArray([]string{"gpt-5.1-codex-mini", "gpt-5.1-codex-mini-medium", "gpt-5.1-codex-mini-high"}, req.Model) { + body, _ = sjson.SetBytes(body, "model", "gpt-5.1-codex-mini") + switch req.Model { + case "gpt-5.1-codex-mini-medium": + body, _ = sjson.SetBytes(body, "reasoning.effort", "medium") + case "gpt-5.1-codex-mini-high": + body, _ = sjson.SetBytes(body, "reasoning.effort", "high") + default: + body, _ = sjson.SetBytes(body, "reasoning.effort", "medium") + } } body, _ = sjson.SetBytes(body, "stream", true) diff --git a/internal/runtime/executor/token_helpers.go b/internal/runtime/executor/token_helpers.go index c196bd00..f4236f9b 100644 --- a/internal/runtime/executor/token_helpers.go +++ b/internal/runtime/executor/token_helpers.go @@ -16,6 +16,8 @@ func tokenizerForModel(model string) (tokenizer.Codec, error) { return tokenizer.Get(tokenizer.Cl100kBase) case strings.HasPrefix(sanitized, "gpt-5"): return tokenizer.ForModel(tokenizer.GPT5) + case strings.HasPrefix(sanitized, "gpt-5.1"): + return tokenizer.ForModel(tokenizer.GPT5) case strings.HasPrefix(sanitized, "gpt-4.1"): return tokenizer.ForModel(tokenizer.GPT41) case strings.HasPrefix(sanitized, "gpt-4o"):