Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ LanguageDetector.create(options)
- `monitor` {{optional_inline}}
- : A callback function with a {{domxref("CreateMonitor")}} argument that enables monitoring download progress of the AI model.
- `signal` {{optional_inline}}
- : An {{domxref("AbortSignal")}} object instance, which allows the `create()` operation to be aborted via the associated {{domxref("AbortController")}}.
- : An {{domxref("AbortSignal")}} object instance, which allows a `create()` operation to be aborted via the associated {{domxref("AbortController")}}. The exact effect is dependant on when {{domxref("AbortController.abort()")}} is called:
- If `abort()` is called before the `create()` promise resolves, the `create()` operation is cancelled.
- If `abort()` is called after the `create()` promise fulfills, it has the same effect as calling {{domxref("LanguageDetector.destroy()")}}: The resources assigned to the resulting `LanguageDetector` instance are released, and any ongoing and subsequent `LanguageDetector` method calls will reject with an `AbortError`.

### Return value

Expand Down
4 changes: 3 additions & 1 deletion files/en-us/web/api/languagedetector/destroy/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ browser-compat: api.LanguageDetector.destroy

{{APIRef("Translator and Language Detector APIs")}}{{SeeCompatTable}}{{securecontext_header}}

The **`destroy()`** method of the {{domxref("LanguageDetector")}} interface destroys the `LanguageDetector` instance it is called on. It makes sense to destroy these objects if they are no longer going to be used, as they tie up significant resources in their handling.
The **`destroy()`** method of the {{domxref("LanguageDetector")}} interface releases the resources assigned to the `LanguageDetector` instance it is called on and stops any further activity on it. This means that any ongoing and subsequent method calls made on the `LanguageDetector` will reject with an `AbortError`.

It makes sense to destroy `LanguageDetector` objects if they are no longer being used, as they tie up significant resources in their handling.

## Syntax

Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/api/languagedetector/detect/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ The last array element returned will always have a `detectedLanguage` value of `

### Exceptions

- `AbortError` {{domxref("DOMException")}}
- : Thrown if the `LanguageDetector` was previously destroyed (had {{domxref("LanguageDetector.destroy()")}} called on it, or was aborted via its abort [`signal`](/en-US/docs/Web/API/LanguageDetector/create_static#signal) after creation).
- `InvalidStateError` {{domxref("DOMException")}}
- : Thrown if the current {{domxref("Document")}} is not active.
- {{domxref("QuotaExceededError")}}
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/languagedetector/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The **`LanguageDetector`** interface of the {{domxref("Translator and Language D
## Instance methods

- {{domxref("LanguageDetector.destroy", "destroy()")}} {{Experimental_Inline}}
- : Destroys the `LanguageDetector` instance it is called on.
- : Releases the resources assigned to the `LanguageDetector` instance it is called on and stops any further activity on it.
- {{domxref("LanguageDetector.detect", "detect()")}} {{Experimental_Inline}}
- : Detects the closest matching language or languages that a given text string is most likely to be written in.
- {{domxref("LanguageDetector.measureInputUsage", "measureInputUsage()")}} {{Experimental_Inline}}
Expand Down
4 changes: 3 additions & 1 deletion files/en-us/web/api/summarizer/create_static/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ Summarizer.create(options)
- `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")}}.
- : An {{domxref("AbortSignal")}} object instance, which allows a `create()` operation to be aborted via the associated {{domxref("AbortController")}}. The exact effect is dependant on when {{domxref("AbortController.abort()")}} is called:
- If `abort()` is called before the `create()` promise resolves, the `create()` operation is cancelled.
- If `abort()` is called after the `create()` promise fulfills, it has the same effect as calling {{domxref("Summarizer.destroy()")}}: The resources assigned to the resulting `Summarizer` instance are released, and any ongoing and subsequent `Summarizer` method calls will reject with an `AbortError`.
- `type`
- : An enumerated value specifying the {{domxref("Summarizer.type", "type")}} of summary you want this `Summarizer` to generate. Defaults to `key-points`.

