memory leak
This commit is contained in:
35
database/mdb/ai_chats.go
Normal file
35
database/mdb/ai_chats.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package mdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kurumibot/database"
|
||||
"time"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func GetGptChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*AiChatMessage, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := database.GetMongoCollection(db, "gpt_chat_messages")
|
||||
cursor, err := col.Find(ctx, bson.M{"chatId": chatId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]*AiChatMessage, 0)
|
||||
err = cursor.All(ctx, &result)
|
||||
return result, err
|
||||
}
|
||||
func UpdateGptChatHistory(db *laniakea.DatabaseContext, chatId, role, message string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := database.GetMongoCollection(db, "gpt_chat_messages")
|
||||
_, err := col.InsertOne(ctx, AiChatMessage{
|
||||
bson.NewObjectID(),
|
||||
chatId,
|
||||
role,
|
||||
message, 0,
|
||||
})
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user