Skip to content

Commit

Permalink
v1.0 node release (#21)
Browse files Browse the repository at this point in the history
* initial node changes

* chat

* chat demo, docs and workflow

* fix build

* fix test

* update test

* fix test

* test

* fix test

* update test

* fix windows

* fix

* update

* revert

* fix test

* fix doc

* fix doc

* Rev

* rev

* FIx

* update demo

* fix

* build first

* node release
  • Loading branch information
ksyeo1010 authored May 22, 2024
1 parent cdb07e5 commit b33e25d
Show file tree
Hide file tree
Showing 33 changed files with 7,205 additions and 4 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/nodejs-demos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Node.js Demos

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- 'demo/nodejs/**'
- '!demo/nodejs/README.md'
- 'lib/node/**'
- '.github/workflows/nodejs-demos.yml'

pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- 'demo/nodejs/**'
- '!demo/nodejs/README.md'
- 'lib/node/**'
- '.github/workflows/nodejs-demos.yml'

defaults:
run:
working-directory: demo/nodejs

jobs:
build-self-hosted:
runs-on: ${{ matrix.machine }}

strategy:
fail-fast: false
matrix:
xpu: [ cpu ]
machine: [ rpi4-32, rpi4-64, rpi5-32, rpi5-64, pv-linux, pv-ios, pv-windows ]
include:
- xpu: gpu
machine: pv-linux
- xpu: gpu
machine: pv-windows

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

#### Remove after release ####

- name: Build Node.js binding
run: yarn install && yarn build
working-directory: binding/nodejs

####

- name: Install dependencies
run: yarn install

- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/latest/phi2-290.pllm -o phi2-290.pllm

- name: Test
run: yarn completion --access_key ${{secrets.PV_VALID_ACCESS_KEY}} --model_path phi2-290.pllm --completion_token_limit 10 --prompt "Hello my name is" --device ${{matrix.xpu}}
52 changes: 52 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Node.js

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- '.github/workflows/nodejs.yml'
- 'binding/nodejs/**'
- '!binding/nodejs/README.md'
- 'lib/node/**'
- 'resources/.test/**'

pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- '.github/workflows/nodejs.yml'
- 'binding/nodejs/**'
- '!binding/nodejs/README.md'
- 'lib/node/**'
- 'resources/.test/**'

defaults:
run:
working-directory: binding/nodejs

jobs:
build-self-hosted:
runs-on: ${{ matrix.machine }}

strategy:
fail-fast: false
matrix:
xpu: [ cpu ]
machine: [ rpi4-32, rpi4-64, rpi5-32, rpi5-64, pv-linux, pv-ios, pv-windows ]
include:
- xpu: gpu
machine: pv-linux
- xpu: gpu
machine: pv-windows

steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: yarn install

- name: Download resource files
run: curl http://${{secrets.PV_CICD_RES_SERVER_AUTHORITY}}/github/picollm/res/phi2-290.pllm/latest/phi2-290.pllm -o test/phi2-290.pllm

- name: Test
run: yarn test test/index.test.ts --access_key=${{secrets.PV_VALID_ACCESS_KEY}} --device=${{matrix.xpu}}
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ For more information about Python demos go to [demo/python](demo/python/README.m

### Node.js Demos

Install the demo package:

```console
yarn global add @picovoice/picollm-node-demo
```

Run the following in the terminal:

```console
picollm-completion-demo --access_key ${ACCESS_KEY} --model_path ${MODEL_PATH} --prompt ${PROMPT}
```

Replace `${ACCESS_KEY}` with yours obtained from Picovoice Console, `${MODEL_PATH}` with the path to a model file
downloaded from Picovoice Console, and `${PROMPT}` with a prompt string.

For more information about Node.js demos go to [demo/nodejs](./demo/nodejs).

### Android Demos

Using Android Studio, open the [Completion demo](demo/android/Completion/) as an Android project, copy your AccessKey into MainActivity.java, and run the application.
Expand Down Expand Up @@ -202,6 +219,26 @@ the resources using `pllm.release()`.

### Node.js SDK

Install the Node.js SDK:

```console
yarn add @picovoice/picollm-node
```

Create instances of the picoLLM class:

```javascript
const PicoLLM = require("@picovoice/picollm-node");
const pllm = new PicoLLM('${ACCESS_KEY}', '${MODEL_PATH}');

const res = pllm.generate('${PROMPT}');
console.log(res.completion);
```

Replace `${ACCESS_KEY}` with yours obtained from Picovoice Console, `${MODEL_PATH}` to the path to a model file
downloaded from Picovoice Console, and `${PROMPT}` to a prompt string. Finally, when done be sure to explicitly release
the resources using `pllm.release()`.

### Android SDK

Create an instance of the inference engine and generate a prompt completion:
Expand Down
5 changes: 5 additions & 0 deletions binding/nodejs/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
lib
resources
.eslintrc.js
Loading

0 comments on commit b33e25d

Please sign in to comment.