Summarizer:summarizeStreaming() 方法
Summarizer 介面的 summarizeStreaming() 方法會生成一個新的摘要,並將其作為 ReadableStream 返回。
語法
js
summarizeStreaming(input)
summarizeStreaming(input, options)
引數
input-
一個表示待摘要文字的字串。
options可選-
一個指定
summarizeStreaming()操作配置選項的物件。可能的值包括:context-
一個描述輸入文字使用場景的字串,這有助於
Summarizer生成更合適的摘要。 signal-
一個
AbortSignal物件例項,它允許透過關聯的AbortController來中止summarizeStreaming()操作。
返回值
一個包含生成摘要的 ReadableStream。
異常
InvalidStateErrorDOMException-
如果當前
Document未啟用,則丟擲此異常。 NotAllowedErrorDOMException-
如果 Summarizer API 的使用被
summarizerPermissions-Policy阻止,則會丟擲此錯誤。 NotReadableErrorDOMException-
如果輸出摘要被使用者代理過濾,例如因為它被檢測為有害、不準確或無意義,則丟擲此異常。
NotSupportedErrorDOMException-
如果提供的
context的語言不是Summarizer支援的語言,則丟擲此異常。 QuotaExceededError-
如果摘要操作超過了可用的
inputQuota,則丟擲此異常。 UnknownErrorDOMException-
如果
summarizeStreaming()呼叫因任何其他原因失敗,或者使用者代理不希望披露原因,則丟擲此異常。
示例
基本的 summarizeStreaming() 用法
js
const summarizer = await Summarizer.create({
sharedContext:
"A general summary to help a user decide if the text is worth reading",
type: "tldr",
length: "short",
});
const stream = summarizer.summarizeStreaming(myTextString);
let summary = "";
for await (const chunk of stream) {
summary += chunk;
}
console.log("Stream complete");
summaryOutput.textContent = summary;
規範
| 規範 |
|---|
| 寫作輔助 API # dom-summarizer-summarizestreaming |
瀏覽器相容性
載入中…