Skip to content

Commit

Permalink
feat: get channel default models and modelmapping (#5232)
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 authored Nov 25, 2024
1 parent d76306a commit d0c6dd5
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
70 changes: 70 additions & 0 deletions service/aiproxy/controller/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,76 @@ func ChannelDefaultModelsByType(c *gin.Context) {
})
}

func ChannelDefaultModelMapping(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": config.GetDefaultChannelModelMapping(),
})
}

func ChannelDefaultModelMappingByType(c *gin.Context) {
channelType := c.Param("type")
if channelType == "" {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
"message": "type is required",
})
return
}
channelTypeInt, err := strconv.Atoi(channelType)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
"message": "invalid type",
})
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": config.GetDefaultChannelModelMapping()[channelTypeInt],
})
}

func ChannelDefaultModelsAndMapping(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": gin.H{
"models": config.GetDefaultChannelModels(),
"mapping": config.GetDefaultChannelModelMapping(),
},
})
}

func ChannelDefaultModelsAndMappingByType(c *gin.Context) {
channelType := c.Param("type")
if channelType == "" {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
"message": "type is required",
})
return
}
channelTypeInt, err := strconv.Atoi(channelType)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
"message": "invalid type",
})
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": gin.H{
"models": config.GetDefaultChannelModels()[channelTypeInt],
"mapping": config.GetDefaultChannelModelMapping()[channelTypeInt],
},
})
}

func EnabledModels(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"success": true,
Expand Down
4 changes: 4 additions & 0 deletions service/aiproxy/router/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func SetAPIRouter(router *gin.Engine) {
apiRouter.GET("/models/enabled/channel/price", controller.EnabledType2ModelsAndPrice)
apiRouter.GET("/models/enabled/default", controller.ChannelDefaultModels)
apiRouter.GET("/models/enabled/default/:type", controller.ChannelDefaultModelsByType)
apiRouter.GET("/models/enabled/mapping/default", controller.ChannelDefaultModelMapping)
apiRouter.GET("/models/enabled/mapping/default/:type", controller.ChannelDefaultModelMappingByType)
apiRouter.GET("/models/enabled/all/default", controller.ChannelDefaultModelsAndMapping)
apiRouter.GET("/models/enabled/all/default/:type", controller.ChannelDefaultModelsAndMappingByType)

groupsRoute := apiRouter.Group("/groups")
{
Expand Down

0 comments on commit d0c6dd5

Please sign in to comment.