docker compose

This commit is contained in:
1iaan
2026-04-04 16:30:54 +08:00
parent c1a895258f
commit e993eb6c5c
25 changed files with 241 additions and 95 deletions

View File

@@ -1,11 +1,24 @@
FROM chenzhaoyu94/chatgpt-web:v2.10.9 as frontend
FROM arvintian/chatgpt-web-base:v1
COPY --from=frontend /app/public /app/public
ADD dist/server /app/server
EXPOSE 7080
CMD ["/app/server"]
FROM golang:1.23-alpine AS builder
WORKDIR /src
ENV GOPROXY=https://goproxy.cn,direct
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -ldflags="-w -s" -o /out/server ./cmd/main.go
FROM alpine:3.20
WORKDIR /app
RUN apk add --no-cache ca-certificates tzdata
COPY --from=builder /out/server /app/server
COPY ./www /app/www
EXPOSE 7080
CMD ["/app/server"]

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"
"github.com/sashabaranov/go-openai"
)
@@ -16,7 +17,13 @@ type tokenInfo struct {
}
func GetTokenCount(message openai.ChatCompletionMessage, model string) (int, error) {
url := fmt.Sprintf("http://127.0.0.1:5000/tokenizer/%s", model)
// url := fmt.Sprintf("http://127.0.0.1:5000/tokenizer/%s", model)
tokenizerBaseURL := os.Getenv("TOKENIZER_BASE_URL")
if tokenizerBaseURL == "" {
tokenizerBaseURL = "http://tokenizer:3002"
}
url := fmt.Sprintf("%s/tokenizer/%s", tokenizerBaseURL, model)
info := tokenInfo{}
if err := postJSON(url, &message, &info); err != nil {
return 0, err