DEV Community

Cover image for window.ai - running AI LOCALLY from DevTools! 🤯

window.ai - running AI LOCALLY from DevTools! 🤯

GrahamTheDev on June 30, 2024

On-device AI in the browser is here - kinda. It is currently in Chrome canary which means, it will be here soon(ish). In this article I will show...
Collapse
 
best_codes profile image
Best Codes

Opera browser developer has a much better setup for this than Chrome. You can use literally over 100 AI models locally with no internet through Aria, Opera's built in AI.

GPT4ALL.io and Ollama are great for running models from huggingface locally on Linux, Windows, or macOS.

Nice article!

Collapse
 
grahamthedev profile image
GrahamTheDev

That is cool to know, I will have to check that out! 💗

Collapse
 
best_codes profile image
Best Codes

😁 Let me know what you think!

Collapse
 
mindplay profile image
Rasmus Schultz

Also bear in mind that each time you ask a question, it does not automatically have memory of what you asked previously.

There is an API for conversation/chat as well.

It doesn't look like there's any documentation for the JS API yet though. I'm not sure this is open source? so we might not even be able to reference the C++ code.

Based on the announcement from Google, they want us to use the API wrapper for their hosted inference, which has a built-in adapter for the JS API, which can be used with their hosted inference as a fallback.

I'd love a reply if you can find the docs or code?

Collapse
 
grahamthedev profile image
GrahamTheDev

I had a good look, but didn't find anything when I was writing this.

I imagine documentation will come once it all starts to filter down towards production.

If I do find anything I will let you know! 💗

Collapse
 
mariusbongarts profile image
Marius Bongarts

Does anyone know if it's certain that this will become a standard feature in Chrome browsers? Is it safe to start building with this API for the future?

I can't imagine all Chrome users downloading the large Gemini model. How does Chrome plan to handle this?

Collapse
 
grahamthedev profile image
GrahamTheDev

I certainly wouldn't recommend building anything substantial with an API that has not been announced or documented in any meaningful way. It is likely to change, evolve, features get deprecated, change model etc. etc. 💗

Collapse
 
devarshishimpi profile image
Devarshi Shimpi

Time to use it to summarise this article haha

Collapse
 
grahamthedev profile image
GrahamTheDev

Already done that, so that tells me you didn't read it all! hahahahah. 💗

Collapse
 
bobjames profile image
Bob James

Is it any good?
No
Is it fun to play with?
Yes
laugh out loud on this, the story of my life 🤣🤣

Collapse
 
grahamthedev profile image
GrahamTheDev

hehe, well I can't go writing articles on anything that is actually useful, it would ruin my reputation! 🤷🏼‍♂️🤣💗

Collapse
 
bobjames profile image
Bob James

i like fun things 💛💛

Collapse
 
henry_rutte profile image
Henry Rutté

Hi, I'm on chrome://components/ but it doesn't appear "Optimization Guide On Device Model". Do you know why this could be happening?

Collapse
 
grahamthedev profile image
GrahamTheDev

Check your Canary Chrome is up to date, other than that I am not sure I am afraid. 💗

Collapse
 
henry_rutte profile image
Henry Rutté • Edited

Image description

Image description

Collapse
 
ehsankey profile image
EhsanKey_

Hi, did you find a solution?
I have this problem too

Collapse
 
lyatziv profile image
Lavi Yatziv

This is pretty neat. This could open a lot of doors for accessibility and language translation.

Collapse
 
loris307_95 profile image
Loris Galler

Is this still working in the current version of 128? I tried everything but cant make it work

Collapse
 
grahamthedev profile image
GrahamTheDev

Yes still working.

Chrome version 128.0.6580.0 - up to date

Collapse
 
neolefty profile image
Bill Baker

In the console in 128, I had to do something like this instead:

let session = undefined
window.ai.createTextSession().then(s => session = s)
Enter fullscreen mode Exit fullscreen mode

Then I could do this:

await session.prompt("Say hello.")
Enter fullscreen mode Exit fullscreen mode
Collapse
 
grahamthedev profile image
GrahamTheDev

This is exactly the same, just in a more complicated way.

My guess is you missed an await the first time when creating the session constant. 💗

Collapse
 
irfnrdh profile image
Irfannur Diah

Linux is not supported. haha

Collapse
 
grahamthedev profile image
GrahamTheDev

Oh Really? That is a shame. 💗

Collapse
 
jeeva_d_603e80c912a5ba1d5 profile image
JEEVA D

is this not supported for ubuntu linux os.

Collapse
 
grahamthedev profile image
GrahamTheDev

I am afraid I have no idea, sorry. If you have run the code above on Chrome Canary and it does not function, then for some reason it would seem not.

Collapse
 
franklinthaker profile image
Franklin Thaker

Aren't you guys concerned of setting up AI in browser ? I mean, I'm ok with this in new browser which I don't use often but I don't want a Blackbox to run on my machine.

Collapse
 
grahamthedev profile image
GrahamTheDev

At the moment, no. It is heavily sandboxed.

Am I concerned for what security problems this may pose in the future. Yes, I imagine there will be security holes introduced as they give AI more freedom. 💗

Collapse
 
fmaida profile image
Francesco Maida • Edited

The disaster of Internet Explorer and ActiveX evidently taught us nothing. If this tool were to succeed, I can already imagine an entire platoon of websites and web apps that can only be used with Google Chrome.
Goodbye, browser interoperability.

Collapse
 
davilink profile image
Davilink • Edited

I was thinking the same. That was my first thought when my coworker told me about window.ai, Imagine your boss telling you that the "feature" that "you've develop" don't work correctly on firefox or safari, and you try to tell him that firefox/safari doesn't use the same model of ai that chrome use... good luck fixing that. The only way that window.ai can have a future, is that every browser uses the SAME model, because otherwise it just impossible to have the same expectation of result.