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
|
||||
}
|
||||
|
||||
@@ -61,3 +61,21 @@ func RPGetCounter(db *laniakea.DatabaseContext, userId, waifuId int) int {
|
||||
i, _ := res.Int()
|
||||
return i
|
||||
}
|
||||
|
||||
func RPSetIndex(db *laniakea.DatabaseContext, userId, waifuId, index int) error {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.index", userId, waifuId)
|
||||
return db.Redis.Set(ctx, key, index, 0).Err()
|
||||
}
|
||||
func RPGetIndex(db *laniakea.DatabaseContext, userId, waifuId int) int {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.index", userId, waifuId)
|
||||
res := db.Redis.Get(ctx, key)
|
||||
if res.Err() != nil {
|
||||
return 0
|
||||
}
|
||||
i, err := res.Int()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return i
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user