Expand Down
4 changes: 3 additions & 1 deletion files/en-us/web/api/summarizer/destroy/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ browser-compat: api.Summarizer.destroy

{{APIRef("Summarizer API")}}{{SeeCompatTable}}{{securecontext_header}}

The **`destroy()`** method of the {{domxref("Summarizer")}} interface destroys the `Summarizer` instance it is called on. It makes sense to destroy `Summarizer` objects if they are no longer going to be used, as they tie up significant resources in their handling.
The **`destroy()`** method of the {{domxref("Summarizer")}} interface releases the resources assigned to the `Summarizer` instance it is called on and stops any further activity on it. This means that any ongoing and subsequent method calls made on the `Summarizer` will reject with an `AbortError`.

It makes sense to destroy `Summarizer` objects if they are no longer being used, as they tie up significant resources in their handling.

## Syntax

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/summarizer/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The **`Summarizer`** interface of the {{domxref("Summarizer API", "Summarizer AP
## Instance methods

- {{domxref("Summarizer.destroy", "destroy()")}} {{Experimental_Inline}}
- : Destroys the `Summarizer` instance it is called on.
- : Releases the resources assigned to the `Summarizer` instance it is called on and stops any further activity on it.
- {{domxref("Summarizer.measureInputUsage", "measureInputUsage()")}} {{Experimental_Inline}}
- : Reports how much input quota would be used by a summarize operation for a given text input.
- {{domxref("Summarizer.summarize", "summarize()")}} {{Experimental_Inline}}
Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/api/summarizer/summarize/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ A {{jsxref("Promise")}} that fulfills with a string containing the generated sum

### Exceptions

- `AbortError` {{domxref("DOMException")}}
- : Thrown if the `Summarizer` was previously destroyed (had {{domxref("Summarizer.destroy()")}} called on it, or was aborted via its abort [`signal`](/en-US/docs/Web/API/Summarizer/create_static#signal) after creation).
- `InvalidStateError` {{domxref("DOMException")}}
- : Thrown if the current {{domxref("Document")}} is not active.
- `NotAllowedError` {{domxref("DOMException")}}
Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/api/summarizer/summarizestreaming/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ A {{domxref("ReadableStream")}} containing the generated summary.

### Exceptions

- `AbortError` {{domxref("DOMException")}}
- : Thrown if the `Summarizer` was previously destroyed (had {{domxref("Summarizer.destroy()")}} called on it, or was aborted via its abort [`signal`](/en-US/docs/Web/API/Summarizer/create_static#signal) after creation).
- `InvalidStateError` {{domxref("DOMException")}}
- : Thrown if the current {{domxref("Document")}} is not active.
- `NotAllowedError` {{domxref("DOMException")}}
Expand Down
4 changes: 3 additions & 1 deletion files/en-us/web/api/summarizer_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ This is done using the functionality made available by the {{domxref("Summarizer
> If you want to check whether the browser AI model is able to support your preferences, you can do so with the {{domxref("Summarizer.availability_static", "Summarizer.availability()")}} static method.
2. Run the {{domxref("Summarizer.summarize()")}} instance method to request the summary.

After a `Summarizer` instance has been created, you can remove it again using the {{domxref("Summarizer.destroy()")}} instance method. You can also cancel a pending `create()` or `summarize()` operation using an {{domxref("AbortController")}}.
You can cancel a pending `create()` or `summarize()` operation using an {{domxref("AbortController")}}.

After a `Summarizer` instance has been created, you can release its assigned resources and stop any further activity by calling its {{domxref("Summarizer.destroy()")}} method. You are encouraged to do this after you've finished with the `Summarizer` object as it can consume a lot of resources.

See [Using the Summarizer API](/en-US/docs/Web/API/Summarizer_API/Using) for a walkthrough of how the API works.

Expand Down
14 changes: 10 additions & 4 deletions files/en-us/web/api/summarizer_api/using/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ console.log("Stream complete");
summaryOutput.textContent = summary;
```

After a `Summarizer` instance has been created, you can remove it again using the {{domxref("Summarizer.destroy()")}} instance method. It makes sense to destroy `Summarizer` objects if they are no longer going to be used, as they tie up significant resources in their handling.
## Cancelling operations and destroying instances

## Cancelling summarize operations

You can cancel a pending `create()`, `summarize()`, or `summarizeStreaming()` operation using an {{domxref("AbortController")}}:
You can cancel a pending `create()`, `summarize()`, or `summarizeStreaming()` operation using an {{domxref("AbortController")}}, with the associated {{domxref("AbortSignal")}} being included inside the method options object as a `signal` property value. For example, aborting a `Summarizer.create()` operation would look like this:

```js
const controller = new AbortController();
Expand All @@ -100,6 +98,14 @@ const summary = await summarizer.summarize(myTextString, {
controller.abort();
```

After a `Summarizer` instance has been created, you can release its assigned resources and stop any further activity by calling its {{domxref("Summarizer.destroy()")}} method. You are encouraged to do this after you've finished with the `Summarizer` object as it can consume a lot of resources.

```js
summarizer.destroy();
```

If a `create()` call has an associated {{domxref("AbortController")}}, and you call its {{domxref("AbortController.abort()")}} method after the `create()` call has succeeded, it will have the same effect as calling `destroy()` on the resulting `Summarizer` object.

## Monitoring download progress

If the AI model for a particular summarizer is downloading (`availability()` returns `downloadable` and `downloading`), it is helpful to provide the user with feedback to tell them how long they need to wait before the operation completes.
Expand Down
4 changes: 3 additions & 1 deletion files/en-us/web/api/translator/create_static/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ Translator.create(options)
- `monitor` {{optional_inline}}
- : A callback function with a {{domxref("CreateMonitor")}} argument that enables monitoring download progress of the AI model.
- `signal` {{optional_inline}}
- : An {{domxref("AbortSignal")}} object instance, which allows the `create()` operation to be aborted via the associated {{domxref("AbortController")}}.
- : An {{domxref("AbortSignal")}} object instance, which allows a `create()` operation to be aborted via the associated {{domxref("AbortController")}}. The exact effect is dependant on when {{domxref("AbortController.abort()")}} is called:
- If `abort()` is called before the `create()` promise resolves, the `create()` operation is cancelled.
- If `abort()` is called after the `create()` promise fulfills, it has the same effect as calling {{domxref("Translator.destroy()")}}: The resources assigned to the resulting `Translator` instance are released, and any ongoing and subsequent `Translator` method calls will reject with an `AbortError`.

### Return value

Expand Down
4 changes: 3 additions & 1 deletion files/en-us/web/api/translator/destroy/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ browser-compat: api.Translator.destroy

{{APIRef("Translator and Language Detector APIs")}}{{SeeCompatTable}} {{securecontext_header}}

The **`destroy()`** method of the {{domxref("Translator")}} interface destroys the `Translator` instance it is called on. It makes sense to destroy these objects if they are no longer going to be used, as they tie up significant resources in their handling.
The **`destroy()`** method of the {{domxref("Translator")}} interface releases the resources assigned to the `Translator` instance it is called on and stops any further activity on it. This means that any ongoing and subsequent method calls made on the `Translator` will reject with an `AbortError`.

It makes sense to destroy `Translator` objects if they are no longer being used, as they tie up significant resources in their handling.

## Syntax

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/translator/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The **`Translator`** interface of the {{domxref("Translator and Language Detecto
## Instance methods

- {{domxref("Translator.destroy", "destroy()")}} {{Experimental_Inline}}
- : Destroys the `Translator` instance it is called on.
- : Releases the resources assigned to the `Translator` instance it is called on and stops any further activity on it.
- {{domxref("Translator.measureInputUsage", "measureInputUsage()")}} {{Experimental_Inline}}
- : Reports how much input quota would be used by a translation operation for a given text input.
- {{domxref("Translator.translate", "translate()")}} {{Experimental_Inline}}
Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/api/translator/translate/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ A {{jsxref("Promise")}} that fulfills with a string containing the generated tra

### Exceptions

- `AbortError` {{domxref("DOMException")}}
- : Thrown if the `Translator` was previously destroyed (had {{domxref("Translator.destroy()")}} called on it, or was aborted via its abort [`signal`](/en-US/docs/Web/API/Translator/create_static#signal) after creation).
- `InvalidStateError` {{domxref("DOMException")}}
- : Thrown if the current {{domxref("Document")}} is not active.
- {{domxref("QuotaExceededError")}}
Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/api/translator/translatestreaming/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ A {{domxref("ReadableStream")}} containing the generated translation.

### Exceptions

- `AbortError` {{domxref("DOMException")}}
- : Thrown if the `Translator` was previously destroyed (had {{domxref("Translator.destroy()")}} called on it, or was aborted via its abort [`signal`](/en-US/docs/Web/API/Translator/create_static#signal) after creation).
- `InvalidStateError` {{domxref("DOMException")}}
- : Thrown if the current {{domxref("Document")}} is not active.
- {{domxref("QuotaExceededError")}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ AI is well-suited to facilitating language detection and translation. The Transl
- Language detection is done via the {{domxref("LanguageDetector")}} interface. A `LanguageDetector` object instance is created using the {{domxref("LanguageDetector.create_static", "LanguageDetector.create()")}} static method, then the {{domxref("LanguageDetector.detect", "detect()")}} instance method is passed the text string to detect the language for.
- Translation is done via the {{domxref("Translator")}} interface. A `Translator` object instance is created using the {{domxref("Translator.create_static", "Translator.create()")}} static method, then the {{domxref("Translator.translate", "translate()")}} instance method is passed the text string to translate.

You can also cancel pending operations using an {{domxref("AbortController")}}.
You can cancel a pending `create()`, `detect()`, or `translate()` operation using an {{domxref("AbortController")}}.

The `Translator` and `LanguageDetector` instances consume a lot of resources, so once you're finished with them, you are encouraged to remove them using a `destroy()` instance method (for example, {{domxref("Translator.destroy()")}}).
After a `LanguageDetector` or `Translator` instance has been created, you can release its assigned resources and stop any further activity by calling its {{domxref("LanguageDetector.destroy()")}}/{{domxref("Translator.destroy()")}} method. You are encouraged to do this after you've finished with the object as it can consume a lot of resources.

See [Using the Translator and Language Detector APIs](/en-US/docs/Web/API/Translator_and_Language_Detector_APIs/Using) for a walkthrough of how to use the APIs.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ const translator = await Translator.create({
controller.abort();
```

Once a `Translator` or `LanguageDetector` instance has been created, you can destroy it when it is finished with using the {{domxref("Translator.destroy()")}}/{{domxref("LanguageDetector.destroy()")}} methods:
After a `LanguageDetector` or `Translator` instance has been created, you can release its assigned resources and stop any further activity by calling its {{domxref("LanguageDetector.destroy()")}}/{{domxref("Translator.destroy()")}} method. You are encouraged to do this after you've finished with the object as it can consume a lot of resources.

```js
translator.destroy();
detector.destroy();
```

It makes sense to destroy these objects if they are no longer going to be used, as they tie up significant resources in their handling.
If a `create()` call has an associated {{domxref("AbortController")}}, and you call its {{domxref("AbortController.abort()")}} method after the `create()` call has succeeded, it will have the same effect as calling `destroy()` on the resulting `LanguageDetector` or `Translator` object.

## Monitoring download progress

Expand Down