big build optimization
This commit is contained in:
108
plugins/rp.go
108
plugins/rp.go
@@ -146,6 +146,11 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
err = redisRpRep.SetChatTokens(ctx.FromID, waifuId, 0)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
ctx.Answer("Был создан новый чат")
|
||||
}
|
||||
|
||||
@@ -297,59 +302,58 @@ func generate(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
//kb.AddCallbackButton("Перегенерировать", laniakea.CallbackData{Command: "rp.tokens"})
|
||||
//ctx.Keyboard("Test", kb)
|
||||
ctx.Answer(laniakea.EscapeMarkdown(agentAnswer.Content))
|
||||
return
|
||||
|
||||
counter := redisRpRep.GetCounter(ctx.FromID, waifuId) + 1
|
||||
if counter == 20 {
|
||||
m := ctx.Answer("Запущено сжатие чата.")
|
||||
history, err = mdb.GetChatHistory(db, chatId)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
messages = make([]ai.Message, 0)
|
||||
for _, m := range history {
|
||||
messages = append(messages, ai.Message{
|
||||
Role: m.Role,
|
||||
Content: m.Message,
|
||||
})
|
||||
}
|
||||
res, err = api.CompressChat(messages)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
if len(res.Choices) == 0 {
|
||||
m.Edit("Не удалось сжать диалог")
|
||||
return
|
||||
}
|
||||
|
||||
compressedHistory := res.Choices[0].Message.Content
|
||||
|
||||
chatId = uuid.New().String()
|
||||
err := redisRpRep.SetChatId(ctx.FromID, waifuId, chatId)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
err = mdb.UpdateChatHistory(db, chatId, "assistant", compressedHistory)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
err = mdb.UpdateChatHistory(db, chatId, agentAnswer.Role, agentAnswer.Content)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
counter = 0
|
||||
m.Edit("Сжатие завершено")
|
||||
}
|
||||
err = redisRpRep.SetCounter(ctx.FromID, waifuId, counter)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
//counter := redisRpRep.GetCounter(ctx.FromID, waifuId) + 1
|
||||
//if counter == 20 {
|
||||
// m := ctx.Answer("Запущено сжатие чата.")
|
||||
// history, err = mdb.GetChatHistory(db, chatId)
|
||||
// if err != nil {
|
||||
// ctx.Error(err)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// messages = make([]ai.Message, 0)
|
||||
// for _, m := range history {
|
||||
// messages = append(messages, ai.Message{
|
||||
// Role: m.Role,
|
||||
// Content: m.Message,
|
||||
// })
|
||||
// }
|
||||
// res, err = api.CompressChat(messages)
|
||||
// if err != nil {
|
||||
// ctx.Error(err)
|
||||
// }
|
||||
// if len(res.Choices) == 0 {
|
||||
// m.Edit("Не удалось сжать диалог")
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// compressedHistory := res.Choices[0].Message.Content
|
||||
//
|
||||
// chatId = uuid.New().String()
|
||||
// err := redisRpRep.SetChatId(ctx.FromID, waifuId, chatId)
|
||||
// if err != nil {
|
||||
// ctx.Error(err)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// err = mdb.UpdateChatHistory(db, chatId, "assistant", compressedHistory)
|
||||
// if err != nil {
|
||||
// ctx.Error(err)
|
||||
// return
|
||||
// }
|
||||
// err = mdb.UpdateChatHistory(db, chatId, agentAnswer.Role, agentAnswer.Content)
|
||||
// if err != nil {
|
||||
// ctx.Error(err)
|
||||
// return
|
||||
// }
|
||||
// counter = 0
|
||||
// m.Edit("Сжатие завершено")
|
||||
//}
|
||||
//err = redisRpRep.SetCounter(ctx.FromID, waifuId, counter)
|
||||
//if err != nil {
|
||||
// ctx.Error(err)
|
||||
//}
|
||||
}
|
||||
|
||||
func chatStat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
|
||||
Reference in New Issue
Block a user