Skip to content

Instantly share code, notes, and snippets.

@RahulDas-dev
Last active May 29, 2026 17:23
Show Gist options
  • Select an option

  • Save RahulDas-dev/359bc216c780e87b7b3a2bc761552451 to your computer and use it in GitHub Desktop.

Select an option

Save RahulDas-dev/359bc216c780e87b7b3a2bc761552451 to your computer and use it in GitHub Desktop.
Demonstrates Chrome's experimental built-in LanguageModel API — checks model availability, streams download progress, creates a session, and runs a prompt. Requires Chrome with the Prompt API flag enabled.
(
async () => {
try {
// Check if the built-in LLM is available
const availability = await LanguageModel.availability();
console.log('availability =', availability);
// Create a session with download-progress monitoring
window.browserSession = await LanguageModel.create({
monitor(m) {
m.addEventListener('downloadprogress', (e) => {
const pct = (e.loaded / e.total * 100).toFixed(1);
console.log(`Downloading: ${pct}%`);
});
}
});
console.log('session created');
// Run a prompt against the local model
const result = await window.browserSession.prompt(
'What is the color of the sky?'
);
console.log(result);
} catch (e) {
console.error('Error:', e);
}
}
)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment