markmap enable to select ai model

This commit is contained in:
RockYang
2024-04-15 06:16:53 +08:00
parent 31b02b97d3
commit 9a1368ef17
5 changed files with 124 additions and 33 deletions

View File

@@ -0,0 +1,48 @@
package handler
import (
"chatplus/core"
"chatplus/core/types"
"chatplus/store/model"
"chatplus/store/vo"
"chatplus/utils"
"chatplus/utils/resp"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
// MarkMapHandler 生成思维导图
type MarkMapHandler struct {
BaseHandler
}
func NewMarkMapHandler(app *core.AppServer, db *gorm.DB) *MarkMapHandler {
return &MarkMapHandler{BaseHandler: BaseHandler{App: app, DB: db}}
}
// GetModel get the chat model for generating Markdown text
func (h *MarkMapHandler) GetModel(c *gin.Context) {
modelId := h.App.SysConfig.XMindModelId
session := h.DB.Session(&gorm.Session{}).Where("enabled", true)
if modelId > 0 {
session = session.Where("id", modelId)
} else {
session = session.Where("platform", types.OpenAI)
}
var chatModel model.ChatModel
res := session.First(&chatModel)
if res.Error != nil {
resp.ERROR(c, "No available AI model")
return
}
var modelVo vo.ChatModel
err := utils.CopyObject(chatModel, &modelVo)
if err != nil {
resp.ERROR(c, "error with copy object: "+err.Error())
return
}
resp.SUCCESS(c, modelVo)
}