feat: add LlamaCompletion that provides the ability to complete or infill text
feat: support configuring more options for getLlama when using "lastBuild"
fix: various bug fixes
Infill, also known as fill-in-middle, is used to generate a completion for an input that should connect to a given continuation.
For example, for a prefix input 123 and suffix input 789, the model is expected to generate 456 to make the final text be 123456789.
Not every model supports infill, so only those that do can be used for generating an infill.
How to generate a completion
import {fileURLToPath} from "url";
import path from "path";
import {getLlama, LlamaModel, LlamaContext, LlamaCompletion} from "node-llama-cpp";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const llama = await getLlama();
const model = new LlamaModel({
llama,
modelPath: path.join(__dirname, "models", "stable-code-3b.Q5_K_M.gguf")
});
const context = new LlamaContext({
model,
contextSize: Math.min(4096, model.trainContextSize)
});
const completion = new LlamaCompletion({
contextSequence: context.getSequence()
});
const input = "const arrayFromOneToTwenty = [1, 2, 3,";
console.log("Input: " + input);
const res = await completion.generateCompletion(input);
console.log("Completion: " + res);
[x] This pull request links relevant issues as Fixes #0000
[x] There are new or updated unit tests validating the change
[ ] Documentation has been updated to reflect this change
[x] The new commits and pull request title follow conventions explained in pull request guidelines (PRs that do not follow this convention will not be merged)
Description of change
LlamaCompletion
that provides the ability to complete or infill textgetLlama
when using"lastBuild"
Infill, also known as fill-in-middle, is used to generate a completion for an input that should connect to a given continuation. For example, for a prefix input
123
and suffix input789
, the model is expected to generate456
to make the final text be123456789
.Not every model supports infill, so only those that do can be used for generating an infill.
How to generate a completion
How to generate an infill
Pull-Request Checklist
master
branchnpm run format
to apply eslint formattingnpm run test
passes with this changeFixes #0000