Skip to content

Commit e053e0d

Browse files
authored
Merge pull request #68 from camaze/support_docker_compose_cjn
【CodeFuse】Support startup with docker compose
2 parents cdba51f + 10c9b06 commit e053e0d

12 files changed

+174
-9
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,7 @@ dmypy.json
142142
**/multicache_serving.py
143143
**/modelcache_serving.py
144144

145-
**/model/
145+
**/model/
146+
147+
/data/milvus/db
148+
/data/mysql/db

Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:3.9-slim-bookworm
2+
3+
WORKDIR /home/user
4+
5+
COPY ./requirements.txt /home/user/docker_requirements.txt
6+
7+
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
8+
RUN pip install -r /home/user/docker_requirements.txt --retries 5 --timeout 120

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ModelCache
2424
- [Dependencies](#dependencies)
2525
- [Start service](#start-service)
2626
- [Start demo](#start-demo)
27+
- [Service Startup With Docker-compose](#service-startup-with-docker-compose)
2728
- [Start normal service](#start-normal-service)
2829
- [Visit the service](#visit-the-service)
2930
- [Write cache](#write-cache)
@@ -87,7 +88,23 @@ You can find the start script in `flask4modelcache.py` and `flask4modelcache_dem
8788
```shell
8889
python flask4modelcache_demo.py
8990
```
91+
#### Service Startup With Docker-compose
92+
1. Download the embedding model bin file from [Hugging Face](https://huggingface.co/shibing624/text2vec-base-chinese/tree/main). Place it in the `model/text2vec-base-chinese` folder.
93+
2. Configure docker network, only need to execute once
94+
```shell
95+
cd CodeFuse-ModelCache
96+
```
97+
```shell
98+
docker network create modelcache
99+
```
100+
3. Execute the docker-compose command
101+
```shell
102+
# When the modelcache image does not exist locally for the first time, or when the Dockerfile is changed
103+
docker-compose up --build
90104

105+
# This is not the first run and the Dockerfile has not changed
106+
docker-compose up
107+
```
91108
#### Start normal service
92109

93110
Before you start standard service, do these steps:

README_CN.md

+20
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ModelCache
2424
- [环境依赖](#环境依赖)
2525
- [启动服务](#启动服务)
2626
- [启动 Demo](#启动-demo)
27+
- [通过 docker-compose 启动服务](#通过-docker-compose-启动服务)
2728
- [启动标准服务](#启动标准服务)
2829
- [服务访问](#服务访问)
2930
- [写入 cache](#写入-cache)
@@ -89,6 +90,25 @@ Codefuse-ModelCache 是一个开源的大模型语义缓存系统,通过缓存
8990
python flask4modelcache_demo.py
9091
```
9192

93+
#### 通过 docker-compose 启动服务
94+
- 离线模型 bin 文件下载, 参考地址:[Hugging Face](https://huggingface.co/shibing624/text2vec-base-chinese/tree/main),并将下载的 bin 文件,放到 `model/text2vec-base-chinese` 文件夹中。
95+
96+
- 配置 docker network,只需执行一次
97+
```shell
98+
cd CodeFuse-ModelCache
99+
```
100+
```shell
101+
docker network create modelcache
102+
```
103+
- 执行 docker-compose 命令
104+
```shell
105+
# 首次运行本地不存在 modelcache 镜像、或 Dockerfile 变更时
106+
docker-compose up --build
107+
108+
# 非首次运行,且 Dockerfile 无变更
109+
docker-compose up
110+
```
111+
92112
#### 启动标准服务
93113

94114
在启动标准服务前,应该进行如下环境配置:

data/milvus/embedEtcd.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
listen-client-urls: http://0.0.0.0:2379
2+
advertise-client-urls: http://0.0.0.0:2379
3+
quota-backend-bytes: 4294967296
4+
auto-compaction-mode: revision
5+
auto-compaction-retention: '1000'

data/milvus/user.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Extra config to override default milvus.yaml

data/mysql/init/init.sql

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
CREATE DATABASE IF NOT EXISTS `modelcache`;
2+
3+
USE `modelcache`;
4+
5+
CREATE TABLE IF NOT EXISTS `modelcache_llm_answer` (
6+
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT comment '主键',
7+
`gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment '创建时间',
8+
`gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '修改时间',
9+
`question` text NOT NULL comment 'question',
10+
`answer` text NOT NULL comment 'answer',
11+
`answer_type` int(11) NOT NULL comment 'answer_type',
12+
`hit_count` int(11) NOT NULL DEFAULT '0' comment 'hit_count',
13+
`model` varchar(1000) NOT NULL comment 'model',
14+
`embedding_data` blob NOT NULL comment 'embedding_data',
15+
`is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'delete state(0 Not deleted,-1 deleted)',
16+
PRIMARY KEY(`id`)
17+
) AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COMMENT = 'cache_codegpt_answer';
18+
19+
CREATE TABLE IF NOT EXISTS `modelcache_query_log` (
20+
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT comment '主键',
21+
`gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment '创建时间',
22+
`gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '修改时间',
23+
`error_code` int(11) NOT NULL comment 'errorCode',
24+
`error_desc` varchar(1000) NOT NULL comment 'errorDesc',
25+
`cache_hit` varchar(100) NOT NULL comment 'cacheHit',
26+
`delta_time` float NOT NULL comment 'delta_time',
27+
`model` varchar(1000) NOT NULL comment 'model',
28+
`query` text NOT NULL comment 'query',
29+
`hit_query` text NOT NULL comment 'hitQuery',
30+
`answer` text NOT NULL comment 'answer',
31+
PRIMARY KEY(`id`)
32+
) AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COMMENT = 'modelcache_query_log';

data/mysql/my.conf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[mysqld]
2+
character-set-server=utf8mb4
3+
collation-server=utf8mb4_unicode_ci
4+
5+
[client]
6+
default-character-set=utf8mb4
7+
8+
[mysql]
9+
default-character-set=utf8mb4

docker-compose.yaml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
version: 'Beta'
2+
services:
3+
mysql:
4+
image: mysql:8.0.23
5+
container_name: mysql
6+
environment:
7+
MYSQL_ROOT_PASSWORD: 'root'
8+
MYSQL_DATABASE: 'modelcache'
9+
MYSQL_USER: 'modelcache'
10+
MYSQL_PASSWORD: 'modelcache'
11+
ports:
12+
- 3306:3306
13+
volumes:
14+
- ./data/mysql/db:/var/lib/mysql
15+
- ./data/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
16+
- ./data/mysql/init:/docker-entrypoint-initdb.d
17+
restart: on-failure
18+
networks:
19+
- modelcache
20+
21+
milvus:
22+
image: milvusdb/milvus:v2.5.0-beta
23+
container_name: milvus
24+
security_opt:
25+
- seccomp:unconfined
26+
environment:
27+
ETCD_USE_EMBED: true
28+
ETCD_DATA_DIR: /var/lib/milvus/etcd
29+
ETCD_CONFIG_PATH: /milvus/configs/embedEtcd.yaml
30+
COMMON_STORAGETYPE: local
31+
volumes:
32+
- ./data/milvus/db:/var/lib/milvus
33+
- ./data/milvus/embedEtcd.yaml:/milvus/configs/embedEtcd.yaml
34+
- ./data/milvus/user.yaml:/milvus/configs/user.yaml
35+
ports:
36+
- 19530:19530
37+
- 9091:9091
38+
- 2379:2379
39+
healthcheck:
40+
test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"]
41+
interval: 30s
42+
start_period: 90s
43+
timeout: 20s
44+
retries: 3
45+
networks:
46+
- modelcache
47+
restart: on-failure
48+
command: milvus run standalone
49+
50+
modelcache:
51+
build:
52+
context: .
53+
dockerfile: Dockerfile
54+
container_name: modelcache
55+
image: modelcache:0.1.0
56+
ports:
57+
- 5000:5000
58+
volumes:
59+
- ./model:/home/user/model
60+
- ./modelcache:/home/user/modelcache
61+
- ./modelcache_mm:/home/user/modelcache_mm
62+
- ./fastapi4modelcache.py:/home/user/fastapi4modelcache.py
63+
networks:
64+
- modelcache
65+
restart: on-failure
66+
command: sh -c "uvicorn fastapi4modelcache:app --reload --reload-dir /home/user --port=5000 --host=0.0.0.0"
67+
68+
networks:
69+
modelcache:
70+
external: true

modelcache/config/milvus_config.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[milvus]
2-
host = ''
3-
port = ''
2+
host = milvus
3+
port = 19530
44
user = ''
55
password = ''

modelcache/config/mysql_config.ini

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[mysql]
2-
host = ''
3-
port = ''
4-
username = ''
5-
password = ''
6-
database = ''
2+
host = mysql
3+
port = 3306
4+
username = modelcache
5+
password = modelcache
6+
database = modelcache

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ openai==0.28.1
77
pymilvus==2.3.1
88
PyMySQL==1.1.0
99
Requests==2.31.0
10-
torch==2.1.0
10+
torch==2.1.1
1111
transformers==4.38.2
1212
faiss-cpu==1.7.4
1313
redis==5.0.1

0 commit comments

Comments
 (0)