diff --git a/Dockerfile b/Dockerfile index 6500eb1..dfaa5a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,19 @@ FROM golang:1.25.5-alpine3.23 AS builder +ARG BUILD_TIME +ARG GIT_COMMIT WORKDIR /usr/src/kurumi COPY go.mod go.sum ./ -RUN go mod download +RUN --mount=type=cache,target=/go/pkg/mod go mod download COPY ./database ./database COPY ./laniakea ./laniakea COPY ./plugins ./plugins COPY ./utils ./utils COPY ./main.go ./ -RUN --mount=type=cache,target=/go/pkg/mod CGO_ENABLED=0 go build -trimpath -ldflags="-s -w -X kurumibot/utils.BuildTime=$(date \"+%H:%M:%S %d.%m.%Y\")" -v -o /usr/local/bin/kurumi ./ +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + CGO_ENABLED=0 go build -trimpath \ + -ldflags="-s -w -X 'kurumibot/utils.BuildTime=$BUILD_TIME' -X 'kurumibot/utils.GitCommit=$GIT_COMMIT'" \ + -v -o /usr/local/bin/kurumi ./ FROM alpine:3.23 AS runner WORKDIR /app diff --git a/Makefile b/Makefile index 866bd51..ee8b22f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,9 @@ +export GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") +export BUILD_TIME := $(shell date "+%H:%M:%S %d.%m.%Y") + build: + @echo "Building commit $(GIT_COMMIT)" + @echo "Build time $(BUILD_TIME)" go mod tidy - docker build -t git.nix13.pw/scuroneko/kurumibotgo:latest -t git.nix13.pw/scuroneko/kurumibotgo:0.2.0 -f ./Dockerfile . + docker build --build-arg GIT_COMMIT --build-arg BUILD_TIME -t git.nix13.pw/scuroneko/kurumibotgo:latest -t git.nix13.pw/scuroneko/kurumibotgo:0.2.0 -f ./Dockerfile . docker push git.nix13.pw/scuroneko/kurumibotgo --all-tags \ No newline at end of file diff --git a/plugins/economy.go b/plugins/economy.go index 2c3b202..2bcb7d7 100644 --- a/plugins/economy.go +++ b/plugins/economy.go @@ -38,8 +38,9 @@ func RegisterEconomy(bot *laniakea.Bot) { func about(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) { out := []string{ fmt.Sprintf("Go: %s", runtime.Version()), - fmt.Sprintf("Время сборки: %s", utils.BuildTime), fmt.Sprintf("Версия Laniakea: %s", laniakea.VersionString), + fmt.Sprintf("Время сборки: %s", utils.BuildTime), + fmt.Sprintf("Git хеш: %s", utils.GitCommit), } ctx.Answer(strings.Join(out, "\n")) } diff --git a/plugins/logs.go b/plugins/logs.go index f416199..9a8a05b 100644 --- a/plugins/logs.go +++ b/plugins/logs.go @@ -28,6 +28,7 @@ func logMiddleware(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) { fmt.Println(err) } } + func DatabaseLogger(db *laniakea.DatabaseContext) laniakea.LoggerWriter { return func(level laniakea.LogLevel, prefix, traceback string, m []any) { t := time.Now() diff --git a/plugins/rp.go b/plugins/rp.go index 2222fa4..ad6179d 100644 --- a/plugins/rp.go +++ b/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) { diff --git a/utils/constants.go b/utils/constants.go index 352aa8a..bbd707d 100644 --- a/utils/constants.go +++ b/utils/constants.go @@ -1,3 +1,4 @@ package utils var BuildTime = "" +var GitCommit = ""