Skip to content
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

AbortSignal support #144

Merged
merged 31 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4e033fd
Add RequestOptions to FileManager
DellaBitta May 7, 2024
e706597
Merge branch 'main' into ddb-request-abort-signal
DellaBitta May 15, 2024
a9440ae
Added RequestOptions to FileManager operations.
DellaBitta May 15, 2024
58bdc31
format
DellaBitta May 15, 2024
291f5bc
remove debug output
DellaBitta May 20, 2024
2d19db5
Added FileManager abort integration tests.
DellaBitta May 20, 2024
2f67539
docs
DellaBitta May 20, 2024
c1f6ddf
Update count-tokens.test.ts
DellaBitta May 20, 2024
c5e8b37
RequestOptions parameter changes. Removal of a cat.
DellaBitta May 20, 2024
95083e1
Created SingleRequestOptions sub interface
DellaBitta May 20, 2024
f4f168c
asynchronous typo.
DellaBitta May 20, 2024
2b30a9e
Rename abortSignal to signal.
DellaBitta May 21, 2024
b125380
docs
DellaBitta May 21, 2024
f7b7b6d
predendence -> precedence typo fix
DellaBitta May 22, 2024
fbc68fd
tests timeout config in conjunction with signal
DellaBitta May 22, 2024
1ec0275
merge main
DellaBitta Jun 5, 2024
1e440f4
docs gen
DellaBitta Jun 5, 2024
7ebd83b
Merge branch 'main' into ddb-request-abort-signal
DellaBitta Jul 16, 2024
b73cb1a
merge main
DellaBitta Jul 16, 2024
20b16fb
ChatSession and GenerativeModel implementation
DellaBitta Jul 17, 2024
c4c8426
remove SRO from some FileManager functions
DellaBitta Jul 17, 2024
c61466a
docs
DellaBitta Jul 17, 2024
6e26b0c
format
DellaBitta Jul 17, 2024
bec6f01
GoogleAIFileManager & GenerativeModel tests.
DellaBitta Jul 17, 2024
5bbbcf5
ChatSessionManager tests
DellaBitta Jul 17, 2024
6abb6d4
extra GoogleAIFileManager variables
DellaBitta Jul 17, 2024
4d7121f
Fix utest failure due to signal now appearing in requests
DellaBitta Jul 18, 2024
5e52c28
yarn docs
DellaBitta Jul 18, 2024
0edc918
AbortSignal in buildFetchOptions only if needed.
DellaBitta Jul 19, 2024
1444eb6
docs
DellaBitta Jul 19, 2024
ac4b721
changeset
DellaBitta Jul 19, 2024
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
5 changes: 3 additions & 2 deletions common/api-review/generative-ai-server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,9 @@ export class GoogleAIFileManager {
// (undocumented)
apiKey: string;
deleteFile(fileId: string): Promise<void>;
getFile(fileId: string): Promise<FileMetadataResponse>;
listFiles(listParams?: ListParams): Promise<ListFilesResponse>;
getFile(fileId: string, requestOptions?: SingleRequestOptions): Promise<FileMetadataResponse>;
// Warning: (ae-forgotten-export) The symbol "SingleRequestOptions" needs to be exported by the entry point index.d.ts
listFiles(listParams?: ListParams, requestOptions?: SingleRequestOptions): Promise<ListFilesResponse>;
uploadFile(filePath: string, fileMetadata: FileMetadata): Promise<UploadFileResponse>;
}

