UNPKG

web-ai-toolkit

Version:

AI powered features on the web made easy

50 lines (49 loc) 1.31 kB
import { p as w } from "./summarization-utils-OoXTUJUI.js"; let i; async function y(t, a, r = 1e3, m = 100, u = 200, s) { return new Promise(async (l, c) => { try { if (!("Summarizer" in self)) throw new Error("Summarizer API is not available in this environment."); const o = { sharedContext: a?.sharedContext || "", type: a?.type || "tldr", format: a?.format || "markdown", length: a?.length || "medium" }, n = await z(o); if (!n) throw new Error("Failed to load the Summarizer API."); if (i = n, t.length <= r) { const e = await n.summarize(t); l(e); return; } const d = await w( t, r, m, u, s, async (e) => await n.summarize(e), (e) => e, (e) => e ); l(d); } catch (o) { c(o); } }); } async function z(t) { if (i) return i; const a = await Summarizer.availability(); let r; if (a !== "unavailable") return a === "available" ? (r = await Summarizer.create(t), i = r) : (r = await Summarizer.create(t), r.addEventListener("downloadprogress", (m) => { console.log(`Downloaded ${m.loaded * 100}%`); }), i = r, await r.ready), i; } export { y as runNativeSummarizer };