Closed sooraj007 closed 9 months ago
@sooraj007 It'll be possible to do this in the next beta version
@sooraj007 Until the next beta is ready, you can use this workaround.
The workaround consists of clearing the context sequence and creating a new ChatSession
with the messages you want to have in it:
Relevant for the
3.0.0-beta.1
versionimport {fileURLToPath} from "url"; import path from "path"; import {LlamaModel, LlamaContext, LlamaChatSession} from "node-llama-cpp";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const model = new LlamaModel({ modelPath: path.join(__dirname, "models", "dolphin-2.1-mistral-7b.Q4_K_M.gguf") }); const context = new LlamaContext({ model, contextSize: Math.min(4096, model.trainContextSize) }); const contextSequence = context.getSequence(); const session = new LlamaChatSession({ contextSequence });
const q1 = "Hi there, how are you?"; console.log("User: " + q1);
const a1 = await session.prompt(q1); console.log("AI: " + a1);
const q2 = "Summerize what you said"; console.log("User: " + q2);
const a2 = await session.prompt(q2); console.log("AI: " + a2);
// clear the context sequence await contextSequence.eraseContextTokenRanges([start: 0, end: contextSequence.nextTokenIndex]);
// create a new chat session on the same context sequence const newSession = new LlamaChatSession({ contextSequence, conversationHistory: [] // restore your conversation history without the last message that you want to discard });
@giladgd thanks , its works , please create a discord group if you got time it would be great. and node-llama-cpp is awesome great work.
@sooraj007 It's a great idea :) I'll do that soon after I finish developing the next version
Issue description
So i am creating a question and answer bot i dont want to add my previous chat messages to session, due to adding my context limit get exausted
Expected Behavior
i want the ability to not saving anything to session or ability to clear session contexts
Actual Behavior
after some chat it quicky exhausted and throwing error
Steps to reproduce
after some chat it quicky exhausted and throwing error
My Environment
node-llama-cpp
versionAdditional Context
No response
Relevant Features Used
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, and I know how to start.