some testing ang enchancments
This commit is contained in:
@@ -34,12 +34,12 @@ func test(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func uploadPhoto(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
ctx.SendAction(laniakea.ChatActionUploadPhoto)
|
||||
photoId := ctx.Msg.Photo.Last().FileID
|
||||
f, err := ctx.Bot.GetFile(&laniakea.GetFileP{FileId: photoId})
|
||||
f, err := ctx.Api.GetFile(&laniakea.GetFileP{FileId: photoId})
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
u := laniakea.NewUploader(ctx.Bot)
|
||||
u := laniakea.NewUploader(ctx.Api)
|
||||
content, err := ctx.Bot.GetFileByLink(f.FilePath)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
|
||||
51
plugins/fun.go
Normal file
51
plugins/fun.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
)
|
||||
|
||||
func RegisterFun(bot *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("Fun")
|
||||
p.Command(beautyFont, "bf")
|
||||
p.Command(beautyFontHeart, "bfh")
|
||||
bot.AddPlugins(p.Build())
|
||||
}
|
||||
|
||||
var ligatures = map[string]string{
|
||||
"A": "𝐴", "B": "𝐵", "C": "𝐶", "D": "𝐷", "E": "𝐸", "F": "𝐹", "G": "𝐺", "H": "𝐻", "I": "𝐼", "J": "𝐽",
|
||||
"K": "𝐾", "L": "𝐿", "M": "𝑀", "N": "𝑁", "O": "𝑂", "P": "𝑃", "Q": "𝑄", "R": "𝑅", "S": "𝑆", "T": "𝑇",
|
||||
"U": "𝑈", "V": "𝑉", "W": "𝑊", "X": "𝑋", "Y": "𝑌", "Z": "𝑍",
|
||||
"a": "𝑎", "b": "𝑏", "c": "𝑐", "d": "𝑑", "e": "𝑒", "f": "𝑓", "g": "𝑔", "h": "𝘩", "i": "𝑖", "j": "𝑗",
|
||||
"k": "𝑘", "l": "𝑙", "m": "𝑚", "n": "𝑛", "o": "𝑜", "p": "𝑝", "q": "𝑞", "r": "𝑟", "s": "𝑠", "t": "𝑡", "u": "𝑢",
|
||||
"v": "𝑣", "w": "𝑤", "x": "𝑥", "y": "𝑦", "z": "𝑧",
|
||||
}
|
||||
|
||||
func beautyFont(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
m := strings.Join(ctx.Args, " ")
|
||||
out := ""
|
||||
for _, r := range m {
|
||||
beautyL, ok := ligatures[string(r)]
|
||||
if !ok {
|
||||
out += string(r)
|
||||
} else {
|
||||
out += beautyL
|
||||
}
|
||||
}
|
||||
ctx.Answer(out)
|
||||
}
|
||||
|
||||
func beautyFontHeart(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
m := strings.Join(ctx.Args, " ")
|
||||
out := ""
|
||||
for _, r := range m {
|
||||
beautyL, ok := ligatures[string(r)]
|
||||
if !ok {
|
||||
out += string(r)
|
||||
} else {
|
||||
out += beautyL
|
||||
}
|
||||
}
|
||||
ctx.Answer(out + "♡")
|
||||
}
|
||||
@@ -507,7 +507,7 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
scenariosPrompt = append(scenariosPrompt, scenario.Prompt)
|
||||
}
|
||||
|
||||
chatPrompt += "Вот дополнительная информация - " + strings.Join(scenariosPrompt, ".")
|
||||
chatPrompt += "Вот дополнительная информация: " + strings.Join(scenariosPrompt, ".")
|
||||
}
|
||||
|
||||
if chatPrompt != "" {
|
||||
@@ -526,7 +526,6 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
|
||||
err = redisRpRep.SetCounter(ctx.FromID, waifuId, 0)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
@@ -535,6 +534,7 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
|
||||
kb := laniakea.NewInlineKeyboard(2)
|
||||
kb.AddCallbackButton("На главную", "rp.info").AddCallbackButton("Закрыть", "general.close")
|
||||
ctx.EditCallback("Был создан новый чат. Для общения используй `/г промпт`.", kb)
|
||||
@@ -724,7 +724,8 @@ func regenerateResponse(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext)
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
messages, err := _getChatHistory(ctx, db)
|
||||
var messages extypes.Slice[ai.Message]
|
||||
messages, err = _getChatHistory(ctx, db)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
@@ -741,7 +742,7 @@ func regenerateResponse(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext)
|
||||
return
|
||||
}
|
||||
|
||||
if len(messages) == count {
|
||||
if messages.Len() == count {
|
||||
ctx.Bot.Logger().Errorln("len(messages) == count. ")
|
||||
return
|
||||
}
|
||||
@@ -760,8 +761,8 @@ func regenerateResponse(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext)
|
||||
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", rpUser.Model.Key)
|
||||
defer api.Close()
|
||||
|
||||
messages = utils.PopSlice(messages, count-1)
|
||||
messages = utils.PopSlice(messages, count-2)
|
||||
messages = messages.Pop(count - 1)
|
||||
messages = messages.Pop(count - 2)
|
||||
|
||||
res, err := api.CreateCompletion(messages, userReq.Content, 1.0)
|
||||
if err != nil {
|
||||
@@ -814,10 +815,14 @@ func _compress(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
})
|
||||
}
|
||||
|
||||
//compressModel := "anthropic/claude-sonnet-4"
|
||||
//compressModel := "gpt-5.1"
|
||||
compressModel := "deepseek-ai/deepseek-v3.1-terminus"
|
||||
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", compressModel)
|
||||
psqlRpRep := psql.NewRPRepository(db)
|
||||
user, err := psqlRpRep.GetUser(int64(ctx.FromID))
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", user.Model.Key)
|
||||
defer api.Close()
|
||||
res, err := api.CompressChat(messages)
|
||||
if err != nil {
|
||||
@@ -831,7 +836,7 @@ func _compress(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
compressedHistory = strings.ReplaceAll(compressedHistory, "*", "")
|
||||
|
||||
ctx.Answer(compressedHistory)
|
||||
tokens := len(compressModel)
|
||||
tokens := len(compressedHistory)
|
||||
|
||||
chatId = uuid.New().String()
|
||||
err = redisRpRep.SetChatId(ctx.FromID, waifuId, chatId)
|
||||
@@ -844,16 +849,34 @@ func _compress(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
offset := utils.Min(len(history), 20)
|
||||
for i, m := range history[len(history)-offset:] {
|
||||
offset := 50
|
||||
if user.CompressMethod == "messages" {
|
||||
offset = user.CompressLimit / 2
|
||||
}
|
||||
offset = utils.Min(len(history), offset)
|
||||
|
||||
// Copy short history from prev chat
|
||||
index := 0
|
||||
for _, m := range history {
|
||||
if m.Role == "assistant" {
|
||||
tokens += len(m.Message)
|
||||
err = mdb.UpdateRPChatHistory(db, chatId, m.Role, m.Message, index)
|
||||
index++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, m := range history[len(history)-offset:] {
|
||||
tokens += len(m.Message)
|
||||
err = mdb.UpdateRPChatHistory(db, chatId, m.Role, m.Message, i+1)
|
||||
err = mdb.UpdateRPChatHistory(db, chatId, m.Role, m.Message, index)
|
||||
index++
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
err = redisRpRep.SetCounter(ctx.FromID, waifuId, offset+1)
|
||||
err = redisRpRep.SetCounter(ctx.FromID, waifuId, index)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user