Error: chrome.aiOriginTrial not supported in this browser

109 views
Skip to first unread message

sangeetha Kumari G

unread,
Nov 28, 2024, 10:36:09 AM11/28/24
to Chrome Built-in AI Early Preview Program Discussions
I am very new to the Chrome developer. 

I am trying to run the code from the github for ai.gemini-on-device to start using the  Chrome Prompt AI feature. 

I have updated the chrome version, tried on Chrome Canary but still getting the error - Error: chrome.aiOriginTrial not supported in this browser .

I have registered to the Origin trails, updated the flag preference for  Enables optimization guide on device  and Prompt API for Gemini Nano.

The chrome://components/ 
Optimization Guide On Device Model - Version: 2024.9.25.2033
Status - Up-to-date
Check for update
Never gives the updated to latest component.

Logs from In the developer console :
await ai.canCreateTextSession()
VM889:1 Uncaught TypeError: ai.canCreateTextSession is not a function
    at <anonymous>:1:10
(anonymous) @ VM889:1Understand this errorAI

Please guide , how to get started.

Sebastian Benz

unread,
Nov 28, 2024, 10:58:57 AM11/28/24
to sangeetha Kumari G, Chrome Built-in AI Early Preview Program Discussions
Can you post your manifest file and the code you're using to call the prompt API?

--
You received this message because you are subscribed to the Google Groups "Chrome Built-in AI Early Preview Program Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chrome-ai-dev-previe...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chrome-ai-dev-preview-discuss/2ab7eab0-ea22-478a-8a80-27ed8564fe86n%40chromium.org.

Dr. Sebastian Benz

Developer Relations Engineer


Google Germany GmbH

Erika-Mann-Straße 33

80636 München


Geschäftsführer: Paul Manicle, Liana Sebastian

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Falls Sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde. 

     

This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.


Message has been deleted
Message has been deleted

sangeetha Kumari G

unread,
Nov 28, 2024, 11:20:31 AM11/28/24
to Chrome Built-in AI Early Preview Program Discussions, Sebastian Benz, Chrome Built-in AI Early Preview Program Discussions, sangeetha Kumari G
Here is the manifest.json and the other code file details used to call the prompt API

