mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-08 06:55:24 +08:00
feat(api): add Codex client models support for OpenAI API
- Introduced Codex client models framework in `openai` package. - Added JSON-based model definitions (`codex_client_models.json`) for Codex, including metadata, reasoning levels, and configuration options. - Implemented handlers to load, clone, and build Codex client models with support for visibility overrides and metadata application. - Enabled sorting and prioritization of models based on configuration or runtime criteria. - Added utility functions for managing and validating model attributes.
This commit is contained in:
@@ -842,6 +842,15 @@ func (s *Server) watchKeepAlive() {
|
||||
// otherwise it routes to OpenAI handler.
|
||||
func (s *Server) unifiedModelsHandler(openaiHandler *openai.OpenAIAPIHandler, claudeHandler *claude.ClaudeCodeAPIHandler) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if _, ok := c.Request.URL.Query()["client_version"]; ok {
|
||||
if s != nil && s.cfg != nil && s.cfg.Home.Enabled {
|
||||
s.handleHomeCodexClientModels(c)
|
||||
return
|
||||
}
|
||||
openaiHandler.OpenAIModels(c)
|
||||
return
|
||||
}
|
||||
|
||||
if s != nil && s.cfg != nil && s.cfg.Home.Enabled {
|
||||
s.handleHomeModels(c)
|
||||
return
|
||||
@@ -860,6 +869,34 @@ func (s *Server) unifiedModelsHandler(openaiHandler *openai.OpenAIAPIHandler, cl
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) handleHomeCodexClientModels(c *gin.Context) {
|
||||
entries, ok := s.loadHomeModelEntries(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
models := make([]map[string]any, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
model := map[string]any{
|
||||
"id": entry.id,
|
||||
"object": "model",
|
||||
}
|
||||
if entry.created > 0 {
|
||||
model["created"] = entry.created
|
||||
}
|
||||
if entry.ownedBy != "" {
|
||||
model["owned_by"] = entry.ownedBy
|
||||
}
|
||||
if entry.displayName != "" {
|
||||
model["display_name"] = entry.displayName
|
||||
model["description"] = entry.displayName
|
||||
}
|
||||
models = append(models, model)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, openai.CodexClientModelsResponse(models))
|
||||
}
|
||||
|
||||
func (s *Server) geminiModelsHandler(geminiHandler *gemini.GeminiAPIHandler) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if s != nil && s.cfg != nil && s.cfg.Home.Enabled {
|
||||
|
||||
Reference in New Issue
Block a user