From c01393cc35ec6ee727c6ff57ddb465ebc02157a0 Mon Sep 17 00:00:00 2001 From: dean <1006393151@qq.com> Date: Wed, 10 Jul 2024 15:45:36 +0800 Subject: [PATCH] fix: image --- common/constants.go | 2 +- discord/processmessage.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/common/constants.go b/common/constants.go index 20773a9b..6cf7851a 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1,6 +1,6 @@ package common -var Version = "v4.5.9" // this hard coding will be replaced automatically when building, no need to manually change +var Version = "v4.5.10" // this hard coding will be replaced automatically when building, no need to manually change const ( RequestIdKey = "X-Request-Id" diff --git a/discord/processmessage.go b/discord/processmessage.go index 577615e5..be77d50f 100644 --- a/discord/processmessage.go +++ b/discord/processmessage.go @@ -38,6 +38,17 @@ func processMessageUpdateForOpenAI(m *discordgo.MessageUpdate) model.OpenAIChatC } } + if len(m.Attachments) != 0 { + for _, attachment := range m.Attachments { + if attachment.ProxyURL != "" && !strings.Contains(m.Content, attachment.ProxyURL) { + if m.Content != "" { + m.Content += "\n" + } + m.Content += fmt.Sprintf("%s\n![Image](%s)", attachment.ProxyURL, attachment.ProxyURL) + } + } + } + promptTokens := common.CountTokens(m.ReferencedMessage.Content) completionTokens := common.CountTokens(m.Content) @@ -158,6 +169,17 @@ func processMessageCreateForOpenAI(m *discordgo.MessageCreate) model.OpenAIChatC } } + if len(m.Attachments) != 0 { + for _, attachment := range m.Attachments { + if attachment.ProxyURL != "" && !strings.Contains(m.Content, attachment.ProxyURL) { + if m.Content != "" { + m.Content += "\n" + } + m.Content += fmt.Sprintf("%s\n![Image](%s)", attachment.ProxyURL, attachment.ProxyURL) + } + } + } + promptTokens := common.CountTokens(m.ReferencedMessage.Content) completionTokens := common.CountTokens(m.Content)