-
Notifications
You must be signed in to change notification settings - Fork 23k
Editorial review: Document the Summarizer API #39263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chrisdavidmills
merged 34 commits into
mdn:main
from
chrisdavidmills:writing-assistance-apis
May 21, 2025
Merged
Changes from 5 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
9eda31a
Document the Summarizer API
chrisdavidmills a8ad5b0
Update files/en-us/web/api/summarizer_api/index.md
chrisdavidmills 7edfeda
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills 4177ab7
Add most of the Summarizer interface docs
chrisdavidmills d9573fa
Finish summarizer API pages
chrisdavidmills e07c245
Merge branch 'main' into writing-assistance-apis
chrisdavidmills 9e20c15
Small updates
chrisdavidmills 1617096
fixes and code improvements
chrisdavidmills 338f147
fixes for tomayac review comments
chrisdavidmills 7fd0393
Merge branch 'main' into writing-assistance-apis
chrisdavidmills d4260fb
Last few bits from the technical review
chrisdavidmills a25ab79
Update CreateMonitor description to be more API neutral
chrisdavidmills db2453f
Update files/en-us/web/api/summarizer/type/index.md
chrisdavidmills 66f4ac1
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills 7a571d8
Update files/en-us/web/api/summarizer/type/index.md
chrisdavidmills 7abb369
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills 34dfe28
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills 1e0b9fc
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills 1e9edf8
Update files/en-us/web/api/summarizer/availability_static/index.md
chrisdavidmills d9a1fc9
Update files/en-us/web/api/summarizer/availability_static/index.md
chrisdavidmills 04a3de8
Update files/en-us/web/api/summarizer/expectedcontextlanguages/index.md
chrisdavidmills 7882a89
Update files/en-us/web/api/summarizer/expectedcontextlanguages/index.md
chrisdavidmills b299312
Update files/en-us/web/api/summarizer/expectedinputlanguages/index.md
chrisdavidmills 4673393
Update files/en-us/web/api/summarizer/inputquota/index.md
chrisdavidmills 9d27864
Update files/en-us/web/api/summarizer/inputquota/index.md
chrisdavidmills 07bb615
Update files/en-us/web/api/summarizer/inputquota/index.md
chrisdavidmills 2141196
Update files/en-us/web/api/summarizer/outputlanguage/index.md
chrisdavidmills 2560383
Update files/en-us/web/api/summarizer/measureinputusage/index.md
chrisdavidmills c7558ca
Update files/en-us/web/api/summarizer_api/index.md
chrisdavidmills 1827e01
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills 921cd3e
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills 2682952
Fixes for bsmth review comments
chrisdavidmills bc4b6ac
Merge branch 'main' into writing-assistance-apis
bsmth 5c9ea97
Update files/en-us/web/api/summarizer_api/using/index.md
chrisdavidmills File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
files/en-us/web/api/createmonitor/downloadprogress_event/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --- | ||
| title: "CreateMonitor: downloadprogress event" | ||
| short-title: downloadprogress | ||
| slug: Web/API/CreateMonitor/downloadprogress_event | ||
| page-type: web-api-event | ||
| status: | ||
| - experimental | ||
| browser-compat: api.CreateMonitor.downloadprogress_event | ||
| --- | ||
|
|
||
| {{APIRef("Summarizer API")}}{{SeeCompatTable}} | ||
|
|
||
| The **`downloadprogress`** event of the {{domxref("CreateMonitor")}} interface is fired when progress is made on the summarizer download. | ||
|
|
||
| EDITORIAL: Again, I'm not really sure about exactly what this is showing the progress of. | ||
|
|
||
| ## Syntax | ||
|
|
||
| Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property. | ||
|
|
||
| ```js | ||
| addEventListener("downloadprogress", (event) => {}); | ||
|
|
||
| ondownloadprogress = (event) => {}; | ||
| ``` | ||
|
|
||
| ## Event type | ||
|
|
||
| A {{domxref("ProgressEvent")}}. Inherits from {{domxref("Event")}}. | ||
|
|
||
| {{InheritanceDiagram("ProgressEvent")}} | ||
|
|
||
| ## Examples | ||
|
|
||
| See the main {{domxref("CreateMonitor")}} page for an example. | ||
|
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - [Using the Summarizer API](/en-US/docs/Web/API/Summarizer_API/Using) | ||
| - [Web AI demos](https://chrome.dev/web-ai-demos/) on chrome.dev. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| --- | ||
| title: CreateMonitor | ||
| slug: Web/API/CreateMonitor | ||
| page-type: web-api-interface | ||
| status: | ||
| - experimental | ||
| browser-compat: api.CreateMonitor | ||
| --- | ||
|
|
||
| {{APIRef("Summarizer API")}}{{SeeCompatTable}} | ||
|
|
||
| The **`CreateMonitor`** interface of the Writing Assistance APIs ({{domxref("Summarizer API", "Summarizer API", "", "nocode")}} provides information on the progress of a summarizer download. | ||
|
|
||
| {{InheritanceDiagram}} | ||
|
|
||
| ## Events | ||
|
|
||
| _Inherits events from its parent, {{DOMxRef("EventTarget")}}._ | ||
|
|
||
| - {{domxref("CreateMonitor/downloadprogress_event", "downloadprogress")}} {{Experimental_Inline}} | ||
| - : Fired when progress is made on the summarizer download. | ||
|
|
||
| ## Examples | ||
|
|
||
| ```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); | ||
| ``` | ||
|
|
||
| EDITORIAL: I can get this to work, but I'm not really sure what exactly it is monitoring progress of. It would be good to get some more information on this. | ||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - [Using the Summarizer API](/en-US/docs/Web/API/Summarizer_API/Using) | ||
| - [Web AI demos](https://chrome.dev/web-ai-demos/) on chrome.dev. | ||
107 changes: 107 additions & 0 deletions
107
files/en-us/web/api/summarizer/availability_static/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| --- | ||
| title: "Summarizer: availability() static method" | ||
| short-title: availability() | ||
| slug: Web/API/Summarizer/availability_static | ||
| page-type: web-api-static-method | ||
| browser-compat: api.Summarizer.availability_static | ||
| --- | ||
|
|
||
| {{APIRef("Summarizer API")}}{{securecontext_header}} | ||
|
|
||
| The **`availability()`** static method of the {{domxref("Summarizer")}} interface returns an enumerated value that indicates whether the browser AI model supports (or will support) a given `Summarizer` configuration. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```js-nolint | ||
| Summarizer.availability() | ||
| Summarizer.availability(options) | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| - `options` {{optional_inline}} | ||
|
|
||
| - : An options object specifying a possible configuration for a `Summarizer`. Possible values include: | ||
|
|
||
| - `expectedInputLanguages` | ||
| - : An array of strings equal to [BCP 47 language tags](https://en.wikipedia.org/wiki/IETF_language_tag#List_of_common_primary_language_subtags) (as specified in [RFC 5646](https://datatracker.ietf.org/doc/html/rfc5646)) specifying the expected languages of the input text. Defaults to an array containing a single value representing the browser's primary language. | ||
| - `expectedContextLanguages` | ||
| - : An array of strings equal to BCP 47 language tags specifying the expected languages of any provided context strings (either the [`sharedContext`](#sharedContext) passed to the `Summarizer`, or a `context` specified during a {{domxref("Summarizer.summarize", "summarize()")}} or {{domxref("Summarizer.summarizeStreaming", "summarizeStreaming()")}} call). Defaults to an array containing a single value representing the browser's primary language. | ||
| - `format` | ||
| - : An enumerated value specifying the text {{domxref("Summarizer.format", "format")}} you want summaries returned in. defaults to `markdown`. | ||
| - `length` | ||
| - : An enumerated value specifying the relative {{domxref("Summarizer.length", "length")}} for the generated summaries. defaults to `short`. | ||
| - `outputLanguage` | ||
| - : A string equal to a BCP 47 language tag specifying the expected language of summaries generated by the `Summarizer`. Defaults to a string representing the browser's primary language. | ||
| - `type` | ||
| - : An enumerated value specifying the {{domxref("Summarizer.type", "type")}} of summary you want this `Summarizer` to generate. defaults to `key-points`. | ||
|
|
||
| EDITORIAL: I don't actually know what the language-related properties default to, or how the browser determines whether a language value is valid for particular browser or not. Needs to be researched. | ||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Return value | ||
|
|
||
| A {{jsxref("Promise")}} that fulfills with an enumerated value indicating whether support is available (or will be available) for a given `Summarizer` configuration, or `null` if support could not be determined. | ||
|
|
||
| Possible values include: | ||
|
|
||
| - `available` | ||
| - : The browser supports the given configuration. | ||
| - `downloadable` | ||
| - : The browser does not support the given configuration, but it could do if an updated language model were downloaded. | ||
| - `downloading` | ||
| - : The browser does not support the given configuration, but it will do when a currently-downloading language model update finishes. | ||
| - `unavailable` | ||
| - : The browser does not support the given configuration. | ||
|
|
||
| EDITORIAL: I am guessing at how language model updates are identified and downloaded. Is this something that is done programmatically, or does the app need to instruct the user to do so? I'm assuming how this is handled will be implementation-dependant, but we ought to given an example of how Chrome does it. I probably need to give some more details on "best fit" languages, as per the example mentioned in the spec. More research needed. | ||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Exceptions | ||
|
|
||
| - `NotAllowedError` {{domxref("DOMException")}} | ||
| - : Thrown if usage of the Summarizer API is blocked by a {{httpheader('Permissions-Policy/summarizer','summarizer')}} {{httpheader("Permissions-Policy")}}. | ||
| - `NotSupportedError` {{domxref("DOMException")}} | ||
| - : Thrown if the provided `context` is not in language the `Summarizer` supports. | ||
| - `UnknownError` {{domxref("DOMException")}} | ||
| - : Thrown if the `measureInputUsage()` call failed for any other reason, or a reason the user agent did not wish to disclose. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Basic `availability()` usage | ||
|
|
||
| ```js | ||
| const availability = await Summarizer.availability({ | ||
| type: "tl;dr", | ||
| length: "short", | ||
| format: "markdown", | ||
| expectedInputLanguages: ["en-US"], | ||
| outputLanguage: "en-US", | ||
| }); | ||
| ``` | ||
|
|
||
| ### Detecting language support | ||
|
|
||
| ```js | ||
| async function langSupport(lang) { | ||
| const availability = await Summarizer.availability({ | ||
| expectedInputLanguages: [lang], | ||
| }); | ||
| return availability; | ||
| } | ||
|
|
||
| langSupport("en-US"); | ||
| langSupport("fr"); | ||
| langSupport("zh-CN"); | ||
| ``` | ||
|
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - [Using the Summarizer API](/en-US/docs/Web/API/Summarizer_API/Using) | ||
| - [Web AI demos](https://chrome.dev/web-ai-demos/) on chrome.dev. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| --- | ||
| title: "Summarizer: create() static method" | ||
| short-title: create() | ||
| slug: Web/API/Summarizer/create_static | ||
| page-type: web-api-static-method | ||
| browser-compat: api.Summarizer.create_static | ||
| --- | ||
|
|
||
| {{APIRef("Summarizer API")}}{{securecontext_header}} | ||
|
|
||
| The **`create()`** static method of the {{domxref("Summarizer")}} interface creates a new `Summarizer` instance from which to generate summaries. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```js-nolint | ||
| Summarizer.create() | ||
| Summarizer.create(options) | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| - `options` {{optional_inline}} | ||
|
|
||
| - : An object specifying configuration options for the `Summarizer`. Possible values include: | ||
|
|
||
| - `expectedInputLanguages` | ||
| - : An array of strings specifying the expected languages of the input text, which should be valid [BCP 47 language tags](https://en.wikipedia.org/wiki/IETF_language_tag#List_of_common_primary_language_subtags) (as specified in [RFC 5646](https://datatracker.ietf.org/doc/html/rfc5646)). Defaults to an array containing a single value representing the browser's primary language. | ||
| - `expectedContextLanguages` | ||
| - : An array of strings specifying the expected languages of any provided context strings (either the [`sharedContext`](#sharedContext) passed to the `Summarizer`, or a `context` specified during a {{domxref("Summarizer.summarize", "summarize()")}} or {{domxref("Summarizer.summarizeStreaming", "summarizeStreaming()")}} call), which should be valid BCP 47 language tags. Defaults to an array containing a single value representing the browser's primary language. | ||
| - `format` | ||
| - : An enumerated value specifying the text {{domxref("Summarizer.format", "format")}} you want summaries returned in. defaults to `markdown`. | ||
bsmth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - `length` | ||
| - : An enumerated value specifying the relative {{domxref("Summarizer.length", "length")}} for the generated summaries. defaults to `short`. | ||
| - `monitor` | ||
| - : A callback function with a {{domxref("CreateMonitor")}} argument that enables monitoring/reporting code to be run in response to LLM download progress. | ||
| - `outputLanguage` | ||
| - : A string specifying the expected language of summaries generated by the `Summarizer`, which should be a valid BCP 47 language tag. Defaults to a string representing the browser's primary language. | ||
| - `sharedContext` | ||
| - : A {{domxref("Summarizer.sharedContext", "sharedContext")}} string describing the context the pieces of text to summarize are being used in, which helps the `Summarizer` generate more suitable summaries. | ||
| - `signal` | ||
| - : An {{domxref("AbortSignal")}} object instance, which allows the `create()` operation to be aborted via the associated {{domxref("AbortController")}}. | ||
| - `type` | ||
| - : An enumerated value specifying the {{domxref("Summarizer.type", "type")}} of summary you want this `Summarizer` to generate. defaults to `key-points`. | ||
|
|
||
| EDITORIAL: I don't actually know what the language-related properties default to, or how the browser determines whether a language value is valid for particular browser or not. Needs to be researched. | ||
|
|
||
| EDITORIAL: I also don't know what the monitor functionality does or how it works. Again, needs researching. | ||
|
|
||
| EDITORIAL: Aborting the call via an abort signal doesn't seem to work. Am I missing something? | ||
|
|
||
| ### Return value | ||
|
|
||
| A {{jsxref("Promise")}} that fulfills with a `Summarizer` object instance. | ||
|
|
||
| ### Exceptions | ||
|
|
||
| - `NotAllowedError` {{domxref("DOMException")}} | ||
| - : Thrown if usage of the Summarizer API is blocked by a {{httpheader('Permissions-Policy/summarizer','summarizer')}} {{httpheader("Permissions-Policy")}}. | ||
| - `NotSupportedError` {{domxref("DOMException")}} | ||
| - : Thrown if any of the language tags specified in `expectedContextLanguages`, `expectedInputLanguages`, or `outputLanguage` are invalid, or not supported. | ||
| - `OperationError` {{domxref("DOMException")}} | ||
| - : General-purpose exception thrown if `Summarizer` creation failed for any other reason. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Basic `Summarizer` creation | ||
|
|
||
| ```js | ||
| const summarizer = await Summarizer.create({ | ||
| sharedContext: | ||
| "A general summary to help a user decide if the text is worth reading", | ||
| type: "tl;dr", | ||
| length: "short", | ||
| format: "markdown", | ||
| expectedInputLanguages: ["en-US"], | ||
| outputLanguage: "en-US", | ||
| }); | ||
| ``` | ||
|
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - [Using the Summarizer API](/en-US/docs/Web/API/Summarizer_API/Using) | ||
| - [Web AI demos](https://chrome.dev/web-ai-demos/) on chrome.dev. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| --- | ||
| title: "Summarizer: destroy() method" | ||
| short-title: destroy() | ||
| slug: Web/API/Summarizer/destroy | ||
| page-type: web-api-instance-method | ||
| status: | ||
| - experimental | ||
| browser-compat: api.Summarizer.destroy | ||
| --- | ||
|
|
||
| {{APIRef("Summarizer API")}}{{SeeCompatTable}} | ||
|
|
||
| The **`destroy()`** method of the {{domxref("Summarizer")}} interface destroys the `Summarizer` instance it is called on. | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```js-nolint | ||
| destroy() | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| None. | ||
|
|
||
| ### Return value | ||
|
|
||
| None ({{jsxref("undefined")}}). | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Basic `destroy()` usage | ||
|
|
||
| ```js | ||
| const summarizer = await Summarizer.create({ | ||
| sharedContext: | ||
| "A general summary to help a user decide if the text is worth reading", | ||
| type: "tl;dr", | ||
| length: "short", | ||
| }); | ||
|
|
||
| summarizer.destroy(); | ||
| ``` | ||
|
|
||
| EDITORIAL: From reading the spec, it sounds like I need to use this along with an `AbortController`, but I'm not sure what this would look like. | ||
chrisdavidmills marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - [Using the Summarizer API](/en-US/docs/Web/API/Summarizer_API/Using) | ||
| - [Web AI demos](https://chrome.dev/web-ai-demos/) on chrome.dev. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.