Public
Edited
Nov 20, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
async function getGeminiNanoCompletionStream(
systemPrompt,
prompt,
{ temperature = 0.0, topK = 3 } = {}
) {
const outputElement = document.getElementById("nano-output");
outputElement.textContent = "";

if (prompt.length == 0) {
return;
}

if ((await ai?.languageModel?.capabilities())?.available !== "readily") {
outputElement.textContent =
"Sorry! It seems like your browser does not have access to Gemini Nano. 😞";
return;
}

const session = await ai.languageModel.create({
temperature: temperature,
topK: topK,
systemPrompt: systemPrompt
});

const stream = await session.promptStreaming(prompt);

for await (const part of stream) {
outputElement.textContent = part;
}
}
Insert cell
import { guard } from "@mootari/inputs-submit"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more