From 5ce75c4fa1afe99b48d4303a6c12f376c3f5ff99 Mon Sep 17 00:00:00 2001 From: dean <1006393151@qq.com> Date: Fri, 21 Jun 2024 04:49:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=EF=BC=8Cresp=20model-name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/constants.go | 2 +- controller/chat.go | 5 ++++- discord/discord.go | 14 +++++++++----- model/openai.go | 5 +++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/common/constants.go b/common/constants.go index 6aa54f7d..6556455e 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1,6 +1,6 @@ package common -var Version = "v4.5.3" // this hard coding will be replaced automatically when building, no need to manually change +var Version = "v4.5.4" // this hard coding will be replaced automatically when building, no need to manually change const ( RequestIdKey = "X-Request-Id" diff --git a/controller/chat.go b/controller/chat.go index 365fb0d5..ed67cbec 100644 --- a/controller/chat.go +++ b/controller/chat.go @@ -285,7 +285,10 @@ loop: } replyChan := make(chan model.OpenAIChatCompletionResponse) - discord.RepliesOpenAIChans[sentMsg.ID] = replyChan + discord.RepliesOpenAIChans[sentMsg.ID] = &model.OpenAIChatCompletionChan{ + Model: request.Model, + Response: replyChan, + } defer delete(discord.RepliesOpenAIChans, sentMsg.ID) stopChan := make(chan model.ChannelStopChan) diff --git a/discord/discord.go b/discord/discord.go index 8b4e5f79..c7cb467e 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -50,7 +50,7 @@ var CreateChannelRiskPreNotifyTime time.Time var BotConfigList []model.BotConfig var RepliesChans = make(map[string]chan model.ReplyResp) -var RepliesOpenAIChans = make(map[string]chan model.OpenAIChatCompletionResponse) +var RepliesOpenAIChans = make(map[string]*model.OpenAIChatCompletionChan) var RepliesOpenAIImageChans = make(map[string]chan model.OpenAIImagesGenerationResponse) var ReplyStopChans = make(map[string]chan model.ChannelStopChan) @@ -302,7 +302,8 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { replyOpenAIChan, exists := RepliesOpenAIChans[m.ReferencedMessage.ID] if exists { reply := processMessageCreateForOpenAI(m) - replyOpenAIChan <- reply + reply.Model = replyOpenAIChan.Model + replyOpenAIChan.Response <- reply } else { replyOpenAIImageChan, exists := RepliesOpenAIImageChans[m.ReferencedMessage.ID] if exists { @@ -333,7 +334,8 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { stopStr := "stop" reply.Choices[0].FinishReason = &stopStr reply.Suggestions = suggestions - replyOpenAIChan <- reply + reply.Model = replyOpenAIChan.Model + replyOpenAIChan.Response <- reply } replyOpenAIImageChan, exists := RepliesOpenAIImageChans[m.ReferencedMessage.ID] @@ -384,7 +386,8 @@ func messageUpdate(s *discordgo.Session, m *discordgo.MessageUpdate) { replyOpenAIChan, exists := RepliesOpenAIChans[m.ReferencedMessage.ID] if exists { reply := processMessageUpdateForOpenAI(m) - replyOpenAIChan <- reply + reply.Model = replyOpenAIChan.Model + replyOpenAIChan.Response <- reply } else { replyOpenAIImageChan, exists := RepliesOpenAIImageChans[m.ReferencedMessage.ID] if exists { @@ -415,7 +418,8 @@ func messageUpdate(s *discordgo.Session, m *discordgo.MessageUpdate) { stopStr := "stop" reply.Choices[0].FinishReason = &stopStr reply.Suggestions = suggestions - replyOpenAIChan <- reply + reply.Model = replyOpenAIChan.Model + replyOpenAIChan.Response <- reply } replyOpenAIImageChan, exists := RepliesOpenAIImageChans[m.ReferencedMessage.ID] diff --git a/model/openai.go b/model/openai.go index c289a158..aa82537c 100644 --- a/model/openai.go +++ b/model/openai.go @@ -27,6 +27,11 @@ type OpenAIError struct { Code string `json:"code"` } +type OpenAIChatCompletionChan struct { + Model string `json:"model"` + Response chan OpenAIChatCompletionResponse +} + type OpenAIChatCompletionResponse struct { ID string `json:"id"` Object string `json:"object"`