Skip to content

Commit

Permalink
Align chat sample
Browse files Browse the repository at this point in the history
  • Loading branch information
vishniakov-nikolai committed Dec 12, 2024
1 parent 6f0e0b4 commit 855c893
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 32 deletions.
28 changes: 0 additions & 28 deletions samples/js/app.js

This file was deleted.

File renamed without changes.
Empty file.
54 changes: 54 additions & 0 deletions samples/js/chat_sample/chat_sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import readline from 'readline';
import { Pipeline } from 'genai-node';

main();

function streamer(subword) {
process.stdout.write(subword);
}

async function main() {
const MODEL_PATH = process.argv[2];

if (!MODEL_PATH) {
console.error('Please specify path to model directory\n'
+ 'Run command must be: `node app.js *path_to_model_dir*`');
process.exit(1);
}

const device = 'CPU'; // GPU can be used as well

// Create interface for reading user input from stdin
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

const pipe = await Pipeline.LLMPipeline(MODEL_PATH, device);
const config = { 'max_new_tokens': 100 };

await pipe.startChat();
promptUser();

// Function to prompt the user for input
function promptUser() {
rl.question('question:\n', handleInput);
}

// Function to handle user input
async function handleInput(input) {
input = input.trim();

// Check for exit command
if (!input) {
await pipe.finishChat();
rl.close();
process.exit(0);
}

await pipe.generate(input, config, streamer);
console.log('\n----------');

promptUser();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "Apache-2.0",
"type": "module",
"devDependencies": {
"genai-node": "../../src/js/"
"genai-node": "../../../src/js/"
},
"engines": {
"node": ">=21.0.0"
Expand Down

0 comments on commit 855c893

Please sign in to comment.