1. Introduction
For now, see the explainer.
2. Shared AI APIs and infrastructure
partial interface WindowOrWorkerGlobalScope { [Replaceable ,SecureContext ]readonly attribute AI ai ; }; [Exposed =(Window ,Worker ),SecureContext ]interface {}; [
AI Exposed =(Window ,Worker ),SecureContext ]interface :
AICreateMonitor EventTarget {attribute EventHandler ondownloadprogress ; };callback =
AICreateMonitorCallback undefined (AICreateMonitor );
monitor enum {
AICapabilityAvailability ,
"readily" ,
"after-download" };
"no"
AICapabilityAvailability
-or-null values availabilities is:
-
If availabilities contains null, then return null.
-
If availabilities contains "
after-download
", then return "after-download
". -
Return "
readily
".
Each WindowOrWorkerGlobalScope
has an AI namespace, an AI
object. Upon creation of the WindowOrWorkerGlobalScope
object, its AI namespace must be set to a new AI
object created in the WindowOrWorkerGlobalScope
object’s relevant realm.
The ai
getter steps are to return this's AI namespace.
Tasks queued by this specification use the AI task source.
The following are the event handlers (and their corresponding event handler event types) that must be supported, as event handler IDL attributes, by all AICreateMonitor
objects:
Event handler | Event handler event type |
---|---|
ondownloadprogress
| downloadprogress
|
3. The summarizer API
partial interface AI {readonly attribute AISummarizerFactory summarizer ; }; [Exposed =(Window ,Worker ),SecureContext ]interface {
AISummarizerFactory Promise <AISummarizer >create (optional AISummarizerCreateOptions = {});
options Promise <AICapabilityAvailability >available (optional AISummarizerCreateCoreOptions = {}); }; [
options Exposed =(Window ,Worker ),SecureContext ]interface {
AISummarizer Promise <DOMString >summarize (DOMString ,
input optional AISummarizerSummarizeOptions = {} );
options ReadableStream summarizeStreaming (DOMString ,
input optional AISummarizerSummarizeOptions = {} );
options readonly attribute DOMString sharedContext ;readonly attribute AISummarizerType type ;readonly attribute AISummarizerFormat format ;readonly attribute AISummarizerLength length ;readonly attribute FrozenArray <DOMString >?expectedInputLanguages ;readonly attribute FrozenArray <DOMString >?expectedContextLanguages ;readonly attribute DOMString ?outputLanguage ;undefined destroy (); };dictionary {
AISummarizerCreateCoreOptions AISummarizerType = "key-points";
type AISummarizerFormat = "markdown";
format AISummarizerLength = "short";
length sequence <DOMString >;
expectedInputLanguages sequence <DOMString >;
expectedContextLanguages DOMString ; };
outputLanguage dictionary :
AISummarizerCreateOptions AISummarizerCreateCoreOptions {AbortSignal ;
signal AICreateMonitorCallback ;
monitor DOMString ; };
sharedContext dictionary {
AISummarizerSummarizeOptions AbortSignal ;
signal DOMString ; };
context enum {
AISummarizerType "tl;dr" ,"teaser" ,"key-points" ,"headline" };enum {
AISummarizerFormat "plain-text" ,"markdown" };enum {
AISummarizerLength "short" ,"medium" ,"long" };
Each AI
has an summarizer factory, an AISummarizerFactory
object. Upon creation of the AI
object, its summarizer factory must be set to a new AISummarizerFactory
object created in the AI
object’s relevant realm.
The summarizer
getter steps are to return this's summarizer factory.
3.1. Creation
create(options)
method steps are:
-
If this's relevant global object is a
Window
whose associated Document is not fully active, then return a promise rejected with an "InvalidStateError
"DOMException
. -
If options["
signal
"] exists and is aborted, then return a promise rejected with options["signal
"]'s abort reason. -
Validate and canonicalize language tags given options. If this throws an exception e, catch it, and return a promise rejected with e.
This can mutate options.
-
Let fireProgressEvent be an algorithm taking two arguments that does nothing.
-
If options["
monitor
"] exists, then:-
Let monitor be a new
AICreateMonitor
created in this's relevant realm. -
Invoke options["
monitor
"] with « monitor » and "rethrow
".If this throws an exception e, catch it, and return a promise rejected with e.
-
Set fireProgressEvent to an algorithm taking arguments loaded and total, which performs the following steps:
-
Assert: this algorithm is running in parallel.
-
Queue a global task on the AI task source given this's relevant global object to perform the following steps:
-
Fire an event named
downloadprogress
at monitor, usingProgressEvent
, with theloaded
attribute initialized to loaded, thetotal
attribute initialized to total, and thelengthComputable
attribute initialized to true.
-
-
-
-
Let abortedDuringDownload be false.
This variable will be written to from the event loop, but read from in parallel.
-
If options["
signal
"] exists, then add the following abort steps to options["signal
"]:-
Set abortedDuringDownload to true.
-
-
Let promise be a new promise created in this's relevant realm.
-
-
Let availability be the result of computing summarizer options availability given options.
This can mutate options.
-
Switch on availability:
- null
-
-
Reject promise with an "
UnknownError
"DOMException
. -
Abort these steps.
-
- "
no
" -
-
Reject promise with a "
NotSupportedError
"DOMException
. -
Abort these steps.
-
- "
readily
" -
-
If initializing the summarization model given promise and options returns false, then abort these steps.
-
Let totalBytes be the total size of the previously-downloaded summarization capabilities, in bytes.
-
Assert: totalBytes is greater than 0.
-
Perform fireProgressEvent given 0 and totalBytes.
-
Perform fireProgressEvent given totalBytes and totalBytes.
-
Finalize summarizer creation given promise and options.
-
- "
after-download
" -
-
Initiate the download process for everything the user agent needs to summarize text according to options.
-
Run the following steps, but abort when abortedDuringDownload becomes true:
-
Wait for the total number of bytes to be downloaded to become determined, and let that number be totalBytes.
-
Let lastProgressTime be the monotonic clock's unsafe current time.
-
Perform fireProgressEvent given 0 and totalBytes.
-
While true:
-
If one or more bytes have been downloaded, then:
-
If the monotonic clock's unsafe current time minus lastProgressTime is greater than 50 ms, then:
-
Let bytesSoFar be the number of bytes downloaded so far.
-
Assert: bytesSoFar is greater than 0 and less than or equal to totalBytes.
-
Perform fireProgressEvent given bytesSoFar and totalBytes.
-
If bytesSoFar equals totalBytes, then break.
-
Set lastProgressTime to the monotonic clock's unsafe current time.
-
-
-
Otherwise, if downloading has failed and cannot continue, then:
-
Queue a global task on the AI task source given this's relevant global object to reject promise with a "
NetworkError
"DOMException
. -
Abort these steps.
-
-
-
-
If aborted, then:
-
Queue a global task on the AI task source given this's relevant global object to perform the following steps:
-
Abort these steps.
-
-
If initializing the summarization model given promise and options returns false, then abort these steps.
-
Finalize summarizer creation given promise and options.
-
-
-
Return promise.
Promise
promise and an AISummarizerCreateOptions
options:
-
Assert: these steps are running in parallel.
-
Perform any necessary initialization operations for the AI model backing the user agent's summarization capabilities.
This could include loading the model into memory, loading options["
sharedContext
"] into the model’s context window, or loading any fine-tunings necessary to support the other options expressed by options. -
If initialization failed for any reason, then:
-
Queue a global task on the AI task source given promise’s relevant global object to reject promise with an "
OperationError
"DOMException
. -
Return false.
-
-
Return true.
Promise
promise and an AISummarizerCreateOptions
options:
-
Assert: these steps are running in parallel.
-
Queue a global task on the AI task source given promise’s relevant global object to perform the following steps:
-
If options["
signal
"] exists and is aborted, then:-
Reject promise with options["
signal
"]'s abort reason. -
Abort these steps.
This check is necessary in case any code running on the event loop caused the
AbortSignal
to become aborted before this task ran. -
-
Let summarizer be a new
AISummarizer
object, created in promise’s relevant realm, with- shared context
-
options["
sharedContext
"] if it exists; otherwise null - summary type
-
options["
type
"] - summary format
-
options["
format
"] - summary length
-
options["
length
"] - expected input languages
-
the result of creating a frozen array given options["
expectedInputLanguages
"] if it is not empty; otherwise null - expected context languages
-
the result of creating a frozen array given options["
expectedContextLanguages
"] if it is not empty; otherwise null - output language
-
options["
outputLanguage
"] if it exists; otherwise null
-
If options["
signal
"] exists, then add the following abort steps to options["signal
"]:-
Destroy summarizer with options["
signal
"]'s abort reason.
-
-
Resolve promise with summarizer.
-
AISummarizerCreateCoreOptions
options, perform the following steps. They mutate options in place to canonicalize and deduplicate language tags, and throw a TypeError
if any are invalid.
-
Let expectedInputLanguages be an empty ordered set.
-
If options["
expectedInputLanguages
"] exists, then for each languageTag of options["expectedInputLanguages
"]:-
If IsStructurallyValidLanguageTag(languageTag) is false, then throw a
TypeError
. -
Append CanonicalizeUnicodeLocaleId(languageTag) to expectedInputLanguages.
-
-
Set options["
expectedInputLanguages
"] to expectedInputLanguages. -
Let expectedContextLanguages be an empty ordered set.
-
If options["
expectedContextLanguages
"] exists, then for each languageTag of options["expectedContextLanguages
"]:-
If IsStructurallyValidLanguageTag(languageTag) is false, then throw a
TypeError
. -
Append CanonicalizeUnicodeLocaleId(languageTag) to expectedContextLanguages.
-
-
Set options["
expectedContextLanguages
"] to expectedContextLanguages. -
If options["
outputLanguage
"] exists, then:-
If IsStructurallyValidLanguageTag(options["
outputLanguage
"]) is false, then throw aTypeError
. -
Set options["
outputLanguage
"] to CanonicalizeUnicodeLocaleId(options["outputLanguage
"]).
-
3.2. Availability
available(options)
method steps are:
-
If this's relevant global object is a
Window
whose associated Document is not fully active, then return a promise rejected with an "InvalidStateError
"DOMException
. -
Validate and canonicalize language tags given options.
-
Let promise be a new promise created in this's relevant realm.
-
-
Let availability be the result of computing summarizer options availability given options.
-
If availability is null, then reject promise with an "
UnknownError
"DOMException
. -
Otherwise, resolve promise with availability.
-
AISummarizerCreateCoreOptions
options, perform the following steps. They return either an AICapabilityAvailability
value or null, and they mutate options in place to update language tags to their best-fit matches.
-
Assert: this algorithm is running in parallel.
-
Let availability be the summarizer non-language options availability given options["
type
"], options["format
"], and options["length
"]. -
If availability is null, then return null.
-
Let languageAvailabilities be the summarizer language availabilities.
-
If languageAvailabilities is null, then return null.
-
For each languageTag of options["
expectedInputLanguages
"]:-
Let bestReadilyAvailableMatch be LookupMatchingLocaleByBestFit(languageAvailabilities’s readily available input languages, languageTag).
-
If bestReadilyAvailableMatch is not undefined, then:
-
Replace languageTag with bestReadilyAvailableMatch in options["
expectedInputLanguages
"].
-
-
Let bestAfterDownloadAvailableMatch be LookupMatchingLocaleByBestFit(languageAvailabilities’s after-download available input languages, languageTag).
-
If bestAfterDownloadAvailableMatch is not undefined, then:
-
Replace languageTag with bestAfterDownloadAvailableMatch in options["
expectedInputLanguages
"]. -
Set availability to the minimum availability given « availability, "
after-download
" ».
-
-
Otherwise, return "
no
".
-
-
For each languageTag of options["
expectedContextLanguages
"]:-
Let bestReadilyAvailableMatch be LookupMatchingLocaleByBestFit(languageAvailabilities’s readily available context languages, languageTag).
-
If bestReadilyAvailableMatch is not undefined, then:
-
Replace languageTag with bestReadilyAvailableMatch in options["
expectedContextLanguages
"].
-
-
Let bestAfterDownloadAvailableMatch be LookupMatchingLocaleByBestFit(languageAvailabilities’s after-download available context languages, languageTag).
-
If bestAfterDownloadAvailableMatch is not undefined, then:
-
Replace languageTag with bestAfterDownloadAvailableMatch in options["
expectedContextLanguages
"]. -
Set availability to the minimum availability given « availability, "
after-download
" ».
-
-
Otherwise, return "
no
".
-
-
If options["
outputLanguage
"] is present, then:-
Let bestReadilyAvailableMatch be LookupMatchingLocaleByBestFit(languageAvailabilities’s readily available output languages, options["
outputLanguage
"]). -
If bestReadilyAvailableMatch is not undefined, then:
-
Set options["
outputLanguage
"] to bestReadilyAvailableMatch.
-
-
Otherwise:
-
Let bestAfterDownloadAvailableMatch be LookupMatchingLocaleByBestFit(languageAvailabilities’s after-download available output languages, options["
outputLanguage
"]). -
If bestAfterDownloadAvailableMatch is not undefined, then:
-
Set options["
outputLanguage
"] to bestAfterDownloadAvailableMatch. -
Set availability to the minimum availability given « availability, "
after-download
" ».
-
-
Otherwise, return "
no
".
-
-
-
Assert: availability is either "
readily
" or "after-download
". -
Return availability.
AISummarizerType
type, AISummarizerFormat
format, and an AISummarizerLength
length, is given by the following steps. They return an AICapabilityAvailability
value or null.
-
Assert: this algorithm is running in parallel.
-
If there is some error attempting to determine whether the user agent supports summarizing text, which the user agent believes to be transient (such that re-querying the summarizer non-language options availability could stop producing such an error), then return null.
-
If the user agent supports summarizing text into the type of summary described by type, in the format described by format, and with the length guidance given by length without performing any downloading operations, then return "
readily
". -
If the user agent believes it can summarize text according to type, format, and length, but only after performing a download (e.g., of an AI model or fine-tuning), then return "
after-download
". -
Otherwise, return "
no
".
A language availabilities is a struct with the following items:
-
readily available input languages
-
after-download available input languages
-
readily available context languages
-
after-download available context languages
-
readily available output languages
-
after-download available output languages
All of these items are sets of strings representing Unicode canonicalized locale identifiers, initially empty. [ECMA-402]
-
Assert: this algorithm is running in parallel.
-
If there is some error attempting to determine whether the user agent supports summarizing text, which the user agent believes to be transient (such that re-querying the summarizer language availabilities could stop producing such an error), then return null.
-
Let availabilities be a language availabilities.
-
Fill language availabilities given availabilities’s readily available input languages, availabilities’s after-download available input languages, and the purpose of summarizing text written in that language.
-
Fill language availabilities given availabilities’s readily available context languages, availabilities’s after-download available context languages, and the purpose of summarizing text using web-developer provided context information written in that language.
-
Fill language availabilities given availabilities’s readily available output languages, availabilities’s after-download available output languages, and the purpose of producing text summaries in that language.
-
Return availabilities.
-
For each human language languageTag, represented as a Unicode canonicalized locale identifier, for which the user agent supports purpose, without performing any downloading operations:
-
Append languageTag to readilyAvailableLanguages.
-
-
For each human language languageTag, represented as a Unicode canonicalized locale identifier, for which the user agent believes it can support purpose, but only after performing a download (e.g., of an AI model or fine-tuning):
-
If the union of readilyAvailableLanguages and afterDownloadAvailableLanguages does not meet the language tag set completeness rules, then:
-
Let missingLanguageTags be the set of missing language tags necessary to meet the language tag set completeness rules.
-
For each languageTag of missingLanguageTags:
-
Append languageTag to either readilyAvailableLanguages or afterDownloadAvailableLanguages. Which of the two sets to append to is implementation-defined, and should be guided by considerations similar to that of LookupMatchingLocaleByBestFit in terms of keeping "best fallback languages" together.
-
-
This definition is intended to align with that of [[AvailableLocales]] in ECMAScript Internationalization API Specification. [ECMA-402]
de-DE
" input text, it will also count as supporting "de
" input text.
The converse direction is supported not by the language tag set completeness rules, but instead by the use of LookupMatchingLocaleByBestFit, which ensures that if an implementation supports summarizing "de
" input text, it also counts as supporting summarization of "de-CH
", "de-Latn-CH
", etc.
One way this could be implemented would be for summarizer language availabilities to return that "zh-Hant
" is in the readily available input languages, and "zh
" and "zh-Hans
" are in the after-download available input languages. This return value conforms to the requirements of the language tag set completeness rules, in ensuring that "zh
" is present. Per the "should"-level guidance, the implementation has determined that "zh
" belongs in the set of after-download available input languages, with "zh-Hans
", instead of in the set of readily available input languages, with "zh-Hant
".
Combined with the use of LookupMatchingLocaleByBestFit, this means available()
will give the following answers:
function inputLangAvailable( languageTag) { return ai. summarizer. available({ expectedInputLanguages: [ languageTag] }); } inputLangAvailable( "zh" ) === "after-download" ; inputLangAvailable( "zh-Hant" ) === "readily" ; inputLangAvailable( "zh-Hans" ) === "after-download" ; inputLangAvailable( "zh-TW" ) === "readily" ; // zh-TW will best-fit to zh-Hant inputLangAvailable( "zh-HK" ) === "readily" ; // zh-HK will best-fit to zh-Hant inputLangAvailable( "zh-CN" ) === "after-download" ; // zh-CN will best-fit to zh-Hans inputLangAvailable( "zh-BR" ) === "after-download" ; // zh-BR will best-fit to zh inputLangAvailable( "zh-Kana" ) === "after-download" ; // zh-Kana will best-fit to zh
3.3. The AISummarizer
class
Every AISummarizer
has a shared context, a string-or-null, set during creation.
Every AISummarizer
has a summary type, an AISummarizerType
, set during creation.
Every AISummarizer
has a summary format, an AISummarizerFormat
, set during creation.
Every AISummarizer
has a summary length, an AISummarizerLength
, set during creation.
Every AISummarizer
has an expected input languages, a
or null, set during creation.FrozenArray
<DOMString
>
Every AISummarizer
has an expected context languages, a
or null, set during creation.FrozenArray
<DOMString
>
Every AISummarizer
has an output language, a string or null, set during creation.
Every AISummarizer
has a destruction reason, a JavaScript value, initially undefined.
Every AISummarizer
has a destroyed boolean, initially false.
This value is separate from the destruction reason so that it can be read from in parallel during the summarization process.
The sharedContext
getter steps are to return this's shared context.
The type
getter steps are to return this's summary type.
The format
getter steps are to return this's summary format.
The length
getter steps are to return this's summary length.
The expectedInputLanguages
getter steps are to return this's expected input languages.
The expectedContextLanguages
getter steps are to return this's expected context languages.
The outputLanguage
getter steps are to return this's output language.
summarize(input, options)
method steps are:
-
If this's relevant global object is a
Window
whose associated Document is not fully active, then return a promise rejected with an "InvalidStateError
"DOMException
. -
If this's destroyed is true, then return a promise rejected with this's destruction reason.
-
If options["
signal
"] exists and is aborted, then return a promise rejected with options["signal
"]'s abort reason. -
Let abortedDuringSummarization be false.
This variable will be written to from the event loop, but read from in parallel.
-
If options["
signal
"] exists, then add the following abort steps to options["signal
"]:-
Set abortedDuringSummarization to true.
-
-
Let promise be a new promise created in this's relevant realm.
-
Let context be options["
context
"] if it exists; otherwise null. -
-
Let summary be the empty string.
-
Let chunkProduced be the following steps given a string chunk:
-
Queue a global task on the AI task source given this's relevant global object to perform the following steps:
-
If abortedDuringSummarization is true, then:
-
Reject promise with options["
signal
"]'s abort reason. -
Abort these steps.
-
-
If this's destroyed is true, then:
-
Reject promise with this's destruction reason.
-
Abort these steps.
-
-
Append chunk to summary.
-
-
-
Let done be the following steps:
-
Queue a global task on the AI task source given this's relevant global object to perform the following steps:
-
If abortedDuringSummarization is true, then:
-
Reject promise with options["
signal
"]'s abort reason. -
Abort these steps.
-
-
If this's destroyed is true, then:
-
Reject promise with this's destruction reason.
-
Abort these steps.
-
-
Resolve promise with summary.
-
-
-
Let error be the following steps given summarization error information errorInfo:
-
Queue a global task on the AI task source given this's relevant global object to perform the following steps:
-
If abortedDuringSummarization is true, then:
-
Reject promise with options["
signal
"]'s abort reason. -
Abort these steps.
-
-
Let exception be the result of creating a
DOMException
with name given by errorInfo’s error name, using errorInfo’s error information to populate the message appropriately. -
Reject promise with exception.
-
-
-
Let stopProducing be the following steps:
-
Return abortedDuringSummarization.
-
-
Summarize input given this's shared context, context, this's summary type, this's summary format, this's summary length, this's output language, chunkProduced, done, error, and stopProducing.
-
-
Return promise.
summarizeStreaming(input, options)
method steps are:
-
If this's relevant global object is a
Window
whose associated Document is not fully active, then throw an "InvalidStateError
"DOMException
. -
If this's destroyed is true, then throw this's destruction reason.
-
If options["
signal
"] exists and is aborted, then throw options["signal
"]'s abort reason. -
Let abortedDuringSummarization be false.
This variable tracks web developer aborts via the options["
signal
"]AbortSignal
, which are surfaced as errors. It will be written to from the event loop, but sometimes read from in parallel. -
If options["
signal
"] exists, then add the following abort steps to options["signal
"]:-
Set abortedDuringSummarization to true.
-
-
Let stream be a new
ReadableStream
created in this's relevant realm. -
Let canceledDuringSummarization be false.
This variable tracks web developer stream cancelations via
stream.cancel()
, which are not surfaced as errors. It will be written to from the event loop, but sometimes read from in parallel. -
Set up stream with cancelAlgorithm set to the following steps (ignoring the reason argument):
-
Set canceledDuringSummarization to true.
-
-
Let context be options["
context
"] if it exists; otherwise null. -
-
Let chunkProduced be the following steps given a string chunk:
-
Queue a global task on the AI task source given this's relevant global object to perform the following steps:
-
If abortedDuringSummarization is true, then:
-
Error stream with options["
signal
"]'s abort reason. -
Abort these steps.
-
-
If this's destroyed is true, then:
-
Error stream with this's destruction reason.
-
Abort these steps.
-
-
Enqueue chunk into stream.
-
-
-
Let done be the following steps:
-
Queue a global task on the AI task source given this's relevant global object to perform the following steps:
-
If abortedDuringSummarization is true, then:
-
Error stream with options["
signal
"]'s abort reason. -
Abort these steps.
-
-
If this's destroyed is true, then:
-
Error stream with this's destruction reason.
-
Abort these steps.
-
-
Close stream.
-
-
-
Let error be the following steps given summarization error information errorInfo:
-
Queue a global task on the AI task source given this's relevant global object to perform the following steps:
-
If abortedDuringSummarization is true, then:
-
Error stream with options["
signal
"]'s abort reason. -
Abort these steps.
-
-
If this's destroyed is true, then:
-
Error stream with this's destruction reason.
-
Abort these steps.
-
-
Let exception be the result of creating a
DOMException
with name given by errorInfo’s error name, using errorInfo’s error information to populate the message appropriately. -
Error stream with exception.
-
-
-
Let stopProducing be the following steps:
-
Summarize input given this's shared context, context, this's summary type, this's summary format, this's summary length, this's output language, chunkProduced, done, error, and stopProducing.
-
-
Return stream.
AISummarizerType
type, an AISummarizerFormat
format, an AISummarizerLength
length, a string-or-null outputLanguage, an algorithm chunkProduced that takes a string and returns nothing, an algorithm done that takes no arguments and returns nothing, an algorithm error that takes summarization error information and returns nothing, and an algorithm stopProducing that takes no arguments and returns a boolean:
-
Assert: this algorithm is running in parallel.
-
In an implementation-defined manner, subject to the following guidelines, begin the processs of summarizing input into a string.
If they are non-null, sharedContext and context should be used to aid in the summarization by providing context on how the web developer wishes the input to be summarized.
The summarization should conform to the guidance given by type, format, and length, in the definitions of each of their enumeration values.
If outputLanguage is non-null, the summarization should be in that language. Otherwise, it should be in the language of input (which might not match that of context or sharedContext). If input contains multiple languages, or the language of input cannot be detected, then either the output language is implementation-defined, or the implementation may treat this as an error, per the guidance in § 3.5 Errors.
-
While true:
-
Wait for the next chunk of summarization data to be produced, for the summarization process to finish, or for the result of calling stopProducing to become true.
-
If such a chunk is successfully produced:
-
Let it be represented as a string chunk.
-
Perform chunkProduced given chunk.
-
-
Otherwise, if the summarization process has finished:
-
Perform done.
-
-
Otherwise, if stopProducing returns true, then break.
The caller will handle signaling cancelation or aborting as necessary.
-
Otherwise, if an error occurred during summarization:
-
Let the error be represented as summarization error information errorInfo according to the guidance in § 3.5 Errors.
-
Perform error given errorInfo.
-
-
The destroy()
method steps are to destroy this given a new "AbortError
" DOMException
.
AISummarizer
summarizer, given a JavaScript value reason:
-
Set summarizer’s destroyed to true.
-
Set summarizer’s destruction reason to reason.
-
The user agent should release any resources associated with summarizer, such as AI models loaded during initialize the summarization model, as long as those resources are not needed for other ongoing operations.
3.4. Options
The summarize algorithm’s details are implementation-defined, as they are expected to be powered by an AI model. However, it is intended to be controllable by the web developer through the AISummarizerType
, AISummarizerFormat
, and AISummarizerLength
enumerations.
This section gives normative guidance on how the implementation of summarize should use each enumeration value to guide the summarization process.
Value | Meaning |
---|---|
"tl;dr "
|
The summary should be short and to the point, providing a quick overview of the input, suitable for a busy reader. |
"teaser "
|
The summary should focus on the most interesting or intriguing parts of the input, designed to draw the reader in to read more. |
"key-points "
|
The summary should extract the most important points from the input, presented as a bulleted list. |
"headline "
|
The summary should effectively contain the main point of the input in a single sentence, in the format of an article headline. |
Value | Meaning |
---|---|
"short "
|
The guidance is dependent on the value of
|
"medium "
|
The guidance is dependent on the value of
|
"long "
|
The guidance is dependent on the value of
|
As with all "should"-level guidance, user agents might not conform perfectly to these. Especially in the case of counting words, it’s expected that language models might not conform perfectly.
Value | Meaning |
---|---|
"plain-text "
|
The summary should not contain any formatting or markup language. |
"markdown "
|
The summary should be formatted using the Markdown markup language, ideally as valid CommonMark. [COMMONMARK] |
3.5. Errors
A summarization error information is a struct with the following items:
- error name
-
a string that will be used for the
DOMException
's name. - error information
-
other information necessary to create a useful
DOMException
for the web developer. (Typically, just an exception message.)
When summarization fails, the following possible reasons may be surfaced to the web developer. This table lists the possible DOMException
names and the cases in which an implementation should use them:
DOMException name
| Scenarios |
---|---|
"NotAllowedError "
|
Summarization is disabled by user choice or user agent policy. |
"NotReadableError "
|
The summarization output was filtered by the user agent, e.g., because it was detected to be harmful, inaccurate, or nonsensical. |
"NotSupportedError "
|
The input to be summarized, or the context to be provided, was in a language that the user agent does not support, or was not provided properly in the call to The summarization output ended up being in a language that the user agent does not support (e.g., because the user agent has not performed sufficient quality control tests on that output language), or was not provided properly in the call to The |
"QuotaExceededError "
|
The input to be summarized was too large for the user agent to handle. |
"UnknownError "
|
All other scenarios, or if the user agent would prefer not to disclose the failure reason. |
This table does not give the complete list of exceptions that can be surfaced by summarizer.summarize()
and summarizer.summarizeStreaming()
. It only contains those which can come from the implementation-defined summarize algorithm.
4. The writer API
Just IDL for now; full spec coming!
[Exposed =(Window ,Worker ),SecureContext ]interface {
AIWriterFactory Promise <AIWriter >(
create optional AIWriterCreateOptions = {});
options Promise <AICapabilityAvailability >(
available optional AIWriterCreateCoreOptions = {}); }; [
options Exposed =(Window ,Worker ),SecureContext ]interface {
AIWriter Promise <DOMString >(
write DOMString ,
writingTask optional AIWriterWriteOptions = {});
options ReadableStream (
writeStreaming DOMString ,
writingTask optional AIWriterWriteOptions = {});
options readonly attribute DOMString ;
sharedContext readonly attribute AIWriterTone ;
tone readonly attribute AIWriterFormat ;
format readonly attribute AIWriterLength ;
length readonly attribute FrozenArray <DOMString >?;
expectedInputLanguages readonly attribute FrozenArray <DOMString >?;
expectedContextLanguages readonly attribute DOMString ?;
outputLanguage undefined (); };
destroy dictionary {
AIWriterCreateCoreOptions AIWriterTone = "neutral";
tone AIWriterFormat = "markdown";
format AIWriterLength = "short";
length sequence <DOMString >;
expectedInputLanguages sequence <DOMString >;
expectedContextLanguages DOMString ; };
outputLanguage dictionary :
AIWriterCreateOptions AIWriterCreateCoreOptions {AbortSignal ;
signal AICreateMonitorCallback ;
monitor DOMString ; };
sharedContext dictionary {
AIWriterWriteOptions DOMString ;
context AbortSignal ; };
signal enum {
AIWriterTone ,
"formal" ,
"neutral" };
"casual" enum {
AIWriterFormat ,
"plain-text" };
"markdown" enum {
AIWriterLength ,
"short" ,
"medium" };
"long"
5. The rewriter API
Just IDL for now; full spec coming!
[Exposed =(Window ,Worker ),SecureContext ]interface {
AIRewriterFactory Promise <AIRewriter >(
create optional AIRewriterCreateOptions = {});
options Promise <AICapabilityAvailability >(
available optional AIRewriterCreateCoreOptions = {}); }; [
options Exposed =(Window ,Worker ),SecureContext ]interface {
AIRewriter Promise <DOMString >(
rewrite DOMString ,
input optional AIRewriterRewriteOptions = {});
options ReadableStream (
rewriteStreaming DOMString ,
input optional AIRewriterRewriteOptions = {});
options readonly attribute DOMString ;
sharedContext readonly attribute AIRewriterTone ;
tone readonly attribute AIRewriterFormat ;
format readonly attribute AIRewriterLength ;
length readonly attribute FrozenArray <DOMString >?;
expectedInputLanguages readonly attribute FrozenArray <DOMString >?;
expectedContextLanguages readonly attribute DOMString ?;
outputLanguage undefined (); };
destroy dictionary {
AIRewriterCreateCoreOptions AIRewriterTone = "as-is";
tone AIRewriterFormat = "as-is";
format AIRewriterLength = "as-is";
length sequence <DOMString >;
expectedInputLanguages sequence <DOMString >;
expectedContextLanguages DOMString ; };
outputLanguage dictionary :
AIRewriterCreateOptions AIRewriterCreateCoreOptions {AbortSignal ;
signal AICreateMonitorCallback ;
monitor DOMString ; };
sharedContext dictionary {
AIRewriterRewriteOptions DOMString ;
context AbortSignal ; };
signal enum {
AIRewriterTone ,
"as-is" ,
"more-formal" };
"more-casual" enum {
AIRewriterFormat ,
"as-is" ,
"plain-text" };
"markdown" enum {
AIRewriterLength ,
"as-is" ,
"shorter" };
"longer"