feat: return user available models in /v1 api

This commit is contained in:
ckt1031 2023-07-24 00:08:25 +08:00
parent bc2f48b1f2
commit 657de89219

View File

@ -2,6 +2,7 @@ package controller
import ( import (
"fmt" "fmt"
"one-api/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -332,9 +333,27 @@ func init() {
} }
func ListModels(c *gin.Context) { func ListModels(c *gin.Context) {
userId := c.GetInt("id")
userGroup, _ := model.CacheGetUserGroup(userId)
// Only return the models that the channel and user have access to
var modalList []OpenAIModels
for _, modalData := range openAIModels {
channel, err := model.CacheGetRandomSatisfiedChannel(userGroup, modalData.Id)
if err != nil {
continue
}
if channel != nil {
modalList = append(modalList, modalData)
}
}
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"object": "list", "object": "list",
"data": openAIModels, "data": modalList,
}) })
} }