Last active
May 29, 2026 17:23
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ( | |
| 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