CreateMonitor

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.

Giao diện CreateMonitor cung cấp thông tin về tiến trình tải xuống của một mô hình AI hoặc một số dữ liệu tinh chỉnh cho mô hình đó.

Nó có thể được dùng thông qua:

EventTarget CreateMonitor

Sự kiện

Kế thừa các sự kiện từ phần tử cha của nó, EventTarget.

downloadprogress Experimental

Được kích hoạt khi tiến trình tải xuống mô hình AI có thay đổi.

Ví dụ

Cách dùng CreateMonitor cơ bản

Một thực thể CreateMonitor được dùng thông qua thuộc tính monitor của phương thức create() trong một AI API (Summarizer.create() được minh họa bên dưới). Thuộc tính monitor nhận một hàm callback làm giá trị, trong đó đối số là thực thể CreateMonitor. Sau đó, bạn có thể theo dõi tiến trình tải xuống thông qua sự kiện downloadprogress của thực thể này.

js
const summarizer = await Summarizer.create({
  sharedContext:
    "A general summary to help a user decide if the text is worth reading",
  monitor(monitor) {
    monitor.addEventListener("downloadprogress", (e) => {
      console.log(`download progress: ${e.loaded}/${e.total}`);
    });
  },
});

const summary = await summarizer.summarize(myText);

Thông số kỹ thuật

Specification
Writing Assistance APIs
# createmonitor

Khả năng tương thích với trình duyệt

Xem thêm