Summarizer: phương thức summarizeStreaming()
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Phương thức summarizeStreaming() của giao diện Summarizer tạo một bản tóm tắt mới dưới dạng ReadableStream.
Cú pháp
summarizeStreaming(input)
summarizeStreaming(input, options)
Tham số
input-
Một chuỗi đại diện cho văn bản cần tóm tắt.
optionsOptional-
Một đối tượng xác định các tùy chọn cấu hình cho thao tác
summarizeStreaming(). Các giá trị có thể bao gồm:context-
Một chuỗi mô tả ngữ cảnh mà văn bản đầu vào đang được sử dụng trong đó, giúp
Summarizertạo ra bản tóm tắt phù hợp hơn. signal-
Một thực thể đối tượng
AbortSignal, cho phép hủy bỏ thao tácsummarizeStreaming()thông quaAbortControllerđược liên kết.
Giá trị trả về
Một ReadableStream chứa bản tóm tắt được tạo.
Ngoại lệ
AbortErrorDOMException-
Được ném ra nếu
Summarizertrước đó đã bị hủy bỏ (đã gọiSummarizer.destroy()hoặc bị hủy bỏ thông quasignalhủy bỏ sau khi tạo). InvalidStateErrorDOMException-
Được ném ra nếu
Documenthiện tại không hoạt động. NotAllowedErrorDOMException-
Được ném ra nếu việc sử dụng Summarizer API bị chặn bởi
summarizerPermissions-Policy. NotReadableErrorDOMException-
Được ném ra nếu bản tóm tắt đầu ra bị lọc bởi tác nhân người dùng, ví dụ vì nó bị phát hiện là có hại, không chính xác hoặc vô nghĩa.
NotSupportedErrorDOMException-
Được ném ra nếu
contextđược cung cấp không ở ngôn ngữ màSummarizerhỗ trợ. QuotaExceededError-
Được ném ra nếu thao tác tóm tắt vượt quá
inputQuotacó sẵn. UnknownErrorDOMException-
Được ném ra nếu lần gọi
summarizeStreaming()thất bại vì bất kỳ lý do nào khác, hoặc lý do mà tác nhân người dùng không muốn tiết lộ.
Ví dụ
>Sử dụng cơ bản summarizeStreaming()
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;
Thông số kỹ thuật
| Specification |
|---|
| Writing Assistance APIs> # dom-summarizer-summarizestreaming> |
Tương thích trình duyệt
Xem thêm
- Sử dụng Summarizer API
- Web AI demos trên chrome.dev