@felipenmoura/laya-node 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +7 -0
- package/Dockerfile +40 -0
- package/README.md +17 -2
- package/package.json +21 -1
package/.dockerignore
ADDED
package/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Use a Python base image because AI models require heavy Python dependencies
|
|
2
|
+
FROM python:3.10-slim
|
|
3
|
+
|
|
4
|
+
# Install Node.js (required for the wrapper)
|
|
5
|
+
RUN apt-get update && apt-get install -y curl && \
|
|
6
|
+
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
|
7
|
+
apt-get install -y nodejs && \
|
|
8
|
+
npm install -g pnpm && \
|
|
9
|
+
rm -rf /var/lib/apt/lists/*
|
|
10
|
+
|
|
11
|
+
# Set the working directory
|
|
12
|
+
WORKDIR /app
|
|
13
|
+
|
|
14
|
+
# Copy package configurations
|
|
15
|
+
COPY package.json pnpm-lock.yaml* ./
|
|
16
|
+
|
|
17
|
+
# Install node dependencies
|
|
18
|
+
# (The postinstall script automatically skips the interactive python setup in Docker)
|
|
19
|
+
RUN pnpm install
|
|
20
|
+
|
|
21
|
+
# Copy application files
|
|
22
|
+
COPY . .
|
|
23
|
+
|
|
24
|
+
# Explicitly setup the python virtual environment inside the container
|
|
25
|
+
RUN python -m venv venv && \
|
|
26
|
+
./venv/bin/pip install --no-cache-dir fastapi uvicorn laya
|
|
27
|
+
|
|
28
|
+
# Pre-download the Laya model weights during the docker build to save time on container startup
|
|
29
|
+
RUN ./venv/bin/python -c "import warnings; warnings.filterwarnings('ignore'); from laya import Router; Router(preload=True)"
|
|
30
|
+
|
|
31
|
+
# Set environment variables
|
|
32
|
+
ENV PORT=4000
|
|
33
|
+
ENV MAX_LEN=8192
|
|
34
|
+
ENV SECRET_API_KEY=""
|
|
35
|
+
|
|
36
|
+
# Expose the API port
|
|
37
|
+
EXPOSE 4000
|
|
38
|
+
|
|
39
|
+
# Start the Node wrapper
|
|
40
|
+
CMD ["pnpm", "start"]
|
package/README.md
CHANGED
|
@@ -14,8 +14,9 @@ Laya is a non-autoregressive decision model designed for text classification, em
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
git clone git@github.com:felipenmoura/laya-node.git
|
|
18
|
+
cd laya-node
|
|
19
|
+
|
|
19
20
|
pnpm install
|
|
20
21
|
```
|
|
21
22
|
|
|
@@ -65,6 +66,20 @@ pnpm stop
|
|
|
65
66
|
npm run stop
|
|
66
67
|
```
|
|
67
68
|
|
|
69
|
+
### Running with Docker
|
|
70
|
+
|
|
71
|
+
You can easily containerize this wrapper and run it anywhere using Docker. The included `Dockerfile` will automatically fetch the model weights during the build phase so container startups remain fast.
|
|
72
|
+
|
|
73
|
+
To build the image:
|
|
74
|
+
```bash
|
|
75
|
+
docker build -t laya-node-wrapper .
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
To run the container (exposing port 4000):
|
|
79
|
+
```bash
|
|
80
|
+
docker run -p 4000:4000 -e SECRET_API_KEY="my-secure-key" laya-node-wrapper
|
|
81
|
+
```
|
|
82
|
+
|
|
68
83
|
## Making Predictions
|
|
69
84
|
|
|
70
85
|
Once running, send a `POST` request to `/predict`. Be sure to include your Bearer token if you enabled API Key protection during setup.
|
package/package.json
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@felipenmoura/laya-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Node wrapper for laya text classification",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Felipe N. Moura",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"type": "module",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"url": "https://github.com/felipenmoura/laya-node",
|
|
14
|
+
"type": "git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"laya",
|
|
18
|
+
"node",
|
|
19
|
+
"ai",
|
|
20
|
+
"text classification",
|
|
21
|
+
"decisions",
|
|
22
|
+
"routing",
|
|
23
|
+
"model",
|
|
24
|
+
"javascript",
|
|
25
|
+
"wrapper",
|
|
26
|
+
"api",
|
|
27
|
+
"http"
|
|
28
|
+
],
|
|
9
29
|
"scripts": {
|
|
10
30
|
"start": "node index.js",
|
|
11
31
|
"stop": "node index.js --stop",
|