File size: 1,773 Bytes
ad9a66f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 这是一个临时的Dockerfile,用于在Hugging Face上部署占位符服务
# TODO: 解决完整版本的依赖问题后替换此文件

# 第一阶段:构建Go服务
FROM golang:1.20-alpine AS go-builder

# 安装基本依赖
RUN apk add --no-cache git build-base ca-certificates

# 设置工作目录
WORKDIR /app

# 初始化go.mod
RUN go mod init tokenizer

# 预先下载依赖
RUN go get github.com/google/generative-ai-go/[email protected]
RUN go get google.golang.org/[email protected]
RUN go get github.com/gin-gonic/[email protected]
RUN go get github.com/go-playground/validator/[email protected]
RUN go get github.com/gabriel-vasile/[email protected]

# 复制源代码
COPY main.go .

# 确保依赖关系
RUN go mod tidy
RUN go mod download

# 构建
RUN CGO_ENABLED=0 GOOS=linux go build -o tokenizer -a -installsuffix cgo -ldflags="-w -s" .

# 第二阶段:构建Python环境
FROM python:3.9-slim

# 安装基本依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# 设置工作目录
WORKDIR /app

# 复制Go二进制文件
COPY --from=go-builder /app/tokenizer .

# 复制Python服务文件和tokenizer文件
COPY deepseek_v3_tokenizer /app/deepseek_v3_tokenizer
COPY openai_service.py /app/

# 安装Python依赖
RUN pip install --no-cache-dir flask transformers tiktoken

# 设置环境变量
ENV GIN_MODE=release
ENV PORT=7860
ENV DEEPSEEK_URL=http://127.0.0.1:7861
ENV OPENAI_URL=http://127.0.0.1:7862

# 创建启动脚本
RUN echo '#!/bin/sh\n\
python /app/deepseek_v3_tokenizer/deepseek_service.py & \n\
python /app/openai_service.py & \n\
sleep 5\n\
./tokenizer' > /app/start.sh && chmod +x /app/start.sh

# 暴露端口
EXPOSE 7860 7861 7862

# 启动服务
CMD ["/app/start.sh"]