Back to all articles

Try Web AI APIs in Opera’s console

This is a quick guide to trying a few Web AI APIs straight from Opera’s developer console. Every API and its parameters can also be tried in the Web AI Playground, along with fuller JavaScript examples. If you want to get going in the console, here’s how.

1. Enable Web AI

  • Download or update Opera One.
  • Go to Settings → Opera AI (or open opera://settings/ai) and turn on Enable Web AI API. This downloads a compatible local model, so it may take a few minutes.

2. Open the console

Open developer tools (Cmd+Option+I on Mac or Ctrl+Shift+I on Windows) and go to the Console tab.

If you paste the code below into the console instead of typing it by hand, you first need to allow pasting by typing allow pasting in the console. Be careful when pasting anything into the console: only paste code you understand and trust.

Translator API

Instantiate a Translator object and set the languages:

JS
> const t = await Translator.create({ sourceLanguage: "en", targetLanguage: "no" });

Let’s see what it produces:

The Opera console showing the Translator object with sourceLanguage “en” and targetLanguage “no”

Then translate something:

JS
> await t.translate("Hello, world!");
'Hallo, verden!'

Decisions API

Start by instantiating a DecisionModel object:

JS
> const d = await DecisionModel.create(
{
  questions:
    [
      {
        id: "isCustomerAngry",
        type: "boolean",
        prompt: "Is the customer angry?"
      }
    ]
}
);

As you can see, we’re setting up the prompt as a question, and in this case we want a boolean type of response.

Let’s try it, first by checking this statement:

JS
> await d.decide("I've waited three weeks and still no refund.");

The returned object looks something like this:

The console result for the refund statement: label “true” with a confidence of about 0.90

You can see that it labels (decides) this statement as “true”, but also with a confidence of 90%.

Let’s try another one:

JS
> await d.decide("This is the best shop on the internet");
The console result for the shop statement: label “false” with a confidence of about 0.97

And the Decision model estimates, with 97% confidence, that this statement is false.

Next steps

Now you know how to test Web AI in the console. To explore the rest, see the full reference at next.opera.com/web-ai.