feat: implement /v1/models endpoint
Some checks failed
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

Added OpenAI-compatible model listing endpoint using the registry data.
This commit is contained in:
2026-03-19 11:31:26 -04:00
parent 2d8f1a1fd0
commit edc6445d70

View File

@@ -89,6 +89,7 @@ func (s *Server) setupRoutes() {
v1 := s.router.Group("/v1") v1 := s.router.Group("/v1")
{ {
v1.POST("/chat/completions", s.handleChatCompletions) v1.POST("/chat/completions", s.handleChatCompletions)
v1.GET("/models", s.handleListModels)
} }
// Dashboard API Group // Dashboard API Group
@@ -140,6 +141,34 @@ func (s *Server) setupRoutes() {
}) })
} }
func (s *Server) handleListModels(c *gin.Context) {
type OpenAIModel struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
OwnedBy string `json:"owned_by"`
}
var data []OpenAIModel
if s.registry != nil {
for pID, pInfo := range s.registry.Providers {
for mID := range pInfo.Models {
data = append(data, OpenAIModel{
ID: mID,
Object: "model",
Created: 1700000000, // Static placeholder
OwnedBy: pID,
})
}
}
}
c.JSON(http.StatusOK, gin.H{
"object": "list",
"data": data,
})
}
func (s *Server) handleChatCompletions(c *gin.Context) { func (s *Server) handleChatCompletions(c *gin.Context) {
startTime := time.Now() startTime := time.Now()
var req models.ChatCompletionRequest var req models.ChatCompletionRequest