From daaca822ac8ec556e2042017d0768682ebd277a8 Mon Sep 17 00:00:00 2001 From: RockYang Date: Mon, 6 Nov 2023 15:03:56 +0800 Subject: [PATCH] opt:update mj api version, wrapper chat api error message as a constant --- CHANGELOG.md | 4 ++++ api/handler/chatimpl/azure_handler.go | 6 +++--- api/handler/chatimpl/baidu_handler.go | 2 +- api/handler/chatimpl/chat_handler.go | 9 +++++---- api/handler/chatimpl/chatglm_handler.go | 2 +- api/handler/chatimpl/openai_handler.go | 6 +++--- api/service/mj/client.go | 2 +- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66bdeaf4..71d3a427 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 更新日志 +## v3.1.7 +1. Bug修复:修复 MidJourney API 参数版本更新导致调用失败的 Bug +2. 功能优化:将聊天报错信息定义为统一常量,方便修改 + ## v3.1.7 1. 功能新增:支持文心4.0 AI 模型 2. 功能新增:可以在管理后台为用户绑定指定的 AI 模型,如只给某个用户使用 GPT-4 模型 diff --git a/api/handler/chatimpl/azure_handler.go b/api/handler/chatimpl/azure_handler.go index c3b44f7e..297fa91a 100644 --- a/api/handler/chatimpl/azure_handler.go +++ b/api/handler/chatimpl/azure_handler.go @@ -44,7 +44,7 @@ func (h *ChatHandler) sendAzureMessage( } utils.ReplyMessage(ws, ErrorMsg) - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) return err } else { defer response.Body.Close() @@ -71,7 +71,7 @@ func (h *ChatHandler) sendAzureMessage( if err != nil || len(responseBody.Choices) == 0 { // 数据解析出错 logger.Error(err, line) utils.ReplyMessage(ws, ErrorMsg) - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) break } @@ -129,7 +129,7 @@ func (h *ChatHandler) sendAzureMessage( // for creating image, check if the user's img_calls > 0 if functionName == types.FuncMidJourney && userVo.ImgCalls <= 0 { utils.ReplyMessage(ws, "**当前用户剩余绘图次数已用尽,请扫描下面二维码联系管理员!**") - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) } else { f := h.App.Functions[functionName] if functionName == types.FuncMidJourney { diff --git a/api/handler/chatimpl/baidu_handler.go b/api/handler/chatimpl/baidu_handler.go index b0b7e7cf..1f8007c5 100644 --- a/api/handler/chatimpl/baidu_handler.go +++ b/api/handler/chatimpl/baidu_handler.go @@ -61,7 +61,7 @@ func (h *ChatHandler) sendBaiduMessage( } utils.ReplyMessage(ws, ErrorMsg) - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) return err } else { defer response.Body.Close() diff --git a/api/handler/chatimpl/chat_handler.go b/api/handler/chatimpl/chat_handler.go index db13b9a0..d56d00aa 100644 --- a/api/handler/chatimpl/chat_handler.go +++ b/api/handler/chatimpl/chat_handler.go @@ -27,6 +27,7 @@ import ( ) const ErrorMsg = "抱歉,AI 助手开小差了,请稍后再试。" +const ErrImg = "![](/images/wx.png)" var logger = logger2.GetLogger() @@ -182,19 +183,19 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio if userVo.Status == false { utils.ReplyMessage(ws, "您的账号已经被禁用,如果疑问,请联系管理员!") - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) return nil } if userVo.Calls <= 0 && userVo.ChatConfig.ApiKeys[session.Model.Platform] == "" { utils.ReplyMessage(ws, "您的对话次数已经用尽,请联系管理员或者点击左下角菜单加入众筹获得100次对话!") - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) return nil } if userVo.ExpiredTime > 0 && userVo.ExpiredTime <= time.Now().Unix() { utils.ReplyMessage(ws, "您的账号已经过期,请联系管理员!") - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) return nil } var req = types.ApiRequest{ @@ -232,7 +233,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio req.MaxTokens = h.App.ChatConfig.XunFei.MaxTokens default: utils.ReplyMessage(ws, "不支持的平台:"+session.Model.Platform+",请联系管理员!") - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) return nil } diff --git a/api/handler/chatimpl/chatglm_handler.go b/api/handler/chatimpl/chatglm_handler.go index 25df5b9e..cfd154d5 100644 --- a/api/handler/chatimpl/chatglm_handler.go +++ b/api/handler/chatimpl/chatglm_handler.go @@ -45,7 +45,7 @@ func (h *ChatHandler) sendChatGLMMessage( } utils.ReplyMessage(ws, ErrorMsg) - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) return err } else { defer response.Body.Close() diff --git a/api/handler/chatimpl/openai_handler.go b/api/handler/chatimpl/openai_handler.go index 478bba19..a6ed62be 100644 --- a/api/handler/chatimpl/openai_handler.go +++ b/api/handler/chatimpl/openai_handler.go @@ -43,7 +43,7 @@ func (h *ChatHandler) sendOpenAiMessage( } utils.ReplyMessage(ws, ErrorMsg) - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) return err } else { defer response.Body.Close() @@ -70,7 +70,7 @@ func (h *ChatHandler) sendOpenAiMessage( if err != nil || len(responseBody.Choices) == 0 { // 数据解析出错 logger.Error(err, line) utils.ReplyMessage(ws, ErrorMsg) - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) break } @@ -128,7 +128,7 @@ func (h *ChatHandler) sendOpenAiMessage( // for creating image, check if the user's img_calls > 0 if functionName == types.FuncMidJourney && userVo.ImgCalls <= 0 { utils.ReplyMessage(ws, "**当前用户剩余绘图次数已用尽,请扫描下面二维码联系管理员!**") - utils.ReplyMessage(ws, "![](/images/wx.png)") + utils.ReplyMessage(ws, ErrImg) } else { f := h.App.Functions[functionName] if functionName == types.FuncMidJourney { diff --git a/api/service/mj/client.go b/api/service/mj/client.go index 844c3c6a..6afb2d2a 100644 --- a/api/service/mj/client.go +++ b/api/service/mj/client.go @@ -31,7 +31,7 @@ func (c *Client) Imagine(prompt string) error { ChannelID: c.config.ChanelId, SessionID: SessionID, Data: map[string]any{ - "version": "1118961510123847772", + "version": "1166847114203123795", "id": "938956540159881230", "name": "imagine", "type": "1",