CreateMonitor
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("Summarizer API")}}{{SeeCompatTable}}{{securecontext_header}}
The **CreateMonitor** interface provides information on the progress of an AI model download, for example a language pack or some fine-tuning data.
It can be used via:
- {{domxref("LanguageDetector.create_static", "LanguageDetector.create()")}}
- {{domxref("LanguageModel.create_static", "LanguageModel.create()")}}
- {{domxref("Summarizer.create_static", "Summarizer.create()")}}
- {{domxref("Translator.create_static", "Translator.create()")}}
{{InheritanceDiagram}}
Events
_Inherits events from its parent, {{DOMxRef("EventTarget")}}._
- {{domxref("CreateMonitor/downloadprogress_event", "downloadprogress")}} {{Experimental_Inline}}
- : Fired when progress is made on the AI model download.
Examples
Basic CreateMonitor usage
A CreateMonitor instance is used via the monitor property of an AI API's create() method ({{domxref("Summarizer.create_static", "Summarizer.create()")}} is shown below). The monitor property takes a callback function as a value, the argument of which is the CreateMonitor instance. You can then monitor download progress via the instance's {{domxref("CreateMonitor/downloadprogress_event", "downloadprogress")}} event.
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);Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- Using the Prompt API
- Using the Summarizer API
- Using the Translator and Language Detector APIs
- Web AI demos on chrome.dev.