compress and regenerate
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user