From 5280fe8a2eb4df03687a7ae5bfa32c5d0c5c9620 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 4 Nov 2024 02:24:00 +0300 Subject: [PATCH] Fixing user request representation in the LLM request context (#40). --- bot/bot.go | 2 +- bot/message_history.go | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bot/bot.go b/bot/bot.go index a0282ca..4e80f90 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -144,7 +144,7 @@ func (b *Bot) processMention(message *telego.Message) { requestContext := b.createLlmRequestContextFromMessage(message) - userMessageData := tgUserMessageToMessageData(message) + userMessageData := tgUserMessageToMessageData(message, true) llmReply, err := b.llm.HandleChatMessage( messageDataToLlmMessage(userMessageData), diff --git a/bot/message_history.go b/bot/message_history.go index e58ee2d..c04887c 100644 --- a/bot/message_history.go +++ b/bot/message_history.go @@ -56,7 +56,7 @@ func (b *Bot) saveChatMessageToHistory(message *telego.Message) { b.history[chatId] = NewMessageHistory(HistoryLength) } - msgData := tgUserMessageToMessageData(message) + msgData := tgUserMessageToMessageData(message, false) b.history[chatId].Push(msgData) } @@ -99,16 +99,17 @@ func (b *Bot) saveBotReplyToHistory(replyTo *telego.Message, text string) { b.history[chatId].Push(msgData) } -func tgUserMessageToMessageData(message *telego.Message) MessageData { +func tgUserMessageToMessageData(message *telego.Message, isUserRequest bool) MessageData { msgData := MessageData{ - Name: message.From.FirstName, - Username: message.From.Username, - Text: message.Text, - IsMe: false, + Name: message.From.FirstName, + Username: message.From.Username, + Text: message.Text, + IsMe: false, + IsUserRequest: isUserRequest, } if message.ReplyToMessage != nil { - replyData := tgUserMessageToMessageData(message.ReplyToMessage) + replyData := tgUserMessageToMessageData(message.ReplyToMessage, false) msgData.ReplyTo = &replyData }