Skip to content

Commit

Permalink
fix: ,resp model-name
Browse files Browse the repository at this point in the history
  • Loading branch information
deanxv committed Jun 20, 2024
1 parent a51f0db commit 5ce75c4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 4 additions & 1 deletion controller/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions model/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 5ce75c4

Please sign in to comment.