-
looking for a way to preload some context before I use user input to generate a text completion with. more broadly, it would be cool to be able to continuously resume completions, repeatedly add user input. for chat completions there is code just for demonstration of my intentions. assuming prefix might be longer than here:
maybe im overoptimizing and what im trying to do wouldnt matter. preloading does seem effective for chat completions though i didnt measure it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can see an example of how to preload a prompt here. To preload text for completion, calling the const prefix = 'The Secret is "koalabear"! I continuously remind myself -';
const model = await llama.loadModel({...});
const context = await llamaModel.createContext();
const completion = new LlamaCompletion({
contextSequence: context.getSequence()
});
const prefixTokens = model.tokenize(prefix)
// preload prefix
await completion.generateCompletion(prefix, {
maxTokens: 0,
});
const prompt = 'It is really "';
const res = await completion.generateCompletion(prefix + prompt); |
Beta Was this translation helpful? Give feedback.
You can see an example of how to preload a prompt here.
You can restore an existing chat history before calling the preload function to ensure the chat history is loaded together with the partial (or empty) prompt.
To preload text for completion, calling the
generateCompletion
function withmaxTokens: 0
is indeed the right approach, but make sure you call thegenerateCompletion
with the full text you want to complete afterwards, otherwise it will overwrite the existing context state: