"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Use the AI ​​Experimental API in Chrome

How to Use the AI ​​Experimental API in Chrome

Published on 2024-11-06
Browse:707

Cómo Utilizar el API Experimental de AI en Chrome

To use the experimental AI API in Chrome, follow these steps:

Hardware Requirements

  • 4GB RAM
  • GPU available
  • Minimum 22GB of space
  • Windows 10.11 or macOS Ventura or newer versions (no Linux specification)

There is no support yet for:

  • ChromeOS
  • Chrome iOS
  • Chrome Android

Software Requirements

  • Install Chrome Canary
  • Activate the AI ​​and the models by modifying the following flags:
  1. Go to chrome://flags/#optimization-guide-on-device-model and select "Enabled BypassPerfRequirement"
  2. Go to chrome://flags/#prompt-api-for-gemini-nano and select "Enable"
  3. Restart Chrome
  4. Verify the installation by running this command in the console: (await ai.assistant.capabilities()).available. It should return "readily".

If it fails, try the following:

  1. Run await ai.assistant.create() to try to force Chrome to activate the API (although it may not work).
  2. Go to chrome://components and check if the "Optimization Guide On Device Model" component has a version equal to or greater than 2024.5.21.1031. If you don't have a version, click "check for updates" and try again.

Note: Sometimes the model installation may take a while. Be patient and repeat the process if necessary.

Model Activation

To activate the models, enable the following flags in Chrome:

  • chrome://flags/#prompt-api-for-gemini-nano
  • chrome://flags/#summarization-api-for-gemini-nano
  • chrome://flags/#rewriter-api-for-gemini-nano
  • chrome://flags/#writer-api-for-gemini-nano
  • chrome://flags/#language-detection-api

Available functions

Prompt API

This is the simplest model, used for general tasks. When you send it a prompt, it tries to return a response. Here is a basic example:

const session = await ai.assistant.create();
const result = await session.prompt("Explain what JavaScript is");

You can also use systemPrompt to pass additional instructions to it:

const session = await ai.assistant.create({
  systemPrompt: "You are an expert in JavaScript, providing helpful code best practices."
});

Language Detection

This API detects the language of a text, supporting more than 100 languages ​​and variants.

Example:

const detector = await translation.createDetector();
const results = await detector.detect("Bonjour le monde");
for (const result of results) {
  console.log(result.detectedLanguage, result.confidence);
}

Writer and Rewriter

Writer API: Create new content.
Example: writing a draft of an application to the bank.

const writer = await ai.writer.create();
const result = await writer.write("Write a email asking for feedback");

Rewriter API: Improves or restructures an existing text.

const rewriter = await ai.rewriter.create();
const result = await rewriter.rewrite("La inteligencia artificial es...", { context: "Use simple words." });

All these APIs are in the experimental phase, so it is normal to find errors or inconsistencies. All feedback is welcome. If you are interested in being aware of the changes, you can fill out this form to access the documentation and receive updates.

Release Statement This article is reproduced at: https://dev.to/marianocodes/como-utilizar-el-api-experimental-de-ai-en-chrome-3c4m?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3