添加普通根据功能获取模型列表
This commit is contained in:
parent
8169815278
commit
04270914b8
11
dao/model.go
11
dao/model.go
|
|
@ -60,6 +60,17 @@ func FindModelByID(id, userID int) []Model {
|
|||
return model
|
||||
}
|
||||
|
||||
// 根据id查找模型
|
||||
func FindModelByIDV2(id int) []Model {
|
||||
var model []Model
|
||||
if proto.Config.SERVER_SQL_LOG {
|
||||
DB.Debug().Where("id = ?", id).Find(&model)
|
||||
} else {
|
||||
DB.Where("id = ?", id).Find(&model)
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
// 根据modelID查找模型
|
||||
func FindModelByModelID(modelID uint) []Model {
|
||||
var model []Model
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ func SetUpFuncModelGroup(router *gin.Engine) {
|
|||
funcGroup.POST("/find", FindFuncModel)
|
||||
funcGroup.POST("/delete", DeleteFuncModel)
|
||||
funcGroup.POST("/update", UpdateFuncModel)
|
||||
funcGroup.POST("/find_models_by_function", FindFuncModelByFunction)
|
||||
}
|
||||
|
||||
type FuncModelReq struct {
|
||||
|
|
@ -113,3 +114,18 @@ func DeleteFuncModel(c *gin.Context) {
|
|||
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": proto.ParameterError, "message": "failed"})
|
||||
}
|
||||
}
|
||||
|
||||
func FindFuncModelByFunction(c *gin.Context) {
|
||||
var req FuncModelReq
|
||||
if err := c.ShouldBind(&req); err == nil {
|
||||
// 查找对应功能
|
||||
models, err2 := service.FindFuncModelListByFunction(req.Function)
|
||||
if err2 == nil {
|
||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": models})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{"code": proto.ErrorCode, "message": "get models error:" + err.Error(), "data": models})
|
||||
}
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": proto.ParameterError, "message": "failed"})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package service
|
|||
|
||||
import (
|
||||
"StuAcaWorksAI/dao"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
)
|
||||
|
||||
// 创建模型信息
|
||||
|
|
@ -144,3 +146,25 @@ func FindFuncModelByFunction(function string, userID int) ([]dao.Model, []dao.Fu
|
|||
//再查找对应模型
|
||||
return dao.FindModelByModelID(modelID), funcModels
|
||||
}
|
||||
|
||||
// 根据功能查找对应的功能模型列表(不查询密钥等信息,只差id,类型及名称)
|
||||
func FindFuncModelListByFunction(function string) ([]dao.Model, error) {
|
||||
funcModels := dao.FindFunctionModelByFunction(function)
|
||||
modelIDs := map[int]bool{}
|
||||
err := json.Unmarshal([]byte(funcModels[0].ModelIDS), &modelIDs)
|
||||
if err != nil {
|
||||
log.Println("FindFuncModelListByFunction json unmarshal error:", err)
|
||||
return nil, err
|
||||
}
|
||||
var models []dao.Model
|
||||
for k := range modelIDs {
|
||||
models_ := dao.FindModelByIDV2(k)
|
||||
for _, v := range models_ {
|
||||
v.Url = ""
|
||||
v.Parameter = ""
|
||||
v.Description = ""
|
||||
models = append(models, v)
|
||||
}
|
||||
}
|
||||
return models, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue