const session = await LanguageModel.create();
session.addEventListener("contextoverflow", () => {
console.warn("Context overflow detected.");
});LanguageModel: contextoverflow event / notebook
LanguageModel: contextoverflow event
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const session = await LanguageModel.create();
session.oncontextoverflow = () => {
console.warn(
"The session's context window is full. " +
"Consider cloning the session or starting a new one.",
);
};let session = await LanguageModel.create({
initialPrompts: [{ role: "system", content: "You are a helpful assistant." }],
});
session.addEventListener("contextoverflow", async () => {
console.log("Context full — creating a fresh session.");
session.destroy();
session = await LanguageModel.create({
initialPrompts: [
{ role: "system", content: "You are a helpful assistant." },
],
});
});
async function chat(userMessage) {
const response = await session.prompt(userMessage);
return response;
}