Chat history and context improvements #35

Merged
skobkin merged 3 commits from fix_quoted_messages_usernames_context into main 2024-11-03 22:28:40 +00:00
2 changed files with 9 additions and 9 deletions
Showing only changes of commit a783a84faa - Show all commits

View file

@ -30,7 +30,7 @@ type Bot struct {
extractor *extractor.Extractor
stats *stats.Stats
models ModelSelection
history map[int64]*MessageRingBuffer
history map[int64]*MessageHistory
profile BotInfo
markdownV1Replacer *strings.Replacer
@ -48,7 +48,7 @@ func NewBot(
extractor: extractor,
stats: stats.NewStats(),
models: models,
history: make(map[int64]*MessageRingBuffer),
history: make(map[int64]*MessageHistory),
profile: BotInfo{0, "", ""},
markdownV1Replacer: strings.NewReplacer(

View file

@ -16,19 +16,19 @@ type MessageData struct {
ReplyTo *MessageData
}
type MessageRingBuffer struct {
type MessageHistory struct {
messages []MessageData
capacity int
}
func NewMessageBuffer(capacity int) *MessageRingBuffer {
return &MessageRingBuffer{
func NewMessageHistory(capacity int) *MessageHistory {
return &MessageHistory{
messages: make([]MessageData, 0, capacity),
capacity: capacity,
}
}
func (b *MessageRingBuffer) Push(element MessageData) {
func (b *MessageHistory) Push(element MessageData) {
if len(b.messages) >= b.capacity {
b.messages = b.messages[1:]
}
@ -36,7 +36,7 @@ func (b *MessageRingBuffer) Push(element MessageData) {
b.messages = append(b.messages, element)
}
func (b *MessageRingBuffer) GetAll() []MessageData {
func (b *MessageHistory) GetAll() []MessageData {
return b.messages
}
@ -53,7 +53,7 @@ func (b *Bot) saveChatMessageToHistory(message *telego.Message) {
_, ok := b.history[chatId]
if !ok {
b.history[chatId] = NewMessageBuffer(HistoryLength)
b.history[chatId] = NewMessageHistory(HistoryLength)
}
msgData := tgUserMessageToMessageData(message)
@ -74,7 +74,7 @@ func (b *Bot) saveBotReplyToHistory(message *telego.Message, text string) {
_, ok := b.history[chatId]
if !ok {
b.history[chatId] = NewMessageBuffer(HistoryLength)
b.history[chatId] = NewMessageHistory(HistoryLength)
}
msgData := MessageData{