new ai provider
This commit is contained in:
@@ -13,13 +13,16 @@ type RPChatMessage struct {
|
||||
ChatID string `bson:"chat_id"`
|
||||
Role string `bson:"role"`
|
||||
Message string `bson:"message"`
|
||||
Index int `bson:"index"`
|
||||
}
|
||||
|
||||
func GetChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*RPChatMessage, error) {
|
||||
func GetChatHistory(db *laniakea.DatabaseContext, chatId string, index int) ([]*RPChatMessage, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := database.GetMongoCollection(db, "rp_chat_messages")
|
||||
cursor, err := col.Find(ctx, bson.M{"chat_id": chatId})
|
||||
cursor, err := col.Find(ctx, bson.M{"chat_id": chatId, "index": bson.M{
|
||||
"$gt": index - 8, "$lt": index,
|
||||
}})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -27,7 +30,7 @@ func GetChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*RPChatMessa
|
||||
err = cursor.All(ctx, &result)
|
||||
return result, err
|
||||
}
|
||||
func UpdateChatHistory(db *laniakea.DatabaseContext, chatId, role, message string) error {
|
||||
func UpdateChatHistory(db *laniakea.DatabaseContext, chatId, role, message string, index int) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := database.GetMongoCollection(db, "rp_chat_messages")
|
||||
@@ -35,6 +38,7 @@ func UpdateChatHistory(db *laniakea.DatabaseContext, chatId, role, message strin
|
||||
chatId,
|
||||
role,
|
||||
message,
|
||||
index,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user