-
Notifications
You must be signed in to change notification settings - Fork 940
feat(ai): Add support for AbortSignal
#8890
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
Open
dlarocque
wants to merge
9
commits into
main
Choose a base branch
from
dl/abort-signal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c616128
feat(vertexai): Add support for `AbortSignal`
dlarocque 54589ad
Run formatter
dlarocque b4ae062
Merge branch 'main' into dl/abort-signal
dlarocque a82a809
Fix docs
dlarocque f690611
Update changeset to use `@firebase/ai`
dlarocque 821e580
remove ghost changeset
dlarocque 15239fb
update example in docs
dlarocque 0096b9a
Docs review
dlarocque 931972d
Merge branch 'main' into dl/abort-signal
dlarocque 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
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
--- | ||
'firebase': minor | ||
'@firebase/ai': minor | ||
--- | ||
|
||
Add support for `AbortSignal`, allowing requests to be aborted. |
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
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
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
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
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
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
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
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,61 @@ | ||
Project: /docs/reference/js/_project.yaml | ||
Book: /docs/reference/_book.yaml | ||
page_type: reference | ||
|
||
{% comment %} | ||
DO NOT EDIT THIS FILE! | ||
This is generated by the JS SDK team, and any local changes will be | ||
overwritten. Changes should be made in the source code at | ||
https://github.com/firebase/firebase-js-sdk | ||
{% endcomment %} | ||
|
||
# SingleRequestOptions interface | ||
Options that can be provided per-request. Extends the base [RequestOptions](./ai.requestoptions.md#requestoptions_interface) (like `timeout` and `baseUrl`<!-- -->) with request-specific controls like cancellation via `AbortSignal`<!-- -->. | ||
|
||
Options specified here will override any default [RequestOptions](./ai.requestoptions.md#requestoptions_interface) configured on a model (e.g. [GenerativeModel](./ai.generativemodel.md#generativemodel_class)<!-- -->). | ||
dlarocque marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface SingleRequestOptions extends RequestOptions | ||
``` | ||
<b>Extends:</b> [RequestOptions](./ai.requestoptions.md#requestoptions_interface) | ||
|
||
## Properties | ||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| [signal](./ai.singlerequestoptions.md#singlerequestoptionssignal) | AbortSignal | An <code>AbortSignal</code> instance that allows cancelling ongoing requests (like <code>generateContent</code> or <code>generateImages</code>).<!-- -->If provided, calling <code>abort()</code> on the corresponding <code>AbortController</code> will attempt to cancel the underlying HTTP request. An <code>AbortError</code> will be thrown if cancellation is successful.<!-- -->Note that this will not cancel the request in the backend, so billing will still be applied despite cancellation. | | ||
dlarocque marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## SingleRequestOptions.signal | ||
|
||
An `AbortSignal` instance that allows cancelling ongoing requests (like `generateContent` or `generateImages`<!-- -->). | ||
|
||
If provided, calling `abort()` on the corresponding `AbortController` will attempt to cancel the underlying HTTP request. An `AbortError` will be thrown if cancellation is successful. | ||
|
||
Note that this will not cancel the request in the backend, so billing will still be applied despite cancellation. | ||
dlarocque marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
signal?: AbortSignal; | ||
``` | ||
|
||
### Example | ||
|
||
|
||
```javascript | ||
const controller = new AbortController(); | ||
const model = getGenerativeModel({ | ||
// ... | ||
}); | ||
model.generateContent( | ||
"Write a story about a magic backpack.", | ||
{ signal: controller.signal } | ||
); | ||
|
||
// To cancel request: | ||
controller.abort(); | ||
|
||
``` | ||
|
Oops, something went wrong.
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.