添加普通根据功能获取模型列表

This commit is contained in:
junleea 2025-03-30 19:13:15 +08:00
parent 2e2fbf60a0
commit 5592e47f72
1 changed files with 18 additions and 19 deletions

View File

@ -3,7 +3,6 @@ package handler
import (
"StuAcaWorksAI/proto"
"StuAcaWorksAI/service"
"encoding/json"
"github.com/gin-gonic/gin"
"net/http"
)
@ -27,7 +26,7 @@ type FuncModelReq struct {
Function string `json:"function" form:"function"`
Name string `json:"name" form:"name"`
Info string `json:"info" form:"info"`
ModelIDS []FunctionModelIDs `json:"model_ids" form:"model_ids"`
ModelIDS string `json:"model_ids" form:"model_ids"`
}
func CreateFuncModel(c *gin.Context) {
@ -35,13 +34,13 @@ func CreateFuncModel(c *gin.Context) {
userID := int(id.(float64))
var req FuncModelReq
if err := c.ShouldBind(&req); err == nil {
modelIDs, err3 := json.Marshal(req.ModelIDS)
if err3 != nil {
c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.FuncModelCreateFailed, "message": "failed"})
return
}
//modelIDs, err3 := json.Marshal(req.ModelIDS)
//if err3 != nil {
// c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.FuncModelCreateFailed, "message": "failed"})
// return
//}
// 创建功能模型
err2, mid := service.CreateFuncModel(int(uint(userID)), req.ModelID, req.Name, req.Info, req.Function, string(modelIDs))
err2, mid := service.CreateFuncModel(int(uint(userID)), req.ModelID, req.Name, req.Info, req.Function, req.ModelIDS)
if err2 == nil {
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": mid})
} else {
@ -84,13 +83,13 @@ func UpdateFuncModel(c *gin.Context) {
userID := int(id.(float64))
var req FuncModelReq
if err := c.ShouldBind(&req); err == nil {
modelIDs, err3 := json.Marshal(req.ModelIDS)
if err3 != nil {
c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.FuncModelCreateFailed, "message": "failed"})
return
}
//modelIDs, err3 := json.Marshal(req.ModelIDS)
//if err3 != nil {
// c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.FuncModelCreateFailed, "message": "failed"})
// return
//}
// 修改功能模型
err2 := service.UpdateFuncModelByID(req.ID, uint(userID), uint(req.ModelID), req.Name, req.Info, req.Function, string(modelIDs))
err2 := service.UpdateFuncModelByID(req.ID, uint(userID), uint(req.ModelID), req.Name, req.Info, req.Function, req.ModelIDS)
if err2 == nil {
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
} else {