Home > Web Front-end > JS Tutorial > How to Use the AI ​​Experimental API in Chrome

How to Use the AI ​​Experimental API in Chrome

Susan Sarandon
Release: 2024-10-01 12:17:02
Original
1074 people have browsed it

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");
Copy after login

You can also use systemPrompt to pass additional instructions:

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

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);
}
Copy after login

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");
Copy after login

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." });
Copy after login

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.

The above is the detailed content of How to Use the AI ​​Experimental API in Chrome. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template