Ran into error while using summarization api

139 views
Skip to first unread message

Harsh Jain

unread,
Nov 26, 2024, 5:32:00 AM11/26/24
to Chrome Built-in AI Early Preview Program Discussions
hello everyone,

I have been using summarization api and it was working fine but today i get this error while using it,
   TypeError: Cannot read properties of undefined (reading 'summarize')

const canSummarize = await ai.summarizer.capabilities();
    let summarizer;
    if (canSummarize && canSummarize.available !== "no") {
      summarizer = await ai.summarizer.create();
      if (canSummarize.available === 'readily') {
        // The summarizer can immediately be used.
        console.log("ready");
        summarizer = await ai.summarizer.create();
      } else {
        // The summarizer can be used after the model download.
        summarizer = await ai.summarizer.create();
        summarizer.addEventListener('downloadprogress', (e) => {
          console.log(e.loaded, e.total);
        });
        await summarizer.ready;
      }
   
    }
      const result = await summarizer.summarize(desc); ON THIS LINE
Kindly look into it.

Regards
Harsh

Sebastian Benz

unread,
Nov 26, 2024, 5:48:35 AM11/26/24
to Harsh Jain, Chrome Built-in AI Early Preview Program Discussions
Hey Harsh,

I'd recommend moving the line throwing the error two lines higher so that it's inside the if block. Otherwise, users whose browser doesn't support the API will always get the error. In your particular case, this might happen when you're running out of disk space and Chrome removes the model as a consequence. 

Hope that helps,

Sebastian

--
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/5cd2dc6b-8402-443a-8f21-c26039efbf36n%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.


Thomas Steiner

unread,
Nov 26, 2024, 5:49:03 AM11/26/24
to Harsh Jain, Chrome Built-in AI Early Preview Program Discussions
Hello Harsh,

I suggest you switch the flow as in the following snippet:

const options = {
  sharedContext: 'This is a scientific article',
  type: 'key-points',
  format: 'markdown',
  length: 'medium',
};

const available = (await self.ai.summarizer.capabilities()).available;
let summarizer;
if (available === 'no') {
  // The Summarizer API isn't usable.
  return;
}
if (available === 'readily') {
  // The Summarizer API can be used immediately .
  summarizer = await self.ai.summarizer.create(options);
} else {
  // The Summarizer API can be used after the model is downloaded.
  summarizer = await self.ai.summarizer.create(options);

  summarizer.addEventListener('downloadprogress', (e) => {
    console.log(e.loaded, e.total);
  });
  await summarizer.ready;
}

This makes sure the API is usable before trying to create the summarizer.

Cheers,
Tom


On Tue, Nov 26, 2024 at 11:32 AM Harsh Jain <jain.ris...@gmail.com> wrote:
--
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/5cd2dc6b-8402-443a-8f21-c26039efbf36n%40chromium.org.


--
Thomas Steiner, PhD—Developer Relations Engineer (blog.tomayac.comtoot.cafe/@tomayac)

Google Germany GmbH, ABC-Str. 19, 20354 Hamburg, Germany

Geschäftsführer: Paul Manicle, Liana Sebastian
Registergericht und -nummer: Hamburg, HRB 86891

----- BEGIN PGP SIGNATURE -----
Version: GnuPG v2.4.3 (GNU/Linux)

iFy0uwAntT0bE3xtRa5AfeCheCkthAtTh3reSabiGbl0ck
0fjumBl3DCharaCTersAttH3b0ttom.xKcd.cOm/1181.
----- END PGP SIGNATURE -----
Reply all
Reply to author
Forward
0 new messages