utils
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"kurumibot/database/psql"
|
"kurumibot/database/psql"
|
||||||
"kurumibot/database/red"
|
"kurumibot/database/red"
|
||||||
"kurumibot/laniakea"
|
"kurumibot/laniakea"
|
||||||
|
"kurumibot/utils"
|
||||||
"kurumibot/utils/ai"
|
"kurumibot/utils/ai"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -612,8 +613,8 @@ func compress(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//compressModel := "anthropic/claude-sonnet-4"
|
//compressModel := "anthropic/claude-sonnet-4"
|
||||||
compressModel := "gpt-5.1"
|
//compressModel := "gpt-5.1"
|
||||||
//compressModel := "deepseek-ai/deepseek-v3.2"
|
compressModel := "deepseek-ai/deepseek-v3.2"
|
||||||
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", compressModel)
|
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", compressModel)
|
||||||
res, err := api.CompressChat(messages)
|
res, err := api.CompressChat(messages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -637,10 +638,7 @@ func compress(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(err)
|
ctx.Error(err)
|
||||||
}
|
}
|
||||||
offset := 20
|
offset := utils.Min(len(history), 20)
|
||||||
if len(history) < 20 {
|
|
||||||
offset = len(history)
|
|
||||||
}
|
|
||||||
for _, m := range history[len(history)-offset:] {
|
for _, m := range history[len(history)-offset:] {
|
||||||
err = mdb.UpdateChatHistory(db, chatId, m.Role, m.Message)
|
err = mdb.UpdateChatHistory(db, chatId, m.Role, m.Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -5,3 +5,15 @@ import "math/rand/v2"
|
|||||||
func RandRange(min, max int) int {
|
func RandRange(min, max int) int {
|
||||||
return rand.IntN(max-min) + min
|
return rand.IntN(max-min) + min
|
||||||
}
|
}
|
||||||
|
func Min(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
func Max(a, b int) int {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user