Question about getting a model and handling downloads

11 views
Skip to first unread message

Raymond Camden

unread,
Sep 5, 2025, 10:54:27 AM (2 days ago) Sep 5
to Chrome Built-in AI Early Preview Program Discussions
For many of my demos, I take the easy way out and if the status for the API is not "available", I just abort. That's wrong of course, but was simpler, and as I'm just building demos, I figured it was ok to cut some corners.

Now - I'm trying to be better about that - and wanted to update my default code to better handle these cases. I started working on a somewhat complex wrapper that I could reuse and I realized I had over-engineered it. I have a simpler solution, and would love a sanity check. 

This sample code is for Prompt, but obviously I'd use it for all. Ok, given you've already checked for the presence of window.LanguageModel and status was either available or downloadable, consider this code:

async function doAITest() {
console.log('doAITest');
session = await LanguageModel.create({
monitor(m) {
m.addEventListener('downloadprogress', e => {
console.log(`Downloading prompt model: ${e.loaded * 100}%`);
});
}
});
console.log('hello', session);
}

From what I see - on a virgin profile, I get the download messages, and when it's done, the final console runs. On reload after download, I get the final console. 

So outside of ensuring I give proper user feedback (more than a console message), this simple code is perfectly fine to handle both cases, right?

François Beaufort

unread,
Sep 5, 2025, 11:06:43 AM (2 days ago) Sep 5
to Raymond Camden, Chrome Built-in AI Early Preview Program Discussions
Ideally, there would be a progress bar somewhere to indicate to the user what's happening while LanguageModel.create() is called.
Otherwise, LGTM ;)

--
You received this message because you are subscribed to the Google Groups "Chrome Built-in AI Early Preview Program Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chrome-ai-dev-previe...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chrome-ai-dev-preview-discuss/189c39d2-5723-4767-83cc-6dbd5aff0ab5n%40chromium.org.

Raymond Camden

unread,
Sep 5, 2025, 11:10:59 AM (2 days ago) Sep 5
to François Beaufort, Chrome Built-in AI Early Preview Program Discussions
Thank you - this will also help simplify that comic demo you're helping on. 
--
===========================================================================
Raymond Camden

Email : raymon...@gmail.com
Blog : www.raymondcamden.com
Twitter: raymondcamden

Raymond Camden

unread,
Sep 5, 2025, 1:17:09 PM (2 days ago) Sep 5
to Chrome Built-in AI Early Preview Program Discussions, Raymond Camden, Chrome Built-in AI Early Preview Program Discussions, François Beaufort
So, taking what I've learned today, I'm working on a blog post that shows "kinda" best practice for this (not saying it's perfect of course) and came up with the demo here:


Which shows a wrapper function, getLM, that lets you pass an object of options and a 'notifier' function that gets passed the current loaded value of a download. From outside, you can do:

session = await getLM({}, loaded => {
console.log(`My own notifier, loaded value is ${loaded}`);
});

Which the idea that your notifier function will do something nice in the UI for the user. So far, this works fine, but I'm seeing that the downloadprogress event *always* fires. Once for 0, once for 1. Two questions/ideas:

1) Is this just a temporary bug I can ignore?
2) If not, should my wrapper perhaps do a call to availability, and if it's available, disregard any custom notification function passed it? (

François Beaufort

unread,
Sep 5, 2025, 2:35:08 PM (2 days ago) Sep 5
to Raymond Camden, Chrome Built-in AI Early Preview Program Discussions
On Fri, Sep 5, 2025 at 7:17 PM Raymond Camden <raymon...@gmail.com> wrote:
So, taking what I've learned today, I'm working on a blog post that shows "kinda" best practice for this (not saying it's perfect of course) and came up with the demo here:


Which shows a wrapper function, getLM, that lets you pass an object of options and a 'notifier' function that gets passed the current loaded value of a download. From outside, you can do:

session = await getLM({}, loaded => {
console.log(`My own notifier, loaded value is ${loaded}`);
});

Which the idea that your notifier function will do something nice in the UI for the user. So far, this works fine, but I'm seeing that the downloadprogress event *always* fires. Once for 0, once for 1. Two questions/ideas:

1) Is this just a temporary bug I can ignore?

As highlighted in https://github.com/webmachinelearning/prompt-api?tab=readme-ov-file#download-progress, at least two events, with e.loaded === 0 and e.loaded === 1, will always be fired. This is true even if creating the model doesn't require any downloading.

Raymond Camden

unread,
Sep 5, 2025, 2:51:56 PM (2 days ago) Sep 5
to François Beaufort, Chrome Built-in AI Early Preview Program Discussions
Cool - I'll go with the option of checking the status and disabling notifications if available. And... I swear I read *most* of the docs. Honest. ;)
Reply all
Reply to author
Forward
0 new messages