Skip to content

Commit

Permalink
Demo and workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ErisMik committed Apr 22, 2024
1 parent 2a201ba commit ae3ce17
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 84 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/nodejs-codesyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Node.js Codestyle

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- '**/nodejs/*.js'
- '**/nodejs/*.ts'
- '.github/workflows/nodejs-codestyle.yml'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- '**/nodejs/*.js'
- '**/nodejs/*.ts'
- '.github/workflows/nodejs-codestyle.yml'

jobs:
check-nodejs-codestyle:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node.js LTS
uses: actions/setup-node@v3
with:
node-version: lts/*

- name: Pre-build dependencies
run: npm install yarn

- name: Run Binding Linter
run: yarn && yarn lint
working-directory: binding/nodejs
52 changes: 52 additions & 0 deletions .github/workflows/nodejs-demos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Node.js Demos

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

pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- 'demo/nodejs/**'
- 'demo/expressjs/**'
- '!demo/nodejs/README.md'
- '!demo/expressjs/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:
machine: [rpi4-32, rpi4-64, rpi5-32, rpi5-64, pv-linux, pv-ios, pv-windows]

steps:
- uses: actions/checkout@v3

- name: Install and build Node Binding
run: yarn && 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.bin/latest/phi2-290.bin -o phi2-290.bin

- name: Test
run: yarn generate --access_key ${{secrets.PV_VALID_ACCESS_KEY}} --model_file_path phi2-290.bin --completion_token_limit 10 --generate "Hello my name is"
2 changes: 0 additions & 2 deletions .github/workflows/nodejs-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
- '!binding/nodejs/README.md'
- 'lib/common/**'
- 'lib/node/**'
- 'resources/audio_samples/**'
- 'resources/.test/**'

pull_request:
Expand All @@ -21,7 +20,6 @@ on:
- '!binding/nodejs/README.md'
- 'lib/common/**'
- 'lib/node/**'
- 'resources/audio_samples/**'
- 'resources/.test/**'

defaults:
Expand Down
2 changes: 1 addition & 1 deletion binding/nodejs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export enum PicoLLMEndpoint {
EndOfSentence = 0,
CompletionTokenLimitReached = 1,
StopPhraseEncountered = 2,
};
}

export type PicoLLMToken = {
token: string;
Expand Down
2 changes: 1 addition & 1 deletion binding/nodejs/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
'use strict';

import { PicoLLM, PicoLLMCompletion } from '../src';
import { PicoLLM, PicoLLMCompletion } from '../src';

import * as fs from 'fs';

Expand Down
80 changes: 0 additions & 80 deletions binding/nodejs/test/test_utils.ts

This file was deleted.

4 changes: 4 additions & 0 deletions demo/nodejs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
lib
resources
package-lock.json
1 change: 1 addition & 0 deletions demo/nodejs/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 5 additions & 0 deletions demo/nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# PicoLLM Demos

Made in Vancouver, Canada by [Picovoice](https://picovoice.ai)

## PicoLLM
95 changes: 95 additions & 0 deletions demo/nodejs/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#! /usr/bin/env node
//
// Copyright 2022-2023 Picovoice Inc.
//
// You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
// file accompanying this source.
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
//
"use strict";

const { program } = require("commander");
const fs = require("fs");

const { PicoLLM, PicoLLMActivationLimitReachedError } = require("@picovoice/picollm-node");


program
.requiredOption(
"-a, --access_key <string>",
"AccessKey obtain from the Picovoice Console (https://con sole.picovoice.ai/)"
)
.requiredOption(
"-m, --model_file_path <string>",
"absolute path to picollm model"
)
.requiredOption(
"-g, --generate <string>",
"prompt"
)
.option(
"-d, --device <string>",
"device string to run engine on"
)
.option(
"-c, --completion_token_limit <number>",
"completion token limit"
)
.option(
"-l, --library_file_path <string>",
"absolute path to picollm dynamic library"
)
.option("-v, --verbose", "verbose mode, prints usage");


if (process.argv.length < 2) {
program.help();
}
program.parse(process.argv);

function demo() {
let accessKey = program["access_key"]
let modelFilePath = program["model_file_path"];
let generate = program["generate"];
let device = program["device"];
let completionTokenLimit = parseInt(program["completion_token_limit"]);
let libraryFilePath = program["library_file_path"];
let verbose = program["verbose"];

let engineInstance = new PicoLLM(
accessKey,
modelFilePath,
{
'device': device,
'libraryPath': libraryFilePath,
}
);

try {
const res = engineInstance.generate(
generate,
{
'completionTokenLimit': isNaN(completionTokenLimit) ? 128 : completionTokenLimit,
'streamCallback': (completion => process.stdout.write(completion))
}
);
console.log("\n");
if (verbose) {
console.log("Prompt Tokens: " + res.usage.prompt_tokens);
console.log("Completion Tokens: " + res.usage.completion_tokens);
}
} catch (err) {
if (err instanceof PicoLLMActivationLimitReachedError) {
console.error(`AccessKey '${accessKey}' has reached it's processing limit.`);
} else {
console.error(err);
}
}

engineInstance.release();
}

demo();
39 changes: 39 additions & 0 deletions demo/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@picovoice/picollm-node-demo",
"version": "2.0.2",
"description": "Picovoice PicoLLM Node.js demos",
"scripts": {
"generate": "node generate.js"
},
"bin": {
"picollm-generate-demo": "./generate.js",
"picollm-mic-demo": "./mic.js"
},
"keywords": [
"picollm, picovoice, nlu, offline, private, voice ai, speech recognition, microphone, mic, realtime"
],
"author": "Picovoice Inc.",
"license": "Apache-2.0",
"dependencies": {
"@picovoice/picollm-node": "../../binding/nodejs",
"commander": "^6.1.0",
"readline": "^1.3.0",
"prettier": "^2.6.2"
},
"devDependencies": {},
"homepage": "https://picovoice.ai/platform/picollm/",
"repository": {
"type": "git",
"url": "https://github.com/Picovoice/picollm.git",
"directory": "demo/nodejs"
},
"engines": {
"node": ">=16.0.0"
},
"cpu": [
"!ia32",
"!mips",
"!ppc",
"!ppc64"
]
}
21 changes: 21 additions & 0 deletions demo/nodejs/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@picovoice/picollm-node@../../binding/nodejs":
version "0.0.1"

commander@^6.1.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c"
integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==

prettier@^2.6.2:
version "2.8.8"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==

readline@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/readline/-/readline-1.3.0.tgz#c580d77ef2cfc8752b132498060dc9793a7ac01c"
integrity sha512-k2d6ACCkiNYz222Fs/iNze30rRJ1iIicW7JuX/7/cozvih6YCkFZH+J6mAFDVgv0dRBaAyr4jDqC95R2y4IADg==

0 comments on commit ae3ce17

Please sign in to comment.