Compare commits

..

3 commits

Author SHA1 Message Date
Alexey Skobkin 7d9d08fbff Merge pull request 'Fixing user request representation in the LLM request context (#40)' (#41) from fix_quoted_messages_usernames_context into main
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
Reviewed-on: #41
2024-11-03 23:25:11 +00:00
Alexey Skobkin 5280fe8a2e
Fixing user request representation in the LLM request context (#40).
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2024-11-04 02:24:00 +03:00
Alexey Skobkin b4b0f7baba
Context prompt format fix. 2024-11-04 02:10:57 +03:00
4 changed files with 11 additions and 10 deletions

View file

@ -144,7 +144,7 @@ func (b *Bot) processMention(message *telego.Message) {
requestContext := b.createLlmRequestContextFromMessage(message) requestContext := b.createLlmRequestContextFromMessage(message)
userMessageData := tgUserMessageToMessageData(message) userMessageData := tgUserMessageToMessageData(message, true)
llmReply, err := b.llm.HandleChatMessage( llmReply, err := b.llm.HandleChatMessage(
messageDataToLlmMessage(userMessageData), messageDataToLlmMessage(userMessageData),

View file

@ -56,7 +56,7 @@ func (b *Bot) saveChatMessageToHistory(message *telego.Message) {
b.history[chatId] = NewMessageHistory(HistoryLength) b.history[chatId] = NewMessageHistory(HistoryLength)
} }
msgData := tgUserMessageToMessageData(message) msgData := tgUserMessageToMessageData(message, false)
b.history[chatId].Push(msgData) b.history[chatId].Push(msgData)
} }
@ -99,16 +99,17 @@ func (b *Bot) saveBotReplyToHistory(replyTo *telego.Message, text string) {
b.history[chatId].Push(msgData) b.history[chatId].Push(msgData)
} }
func tgUserMessageToMessageData(message *telego.Message) MessageData { func tgUserMessageToMessageData(message *telego.Message, isUserRequest bool) MessageData {
msgData := MessageData{ msgData := MessageData{
Name: message.From.FirstName, Name: message.From.FirstName,
Username: message.From.Username, Username: message.From.Username,
Text: message.Text, Text: message.Text,
IsMe: false, IsMe: false,
IsUserRequest: isUserRequest,
} }
if message.ReplyToMessage != nil { if message.ReplyToMessage != nil {
replyData := tgUserMessageToMessageData(message.ReplyToMessage) replyData := tgUserMessageToMessageData(message.ReplyToMessage, false)
msgData.ReplyTo = &replyData msgData.ReplyTo = &replyData
} }

View file

@ -56,7 +56,7 @@ func (c RequestContext) Prompt() string {
prompt += "Chat description is \"" + c.Chat.Description + "\". " prompt += "Chat description is \"" + c.Chat.Description + "\". "
} }
prompt += "\nProfile of the user who mentioned you in the chat:" + prompt += "\nProfile of the user who mentioned you in the chat:\n" +
"First name: \"" + c.User.FirstName + "\"\n" "First name: \"" + c.User.FirstName + "\"\n"
if c.User.Username != "" { if c.User.Username != "" {
prompt += "Username: @" + c.User.Username + ".\n" prompt += "Username: @" + c.User.Username + ".\n"