big build optimization

This commit is contained in:
2026-01-22 10:27:08 +03:00
parent 3489d0fff2
commit 8c44707434
6 changed files with 74 additions and 56 deletions

View File

@@ -1,13 +1,19 @@
FROM golang:1.25.5-alpine3.23 AS builder FROM golang:1.25.5-alpine3.23 AS builder
ARG BUILD_TIME
ARG GIT_COMMIT
WORKDIR /usr/src/kurumi WORKDIR /usr/src/kurumi
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN --mount=type=cache,target=/go/pkg/mod go mod download
COPY ./database ./database COPY ./database ./database
COPY ./laniakea ./laniakea COPY ./laniakea ./laniakea
COPY ./plugins ./plugins COPY ./plugins ./plugins
COPY ./utils ./utils COPY ./utils ./utils
COPY ./main.go ./ 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 FROM alpine:3.23 AS runner
WORKDIR /app WORKDIR /app

View File

@@ -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: build:
@echo "Building commit $(GIT_COMMIT)"
@echo "Build time $(BUILD_TIME)"
go mod tidy 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 docker push git.nix13.pw/scuroneko/kurumibotgo --all-tags

View File

@@ -38,8 +38,9 @@ func RegisterEconomy(bot *laniakea.Bot) {
func about(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) { func about(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
out := []string{ out := []string{
fmt.Sprintf("Go: %s", runtime.Version()), fmt.Sprintf("Go: %s", runtime.Version()),
fmt.Sprintf("Время сборки: %s", utils.BuildTime),
fmt.Sprintf("Версия Laniakea: %s", laniakea.VersionString), fmt.Sprintf("Версия Laniakea: %s", laniakea.VersionString),
fmt.Sprintf("Время сборки: %s", utils.BuildTime),
fmt.Sprintf("Git хеш: %s", utils.GitCommit),
} }
ctx.Answer(strings.Join(out, "\n")) ctx.Answer(strings.Join(out, "\n"))
} }

View File

@@ -28,6 +28,7 @@ func logMiddleware(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
fmt.Println(err) fmt.Println(err)
} }
} }
func DatabaseLogger(db *laniakea.DatabaseContext) laniakea.LoggerWriter { func DatabaseLogger(db *laniakea.DatabaseContext) laniakea.LoggerWriter {
return func(level laniakea.LogLevel, prefix, traceback string, m []any) { return func(level laniakea.LogLevel, prefix, traceback string, m []any) {
t := time.Now() t := time.Now()

View File

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

View File

@@ -1,3 +1,4 @@
package utils package utils
var BuildTime = "" var BuildTime = ""
var GitCommit = ""