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 Chrome AI as a Provider for our text generation Features #819

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

dkotter
Copy link
Collaborator

@dkotter dkotter commented Oct 16, 2024

Description of the Change

Chrome is experimenting with adding built-in AI to their browser. The model they include is fairly lightweight and doesn't give quite as good results as larger models, but since it's built-in, there's no cost and all data stays private (also allows easy testing of some AI features without having to sign up for something).

At the moment, this feature is still being worked on and is only available in Chrome Canary, so there's a chance this never releases publicly or it may change quite a bit before the public release.

This PR integrates this browser AI API into our Title Generation, Excerpt Generation and Content Resizing Features. Because this API is 100% javascript, the way we integrate is a little unique compared to our other Providers:

  • We still register a new Provider for Chrome AI
  • This Provider still listens for REST requests on the same endpoint as our other Providers
  • Instead of sending off API requests when a REST request comes in, we return the prompt and content
  • I've added a new helper JS method that checks if the Chrome AI API is available
  • This helper method is now used if the REST request returns the above data instead of the existing data structure. The AI request is then made at the javascript level, passing in the prompt and content returned from the REST request

How to test the Change

  1. Install Chrome Canary v128.0.6545.0 or newer
  2. Open a new tab in Chrome, go to chrome://flags/#optimization-guide-on-device-model and select Enabled BypassPerfRequirement
  3. Go to chrome://flags/#prompt-api-for-gemini-nano and select Enabled
  4. Relaunch Chrome
  5. Open DevTools and send (await ai.languageModel.capabilities()).available; in the console
  6. If this returns “readily”, then you are all set
  7. If it fails, force Chrome to recognize that you want to use this API. To do so, open DevTools and send await ai.languageModel.create(); in the console. This will likely fail but it’s intended
  8. Relaunch Chrome
  9. Open a new tab in Chrome, go to chrome://components
  10. Confirm that Gemini Nano is either available or is being downloaded. You'll want to see the Optimization Guide On Device Model present with a version greater or equal to 2024.5.21.1031. If there is no version listed, click on Check for update to force the download
  11. Once the model has downloaded and has reached a version greater than shown above, open DevTools and send (await ai.languageModel.capabilities()).available; in the console. If this returns “readily”, then you are all set
  12. Within the Title Generation, Excerpt Generation and Content Resizing Features, select Chrome AI as the Provider
  13. Test that all three Features still work as expected. Note I had to massage the prompts a bit to get better results but as long as you're seeing results show up, things are working

Changelog Entry

Added - Chrome AI as a new text generation Provider, allowing completely on-device AI usage

Credits

Props @dkotter, @jeffpaul, @iamdharmesh, @faisal-alvi

Checklist:

@dkotter dkotter added this to the 3.2.0 milestone Oct 16, 2024
@dkotter dkotter self-assigned this Oct 16, 2024
@dkotter dkotter requested review from jeffpaul and a team as code owners October 16, 2024 02:53
@github-actions github-actions bot added the needs:code-review This requires code review. label Oct 16, 2024
@@ -45,6 +46,7 @@ public function __construct() {
ChatGPT::ID => __( 'OpenAI ChatGPT', 'classifai' ),
GeminiAPI::ID => __( 'Google AI (Gemini API)', 'classifai' ),
OpenAI::ID => __( 'Azure OpenAI', 'classifai' ),
ChromeAI::ID => __( 'Chrome AI', 'classifai' ), // TODO: only add this Provider if the browser supports AI.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right now this Provider shows up even if your browser doesn't support Chrome AI. Would be great to remove it but doesn't cause any problems if you do select it. With the settings refactor in #502, I think will be much easier to remove this since all settings are registered in javascript at that point, so may leave this until it's integrated in there

@jeffpaul jeffpaul requested review from a team and removed request for a team November 12, 2024 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:code-review This requires code review.
Projects
Status: Code Review
Development

Successfully merging this pull request may close these issues.

1 participant