mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-05-31 03:41:59 +08:00
refactor(api): move Codex client model handling to registry package
- Relocated Codex client model JSON and related logic from `openai` package to `registry` for better modularity. - Updated references to use `registry.GetCodexClientModelsJSON()` in loading logic. - Extended test cases to cover additional field removals (`upgrade`, `availability_nux`).
This commit is contained in:
@@ -346,6 +346,12 @@ func TestModelsWithClientVersionReturnsCodexCatalog(t *testing.T) {
|
||||
if _, ok := custom["apply_patch_tool_type"]; ok {
|
||||
t.Fatal("expected custom model to omit apply_patch_tool_type")
|
||||
}
|
||||
if _, ok := custom["upgrade"]; ok {
|
||||
t.Fatal("expected custom model to omit upgrade")
|
||||
}
|
||||
if _, ok := custom["availability_nux"]; ok {
|
||||
t.Fatal("expected custom model to omit availability_nux")
|
||||
}
|
||||
|
||||
hiddenModels := map[string]bool{
|
||||
"grok-imagine-image-quality": false,
|
||||
|
||||
11
internal/registry/codex_client_models.go
Normal file
11
internal/registry/codex_client_models.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package registry
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed models/codex_client_models.json
|
||||
var codexClientModelsJSON []byte
|
||||
|
||||
// GetCodexClientModelsJSON returns the embedded Codex client model catalog.
|
||||
func GetCodexClientModelsJSON() []byte {
|
||||
return append([]byte(nil), codexClientModelsJSON...)
|
||||
}
|
||||
@@ -66,7 +66,7 @@ func buildCodexClientModels(models []map[string]any) []map[string]any {
|
||||
func loadCodexClientModelTemplates() (map[string]map[string]any, map[string]any, error) {
|
||||
codexClientModelTemplatesOnce.Do(func() {
|
||||
var payload codexClientModelsPayload
|
||||
codexClientModelTemplatesErr = json.Unmarshal(codexClientModelsJSON, &payload)
|
||||
codexClientModelTemplatesErr = json.Unmarshal(registry.GetCodexClientModelsJSON(), &payload)
|
||||
if codexClientModelTemplatesErr != nil {
|
||||
return
|
||||
}
|
||||
@@ -120,6 +120,8 @@ func applyCodexClientModelMetadata(entry map[string]any, id string, model map[st
|
||||
entry["priority"] = 100
|
||||
entry["prefer_websockets"] = false
|
||||
delete(entry, "apply_patch_tool_type")
|
||||
delete(entry, "upgrade")
|
||||
delete(entry, "availability_nux")
|
||||
|
||||
if contextWindow > 0 {
|
||||
entry["context_window"] = contextWindow
|
||||
|
||||
@@ -8,7 +8,6 @@ package openai
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -30,9 +29,6 @@ type OpenAIAPIHandler struct {
|
||||
*handlers.BaseAPIHandler
|
||||
}
|
||||
|
||||
//go:embed codex_client_models.json
|
||||
var codexClientModelsJSON []byte
|
||||
|
||||
// NewOpenAIAPIHandler creates a new OpenAI API handlers instance.
|
||||
// It takes an BaseAPIHandler instance as input and returns an OpenAIAPIHandler.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user