Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ChromeAI #27

Merged
merged 14 commits into from
Feb 7, 2025
Merged

Add ChromeAI #27

merged 14 commits into from
Feb 7, 2025

Conversation

jtpio
Copy link
Member

@jtpio jtpio commented Jan 24, 2025

Towards #24

Experimenting with built-in (on device) AI, such as Chrome AI: https://developer.chrome.com/docs/ai/built-in

langchain.js supports it as a text completion model, still experimental for now: https://js.langchain.com/docs/integrations/llms/chrome_ai/

This requires:

  • using Google Chrome
  • enabling some flags
  • downloading the model (likely Gemini Nano), which should happen automatically on first use

One of the main advantages (omitting the browser limitation and required flag) is the zero setup needed (no API key).

jupyterlite-ai-chrome-ai.mp4

@jtpio jtpio added the enhancement New feature or request label Jan 24, 2025
This was referenced Jan 24, 2025
@jtpio jtpio marked this pull request as ready for review February 5, 2025 11:04
@jtpio
Copy link
Member Author

jtpio commented Feb 5, 2025

OK looks like we could stop here for now as this seems to be working fine, provided that requirements are met (Chrome + flags enabled).

@jtpio
Copy link
Member Author

jtpio commented Feb 6, 2025

Pushed one more commit to not discard completions that may be formatted as code blocks.

@brichet
Copy link
Collaborator

brichet commented Feb 7, 2025

Thanks @jtpio.

I had to enable more flags to download the model locally. These steps where describes in https://chromeai.org/ (the link you mentioned in the README. I wonder if we should add these steps directly in the README.

Necessary Experimental Flags

  1. chrome://flags/#prompt-api-for-gemini-nano
    Select 'Enabled'
  1. chrome://flags/#optimization-guide-on-device-model
    Select 'Enabled BypassPrefRequirement'
  1. chrome://components
    Click 'Check for Update' on Optimization Guide On Device Model to download the model. If you don't see Optimization Guide, ensure you have set the flags correctly above, relaunch your browser, and refresh the page.

@brichet
Copy link
Collaborator

brichet commented Feb 7, 2025

Also on my side this is really slow. Do you know if there are some set up to make it faster ?

@brichet
Copy link
Collaborator

brichet commented Feb 7, 2025

On a side note, I realized from you demo that the dates of messages are wrong.
I have the same locally, this probably need to be fixed in jupyter-chat.

## Using ChromeAI

> [!WARNING]
> Support for ChromeAI is still experimental and only available in Google Chrome.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if there a way to detect the browser, and have this provider available for chrome only ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just checking for window.ai availability could be enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we specify the name of the model as part of the settings definition:

"enum": ["None", "Anthropic", "ChromeAI", "MistralAI"]

Not sure there could be a nice way to dynamically enable / disable support for ChromeAI, based on window.ai? Unless we manually check for "ChromeAI" and remove it from the settings if window.ai === undefined.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure there could be a nice way to dynamically enable / disable support for ChromeAI, based on window.ai?

Yes, that settings management is already hazardous, don't no neither if we want to add more manual changes.
Maybe the way to go will be to add a dedicated configuration panel that doesn't rely on settings...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the way to go will be to add a dedicated configuration panel that doesn't rely on settings...

Agreed, sounds like it would give more flexibility 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #35

@jtpio
Copy link
Member Author

jtpio commented Feb 7, 2025

Also on my side this is really slow. Do you know if there are some set up to make it faster ?

Yeah it may be quite slow on some devices indeed.

We could mention the same list of flags as on https://chromeai.org/ for completeness, and also leave a note the performance may not be great on some devices. Not sure there is anything more to do about this at the moment.

Copy link
Collaborator

@brichet brichet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

@brichet brichet merged commit 640f525 into jupyterlite:main Feb 7, 2025
7 checks passed
@jtpio jtpio deleted the chrome-ai branch February 7, 2025 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants