feat: expose model groups in /v1/models endpoint
Add Groups() method to Router so handleListModels can append model group IDs (e.g. 'deepseek-auto', 'openai-auto') to the model list, marked with owned_by: 'gophergate'. This lets clients discover and use groups via the standard OpenAI /v1/models endpoint.
This commit is contained in:
@@ -36,6 +36,15 @@ func New(groups []db.ModelGroup, classify ClassifierFunc) *Router {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Groups returns all registered model group IDs.
|
||||||
|
func (r *Router) Groups() []string {
|
||||||
|
ids := make([]string, 0, len(r.groups))
|
||||||
|
for id := range r.groups {
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
// IsGroup returns true if the model name is a group ID.
|
// IsGroup returns true if the model name is a group ID.
|
||||||
func (r *Router) IsGroup(modelID string) bool {
|
func (r *Router) IsGroup(modelID string) bool {
|
||||||
_, ok := r.groups[modelID]
|
_, ok := r.groups[modelID]
|
||||||
|
|||||||
@@ -467,6 +467,20 @@ func (s *Server) handleListModels(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add model groups so clients can discover them
|
||||||
|
if s.modelRouter != nil {
|
||||||
|
for _, gid := range s.modelRouter.Groups() {
|
||||||
|
if _, exists := modelMap[gid]; !exists {
|
||||||
|
modelMap[gid] = OpenAIModel{
|
||||||
|
ID: gid,
|
||||||
|
Object: "model",
|
||||||
|
Created: 1700000000,
|
||||||
|
OwnedBy: "gophergate",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var data []OpenAIModel
|
var data []OpenAIModel
|
||||||
for _, m := range modelMap {
|
for _, m := range modelMap {
|
||||||
data = append(data, m)
|
data = append(data, m)
|
||||||
|
|||||||
Reference in New Issue
Block a user