Skip to content

Commit 64d7ea5

Browse files
authored
update setup scripts (#10)
* update build commands Signed-off-by: cbh778899 <[email protected]> * add copyright statement Signed-off-by: cbh778899 <[email protected]> * update env Signed-off-by: cbh778899 <[email protected]> * update readme Signed-off-by: cbh778899 <[email protected]> * change monitor route to stats Signed-off-by: cbh778899 <[email protected]> --------- Signed-off-by: cbh778899 <[email protected]>
1 parent 87bc994 commit 64d7ea5

17 files changed

+225
-16
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
APP_PORT=8000
2+
ENG_ACCESS_PORT=8080
3+
MODEL_SAVE_PATH=volumes/models
24
INFERENCE_ENG=llamacpp
35
INFERENCE_ENG_PORT=8080
46
INFERENCE_ENG_VERSION=server--b1-2321a5e

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ APP_PORT:=8000
55
# compose build related
66
ENV_FILE:=.env
77

8+
ENG_ACCESS_PORT:=8080
9+
MODEL_SAVE_PATH:=volumes/models
10+
811
INFERENCE_ENG:=llamacpp
912
INFERENCE_ENG_PORT:=8080
1013
INFERENCE_ENG_VERSION:=server--b1-2321a5e
@@ -32,6 +35,8 @@ run: build
3235
.PHONY: env
3336
env:
3437
@echo "APP_PORT=$(APP_PORT)"> $(ENV_FILE)
38+
@echo "ENG_ACCESS_PORT=$(ENG_ACCESS_PORT)">> $(ENV_FILE)
39+
@echo "MODEL_SAVE_PATH=$(MODEL_SAVE_PATH)">> $(ENV_FILE)
3540
@echo "INFERENCE_ENG=$(INFERENCE_ENG)">> $(ENV_FILE)
3641
@echo "INFERENCE_ENG_PORT=$(INFERENCE_ENG_PORT)">> $(ENV_FILE)
3742
@echo "INFERENCE_ENG_VERSION=$(INFERENCE_ENG_VERSION)">> $(ENV_FILE)
@@ -44,8 +49,13 @@ env:
4449
@echo "EMBEDDING_MODEL_NAME=$(EMBEDDING_MODEL_NAME)">> $(ENV_FILE)
4550
@echo "EMBEDDING_MODEL_URL=$(EMBEDDING_MODEL_URL)">> $(ENV_FILE)
4651

52+
.PHONY: model-prepare
53+
model-prepare:
54+
@mkdir -p $(MODEL_SAVE_PATH) && [ -f $(MODEL_SAVE_PATH)/$(LANGUAGE_MODEL_NAME) ] || wget -O $(MODEL_SAVE_PATH)/$(LANGUAGE_MODEL_NAME) $(LANGUAGE_MODEL_URL)
55+
@mkdir -p $(MODEL_SAVE_PATH) && [ -f $(MODEL_SAVE_PATH)/$(EMBEDDING_MODEL_NAME) ] || wget -O $(MODEL_SAVE_PATH)/$(EMBEDDING_MODEL_NAME) $(EMBEDDING_MODEL_URL)
56+
4757
.PHONY: compose-build
48-
compose-build: env
58+
compose-build: env model-prepare
4959
@docker compose -f docker-compose.yaml build
5060

5161
.PHONY: up

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ This project is OpenAI-like API set for SkywardAI project.
44
## BUILD & RUN
55

66
### Local Machine
7+
* Please make sure you installed `Node.js` on your local machine.
78
* This project developed on Node Version `v20.15.0`.
8-
* Make sure you installed `Node.js`.
99

1010
```shell
1111
# Manage package by pnpm
@@ -22,7 +22,8 @@ npm run
2222
```
2323

2424
### Container
25-
**Please make sure you have `docker` and `make` installed in your server**
25+
* Please make sure you have `docker` and `make` installed in your server.
26+
* Docker version for testing is `27.0.3, build 7d4bcd8`.
2627
```shell
2728
# to simply start with all needed containers started, please run
2829
make up
@@ -40,4 +41,4 @@ npm run lint
4041
```
4142

4243
## Monitor
43-
This project got monitor build with swagger-stats, when you got this project running, just go to `<Your Server>:<Your Port>/swagger-stats`
44+
This project got monitor build with swagger-stats, when you got this project running, just go to `<Your Server>:<Your Port>/stats`

actions/inference.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// coding=utf-8
2+
3+
// Copyright [2024] [SkywardAI]
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
116
import { formatOpenAIContext } from "../tools/formatContext.js";
217
import { generateFingerprint } from "../tools/generator.js";
318
import { post } from "../tools/request.js";

docker-compose.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,47 @@ services:
22
llamacpp:
33
container_name: ${INFERENCE_ENG}
44
image: gclub/llama.cpp:${INFERENCE_ENG_VERSION}
5-
restart: no
5+
restart: always
66
deploy: # https://github.com/compose-spec/compose-spec/blob/master/deploy.md
77
resources:
88
reservations:
99
cpus: "${NUM_CPU_CORES}"
1010
volumes:
11-
- "${DOCKER_VOLUME_DIRECTORY:-.}/volumes/models:/models"
11+
- "${DOCKER_VOLUME_DIRECTORY:-.}/${MODEL_SAVE_PATH}:/models"
1212
expose:
13-
- 8080
13+
- ${ENG_ACCESS_PORT}
1414
ports:
15-
- ${INFERENCE_ENG_PORT}:8080
15+
- ${INFERENCE_ENG_PORT}:${ENG_ACCESS_PORT}
1616
command: ["-m", "models/${LANGUAGE_MODEL_NAME}","-c","8192"]
1717

1818
embedding_eng:
1919
container_name: ${EMBEDDING_ENG}
2020
image: gclub/llama.cpp:${INFERENCE_ENG_VERSION}
21-
restart: no
21+
restart: always
2222
deploy: # https://github.com/compose-spec/compose-spec/blob/master/deploy.md
2323
resources:
2424
reservations:
2525
cpus: "${NUM_CPU_CORES_EMBEDDING}"
2626
volumes:
27-
- "${DOCKER_VOLUME_DIRECTORY:-.}/volumes/models:/models"
27+
- "${DOCKER_VOLUME_DIRECTORY:-.}/${MODEL_SAVE_PATH}:/models"
2828
expose:
29-
- 8080
29+
- ${ENG_ACCESS_PORT}
3030
ports:
31-
- ${EMBEDDING_ENG_PORT}:8080
31+
- ${EMBEDDING_ENG_PORT}:${ENG_ACCESS_PORT}
3232
command: ["-m", "models/${EMBEDDING_MODEL_NAME}","--embeddings","--pooling","mean","-c","512"]
3333

3434
voyager:
3535
container_name: voyager
36-
restart: no
36+
restart: always
3737
build:
3838
dockerfile: Dockerfile
3939
context: .
4040
volumes:
4141
- .:/app
4242
expose:
43-
- 8000
43+
- ${APP_PORT}
4444
ports:
45-
- 8000:8000
45+
- ${APP_PORT}:${APP_PORT}
4646
depends_on:
4747
- llamacpp
4848
- embedding_eng

healthy-check.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1+
// coding=utf-8
2+
3+
// Copyright [2024] [SkywardAI]
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
116
await fetch('http://localhost:8000/healthy');
217
console.log('Healthy check passed.')

index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// coding=utf-8
2+
3+
// Copyright [2024] [SkywardAI]
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
116
import express from 'express';
217
import cors from 'cors';
318
import bodyParser from 'body-parser';
@@ -13,7 +28,8 @@ const app = express();
1328
app.use(cors());
1429
app.use(bodyParser.json());
1530
app.use(swStats.getMiddleware({
16-
name: "Voyager Swagger Monitor"
31+
name: "Voyager Swagger Monitor",
32+
uriPath: '/stats'
1733
}))
1834

1935
buildRoutes(app);

routes/decoder.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// coding=utf-8
2+
3+
// Copyright [2024] [SkywardAI]
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
116
import { Router } from "express";
217

318
export default function decoderRoute() {

routes/embedding.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// coding=utf-8
2+
3+
// Copyright [2024] [SkywardAI]
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
116
import { Router } from "express";
217

318
export default function embeddingRoute() {

routes/encoder.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// coding=utf-8
2+
3+
// Copyright [2024] [SkywardAI]
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
116
import { Router } from "express";
217

318
export default function encoderRoute() {

0 commit comments

Comments
 (0)