From ea4262adf04c4a83c6eef7940e46c36517060ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Wed, 31 Jan 2024 12:02:33 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20=E6=8E=A7=E5=88=B6=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=BE=E7=BD=AEAI=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/friend.go | 28 ++++++++++++++++++++++++++++ app/index.go | 1 + config.yaml | 15 ++++++++++++++- config/ai.go | 18 +++++++++++++----- router/router.go | 1 + views/index.html | 21 ++++++++++++++++++++- views/static/js/index.js | 23 ++++++++++++++++++++++- 7 files changed, 99 insertions(+), 8 deletions(-) diff --git a/app/friend.go b/app/friend.go index fc4ddc6..d131d7a 100644 --- a/app/friend.go +++ b/app/friend.go @@ -16,6 +16,13 @@ type changeStatusParam struct { UserId string `json:"userId"` } +// changeUseAiModelParam +// @description: 修改使用的AI模型用的参数集 +type changeUseAiModelParam struct { + WxId string `json:"wxid" binding:"required"` // 群Id或微信Id + Model string `json:"model" binding:"required"` // 模型代码 +} + // ChangeEnableAiStatus // @description: 修改是否开启AI // @param ctx @@ -39,6 +46,27 @@ func ChangeEnableAiStatus(ctx *gin.Context) { ctx.String(http.StatusOK, "操作成功") } +// ChangeUseAiModel +// @description: 修改使用的AI模型 +// @param ctx +func ChangeUseAiModel(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("`ai_model`", 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/index.go b/app/index.go index 49a4a62..affe9b4 100644 --- a/app/index.go +++ b/app/index.go @@ -23,6 +23,7 @@ func Index(ctx *gin.Context) { result["friends"] = friends result["groups"] = groups result["vnc"] = config.Conf.Wechat.VncUrl + result["aiModels"] = config.Conf.Ai.Models // 渲染页面 ctx.HTML(http.StatusOK, "index.html", result) } diff --git a/config.yaml b/config.yaml index 52dac8a..e1f8067 100644 --- a/config.yaml +++ b/config.yaml @@ -3,7 +3,7 @@ wechat: # 微信HOOK接口地址 host: 10.0.0.73:19088 # 微信容器映射出来的vnc页面地址,没有就不填 - vncUrl: http://192.168.1.175:19087/vnc_lite.html +# vncUrl: http://192.168.1.175:19087/vnc_lite.html # 是否在启动的时候自动设置hook服务的回调 autoSetCallback: false # 回调IP,如果是Docker运行,本参数必填(填auto表示自动,不适用于 docker 环境),如果Docker修改了映射,格式为 ip:port @@ -45,6 +45,19 @@ ai: baseUrl: https://sxxx # 人设 personality: 你的名字叫张三,你是一个百科机器人,你的爱好是看电影,你的性格是开朗的,你的专长是讲故事,你的梦想是当一名童话故事作家。你对政治没有一点儿兴趣,也不会讨论任何与政治相关的话题,你甚至可以拒绝回答这一类话题。 + models: + - name: ChatGPT-4 + model: gpt-4-0613 + - name: 讯飞星火v3 + model: SparkDesk3 + - name: 讯飞星火随机 + model: SparkDesk + - name: 月之暗面-8k + model: moonshot-v1-8k + - name: 月之暗面-32k + model: moonshot-v1-32k + - name: 月之暗面-128k + model: moonshot-v1-128k # 资源配置 # map[k]v结构,k 会变成全小写,所以这儿不能用大写字母 diff --git a/config/ai.go b/config/ai.go index b27e3ea..1aeff19 100644 --- a/config/ai.go +++ b/config/ai.go @@ -3,9 +3,17 @@ package config // ai // @description: AI配置 type ai struct { - Enable bool `json:"enable" yaml:"enable"` // 是否启用AI - Model string `json:"model" yaml:"model"` // 模型 - ApiKey string `json:"apiKey" yaml:"apiKey"` // API Key - BaseUrl string `json:"baseUrl" yaml:"baseUrl"` // API地址 - Personality string `json:"personality" yaml:"personality"` // 人设 + Enable bool `json:"enable" yaml:"enable"` // 是否启用AI + Model string `json:"model" yaml:"model"` // 模型 + ApiKey string `json:"apiKey" yaml:"apiKey"` // API Key + BaseUrl string `json:"baseUrl" yaml:"baseUrl"` // API地址 + Personality string `json:"personality" yaml:"personality"` // 人设 + Models []aiModel `json:"models" yaml:"models"` // 模型列表 +} + +// aiModel +// @description: AI模型 +type aiModel struct { + Name string `json:"name" yaml:"name"` // 模型名称 + Model string `json:"model" yaml:"model"` // 模型代码 } diff --git a/router/router.go b/router/router.go index 4ee0598..5213f82 100644 --- a/router/router.go +++ b/router/router.go @@ -22,6 +22,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.PUT("/welcome/status", app.ChangeEnableWelcomeStatus) // 修改是否开启迎新状态 api.PUT("/command/status", app.ChangeEnableCommandStatus) // 修改是否开启指令状态 api.PUT("/grouprank/status", app.ChangeEnableGroupRankStatus) // 修改是否开启水群排行榜状态 diff --git a/views/index.html b/views/index.html index c197d94..e0e72f6 100644 --- a/views/index.html +++ b/views/index.html @@ -4,7 +4,6 @@ 水群助手 - @@ -71,6 +70,16 @@
✔️已启用
❌已禁用
+ {{ if .EnableAi }} +
+ + {{ end }} + {{ if .EnableAi }} +
+ + {{ end }} diff --git a/views/static/js/index.js b/views/static/js/index.js index 200c819..52e1404 100644 --- a/views/static/js/index.js +++ b/views/static/js/index.js @@ -134,4 +134,25 @@ function getGroupUsers(groupId, groupName) { // loading.style.display = "none" groupNameTag.innerHTML = groupName }) -} \ No newline at end of file +} + +// AI模型变动 +function aiModelChange(event, wxid) { + // 取出变动后的值 + const modelStr = event.target.value; + console.log("AI模型变动: ", wxid, modelStr) + axios({ + method: 'post', + url: '/api/ai/model', + data: { + wxid: wxid, + model: modelStr + } + }).then(function (response) { + console.log(`返回结果: ${JSON.stringify(response)}`); + alert(`${response.data}`) + }).catch(function (error) { + console.log(`错误信息: ${error}`); + alert("修改失败") + }) +}