-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
254 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
lib | ||
resources | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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== |