compress and regenerate

This commit is contained in:
2026-02-02 13:43:27 +03:00
parent 2ed1fc9f80
commit 2a71754c6f
3 changed files with 150 additions and 35 deletions

View File

@@ -10,9 +10,10 @@ import (
)
type RPChatMessage struct {
ChatID string `bson:"chat_id"`
Role string `bson:"role"`
Message string `bson:"message"`
Id bson.ObjectID `bson:"_id"`
ChatID string `bson:"chat_id"`
Role string `bson:"role"`
Message string `bson:"message"`
}
func GetChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*RPChatMessage, error) {
@@ -32,6 +33,7 @@ func UpdateChatHistory(db *laniakea.DatabaseContext, chatId, role, message strin
defer cancel()
col := database.GetMongoCollection(db, "rp_chat_messages")
_, err := col.InsertOne(ctx, RPChatMessage{
bson.NewObjectID(),
chatId,
role,
message,
@@ -44,3 +46,10 @@ func GetChatHistorySize(db *laniakea.DatabaseContext, chatId string) (int64, err
col := database.GetMongoCollection(db, "rp_chat_messages")
return col.CountDocuments(ctx, bson.M{"chat_id": chatId})
}
func DeleteChatEntry(db *laniakea.DatabaseContext, entry *RPChatMessage) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "rp_chat_messages")
_, err := col.DeleteOne(ctx, bson.M{"chat_id": entry.ChatID})
return err
}