{
  "name": "Chrome Prompt AI Demo_test",
  "version": "0.2",
  "manifest_version": 3,
  "description": "Try Chrome's built-in prompt API.",
  "background": {
    "service_worker": "background.js"
  },
  "permissions": ["sidePanel", "aiLanguageModelOriginTrial"],
  "trial_tokens": [
"AlAAbp4Y/qRC8KYxILmp3a8BjfcLUoyrHqbSiCqyQ/LY5ga6GdJ/jYyQnDi7iUI5EVmUxzXLcb3fIiaI7m9wNg8AAAByeyJvcmlnaW4iOiJodHRwczovL3d3dy5weXRob24ub3JnOjQ0MyIsImZlYXR1cmUiOiJBSVByb21wdEFQSUZvckV4dGVuc2lvbiIsImV4cGlyeSI6MTc2MDQ4NjM5OSwiaXNTdWJkb21haW4iOnRydWV9  ],
  "minimum_chrome_version": "131",
  "side_panel": {
    "default_path": "sidepanel/index.html"
  },
  "action": {
    "default_icon": {
      "16": "images/icon16.png",
      "32": "images/icon32.png",
      "48": "images/icon48.png",
      "128": "images/icon128.png"
    },
    "default_title": "Open Chat Interface"
  }
}

index.js

import DOMPurify from 'dompurify';
import { marked } from 'marked';

const inputPrompt = document.body.querySelector('#input-prompt');
const buttonPrompt = document.body.querySelector('#button-prompt');
const buttonReset = document.body.querySelector('#button-reset');
const elementResponse = document.body.querySelector('#response');
const elementLoading = document.body.querySelector('#loading');
const elementError = document.body.querySelector('#error');
const sliderTemperature = document.body.querySelector('#temperature');
const sliderTopK = document.body.querySelector('#top-k');
const labelTemperature = document.body.querySelector('#label-temperature');
const labelTopK = document.body.querySelector('#label-top-k');

let session;

async function runPrompt(prompt, params) {
  try {
    if (!session) {
      session = await chrome.aiOriginTrial.languageModel.create(params);
    }
    return session.prompt(prompt);
  } catch (e) {
    console.log('Prompt failed');
    console.error(e);
    console.log('Prompt:', prompt);
    // Reset session
    reset();
    throw e;
  }
}

async function reset() {
  if (session) {
    session.destroy();
  }
  session = null;
}

async function initDefaults() {
  if (!('aiOriginTrial' in chrome)) {
    showResponse('Error: chrome.aiOriginTrial not supported in this browser');
    return;
  }
  const defaults = await chrome.aiOriginTrial.languageModel.capabilities();
  console.log('Model default:', defaults);
  if (defaults.available !== 'readily') {
    showResponse(
      `Model not yet available (current state: "${defaults.available}")`
    );
    return;
  }
  sliderTemperature.value = defaults.defaultTemperature;
  // Pending https://issues.chromium.org/issues/367771112.
  // sliderTemperature.max = defaults.maxTemperature;
  if (defaults.defaultTopK > 3) {
    // limit default topK to 3
    sliderTopK.value = 3;
    labelTopK.textContent = 3;
  } else {
    sliderTopK.value = defaults.defaultTopK;
    labelTopK.textContent = defaults.defaultTopK;
  }
  sliderTopK.max = defaults.maxTopK;
  labelTemperature.textContent = defaults.defaultTemperature;
}

initDefaults();

buttonReset.addEventListener('click', () => {
  hide(elementLoading);
  hide(elementError);
  hide(elementResponse);
  reset();
  buttonReset.setAttribute('disabled', '');
});

sliderTemperature.addEventListener('input', (event) => {
  labelTemperature.textContent = event.target.value;
  reset();
});

sliderTopK.addEventListener('input', (event) => {
  labelTopK.textContent = event.target.value;
  reset();
});

inputPrompt.addEventListener('input', () => {
  if (inputPrompt.value.trim()) {
    buttonPrompt.removeAttribute('disabled');
  } else {
    buttonPrompt.setAttribute('disabled', '');
  }
});

buttonPrompt.addEventListener('click', async () => {
  const prompt = inputPrompt.value.trim();
  showLoading();
  try {
    const params = {
      systemPrompt: 'You are a helpful and friendly assistant.',
      temperature: sliderTemperature.value,
      topK: sliderTopK.value
    };
    const response = await runPrompt(prompt, params);
    showResponse(response);
  } catch (e) {
    showError(e);
  }
});

function showLoading() {
  buttonReset.removeAttribute('disabled');
  hide(elementResponse);
  hide(elementError);
  show(elementLoading);
}

function showResponse(response) {
  hide(elementLoading);
  show(elementResponse);
  elementResponse.innerHTML = DOMPurify.sanitize(marked.parse(response));
}

function showError(error) {
  show(elementError);
  hide(elementResponse);
  hide(elementLoading);
  elementError.textContent = error;
}

function show(element) {
  element.removeAttribute('hidden');
}

function hide(element) {
  element.setAttribute('hidden', '');
}


background.js
chrome.sidePanel
  .setPanelBehavior({ openPanelOnActionClick: true })
  .catch((error) => console.error(error));

Anil Kumar

unread,
Nov 28, 2024, 11:22:31 AM11/28/24
to Chrome Built-in AI Early Preview Program Discussions, sangeetha Kumari G
Run console.dir(ai) in console.

canCreateTextSession method not available in object.

I think you follow outdated docs or third-part js library.
Please share github link.
Please explain what you try to do. For using prompt API: follow this docs
https://docs.google.com/document/d/1VG8HIyz361zGduWgNG7R_R8Xkv0OOJ8b5C9QKeCjU0c/edit?tab=t.0


Anil Kumar

unread,
Nov 28, 2024, 11:26:47 AM11/28/24
to Chrome Built-in AI Early Preview Program Discussions, Anil Kumar, sangeetha Kumari G

sangeetha Kumari G

unread,
Nov 28, 2024, 11:33:02 AM11/28/24
to Chrome Built-in AI Early Preview Program Discussions, Anil Kumar, sangeetha Kumari G
Thank you for your support.

I will check the documents and check with  the Github code for the prompt-ai-playground and update.

Lars H

unread,
Nov 29, 2024, 3:30:11 PM11/29/24
to Chrome Built-in AI Early Preview Program Discussions, sangeetha Kumari G, Anil Kumar
I got it to work in Chrome Canary (Version 133.0.6865.0 (Official Build) canary (x86_64)) on MacOS. 

I also tried normal Chrome, Chrome Beta, Chrome Dev. It didn't work in any of these browser models.

Thomas Steiner

unread,
Nov 29, 2024, 6:18:48 PM11/29/24
to Lars H, Chrome Built-in AI Early Preview Program Discussions, sangeetha Kumari G, Anil Kumar
Glad you got it working. 

--
You received this message because you are subscribed to the Google Groups "Chrome Built-in AI Early Preview Program Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chrome-ai-dev-previe...@chromium.org.
Reply all
Reply to author
Forward
0 new messages