feat: implement /v1/models endpoint
Added OpenAI-compatible model listing endpoint using the registry data.
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user