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;
}
}