mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-10 11:13:42 +08:00
markmap enable to select ai model
This commit is contained in:
@@ -218,6 +218,7 @@ func needLogin(c *gin.Context) bool {
|
||||
c.Request.URL.Path == "/api/config/get" ||
|
||||
c.Request.URL.Path == "/api/product/list" ||
|
||||
c.Request.URL.Path == "/api/menu/list" ||
|
||||
c.Request.URL.Path == "/api/markMap/model" ||
|
||||
strings.HasPrefix(c.Request.URL.Path, "/api/test") ||
|
||||
strings.HasPrefix(c.Request.URL.Path, "/api/function/") ||
|
||||
strings.HasPrefix(c.Request.URL.Path, "/api/sms/") ||
|
||||
|
||||
48
api/handler/markmap_handler.go
Normal file
48
api/handler/markmap_handler.go
Normal 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)
|
||||
}
|
||||
@@ -436,6 +436,11 @@ func main() {
|
||||
group := s.Engine.Group("/api/menu/")
|
||||
group.GET("list", h.List)
|
||||
}),
|
||||
fx.Provide(handler.NewMarkMapHandler),
|
||||
fx.Invoke(func(s *core.AppServer, h *handler.MarkMapHandler) {
|
||||
group := s.Engine.Group("/api/markMap/")
|
||||
group.GET("model", h.GetModel)
|
||||
}),
|
||||
fx.Invoke(func(s *core.AppServer, db *gorm.DB) {
|
||||
go func() {
|
||||
err := s.Run(db)
|
||||
|
||||
Reference in New Issue
Block a user