Skip to content

Commit 610dc37

Browse files
author
liyuyang
committed
Fix Codex template context override
1 parent 64a4685 commit 610dc37

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

sdk/api/handlers/openai/codex_client_models.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func buildCodexClientModels(models []map[string]any) []map[string]any {
5353

5454
if template, ok := templates[id]; ok {
5555
entry := cloneCodexClientModelMap(template)
56+
applyCodexClientContextWindowOverride(entry, id, model)
5657
sanitizeCodexClientReasoningMetadata(entry)
5758
applyCodexClientVisibilityOverride(entry, id)
5859
result = append(result, entry)
@@ -97,6 +98,20 @@ func loadCodexClientModelTemplates() (map[string]map[string]any, map[string]any,
9798
return codexClientModelTemplates, codexClientDefaultTemplate, codexClientModelTemplatesErr
9899
}
99100

101+
func applyCodexClientContextWindowOverride(entry map[string]any, id string, model map[string]any) {
102+
contextWindow := intModelValue(model, "context_length")
103+
if contextWindow <= 0 {
104+
if info := registry.LookupModelInfo(id); info != nil {
105+
contextWindow = info.ContextLength
106+
}
107+
}
108+
if contextWindow <= 0 {
109+
return
110+
}
111+
entry["context_window"] = contextWindow
112+
entry["max_context_window"] = contextWindow
113+
}
114+
100115
func applyCodexClientModelMetadata(entry map[string]any, id string, model map[string]any) {
101116
info := registry.LookupModelInfo(id)
102117

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package openai
2+
3+
import "testing"
4+
5+
func TestBuildCodexClientModelsAppliesContextLengthToTemplateModel(t *testing.T) {
6+
models := buildCodexClientModels([]map[string]any{{
7+
"id": "gpt-5.4",
8+
"object": "model",
9+
"owned_by": "heybox",
10+
"context_length": 700000,
11+
}})
12+
13+
if len(models) != 1 {
14+
t.Fatalf("models len = %d, want 1", len(models))
15+
}
16+
if got := intModelValue(models[0], "context_window"); got != 700000 {
17+
t.Fatalf("context_window = %d, want 700000", got)
18+
}
19+
if got := intModelValue(models[0], "max_context_window"); got != 700000 {
20+
t.Fatalf("max_context_window = %d, want 700000", got)
21+
}
22+
if _, ok := models[0]["apply_patch_tool_type"]; !ok {
23+
t.Fatal("expected template metadata to be preserved")
24+
}
25+
}

0 commit comments

Comments
 (0)