Expand Down
25 changes: 14 additions & 11 deletions common/api-review/generative-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ export interface CachedContentBase {

// @public
export class ChatSession {
constructor(apiKey: string, model: string, params?: StartChatParams, requestOptions?: RequestOptions);
constructor(apiKey: string, model: string, params?: StartChatParams, _requestOptions?: RequestOptions);
getHistory(): Promise<Content[]>;
// (undocumented)
model: string;
// (undocumented)
params?: StartChatParams;
// (undocumented)
requestOptions?: RequestOptions;
sendMessage(request: string | Array<string | Part>): Promise<GenerateContentResult>;
sendMessageStream(request: string | Array<string | Part>): Promise<GenerateContentStreamResult>;
sendMessage(request: string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentResult>;
sendMessageStream(request: string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;
}

// @public
Expand Down Expand Up @@ -462,16 +460,16 @@ export interface GenerativeContentBlob {

// @public
export class GenerativeModel {
constructor(apiKey: string, modelParams: ModelParams, requestOptions?: RequestOptions);
constructor(apiKey: string, modelParams: ModelParams, _requestOptions?: RequestOptions);
// (undocumented)
apiKey: string;
batchEmbedContents(batchEmbedContentRequest: BatchEmbedContentsRequest): Promise<BatchEmbedContentsResponse>;
batchEmbedContents(batchEmbedContentRequest: BatchEmbedContentsRequest, requestOptions?: SingleRequestOptions): Promise<BatchEmbedContentsResponse>;
// (undocumented)
cachedContent: CachedContent;
countTokens(request: CountTokensRequest | string | Array<string | Part>): Promise<CountTokensResponse>;
embedContent(request: EmbedContentRequest | string | Array<string | Part>): Promise<EmbedContentResponse>;
generateContent(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentResult>;
generateContentStream(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentStreamResult>;
countTokens(request: CountTokensRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<CountTokensResponse>;
embedContent(request: EmbedContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<EmbedContentResponse>;
generateContent(request: GenerateContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentResult>;
generateContentStream(request: GenerateContentRequest | string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;
// (undocumented)
generationConfig: GenerationConfig;
// (undocumented)
Expand Down Expand Up @@ -667,6 +665,11 @@ export interface Schema {
type?: FunctionDeclarationSchemaType;
}

// @public
export interface SingleRequestOptions extends RequestOptions {
signal?: AbortSignal;
}

// @public
export interface StartChatParams extends BaseParams {
cachedContent?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@

## GoogleAIFileManager.deleteFile() method

Delete file with given ID
Delete file with given ID.

Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization.

**Signature:**

```typescript
deleteFile(fileId: string): Promise<void>;
deleteFile(fileId: string, requestOptions?: SingleRequestOptions): Promise<void>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| fileId | string | |
| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ |

**Returns:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@

## GoogleAIFileManager.getFile() method

Get metadata for file with given ID
Get metadata for file with given ID.

Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization.

**Signature:**

```typescript
getFile(fileId: string): Promise<FileMetadataResponse>;
getFile(fileId: string, requestOptions?: SingleRequestOptions): Promise<FileMetadataResponse>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| fileId | string | |
| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ |

**Returns:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@

## GoogleAIFileManager.listFiles() method

List all uploaded files
List all uploaded files.

Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization.

**Signature:**

```typescript
listFiles(listParams?: ListParams): Promise<ListFilesResponse>;
listFiles(listParams?: ListParams, requestOptions?: SingleRequestOptions): Promise<ListFilesResponse>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| listParams | [ListParams](./generative-ai.listparams.md) | _(Optional)_ |
| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ |

**Returns:**

Expand Down
8 changes: 4 additions & 4 deletions docs/reference/files/generative-ai.googleaifilemanager.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export declare class GoogleAIFileManager

| Method | Modifiers | Description |
| --- | --- | --- |
| [deleteFile(fileId)](./generative-ai.googleaifilemanager.deletefile.md) | | Delete file with given ID |
| [getFile(fileId)](./generative-ai.googleaifilemanager.getfile.md) | | Get metadata for file with given ID |
| [listFiles(listParams)](./generative-ai.googleaifilemanager.listfiles.md) | | List all uploaded files |
| [uploadFile(filePath, fileMetadata)](./generative-ai.googleaifilemanager.uploadfile.md) | | Upload a file |
| [deleteFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.deletefile.md) | | <p>Delete file with given ID.</p><p>Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization.</p> |
| [getFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.getfile.md) | | <p>Get metadata for file with given ID.</p><p>Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization.</p> |
| [listFiles(listParams, requestOptions)](./generative-ai.googleaifilemanager.listfiles.md) | | <p>List all uploaded files.</p><p>Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization.</p> |
| [uploadFile(filePath, fileMetadata, requestOptions)](./generative-ai.googleaifilemanager.uploadfile.md) | | <p>Upload a file.</p><p>Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization.</p> |

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

## GoogleAIFileManager.uploadFile() method

Upload a file
Upload a file.

Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization.

**Signature:**

```typescript
uploadFile(filePath: string, fileMetadata: FileMetadata): Promise<UploadFileResponse>;
uploadFile(filePath: string, fileMetadata: FileMetadata, requestOptions?: SingleRequestOptions): Promise<UploadFileResponse>;
```

## Parameters
Expand All @@ -18,6 +20,7 @@ uploadFile(filePath: string, fileMetadata: FileMetadata): Promise<UploadFileResp
| --- | --- | --- |
| filePath | string | |
| fileMetadata | [FileMetadata](./generative-ai.filemetadata.md) | |
| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ |

**Returns:**

Expand Down
1 change: 1 addition & 0 deletions docs/reference/files/generative-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
| [ListParams](./generative-ai.listparams.md) | Params to pass to [GoogleAIFileManager.listFiles()](./generative-ai.googleaifilemanager.listfiles.md) |
| [RequestOptions](./generative-ai.requestoptions.md) | Params passed to getGenerativeModel() or GoogleAIFileManager(). |
| [RpcStatus](./generative-ai.rpcstatus.md) | Standard RPC error status object. |
| [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | Params passed to atomic asynchronous operations. |
| [UploadFileResponse](./generative-ai.uploadfileresponse.md) | Response from calling [GoogleAIFileManager.uploadFile()](./generative-ai.googleaifilemanager.uploadfile.md) |
| [VideoMetadata](./generative-ai.videometadata.md) | Metadata populated when video has been processed. |

21 changes: 21 additions & 0 deletions docs/reference/files/generative-ai.singlerequestoptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [SingleRequestOptions](./generative-ai.singlerequestoptions.md)

## SingleRequestOptions interface

Params passed to atomic asynchronous operations.

**Signature:**

```typescript
export interface SingleRequestOptions extends RequestOptions
```
**Extends:** [RequestOptions](./generative-ai.requestoptions.md)

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [signal?](./generative-ai.singlerequestoptions.signal.md) | | AbortSignal | _(Optional)_ An object that may be used to abort asynchronous requests. The request may also be aborted due to the expiration of the timeout value, if provided, and if the timeout occurs first. |

13 changes: 13 additions & 0 deletions docs/reference/files/generative-ai.singlerequestoptions.signal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [SingleRequestOptions](./generative-ai.singlerequestoptions.md) &gt; [signal](./generative-ai.singlerequestoptions.signal.md)

## SingleRequestOptions.signal property

An object that may be used to abort asynchronous requests. The request may also be aborted due to the expiration of the timeout value, if provided, and if the timeout occurs first.

**Signature:**

```typescript
signal?: AbortSignal;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Constructs a new instance of the `ChatSession` class
**Signature:**

```typescript
constructor(apiKey: string, model: string, params?: StartChatParams, requestOptions?: RequestOptions);
constructor(apiKey: string, model: string, params?: StartChatParams, _requestOptions?: RequestOptions);
```

## Parameters
Expand All @@ -19,5 +19,5 @@ constructor(apiKey: string, model: string, params?: StartChatParams, requestOpti
| apiKey | string | |
| model | string | |
| params | [StartChatParams](./generative-ai.startchatparams.md) | _(Optional)_ |
| requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ |
| \_requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ |

7 changes: 3 additions & 4 deletions docs/reference/main/generative-ai.chatsession.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ export declare class ChatSession

| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(apiKey, model, params, requestOptions)](./generative-ai.chatsession._constructor_.md) | | Constructs a new instance of the <code>ChatSession</code> class |
| [(constructor)(apiKey, model, params, \_requestOptions)](./generative-ai.chatsession._constructor_.md) | | Constructs a new instance of the <code>ChatSession</code> class |

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [model](./generative-ai.chatsession.model.md) | | string | |
| [params?](./generative-ai.chatsession.params.md) | | [StartChatParams](./generative-ai.startchatparams.md) | _(Optional)_ |
| [requestOptions?](./generative-ai.chatsession.requestoptions.md) | | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ |

## Methods

| Method | Modifiers | Description |
| --- | --- | --- |
| [getHistory()](./generative-ai.chatsession.gethistory.md) | | Gets the chat history so far. Blocked prompts are not added to history. Blocked candidates are not added to history, nor are the prompts that generated them. |
| [sendMessage(request)](./generative-ai.chatsession.sendmessage.md) | | Sends a chat message and receives a non-streaming [GenerateContentResult](./generative-ai.generatecontentresult.md) |
| [sendMessageStream(request)](./generative-ai.chatsession.sendmessagestream.md) | | Sends a chat message and receives the response as a [GenerateContentStreamResult](./generative-ai.generatecontentstreamresult.md) containing an iterable stream and a response promise. |
| [sendMessage(request, requestOptions)](./generative-ai.chatsession.sendmessage.md) | | <p>Sends a chat message and receives a non-streaming [GenerateContentResult](./generative-ai.generatecontentresult.md)<!-- -->.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.</p> |
| [sendMessageStream(request, requestOptions)](./generative-ai.chatsession.sendmessagestream.md) | | <p>Sends a chat message and receives the response as a [GenerateContentStreamResult](./generative-ai.generatecontentstreamresult.md) containing an iterable stream and a response promise.</p><p>Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.</p> |

11 changes: 0 additions & 11 deletions docs/reference/main/generative-ai.chatsession.requestoptions.md

This file was deleted.

7 changes: 5 additions & 2 deletions docs/reference/main/generative-ai.chatsession.sendmessage.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@

## ChatSession.sendMessage() method

Sends a chat message and receives a non-streaming [GenerateContentResult](./generative-ai.generatecontentresult.md)
Sends a chat message and receives a non-streaming [GenerateContentResult](./generative-ai.generatecontentresult.md)<!-- -->.

Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.

**Signature:**

```typescript
sendMessage(request: string | Array<string | Part>): Promise<GenerateContentResult>;
sendMessage(request: string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentResult>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| request | string \| Array&lt;string \| [Part](./generative-ai.part.md)<!-- -->&gt; | |
| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ |

**Returns:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@

Sends a chat message and receives the response as a [GenerateContentStreamResult](./generative-ai.generatecontentstreamresult.md) containing an iterable stream and a response promise.

Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.

**Signature:**

```typescript
sendMessageStream(request: string | Array<string | Part>): Promise<GenerateContentStreamResult>;
sendMessageStream(request: string | Array<string | Part>, requestOptions?: SingleRequestOptions): Promise<GenerateContentStreamResult>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| request | string \| Array&lt;string \| [Part](./generative-ai.part.md)<!-- -->&gt; | |
| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ |

**Returns:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Constructs a new instance of the `GenerativeModel` class
**Signature:**

```typescript
constructor(apiKey: string, modelParams: ModelParams, requestOptions?: RequestOptions);
constructor(apiKey: string, modelParams: ModelParams, _requestOptions?: RequestOptions);
```

## Parameters
Expand All @@ -18,5 +18,5 @@ constructor(apiKey: string, modelParams: ModelParams, requestOptions?: RequestOp
| --- | --- | --- |
| apiKey | string | |
| modelParams | [ModelParams](./generative-ai.modelparams.md) | |
| requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ |
| \_requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ |

Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@

Embeds an array of [EmbedContentRequest](./generative-ai.embedcontentrequest.md)<!-- -->s.

Fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take precedence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the initialization.

**Signature:**

```typescript
batchEmbedContents(batchEmbedContentRequest: BatchEmbedContentsRequest): Promise<BatchEmbedContentsResponse>;
batchEmbedContents(batchEmbedContentRequest: BatchEmbedContentsRequest, requestOptions?: SingleRequestOptions): Promise<BatchEmbedContentsResponse>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| batchEmbedContentRequest | [BatchEmbedContentsRequest](./generative-ai.batchembedcontentsrequest.md) | |
| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ |

**Returns:**

Expand Down
Loading
Loading