ai work
This commit is contained in:
@@ -18,7 +18,7 @@ type RPChatMessage struct {
|
||||
func GetChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*RPChatMessage, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := database.GetMongoCollection(db, "rp_chat_history")
|
||||
col := database.GetMongoCollection(db, "rp_chat_messages")
|
||||
cursor, err := col.Find(ctx, bson.M{"chat_id": chatId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -30,7 +30,7 @@ func GetChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*RPChatMessa
|
||||
func UpdateChatHistory(db *laniakea.DatabaseContext, chatId, role, message string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := database.GetMongoCollection(db, "rp_chat_history")
|
||||
col := database.GetMongoCollection(db, "rp_chat_messages")
|
||||
_, err := col.InsertOne(ctx, RPChatMessage{
|
||||
chatId,
|
||||
role,
|
||||
|
||||
@@ -47,3 +47,17 @@ func RPGetChatPrompt(db *laniakea.DatabaseContext, userId, waifuId int) string {
|
||||
}
|
||||
return res.Val()
|
||||
}
|
||||
|
||||
func RPSetCounter(db *laniakea.DatabaseContext, userId, waifuId, counter int) error {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.counter", userId, waifuId)
|
||||
return db.Redis.Set(ctx, key, counter, 0).Err()
|
||||
}
|
||||
func RPGetCounter(db *laniakea.DatabaseContext, userId, waifuId int) int {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.counter", userId, waifuId)
|
||||
res := db.Redis.Get(ctx, key)
|
||||
if res.Err() != nil {
|
||||
return 0
|
||||
}
|
||||
i, _ := res.Int()
|
||||
return i
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user