diff --git a/app/friend.go b/app/friend.go index 0789420..3849f2b 100644 --- a/app/friend.go +++ b/app/friend.go @@ -67,6 +67,28 @@ func ChangeUseAiModel(ctx *gin.Context) { ctx.String(http.StatusOK, "操作成功") } +// ChangeUseAiAssistant +// @description: 修改使用的AI助手 +// @param ctx +func ChangeUseAiAssistant(ctx *gin.Context) { + // 此处复用一下结构体 + var p changeUseAiModelParam + if err := ctx.ShouldBind(&p); err != nil { + ctx.String(http.StatusBadRequest, "参数错误") + return + } + err := client.MySQL.Model(&entity.Friend{}). + Where("wxid = ?", p.WxId). + Update("`prompt`", p.Model).Error + if err != nil { + log.Printf("修改【%s】的AI助手失败:%s", p.WxId, err) + ctx.String(http.StatusInternalServerError, "操作失败: %s", err) + return + } + + ctx.String(http.StatusOK, "操作成功") +} + // ChangeEnableGroupRankStatus // @description: 修改是否开启水群排行榜 // @param ctx diff --git a/app/pages.go b/app/pages.go index 13d5fc7..2770588 100644 --- a/app/pages.go +++ b/app/pages.go @@ -66,6 +66,7 @@ func Friend(ctx *gin.Context) { result["friends"] = friends result["vnc"] = config.Conf.Wechat.VncUrl result["aiModels"] = config.Conf.Ai.Models + result["assistant"], _ = service.GetAllAiAssistant() // 渲染页面 ctx.HTML(http.StatusOK, "friend.html", result) } @@ -85,6 +86,7 @@ func Group(ctx *gin.Context) { result["groups"] = groups result["vnc"] = config.Conf.Wechat.VncUrl result["aiModels"] = config.Conf.Ai.Models + result["assistant"], _ = service.GetAllAiAssistant() // 渲染页面 ctx.HTML(http.StatusOK, "group.html", result) diff --git a/entity/aiassistant.go b/entity/aiassistant.go new file mode 100644 index 0000000..61cd66b --- /dev/null +++ b/entity/aiassistant.go @@ -0,0 +1,39 @@ +package entity + +import ( + "github.com/google/uuid" + "go-wechat/common/types" + "gorm.io/gorm" + "strings" +) + +// AiAssistant +// @description: AI助手表 +type AiAssistant struct { + Id string `json:"id" gorm:"type:varchar(32);primarykey"` + CreatedAt types.DateTime `json:"createdAt"` + Name string `json:"name" gorm:"type:varchar(10);not null;comment:'名称'"` + Personality string `json:"personality" gorm:"type:varchar(999);not null;comment:'人设'"` + Model string `json:"model" gorm:"type:varchar(50);not null;comment:'使用的模型'"` + Enable bool `json:"enable" gorm:"type:tinyint(1);not null;default:1;comment:'是否启用'"` +} + +// TableName +// @description: 表名 +// @receiver AiAssistant +// @return string +func (AiAssistant) TableName() string { + return "t_ai_assistant" +} + +// BeforeCreate +// @description: 创建数据库对象之前生成UUID +// @receiver m +// @param *gorm.DB +// @return err +func (m *AiAssistant) BeforeCreate(*gorm.DB) (err error) { + if m.Id == "" { + m.Id = strings.ReplaceAll(uuid.New().String(), "-", "") + } + return +} diff --git a/router/router.go b/router/router.go index f10f30a..3b606c2 100644 --- a/router/router.go +++ b/router/router.go @@ -24,6 +24,7 @@ func Init(g *gin.Engine) { api := g.Group("/api") api.PUT("/ai/status", app.ChangeEnableAiStatus) // 修改是否开启AI状态 api.POST("/ai/model", app.ChangeUseAiModel) // 修改使用的AI模型 + api.POST("/ai/assistant", app.ChangeUseAiAssistant) // 修改使用的AI助手 api.PUT("/welcome/status", app.ChangeEnableWelcomeStatus) // 修改是否开启迎新状态 api.PUT("/command/status", app.ChangeEnableCommandStatus) // 修改是否开启指令状态 api.PUT("/news/status", app.ChangeEnableNewsStatus) // 修改是否开启早报状态 diff --git a/service/aiassistant.go b/service/aiassistant.go new file mode 100644 index 0000000..f5608fe --- /dev/null +++ b/service/aiassistant.go @@ -0,0 +1,14 @@ +package service + +import ( + "go-wechat/client" + "go-wechat/entity" +) + +// GetAllAiAssistant +// @description: 取出所有AI助手 +// @return records +func GetAllAiAssistant() (records []entity.AiAssistant, err error) { + err = client.MySQL.Order("created_at DESC").Find(&records).Error + return +} diff --git a/views/friend.html b/views/friend.html index d301e91..e97c719 100644 --- a/views/friend.html +++ b/views/friend.html @@ -76,6 +76,24 @@ + +