-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (24 loc) · 918 Bytes
/
Copy pathindex.js
File metadata and controls
30 lines (24 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { pipeline } = require("@xenova/transformers");
const readlineSync = require('readline-sync');
async function generateCode(prompt) {
const modelPipeline = await require("@xenova/transformers");
const pipelineFunction = modelPipeline.pipeline;
const results = await pipelineFunction("text-generation", {
model: "bigcode/starcoder2-7b"
})(prompt, { max_length: 50 });
return results[0].generated_text;
}
async function main() {
while (true) {
console.log("What kind of code would you like to generate?");
let prompt = readlineSync.question();
const generatedCode = await generateCode(prompt);
console.log("Generated Code:\n", generatedCode);
console.log("Would you like to generate more code (y/n)?");
let answer = readlineSync.question().toLowerCase();
if (answer !== "y") {
break;
}
}
}
main();