mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-03 06:35:00 +08:00
Merge pull request #4994 from router-for-me/models
feat(models): add max_completion_tokens to model definitions and responses
This commit is contained in:
@@ -61,6 +61,7 @@ func buildCodexClientModels(models []map[string]any, providersForModel Providers
|
||||
entry := cloneCodexClientModelMap(template)
|
||||
applyCodexClientDisplayName(entry, model)
|
||||
applyCodexClientMaxContextLengthOverride(entry, model)
|
||||
applyCodexClientMaxTokens(entry, model)
|
||||
applyCodexClientSearchToolSupport(entry, id, true, providersForModel)
|
||||
sanitizeCodexClientReasoningMetadata(entry)
|
||||
applyCodexClientVisibilityOverride(entry, id)
|
||||
@@ -73,6 +74,7 @@ func buildCodexClientModels(models []map[string]any, providersForModel Providers
|
||||
|
||||
entry := cloneCodexClientModelMap(defaultTemplate)
|
||||
applyCodexClientModelMetadata(entry, id, model, optimizeMultiAgentV2)
|
||||
applyCodexClientMaxTokens(entry, model)
|
||||
applyCodexClientSearchToolSupport(entry, id, false, providersForModel)
|
||||
sanitizeCodexClientReasoningMetadata(entry)
|
||||
applyCodexClientVisibilityOverride(entry, id)
|
||||
@@ -193,6 +195,12 @@ func applyCodexClientMaxContextLengthOverride(entry map[string]any, model map[st
|
||||
}
|
||||
}
|
||||
|
||||
func applyCodexClientMaxTokens(entry map[string]any, model map[string]any) {
|
||||
if maxCompletionTokens := intModelValue(model, "max_completion_tokens"); maxCompletionTokens > 0 {
|
||||
entry["max_tokens"] = maxCompletionTokens
|
||||
}
|
||||
}
|
||||
|
||||
func applyCodexClientSearchToolSupport(entry map[string]any, id string, templateModel bool, providersForModel ProvidersForModelFunc) {
|
||||
supportsSearch, _ := entry["supports_search_tool"].(bool)
|
||||
if !supportsSearch {
|
||||
|
||||
@@ -363,3 +363,38 @@ func TestCodexClientModelsResponseAppliesMaxContextLengthOverride(t *testing.T)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCodexClientModelsResponseMapsMaxCompletionTokensToMaxTokens(t *testing.T) {
|
||||
const wantTemplateLimit = 64000
|
||||
const wantSynthesizedLimit = 32000
|
||||
|
||||
resp := BuildResponse([]map[string]any{
|
||||
{"id": "gpt-5.5", "max_completion_tokens": wantTemplateLimit},
|
||||
{"id": "custom-output-limit-model", "max_completion_tokens": wantSynthesizedLimit},
|
||||
}, nil, false)
|
||||
models, ok := resp["models"].([]map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("models type = %T, want []map[string]any", resp["models"])
|
||||
}
|
||||
|
||||
bySlug := make(map[string]map[string]any, len(models))
|
||||
for _, model := range models {
|
||||
bySlug[stringModelValue(model, "slug")] = model
|
||||
}
|
||||
|
||||
for _, testCase := range []struct {
|
||||
slug string
|
||||
want int
|
||||
}{
|
||||
{slug: "gpt-5.5", want: wantTemplateLimit},
|
||||
{slug: "custom-output-limit-model", want: wantSynthesizedLimit},
|
||||
} {
|
||||
entry := bySlug[testCase.slug]
|
||||
if entry == nil {
|
||||
t.Fatalf("missing model %q", testCase.slug)
|
||||
}
|
||||
if got := intModelValue(entry, "max_tokens"); got != testCase.want {
|
||||
t.Errorf("%s max_tokens = %d, want %d", testCase.slug, got, testCase.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user