From 4e033fdde19fcbc14c6edb37581b2f2b42ecd96b Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Tue, 7 May 2024 14:57:11 -0400 Subject: [PATCH 01/28] Add RequestOptions to FileManager --- packages/main/src/files/file-manager.ts | 56 +++++++++++++++++++++---- packages/main/src/files/request.ts | 22 +++++++--- packages/main/types/requests.ts | 5 +++ 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/packages/main/src/files/file-manager.ts b/packages/main/src/files/file-manager.ts index e8577d68..6b83e907 100644 --- a/packages/main/src/files/file-manager.ts +++ b/packages/main/src/files/file-manager.ts @@ -39,10 +39,14 @@ export interface UploadMetadata { * @public */ export class GoogleAIFileManager { + private _requestOptions: RequestOptions; constructor( public apiKey: string, - private _requestOptions?: RequestOptions, - ) {} + requestOptions?: RequestOptions, + ) { + Object.assign(this._requestOptions, requestOptions); + delete this._requestOptions.abortSignal; + } /** * Upload a file @@ -50,12 +54,19 @@ export class GoogleAIFileManager { async uploadFile( filePath: string, fileMetadata: FileMetadata, + requestOptions?: RequestOptions, ): Promise { const file = readFileSync(filePath); + let filesRequestOptions = {}; + Object.assign( + filesRequestOptions, + this._requestOptions || {}, + requestOptions || {}, + ); const url = new FilesRequestUrl( FilesTask.UPLOAD, this.apiKey, - this._requestOptions, + filesRequestOptions, ); const uploadHeaders = getHeaders(url); @@ -98,11 +109,20 @@ export class GoogleAIFileManager { /** * List all uploaded files */ - async listFiles(listParams?: ListParams): Promise { + async listFiles( + listParams?: ListParams, + requestOptions?: RequestOptions, + ): Promise { + let filesRequestOptions = {}; + Object.assign( + filesRequestOptions, + this._requestOptions || {}, + requestOptions || {}, + ); const url = new FilesRequestUrl( FilesTask.LIST, this.apiKey, - this._requestOptions, + filesRequestOptions, ); if (listParams?.pageSize) { url.appendParam("pageSize", listParams.pageSize.toString()); @@ -118,11 +138,20 @@ export class GoogleAIFileManager { /** * Get metadata for file with given ID */ - async getFile(fileId: string): Promise { + async getFile( + fileId: string, + requestOptions?: RequestOptions, + ): Promise { + let filesRequestOptions = {}; + Object.assign( + filesRequestOptions, + this._requestOptions || {}, + requestOptions || {}, + ); const url = new FilesRequestUrl( FilesTask.GET, this.apiKey, - this._requestOptions, + filesRequestOptions, ); url.appendPath(parseFileId(fileId)); const uploadHeaders = getHeaders(url); @@ -133,11 +162,20 @@ export class GoogleAIFileManager { /** * Delete file with given ID */ - async deleteFile(fileId: string): Promise { + async deleteFile( + fileId: string, + requestOptions?: RequestOptions, + ): Promise { + let filesRequestOptions = {}; + Object.assign( + filesRequestOptions, + this._requestOptions || {}, + requestOptions || {}, + ); const url = new FilesRequestUrl( FilesTask.DELETE, this.apiKey, - this._requestOptions, + filesRequestOptions, ); url.appendPath(parseFileId(fileId)); const uploadHeaders = getHeaders(url); diff --git a/packages/main/src/files/request.ts b/packages/main/src/files/request.ts index 489a1022..4f3db960 100644 --- a/packages/main/src/files/request.ts +++ b/packages/main/src/files/request.ts @@ -131,13 +131,23 @@ export async function makeFilesRequest( } /** - * Get AbortSignal if timeout is specified + * Create an AbortSignal based on the timeout and abortSignal in the + * RequestOptions. */ function getSignal(requestOptions?: RequestOptions): AbortSignal | null { - if (requestOptions?.timeout >= 0) { - const abortController = new AbortController(); - const signal = abortController.signal; - setTimeout(() => abortController.abort(), requestOptions.timeout); - return signal; + if ( + requestOptions.abortSignal !== undefined || + requestOptions?.timeout >= 0 + ) { + const controller = new AbortController(); + if (requestOptions?.timeout >= 0) { + setTimeout(() => controller.abort(), requestOptions.timeout); + } + if (requestOptions.abortSignal) { + requestOptions.abortSignal.addEventListener("abort", () => { + controller.abort(); + }); + } + return controller.signal; } } diff --git a/packages/main/types/requests.ts b/packages/main/types/requests.ts index eefa3825..e63a1e6b 100644 --- a/packages/main/types/requests.ts +++ b/packages/main/types/requests.ts @@ -140,6 +140,11 @@ export interface RequestOptions { * Custom HTTP request headers. */ customHeaders?: Headers | Record; + /** + * An object that may be used to abort aynchronous requests. This is only available on + * a per request basis, and is ignored by models constructed with a RequestOptions object. + */ + abortSignal?: AbortSignal; } /** From a9440aed9acef4e3d99ac774f4e3d2d34fe51946 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 15 May 2024 14:49:29 -0400 Subject: [PATCH 02/28] Added RequestOptions to FileManager operations. --- packages/main/src/files/file-manager.ts | 50 ++++++++++++------------- packages/main/src/files/request.ts | 2 +- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/packages/main/src/files/file-manager.ts b/packages/main/src/files/file-manager.ts index 36056d02..f444743e 100644 --- a/packages/main/src/files/file-manager.ts +++ b/packages/main/src/files/file-manager.ts @@ -47,8 +47,11 @@ export class GoogleAIFileManager { public apiKey: string, requestOptions?: RequestOptions, ) { - Object.assign(this._requestOptions, requestOptions); - delete this._requestOptions.abortSignal; + this._requestOptions = { }; + if (requestOptions) { + Object.assign(this._requestOptions, requestOptions); + delete this._requestOptions.abortSignal; + } } /** @@ -60,12 +63,13 @@ export class GoogleAIFileManager { requestOptions?: RequestOptions, ): Promise { const file = readFileSync(filePath); - let filesRequestOptions = {}; - Object.assign( - filesRequestOptions, - this._requestOptions || {}, - requestOptions || {}, - ); + const filesRequestOptions = Object.create(this._requestOptions); + if (requestOptions) { + Object.assign(filesRequestOptions, requestOptions); + } + + console.error("DEDB requestOptions: ", filesRequestOptions); + const url = new FilesRequestUrl( FilesTask.UPLOAD, this.apiKey, @@ -110,12 +114,10 @@ export class GoogleAIFileManager { listParams?: ListParams, requestOptions?: RequestOptions, ): Promise { - let filesRequestOptions = {}; - Object.assign( - filesRequestOptions, - this._requestOptions || {}, - requestOptions || {}, - ); + const filesRequestOptions = Object.create(this._requestOptions); + if (requestOptions) { + Object.assign(filesRequestOptions, requestOptions); + } const url = new FilesRequestUrl( FilesTask.LIST, this.apiKey, @@ -139,12 +141,10 @@ export class GoogleAIFileManager { fileId: string, requestOptions?: RequestOptions, ): Promise { - let filesRequestOptions = {}; - Object.assign( - filesRequestOptions, - this._requestOptions || {}, - requestOptions || {}, - ); + const filesRequestOptions = Object.create(this._requestOptions); + if (requestOptions) { + Object.assign(filesRequestOptions, requestOptions); + } const url = new FilesRequestUrl( FilesTask.GET, this.apiKey, @@ -163,12 +163,10 @@ export class GoogleAIFileManager { fileId: string, requestOptions?: RequestOptions, ): Promise { - let filesRequestOptions = {}; - Object.assign( - filesRequestOptions, - this._requestOptions || {}, - requestOptions || {}, - ); + const filesRequestOptions = Object.create(this._requestOptions); + if (requestOptions) { + Object.assign(filesRequestOptions, requestOptions); + } const url = new FilesRequestUrl( FilesTask.DELETE, this.apiKey, diff --git a/packages/main/src/files/request.ts b/packages/main/src/files/request.ts index 4f3db960..0bfc5587 100644 --- a/packages/main/src/files/request.ts +++ b/packages/main/src/files/request.ts @@ -136,7 +136,7 @@ export async function makeFilesRequest( */ function getSignal(requestOptions?: RequestOptions): AbortSignal | null { if ( - requestOptions.abortSignal !== undefined || + requestOptions?.abortSignal !== undefined || requestOptions?.timeout >= 0 ) { const controller = new AbortController(); From 58bdc31c9ec913c87d45f6883fe3662d9a4a862d Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 15 May 2024 15:46:28 -0400 Subject: [PATCH 03/28] format --- packages/main/src/files/file-manager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/main/src/files/file-manager.ts b/packages/main/src/files/file-manager.ts index f444743e..f7d932be 100644 --- a/packages/main/src/files/file-manager.ts +++ b/packages/main/src/files/file-manager.ts @@ -47,7 +47,7 @@ export class GoogleAIFileManager { public apiKey: string, requestOptions?: RequestOptions, ) { - this._requestOptions = { }; + this._requestOptions = {}; if (requestOptions) { Object.assign(this._requestOptions, requestOptions); delete this._requestOptions.abortSignal; From 291f5bc2bd86c061ddb5992029a4eb60bbdeadfd Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Mon, 20 May 2024 10:48:47 -0400 Subject: [PATCH 04/28] remove debug output --- packages/main/src/files/file-manager.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/main/src/files/file-manager.ts b/packages/main/src/files/file-manager.ts index f7d932be..dc3ff994 100644 --- a/packages/main/src/files/file-manager.ts +++ b/packages/main/src/files/file-manager.ts @@ -68,8 +68,6 @@ export class GoogleAIFileManager { Object.assign(filesRequestOptions, requestOptions); } - console.error("DEDB requestOptions: ", filesRequestOptions); - const url = new FilesRequestUrl( FilesTask.UPLOAD, this.apiKey, From 2d19db5e502e701ed1638a6551f14d828830fec9 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Mon, 20 May 2024 11:45:17 -0400 Subject: [PATCH 05/28] Added FileManager abort integration tests. --- .../node/abort-signal.test.ts | 75 ++++++++++++++++++ .../main/test-integration/resources/cat.jpg | Bin 0 -> 17858 bytes 2 files changed, 75 insertions(+) create mode 100644 packages/main/test-integration/node/abort-signal.test.ts create mode 100644 packages/main/test-integration/resources/cat.jpg diff --git a/packages/main/test-integration/node/abort-signal.test.ts b/packages/main/test-integration/node/abort-signal.test.ts new file mode 100644 index 00000000..8f335550 --- /dev/null +++ b/packages/main/test-integration/node/abort-signal.test.ts @@ -0,0 +1,75 @@ +/** + * @license + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect, use } from "chai"; +import * as chaiAsPromised from "chai-as-promised"; +import { RequestOptions } from "../.."; +import { GoogleAIFileManager } from "../../dist/files"; + +use(chaiAsPromised); + +/** + * Integration tests against live backend. + */ +describe("abortSignal", function () { + this.timeout(60e3); + this.slow(10e3); + it("file manager uploadFile abort test", async () => { + const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); + const filePathInService = "abortsignal.jpg"; + + // This delete step should cleanup the state of the service for this and + // future executions. + try { + await fileManager.deleteFile("files/abortsignal"); + } catch (error) {} + + const abortSignal = AbortSignal.timeout(1); + const promise = fileManager.uploadFile( + "test-integration/resources/cat.jpg", + { + mimeType: "image/jpeg", + name: filePathInService, + }, + { + abortSignal, + }, + ); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("file manager listFiles abort test", async () => { + const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); + const abortSignal = AbortSignal.timeout(1); + const requestOptions: RequestOptions = { abortSignal }; + const promise = fileManager.listFiles(/* listParams= */ {}, requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("file manager getFile abort test", async () => { + const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); + const abortSignal = AbortSignal.timeout(1); + const requestOptions: RequestOptions = { abortSignal }; + const promise = fileManager.getFile("abortSignal.jpg", requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("file manager deleteFile abort test", async () => { + const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); + const abortSignal = AbortSignal.timeout(1); + const requestOptions: RequestOptions = { abortSignal }; + const promise = fileManager.deleteFile("abortSignal.jpg", requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); +}); diff --git a/packages/main/test-integration/resources/cat.jpg b/packages/main/test-integration/resources/cat.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8d2069e6c979ef6fe4fb52e7873e1019f008d2e1 GIT binary patch literal 17858 zcmb4KRa9KTvK?H5JA=;P65QS0U4jRf!6mo^9T?o*-91Qff?MzqG`K?ogk0|Xcc7*ycGo$p*4ewOtNyM2+X3Jx$tlVK;Nai@3U34OZv!9=Kt@DDMnXhJMnXnGK}JQ# zK}SbJLnpw(#>62eAR!?pAR;28praxq2LXwQs9C8&^bAbQOr%t79Bhmnbc{@l{{?|V zK|w)BMaM@+$7duXB4hl2+rI$-E-GLdP67cA7XXh7hky(BZx{ds0N~*f-n{)^LqLQ_ zffswe#3iUXW0AGz1l(sbGGXy>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*0MtI1k;;O+&ep%%_G=z?v{*^RQ86=k6 zv}-BaIl}NMQh5OjnTa8ra~`8Dz&&b`LL+XCbjlgZ3}@0QyZ~8l7CVt{sB?ff?&g(V zLd#Ty;!y5eX3{%wY6_w{gb|Adl@tcsk)CMbTFh)C}2%rTQ$ITzHfmr0H`qcqnsa?DZ$82UvNE?EIw0m*=YNHg%Zi_gU zHCQ7^kyVIOfzPMDed{*zTFM)_xG^r&Md_TMfk_2|uxGeNEc-}5!YFQoV<{5($TIog zjDzt?#vS2}BMgCoQgCz6 Date: Mon, 20 May 2024 11:49:36 -0400 Subject: [PATCH 06/28] docs --- ...nerative-ai.googleaifilemanager._constructor_.md | 4 ++-- .../generative-ai.googleaifilemanager.deletefile.md | 3 ++- .../generative-ai.googleaifilemanager.getfile.md | 3 ++- .../generative-ai.googleaifilemanager.listfiles.md | 3 ++- .../files/generative-ai.googleaifilemanager.md | 10 +++++----- .../generative-ai.googleaifilemanager.uploadfile.md | 3 ++- .../generative-ai.requestoptions.abortsignal.md | 13 +++++++++++++ .../reference/files/generative-ai.requestoptions.md | 1 + .../generative-ai.requestoptions.abortsignal.md | 13 +++++++++++++ docs/reference/main/generative-ai.requestoptions.md | 1 + .../main/test-integration/node/count-tokens.test.ts | 1 - 11 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 docs/reference/files/generative-ai.requestoptions.abortsignal.md create mode 100644 docs/reference/main/generative-ai.requestoptions.abortsignal.md diff --git a/docs/reference/files/generative-ai.googleaifilemanager._constructor_.md b/docs/reference/files/generative-ai.googleaifilemanager._constructor_.md index 5c49872e..471ab1ec 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager._constructor_.md +++ b/docs/reference/files/generative-ai.googleaifilemanager._constructor_.md @@ -9,7 +9,7 @@ Constructs a new instance of the `GoogleAIFileManager` class **Signature:** ```typescript -constructor(apiKey: string, _requestOptions?: RequestOptions); +constructor(apiKey: string, requestOptions?: RequestOptions); ``` ## Parameters @@ -17,5 +17,5 @@ constructor(apiKey: string, _requestOptions?: RequestOptions); | Parameter | Type | Description | | --- | --- | --- | | apiKey | string | | -| \_requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | +| requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | diff --git a/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md b/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md index e5ecfdad..7efa89b4 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md @@ -9,7 +9,7 @@ Delete file with given ID **Signature:** ```typescript -deleteFile(fileId: string): Promise; +deleteFile(fileId: string, requestOptions?: RequestOptions): Promise; ``` ## Parameters @@ -17,6 +17,7 @@ deleteFile(fileId: string): Promise; | Parameter | Type | Description | | --- | --- | --- | | fileId | string | | +| requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/files/generative-ai.googleaifilemanager.getfile.md b/docs/reference/files/generative-ai.googleaifilemanager.getfile.md index 613d6b6c..59570d68 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.getfile.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.getfile.md @@ -9,7 +9,7 @@ Get metadata for file with given ID **Signature:** ```typescript -getFile(fileId: string): Promise; +getFile(fileId: string, requestOptions?: RequestOptions): Promise; ``` ## Parameters @@ -17,6 +17,7 @@ getFile(fileId: string): Promise; | Parameter | Type | Description | | --- | --- | --- | | fileId | string | | +| requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/files/generative-ai.googleaifilemanager.listfiles.md b/docs/reference/files/generative-ai.googleaifilemanager.listfiles.md index ef116fb6..8f868b75 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.listfiles.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.listfiles.md @@ -9,7 +9,7 @@ List all uploaded files **Signature:** ```typescript -listFiles(listParams?: ListParams): Promise; +listFiles(listParams?: ListParams, requestOptions?: RequestOptions): Promise; ``` ## Parameters @@ -17,6 +17,7 @@ listFiles(listParams?: ListParams): Promise; | Parameter | Type | Description | | --- | --- | --- | | listParams | [ListParams](./generative-ai.listparams.md) | _(Optional)_ | +| requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/files/generative-ai.googleaifilemanager.md b/docs/reference/files/generative-ai.googleaifilemanager.md index 655c8d0c..f088cee4 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.md @@ -16,7 +16,7 @@ export declare class GoogleAIFileManager | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(apiKey, \_requestOptions)](./generative-ai.googleaifilemanager._constructor_.md) | | Constructs a new instance of the GoogleAIFileManager class | +| [(constructor)(apiKey, requestOptions)](./generative-ai.googleaifilemanager._constructor_.md) | | Constructs a new instance of the GoogleAIFileManager class | ## Properties @@ -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) | | Delete file with given ID | +| [getFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.getfile.md) | | Get metadata for file with given ID | +| [listFiles(listParams, requestOptions)](./generative-ai.googleaifilemanager.listfiles.md) | | List all uploaded files | +| [uploadFile(filePath, fileMetadata, requestOptions)](./generative-ai.googleaifilemanager.uploadfile.md) | | Upload a file | diff --git a/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md b/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md index 90648e90..6b7f9c35 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md @@ -9,7 +9,7 @@ Upload a file **Signature:** ```typescript -uploadFile(filePath: string, fileMetadata: FileMetadata): Promise; +uploadFile(filePath: string, fileMetadata: FileMetadata, requestOptions?: RequestOptions): Promise; ``` ## Parameters @@ -18,6 +18,7 @@ uploadFile(filePath: string, fileMetadata: FileMetadata): Promise + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RequestOptions](./generative-ai.requestoptions.md) > [abortSignal](./generative-ai.requestoptions.abortsignal.md) + +## RequestOptions.abortSignal property + +An object that may be used to abort aynchronous requests. This is only available on a per request basis, and is ignored by models constructed with a RequestOptions object. + +**Signature:** + +```typescript +abortSignal?: AbortSignal; +``` diff --git a/docs/reference/files/generative-ai.requestoptions.md b/docs/reference/files/generative-ai.requestoptions.md index 44aba7de..2b9d7c8d 100644 --- a/docs/reference/files/generative-ai.requestoptions.md +++ b/docs/reference/files/generative-ai.requestoptions.md @@ -16,6 +16,7 @@ export interface RequestOptions | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [abortSignal?](./generative-ai.requestoptions.abortsignal.md) | | AbortSignal | _(Optional)_ An object that may be used to abort aynchronous requests. This is only available on a per request basis, and is ignored by models constructed with a RequestOptions object. | | [apiClient?](./generative-ai.requestoptions.apiclient.md) | | string | _(Optional)_ Additional attribution information to include in the x-goog-api-client header. Used by wrapper SDKs. | | [apiVersion?](./generative-ai.requestoptions.apiversion.md) | | string | _(Optional)_ Version of API endpoint to call (e.g. "v1" or "v1beta"). If not specified, defaults to latest stable version. | | [baseUrl?](./generative-ai.requestoptions.baseurl.md) | | string | _(Optional)_ Base endpoint url. Defaults to "https://generativelanguage.googleapis.com" | diff --git a/docs/reference/main/generative-ai.requestoptions.abortsignal.md b/docs/reference/main/generative-ai.requestoptions.abortsignal.md new file mode 100644 index 00000000..cc36a185 --- /dev/null +++ b/docs/reference/main/generative-ai.requestoptions.abortsignal.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RequestOptions](./generative-ai.requestoptions.md) > [abortSignal](./generative-ai.requestoptions.abortsignal.md) + +## RequestOptions.abortSignal property + +An object that may be used to abort aynchronous requests. This is only available on a per request basis, and is ignored by models constructed with a RequestOptions object. + +**Signature:** + +```typescript +abortSignal?: AbortSignal; +``` diff --git a/docs/reference/main/generative-ai.requestoptions.md b/docs/reference/main/generative-ai.requestoptions.md index 44aba7de..2b9d7c8d 100644 --- a/docs/reference/main/generative-ai.requestoptions.md +++ b/docs/reference/main/generative-ai.requestoptions.md @@ -16,6 +16,7 @@ export interface RequestOptions | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [abortSignal?](./generative-ai.requestoptions.abortsignal.md) | | AbortSignal | _(Optional)_ An object that may be used to abort aynchronous requests. This is only available on a per request basis, and is ignored by models constructed with a RequestOptions object. | | [apiClient?](./generative-ai.requestoptions.apiclient.md) | | string | _(Optional)_ Additional attribution information to include in the x-goog-api-client header. Used by wrapper SDKs. | | [apiVersion?](./generative-ai.requestoptions.apiversion.md) | | string | _(Optional)_ Version of API endpoint to call (e.g. "v1" or "v1beta"). If not specified, defaults to latest stable version. | | [baseUrl?](./generative-ai.requestoptions.baseurl.md) | | string | _(Optional)_ Base endpoint url. Defaults to "https://generativelanguage.googleapis.com" | diff --git a/packages/main/test-integration/node/count-tokens.test.ts b/packages/main/test-integration/node/count-tokens.test.ts index cdf46889..18b30260 100644 --- a/packages/main/test-integration/node/count-tokens.test.ts +++ b/packages/main/test-integration/node/count-tokens.test.ts @@ -40,7 +40,6 @@ describe("countTokens", function () { ], }); const response1 = await model.countTokens("count me"); - const response2 = await model.countTokens({ contents: [{ role: "user", parts: [{ text: "count me" }] }], }); expect(response1.totalTokens).to.equal(3); From c1f6ddf4cf96378eb1810b644ea4c4e15ccf3970 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Mon, 20 May 2024 11:52:50 -0400 Subject: [PATCH 07/28] Update count-tokens.test.ts --- packages/main/test-integration/node/count-tokens.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/main/test-integration/node/count-tokens.test.ts b/packages/main/test-integration/node/count-tokens.test.ts index 18b30260..cdf46889 100644 --- a/packages/main/test-integration/node/count-tokens.test.ts +++ b/packages/main/test-integration/node/count-tokens.test.ts @@ -40,6 +40,7 @@ describe("countTokens", function () { ], }); const response1 = await model.countTokens("count me"); + const response2 = await model.countTokens({ contents: [{ role: "user", parts: [{ text: "count me" }] }], }); expect(response1.totalTokens).to.equal(3); From c5e8b37da2883932a0e61337882dc7585a68d079 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Mon, 20 May 2024 13:59:43 -0400 Subject: [PATCH 08/28] RequestOptions parameter changes. Removal of a cat. --- packages/main/src/files/file-manager.ts | 28 +++++------------- .../node/abort-signal.test.ts | 2 +- .../main/test-integration/resources/cat.jpg | Bin 17858 -> 0 bytes 3 files changed, 9 insertions(+), 21 deletions(-) delete mode 100644 packages/main/test-integration/resources/cat.jpg diff --git a/packages/main/src/files/file-manager.ts b/packages/main/src/files/file-manager.ts index dc3ff994..22c18a33 100644 --- a/packages/main/src/files/file-manager.ts +++ b/packages/main/src/files/file-manager.ts @@ -60,13 +60,10 @@ export class GoogleAIFileManager { async uploadFile( filePath: string, fileMetadata: FileMetadata, - requestOptions?: RequestOptions, + requestOptions: RequestOptions = {}, ): Promise { const file = readFileSync(filePath); - const filesRequestOptions = Object.create(this._requestOptions); - if (requestOptions) { - Object.assign(filesRequestOptions, requestOptions); - } + const filesRequestOptions = { ...this._requestOptions, ...requestOptions }; const url = new FilesRequestUrl( FilesTask.UPLOAD, @@ -110,12 +107,9 @@ export class GoogleAIFileManager { */ async listFiles( listParams?: ListParams, - requestOptions?: RequestOptions, + requestOptions: RequestOptions = {}, ): Promise { - const filesRequestOptions = Object.create(this._requestOptions); - if (requestOptions) { - Object.assign(filesRequestOptions, requestOptions); - } + const filesRequestOptions = { ...this._requestOptions, ...requestOptions }; const url = new FilesRequestUrl( FilesTask.LIST, this.apiKey, @@ -137,12 +131,9 @@ export class GoogleAIFileManager { */ async getFile( fileId: string, - requestOptions?: RequestOptions, + requestOptions: RequestOptions = {}, ): Promise { - const filesRequestOptions = Object.create(this._requestOptions); - if (requestOptions) { - Object.assign(filesRequestOptions, requestOptions); - } + const filesRequestOptions = { ...this._requestOptions, ...requestOptions }; const url = new FilesRequestUrl( FilesTask.GET, this.apiKey, @@ -159,12 +150,9 @@ export class GoogleAIFileManager { */ async deleteFile( fileId: string, - requestOptions?: RequestOptions, + requestOptions: RequestOptions = {}, ): Promise { - const filesRequestOptions = Object.create(this._requestOptions); - if (requestOptions) { - Object.assign(filesRequestOptions, requestOptions); - } + const filesRequestOptions = { ...this._requestOptions, ...requestOptions }; const url = new FilesRequestUrl( FilesTask.DELETE, this.apiKey, diff --git a/packages/main/test-integration/node/abort-signal.test.ts b/packages/main/test-integration/node/abort-signal.test.ts index 8f335550..f7ca7af2 100644 --- a/packages/main/test-integration/node/abort-signal.test.ts +++ b/packages/main/test-integration/node/abort-signal.test.ts @@ -40,7 +40,7 @@ describe("abortSignal", function () { const abortSignal = AbortSignal.timeout(1); const promise = fileManager.uploadFile( - "test-integration/resources/cat.jpg", + "test-utils/cat.jpeg", { mimeType: "image/jpeg", name: filePathInService, diff --git a/packages/main/test-integration/resources/cat.jpg b/packages/main/test-integration/resources/cat.jpg deleted file mode 100644 index 8d2069e6c979ef6fe4fb52e7873e1019f008d2e1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17858 zcmb4KRa9KTvK?H5JA=;P65QS0U4jRf!6mo^9T?o*-91Qff?MzqG`K?ogk0|Xcc7*ycGo$p*4ewOtNyM2+X3Jx$tlVK;Nai@3U34OZv!9=Kt@DDMnXhJMnXnGK}JQ# zK}SbJLnpw(#>62eAR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UgN^O%n1aELYMx zm?wrMRRLNtf(Xw(0;E55KiE;=B^#&V?LHfyHBH zhtk_d>UStVl@>CdZ9Wu~?HJF+T9Xr0PCHcMixAXy>6%tFhGT_AD+&y;D5Nl}7^DZr z74JoWH@1z`h6CD*0MtI1k;;O+&ep%%_G=z?v{*^RQ86=k6 zv}-BaIl}NMQh5OjnTa8ra~`8Dz&&b`LL+XCbjlgZ3}@0QyZ~8l7CVt{sB?ff?&g(V zLd#Ty;!y5eX3{%wY6_w{gb|Adl@tcsk)CMbTFh)C}2%rTQ$ITzHfmr0H`qcqnsa?DZ$82UvNE?EIw0m*=YNHg%Zi_gU zHCQ7^kyVIOfzPMDed{*zTFM)_xG^r&Md_TMfk_2|uxGeNEc-}5!YFQoV<{5($TIog zjDzt?#vS2}BMgCoQgCz6 Date: Mon, 20 May 2024 16:50:17 -0400 Subject: [PATCH 09/28] Created SingleRequestOptions sub interface --- ...ve-ai.googleaifilemanager._constructor_.md | 4 +- ...ative-ai.googleaifilemanager.deletefile.md | 8 ++- ...nerative-ai.googleaifilemanager.getfile.md | 8 ++- ...rative-ai.googleaifilemanager.listfiles.md | 8 ++- .../generative-ai.googleaifilemanager.md | 10 +-- ...ative-ai.googleaifilemanager.uploadfile.md | 8 ++- docs/reference/files/generative-ai.md | 1 + ...enerative-ai.requestoptions.abortsignal.md | 13 ---- .../files/generative-ai.requestoptions.md | 1 - ...ive-ai.singlerequestoptions.abortsignal.md | 13 ++++ .../generative-ai.singlerequestoptions.md | 21 ++++++ docs/reference/main/generative-ai.md | 1 + ...enerative-ai.requestoptions.abortsignal.md | 13 ---- .../main/generative-ai.requestoptions.md | 1 - ...ive-ai.singlerequestoptions.abortsignal.md | 13 ++++ .../generative-ai.singlerequestoptions.md | 21 ++++++ packages/main/src/files/file-manager.ts | 65 ++++++++++++------- packages/main/src/files/index.ts | 2 +- packages/main/src/files/request.ts | 6 +- .../node/abort-signal.test.ts | 8 +-- packages/main/types/requests.ts | 12 +++- 21 files changed, 158 insertions(+), 79 deletions(-) delete mode 100644 docs/reference/files/generative-ai.requestoptions.abortsignal.md create mode 100644 docs/reference/files/generative-ai.singlerequestoptions.abortsignal.md create mode 100644 docs/reference/files/generative-ai.singlerequestoptions.md delete mode 100644 docs/reference/main/generative-ai.requestoptions.abortsignal.md create mode 100644 docs/reference/main/generative-ai.singlerequestoptions.abortsignal.md create mode 100644 docs/reference/main/generative-ai.singlerequestoptions.md diff --git a/docs/reference/files/generative-ai.googleaifilemanager._constructor_.md b/docs/reference/files/generative-ai.googleaifilemanager._constructor_.md index 471ab1ec..5c49872e 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager._constructor_.md +++ b/docs/reference/files/generative-ai.googleaifilemanager._constructor_.md @@ -9,7 +9,7 @@ Constructs a new instance of the `GoogleAIFileManager` class **Signature:** ```typescript -constructor(apiKey: string, requestOptions?: RequestOptions); +constructor(apiKey: string, _requestOptions?: RequestOptions); ``` ## Parameters @@ -17,5 +17,5 @@ constructor(apiKey: string, requestOptions?: RequestOptions); | Parameter | Type | Description | | --- | --- | --- | | apiKey | string | | -| requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | +| \_requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | diff --git a/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md b/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md index 7efa89b4..209ff4a7 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md @@ -4,12 +4,14 @@ ## 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 predendence 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, requestOptions?: RequestOptions): Promise; +deleteFile(fileId: string, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,7 +19,7 @@ deleteFile(fileId: string, requestOptions?: RequestOptions): Promise; | Parameter | Type | Description | | --- | --- | --- | | fileId | string | | -| requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | +| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/files/generative-ai.googleaifilemanager.getfile.md b/docs/reference/files/generative-ai.googleaifilemanager.getfile.md index 59570d68..21d23c70 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.getfile.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.getfile.md @@ -4,12 +4,14 @@ ## 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 predendence 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, requestOptions?: RequestOptions): Promise; +getFile(fileId: string, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,7 +19,7 @@ getFile(fileId: string, requestOptions?: RequestOptions): Promise; +listFiles(listParams?: ListParams, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,7 +19,7 @@ listFiles(listParams?: ListParams, requestOptions?: RequestOptions): PromiseGoogleAIFileManager class | +| [(constructor)(apiKey, \_requestOptions)](./generative-ai.googleaifilemanager._constructor_.md) | | Constructs a new instance of the GoogleAIFileManager class | ## Properties @@ -28,8 +28,8 @@ export declare class GoogleAIFileManager | Method | Modifiers | Description | | --- | --- | --- | -| [deleteFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.deletefile.md) | | Delete file with given ID | -| [getFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.getfile.md) | | Get metadata for file with given ID | -| [listFiles(listParams, requestOptions)](./generative-ai.googleaifilemanager.listfiles.md) | | List all uploaded files | -| [uploadFile(filePath, fileMetadata, requestOptions)](./generative-ai.googleaifilemanager.uploadfile.md) | | Upload a file | +| [deleteFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.deletefile.md) | |

Delete file with given ID.

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

| +| [getFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.getfile.md) | |

Get metadata for file with given ID.

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

| +| [listFiles(listParams, requestOptions)](./generative-ai.googleaifilemanager.listfiles.md) | |

List all uploaded files.

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

| +| [uploadFile(filePath, fileMetadata, requestOptions)](./generative-ai.googleaifilemanager.uploadfile.md) | |

Upload a file.

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

| diff --git a/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md b/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md index 6b7f9c35..2b12f245 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md @@ -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 predendence 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, requestOptions?: RequestOptions): Promise; +uploadFile(filePath: string, fileMetadata: FileMetadata, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -18,7 +20,7 @@ uploadFile(filePath: string, fileMetadata: FileMetadata, requestOptions?: Reques | --- | --- | --- | | filePath | string | | | fileMetadata | [FileMetadata](./generative-ai.filemetadata.md) | | -| requestOptions | [RequestOptions](./generative-ai.requestoptions.md) | _(Optional)_ | +| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/files/generative-ai.md b/docs/reference/files/generative-ai.md index d23363cb..e2a167dd 100644 --- a/docs/reference/files/generative-ai.md +++ b/docs/reference/files/generative-ai.md @@ -25,5 +25,6 @@ | [ListFilesResponse](./generative-ai.listfilesresponse.md) | Response from calling [GoogleAIFileManager.listFiles()](./generative-ai.googleaifilemanager.listfiles.md) | | [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(). | +| [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) | diff --git a/docs/reference/files/generative-ai.requestoptions.abortsignal.md b/docs/reference/files/generative-ai.requestoptions.abortsignal.md deleted file mode 100644 index cc36a185..00000000 --- a/docs/reference/files/generative-ai.requestoptions.abortsignal.md +++ /dev/null @@ -1,13 +0,0 @@ - - -[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RequestOptions](./generative-ai.requestoptions.md) > [abortSignal](./generative-ai.requestoptions.abortsignal.md) - -## RequestOptions.abortSignal property - -An object that may be used to abort aynchronous requests. This is only available on a per request basis, and is ignored by models constructed with a RequestOptions object. - -**Signature:** - -```typescript -abortSignal?: AbortSignal; -``` diff --git a/docs/reference/files/generative-ai.requestoptions.md b/docs/reference/files/generative-ai.requestoptions.md index 2b9d7c8d..44aba7de 100644 --- a/docs/reference/files/generative-ai.requestoptions.md +++ b/docs/reference/files/generative-ai.requestoptions.md @@ -16,7 +16,6 @@ export interface RequestOptions | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [abortSignal?](./generative-ai.requestoptions.abortsignal.md) | | AbortSignal | _(Optional)_ An object that may be used to abort aynchronous requests. This is only available on a per request basis, and is ignored by models constructed with a RequestOptions object. | | [apiClient?](./generative-ai.requestoptions.apiclient.md) | | string | _(Optional)_ Additional attribution information to include in the x-goog-api-client header. Used by wrapper SDKs. | | [apiVersion?](./generative-ai.requestoptions.apiversion.md) | | string | _(Optional)_ Version of API endpoint to call (e.g. "v1" or "v1beta"). If not specified, defaults to latest stable version. | | [baseUrl?](./generative-ai.requestoptions.baseurl.md) | | string | _(Optional)_ Base endpoint url. Defaults to "https://generativelanguage.googleapis.com" | diff --git a/docs/reference/files/generative-ai.singlerequestoptions.abortsignal.md b/docs/reference/files/generative-ai.singlerequestoptions.abortsignal.md new file mode 100644 index 00000000..68d671cc --- /dev/null +++ b/docs/reference/files/generative-ai.singlerequestoptions.abortsignal.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [SingleRequestOptions](./generative-ai.singlerequestoptions.md) > [abortSignal](./generative-ai.singlerequestoptions.abortsignal.md) + +## SingleRequestOptions.abortSignal property + +An object that may be used to abort aynchronous 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 +abortSignal?: AbortSignal; +``` diff --git a/docs/reference/files/generative-ai.singlerequestoptions.md b/docs/reference/files/generative-ai.singlerequestoptions.md new file mode 100644 index 00000000..f85ecb65 --- /dev/null +++ b/docs/reference/files/generative-ai.singlerequestoptions.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [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 | +| --- | --- | --- | --- | +| [abortSignal?](./generative-ai.singlerequestoptions.abortsignal.md) | | AbortSignal | _(Optional)_ An object that may be used to abort aynchronous requests. The request may also be aborted due to the expiration of the timeout value, if provided, and if the timeout occurs first. | + diff --git a/docs/reference/main/generative-ai.md b/docs/reference/main/generative-ai.md index ec5a3a7c..78f92de8 100644 --- a/docs/reference/main/generative-ai.md +++ b/docs/reference/main/generative-ai.md @@ -69,6 +69,7 @@ | [RequestOptions](./generative-ai.requestoptions.md) | Params passed to getGenerativeModel() or GoogleAIFileManager(). | | [SafetyRating](./generative-ai.safetyrating.md) | A safety rating associated with a [GenerateContentCandidate](./generative-ai.generatecontentcandidate.md) | | [SafetySetting](./generative-ai.safetysetting.md) | Safety setting that can be sent as part of request parameters. | +| [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | Params passed to atomic asynchronous operations. | | [StartChatParams](./generative-ai.startchatparams.md) | Params for [GenerativeModel.startChat()](./generative-ai.generativemodel.startchat.md). | | [TextPart](./generative-ai.textpart.md) | Content part interface if the part represents a text string. | | [ToolConfig](./generative-ai.toolconfig.md) | Tool config. This config is shared for all tools provided in the request. | diff --git a/docs/reference/main/generative-ai.requestoptions.abortsignal.md b/docs/reference/main/generative-ai.requestoptions.abortsignal.md deleted file mode 100644 index cc36a185..00000000 --- a/docs/reference/main/generative-ai.requestoptions.abortsignal.md +++ /dev/null @@ -1,13 +0,0 @@ - - -[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [RequestOptions](./generative-ai.requestoptions.md) > [abortSignal](./generative-ai.requestoptions.abortsignal.md) - -## RequestOptions.abortSignal property - -An object that may be used to abort aynchronous requests. This is only available on a per request basis, and is ignored by models constructed with a RequestOptions object. - -**Signature:** - -```typescript -abortSignal?: AbortSignal; -``` diff --git a/docs/reference/main/generative-ai.requestoptions.md b/docs/reference/main/generative-ai.requestoptions.md index 2b9d7c8d..44aba7de 100644 --- a/docs/reference/main/generative-ai.requestoptions.md +++ b/docs/reference/main/generative-ai.requestoptions.md @@ -16,7 +16,6 @@ export interface RequestOptions | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [abortSignal?](./generative-ai.requestoptions.abortsignal.md) | | AbortSignal | _(Optional)_ An object that may be used to abort aynchronous requests. This is only available on a per request basis, and is ignored by models constructed with a RequestOptions object. | | [apiClient?](./generative-ai.requestoptions.apiclient.md) | | string | _(Optional)_ Additional attribution information to include in the x-goog-api-client header. Used by wrapper SDKs. | | [apiVersion?](./generative-ai.requestoptions.apiversion.md) | | string | _(Optional)_ Version of API endpoint to call (e.g. "v1" or "v1beta"). If not specified, defaults to latest stable version. | | [baseUrl?](./generative-ai.requestoptions.baseurl.md) | | string | _(Optional)_ Base endpoint url. Defaults to "https://generativelanguage.googleapis.com" | diff --git a/docs/reference/main/generative-ai.singlerequestoptions.abortsignal.md b/docs/reference/main/generative-ai.singlerequestoptions.abortsignal.md new file mode 100644 index 00000000..68d671cc --- /dev/null +++ b/docs/reference/main/generative-ai.singlerequestoptions.abortsignal.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [SingleRequestOptions](./generative-ai.singlerequestoptions.md) > [abortSignal](./generative-ai.singlerequestoptions.abortsignal.md) + +## SingleRequestOptions.abortSignal property + +An object that may be used to abort aynchronous 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 +abortSignal?: AbortSignal; +``` diff --git a/docs/reference/main/generative-ai.singlerequestoptions.md b/docs/reference/main/generative-ai.singlerequestoptions.md new file mode 100644 index 00000000..f85ecb65 --- /dev/null +++ b/docs/reference/main/generative-ai.singlerequestoptions.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [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 | +| --- | --- | --- | --- | +| [abortSignal?](./generative-ai.singlerequestoptions.abortsignal.md) | | AbortSignal | _(Optional)_ An object that may be used to abort aynchronous requests. The request may also be aborted due to the expiration of the timeout value, if provided, and if the timeout occurs first. | + diff --git a/packages/main/src/files/file-manager.ts b/packages/main/src/files/file-manager.ts index 22c18a33..3da25e2a 100644 --- a/packages/main/src/files/file-manager.ts +++ b/packages/main/src/files/file-manager.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { RequestOptions } from "../../types"; +import { RequestOptions, SingleRequestOptions } from "../../types"; import { readFileSync } from "fs"; import { FilesRequestUrl, getHeaders, makeFilesRequest } from "./request"; import { @@ -42,28 +42,28 @@ export interface UploadMetadata { * @public */ export class GoogleAIFileManager { - private _requestOptions: RequestOptions; constructor( public apiKey: string, - requestOptions?: RequestOptions, - ) { - this._requestOptions = {}; - if (requestOptions) { - Object.assign(this._requestOptions, requestOptions); - delete this._requestOptions.abortSignal; - } - } + private _requestOptions: RequestOptions = {}, + ) {} /** - * Upload a file + * Upload a file. + * + * Any fields set in the optional {@link SingleRequestOptions} parameter will take + * predendence over the {@link RequestOptions} values provided at the time of the + * {@link GoogleAIFileManager} initialization. */ async uploadFile( filePath: string, fileMetadata: FileMetadata, - requestOptions: RequestOptions = {}, + requestOptions: SingleRequestOptions = {}, ): Promise { const file = readFileSync(filePath); - const filesRequestOptions = { ...this._requestOptions, ...requestOptions }; + const filesRequestOptions: SingleRequestOptions = { + ...this._requestOptions, + ...requestOptions, + }; const url = new FilesRequestUrl( FilesTask.UPLOAD, @@ -103,13 +103,20 @@ export class GoogleAIFileManager { } /** - * List all uploaded files + * List all uploaded files. + * + * Any fields set in the optional {@link SingleRequestOptions} parameter will take + * predendence over the {@link RequestOptions} values provided at the time of the + * {@link GoogleAIFileManager} initialization. */ async listFiles( listParams?: ListParams, - requestOptions: RequestOptions = {}, + requestOptions: SingleRequestOptions = {}, ): Promise { - const filesRequestOptions = { ...this._requestOptions, ...requestOptions }; + const filesRequestOptions: SingleRequestOptions = { + ...this._requestOptions, + ...requestOptions, + }; const url = new FilesRequestUrl( FilesTask.LIST, this.apiKey, @@ -127,13 +134,20 @@ export class GoogleAIFileManager { } /** - * Get metadata for file with given ID + * Get metadata for file with given ID. + * + * Any fields set in the optional {@link SingleRequestOptions} parameter will take + * predendence over the {@link RequestOptions} values provided at the time of the + * {@link GoogleAIFileManager} initialization. */ async getFile( fileId: string, - requestOptions: RequestOptions = {}, + requestOptions: SingleRequestOptions = {}, ): Promise { - const filesRequestOptions = { ...this._requestOptions, ...requestOptions }; + const filesRequestOptions: SingleRequestOptions = { + ...this._requestOptions, + ...requestOptions, + }; const url = new FilesRequestUrl( FilesTask.GET, this.apiKey, @@ -146,13 +160,20 @@ export class GoogleAIFileManager { } /** - * Delete file with given ID + * Delete file with given ID. + * + * Any fields set in the optional {@link SingleRequestOptions} parameter will take + * predendence over the {@link RequestOptions} values provided at the time of the + * {@link GoogleAIFileManager} initialization. */ async deleteFile( fileId: string, - requestOptions: RequestOptions = {}, + requestOptions: SingleRequestOptions = {}, ): Promise { - const filesRequestOptions = { ...this._requestOptions, ...requestOptions }; + const filesRequestOptions: SingleRequestOptions = { + ...this._requestOptions, + ...requestOptions, + }; const url = new FilesRequestUrl( FilesTask.DELETE, this.apiKey, diff --git a/packages/main/src/files/index.ts b/packages/main/src/files/index.ts index 6d89670f..e7c0d26f 100644 --- a/packages/main/src/files/index.ts +++ b/packages/main/src/files/index.ts @@ -17,4 +17,4 @@ export { GoogleAIFileManager } from "./file-manager"; export * from "./types"; -export { RequestOptions } from "../../types"; +export { RequestOptions, SingleRequestOptions } from "../../types"; diff --git a/packages/main/src/files/request.ts b/packages/main/src/files/request.ts index 0bfc5587..08ac80d5 100644 --- a/packages/main/src/files/request.ts +++ b/packages/main/src/files/request.ts @@ -24,7 +24,7 @@ import { DEFAULT_BASE_URL, getClientHeaders, } from "../requests/request"; -import { RequestOptions } from "../../types"; +import { SingleRequestOptions } from "../../types"; import { FilesTask } from "./constants"; const taskToMethod = { @@ -40,7 +40,7 @@ export class FilesRequestUrl { constructor( public task: FilesTask, public apiKey: string, - public requestOptions?: RequestOptions, + public requestOptions?: SingleRequestOptions, ) { const apiVersion = this.requestOptions?.apiVersion || DEFAULT_API_VERSION; const baseUrl = this.requestOptions?.baseUrl || DEFAULT_BASE_URL; @@ -134,7 +134,7 @@ export async function makeFilesRequest( * Create an AbortSignal based on the timeout and abortSignal in the * RequestOptions. */ -function getSignal(requestOptions?: RequestOptions): AbortSignal | null { +function getSignal(requestOptions?: SingleRequestOptions): AbortSignal | null { if ( requestOptions?.abortSignal !== undefined || requestOptions?.timeout >= 0 diff --git a/packages/main/test-integration/node/abort-signal.test.ts b/packages/main/test-integration/node/abort-signal.test.ts index f7ca7af2..812d27be 100644 --- a/packages/main/test-integration/node/abort-signal.test.ts +++ b/packages/main/test-integration/node/abort-signal.test.ts @@ -17,7 +17,7 @@ import { expect, use } from "chai"; import * as chaiAsPromised from "chai-as-promised"; -import { RequestOptions } from "../.."; +import { SingleRequestOptions } from "../.."; import { GoogleAIFileManager } from "../../dist/files"; use(chaiAsPromised); @@ -54,21 +54,21 @@ describe("abortSignal", function () { it("file manager listFiles abort test", async () => { const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const abortSignal = AbortSignal.timeout(1); - const requestOptions: RequestOptions = { abortSignal }; + const requestOptions: SingleRequestOptions = { abortSignal }; const promise = fileManager.listFiles(/* listParams= */ {}, requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); it("file manager getFile abort test", async () => { const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const abortSignal = AbortSignal.timeout(1); - const requestOptions: RequestOptions = { abortSignal }; + const requestOptions: SingleRequestOptions = { abortSignal }; const promise = fileManager.getFile("abortSignal.jpg", requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); it("file manager deleteFile abort test", async () => { const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const abortSignal = AbortSignal.timeout(1); - const requestOptions: RequestOptions = { abortSignal }; + const requestOptions: SingleRequestOptions = { abortSignal }; const promise = fileManager.deleteFile("abortSignal.jpg", requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); diff --git a/packages/main/types/requests.ts b/packages/main/types/requests.ts index c0459f38..e7af3940 100644 --- a/packages/main/types/requests.ts +++ b/packages/main/types/requests.ts @@ -147,9 +147,17 @@ export interface RequestOptions { * Custom HTTP request headers. */ customHeaders?: Headers | Record; +} + +/** + * Params passed to atomic asynchronous operations. + * @public + */ +export interface SingleRequestOptions extends RequestOptions { /** - * An object that may be used to abort aynchronous requests. This is only available on - * a per request basis, and is ignored by models constructed with a RequestOptions object. + * An object that may be used to abort aynchronous requests. The request may + * also be aborted due to the expiration of the timeout value, if provided, + * and if the timeout occurs first. */ abortSignal?: AbortSignal; } From f4f168c1bbeb783f38be3da271c8ff748e572b6e Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Mon, 20 May 2024 16:57:40 -0400 Subject: [PATCH 10/28] asynchronous typo. --- .../files/generative-ai.singlerequestoptions.abortsignal.md | 2 +- docs/reference/files/generative-ai.singlerequestoptions.md | 2 +- .../main/generative-ai.singlerequestoptions.abortsignal.md | 2 +- docs/reference/main/generative-ai.singlerequestoptions.md | 2 +- packages/main/types/requests.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/reference/files/generative-ai.singlerequestoptions.abortsignal.md b/docs/reference/files/generative-ai.singlerequestoptions.abortsignal.md index 68d671cc..a88614fd 100644 --- a/docs/reference/files/generative-ai.singlerequestoptions.abortsignal.md +++ b/docs/reference/files/generative-ai.singlerequestoptions.abortsignal.md @@ -4,7 +4,7 @@ ## SingleRequestOptions.abortSignal property -An object that may be used to abort aynchronous requests. The request may also be aborted due to the expiration of the timeout value, if provided, and if the timeout occurs first. +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:** diff --git a/docs/reference/files/generative-ai.singlerequestoptions.md b/docs/reference/files/generative-ai.singlerequestoptions.md index f85ecb65..96a382ed 100644 --- a/docs/reference/files/generative-ai.singlerequestoptions.md +++ b/docs/reference/files/generative-ai.singlerequestoptions.md @@ -17,5 +17,5 @@ export interface SingleRequestOptions extends RequestOptions | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [abortSignal?](./generative-ai.singlerequestoptions.abortsignal.md) | | AbortSignal | _(Optional)_ An object that may be used to abort aynchronous requests. The request may also be aborted due to the expiration of the timeout value, if provided, and if the timeout occurs first. | +| [abortSignal?](./generative-ai.singlerequestoptions.abortsignal.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. | diff --git a/docs/reference/main/generative-ai.singlerequestoptions.abortsignal.md b/docs/reference/main/generative-ai.singlerequestoptions.abortsignal.md index 68d671cc..a88614fd 100644 --- a/docs/reference/main/generative-ai.singlerequestoptions.abortsignal.md +++ b/docs/reference/main/generative-ai.singlerequestoptions.abortsignal.md @@ -4,7 +4,7 @@ ## SingleRequestOptions.abortSignal property -An object that may be used to abort aynchronous requests. The request may also be aborted due to the expiration of the timeout value, if provided, and if the timeout occurs first. +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:** diff --git a/docs/reference/main/generative-ai.singlerequestoptions.md b/docs/reference/main/generative-ai.singlerequestoptions.md index f85ecb65..96a382ed 100644 --- a/docs/reference/main/generative-ai.singlerequestoptions.md +++ b/docs/reference/main/generative-ai.singlerequestoptions.md @@ -17,5 +17,5 @@ export interface SingleRequestOptions extends RequestOptions | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [abortSignal?](./generative-ai.singlerequestoptions.abortsignal.md) | | AbortSignal | _(Optional)_ An object that may be used to abort aynchronous requests. The request may also be aborted due to the expiration of the timeout value, if provided, and if the timeout occurs first. | +| [abortSignal?](./generative-ai.singlerequestoptions.abortsignal.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. | diff --git a/packages/main/types/requests.ts b/packages/main/types/requests.ts index e7af3940..2b04fdbb 100644 --- a/packages/main/types/requests.ts +++ b/packages/main/types/requests.ts @@ -155,7 +155,7 @@ export interface RequestOptions { */ export interface SingleRequestOptions extends RequestOptions { /** - * An object that may be used to abort aynchronous requests. The request may + * 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. */ From 2b30a9eec757ac75a2bfb31c89a501f737fd8be6 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Tue, 21 May 2024 10:42:08 -0400 Subject: [PATCH 11/28] Rename abortSignal to signal. --- packages/main/src/files/request.ts | 11 +++----- .../node/abort-signal.test.ts | 26 +++++++++---------- packages/main/types/requests.ts | 2 +- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/packages/main/src/files/request.ts b/packages/main/src/files/request.ts index 08ac80d5..2a355ea8 100644 --- a/packages/main/src/files/request.ts +++ b/packages/main/src/files/request.ts @@ -131,20 +131,17 @@ export async function makeFilesRequest( } /** - * Create an AbortSignal based on the timeout and abortSignal in the + * Create an AbortSignal based on the timeout and signal in the * RequestOptions. */ function getSignal(requestOptions?: SingleRequestOptions): AbortSignal | null { - if ( - requestOptions?.abortSignal !== undefined || - requestOptions?.timeout >= 0 - ) { + if (requestOptions?.signal !== undefined || requestOptions?.timeout >= 0) { const controller = new AbortController(); if (requestOptions?.timeout >= 0) { setTimeout(() => controller.abort(), requestOptions.timeout); } - if (requestOptions.abortSignal) { - requestOptions.abortSignal.addEventListener("abort", () => { + if (requestOptions.signal) { + requestOptions.signal.addEventListener("abort", () => { controller.abort(); }); } diff --git a/packages/main/test-integration/node/abort-signal.test.ts b/packages/main/test-integration/node/abort-signal.test.ts index 812d27be..b30d2d52 100644 --- a/packages/main/test-integration/node/abort-signal.test.ts +++ b/packages/main/test-integration/node/abort-signal.test.ts @@ -25,20 +25,20 @@ use(chaiAsPromised); /** * Integration tests against live backend. */ -describe("abortSignal", function () { +describe("signal", function () { this.timeout(60e3); this.slow(10e3); it("file manager uploadFile abort test", async () => { const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); - const filePathInService = "abortsignal.jpg"; + const filePathInService = "signal.jpg"; // This delete step should cleanup the state of the service for this and // future executions. try { - await fileManager.deleteFile("files/abortsignal"); + await fileManager.deleteFile("files/signal"); } catch (error) {} - const abortSignal = AbortSignal.timeout(1); + const signal = AbortSignal.timeout(1); const promise = fileManager.uploadFile( "test-utils/cat.jpeg", { @@ -46,30 +46,30 @@ describe("abortSignal", function () { name: filePathInService, }, { - abortSignal, + signal, }, ); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); it("file manager listFiles abort test", async () => { const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); - const abortSignal = AbortSignal.timeout(1); - const requestOptions: SingleRequestOptions = { abortSignal }; + const signal = AbortSignal.timeout(1); + const requestOptions: SingleRequestOptions = { signal }; const promise = fileManager.listFiles(/* listParams= */ {}, requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); it("file manager getFile abort test", async () => { const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); - const abortSignal = AbortSignal.timeout(1); - const requestOptions: SingleRequestOptions = { abortSignal }; - const promise = fileManager.getFile("abortSignal.jpg", requestOptions); + const signal = AbortSignal.timeout(1); + const requestOptions: SingleRequestOptions = { signal }; + const promise = fileManager.getFile("signal.jpg", requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); it("file manager deleteFile abort test", async () => { const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); - const abortSignal = AbortSignal.timeout(1); - const requestOptions: SingleRequestOptions = { abortSignal }; - const promise = fileManager.deleteFile("abortSignal.jpg", requestOptions); + const signal = AbortSignal.timeout(1); + const requestOptions: SingleRequestOptions = { signal }; + const promise = fileManager.deleteFile("signal.jpg", requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); }); diff --git a/packages/main/types/requests.ts b/packages/main/types/requests.ts index 2b04fdbb..a3d626ef 100644 --- a/packages/main/types/requests.ts +++ b/packages/main/types/requests.ts @@ -159,7 +159,7 @@ export interface SingleRequestOptions extends RequestOptions { * also be aborted due to the expiration of the timeout value, if provided, * and if the timeout occurs first. */ - abortSignal?: AbortSignal; + signal?: AbortSignal; } /** From b125380c57a977b2a21b576730442c66660d7769 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Tue, 21 May 2024 11:10:05 -0400 Subject: [PATCH 12/28] docs --- docs/reference/files/generative-ai.singlerequestoptions.md | 2 +- ...gnal.md => generative-ai.singlerequestoptions.signal.md} | 6 +++--- docs/reference/main/generative-ai.singlerequestoptions.md | 2 +- ...gnal.md => generative-ai.singlerequestoptions.signal.md} | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) rename docs/reference/files/{generative-ai.singlerequestoptions.abortsignal.md => generative-ai.singlerequestoptions.signal.md} (72%) rename docs/reference/main/{generative-ai.singlerequestoptions.abortsignal.md => generative-ai.singlerequestoptions.signal.md} (72%) diff --git a/docs/reference/files/generative-ai.singlerequestoptions.md b/docs/reference/files/generative-ai.singlerequestoptions.md index 96a382ed..2cbda55f 100644 --- a/docs/reference/files/generative-ai.singlerequestoptions.md +++ b/docs/reference/files/generative-ai.singlerequestoptions.md @@ -17,5 +17,5 @@ export interface SingleRequestOptions extends RequestOptions | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [abortSignal?](./generative-ai.singlerequestoptions.abortsignal.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. | +| [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. | diff --git a/docs/reference/files/generative-ai.singlerequestoptions.abortsignal.md b/docs/reference/files/generative-ai.singlerequestoptions.signal.md similarity index 72% rename from docs/reference/files/generative-ai.singlerequestoptions.abortsignal.md rename to docs/reference/files/generative-ai.singlerequestoptions.signal.md index a88614fd..9f0672b7 100644 --- a/docs/reference/files/generative-ai.singlerequestoptions.abortsignal.md +++ b/docs/reference/files/generative-ai.singlerequestoptions.signal.md @@ -1,13 +1,13 @@ -[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [SingleRequestOptions](./generative-ai.singlerequestoptions.md) > [abortSignal](./generative-ai.singlerequestoptions.abortsignal.md) +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [SingleRequestOptions](./generative-ai.singlerequestoptions.md) > [signal](./generative-ai.singlerequestoptions.signal.md) -## SingleRequestOptions.abortSignal property +## 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 -abortSignal?: AbortSignal; +signal?: AbortSignal; ``` diff --git a/docs/reference/main/generative-ai.singlerequestoptions.md b/docs/reference/main/generative-ai.singlerequestoptions.md index 96a382ed..2cbda55f 100644 --- a/docs/reference/main/generative-ai.singlerequestoptions.md +++ b/docs/reference/main/generative-ai.singlerequestoptions.md @@ -17,5 +17,5 @@ export interface SingleRequestOptions extends RequestOptions | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [abortSignal?](./generative-ai.singlerequestoptions.abortsignal.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. | +| [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. | diff --git a/docs/reference/main/generative-ai.singlerequestoptions.abortsignal.md b/docs/reference/main/generative-ai.singlerequestoptions.signal.md similarity index 72% rename from docs/reference/main/generative-ai.singlerequestoptions.abortsignal.md rename to docs/reference/main/generative-ai.singlerequestoptions.signal.md index a88614fd..9f0672b7 100644 --- a/docs/reference/main/generative-ai.singlerequestoptions.abortsignal.md +++ b/docs/reference/main/generative-ai.singlerequestoptions.signal.md @@ -1,13 +1,13 @@ -[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [SingleRequestOptions](./generative-ai.singlerequestoptions.md) > [abortSignal](./generative-ai.singlerequestoptions.abortsignal.md) +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [SingleRequestOptions](./generative-ai.singlerequestoptions.md) > [signal](./generative-ai.singlerequestoptions.signal.md) -## SingleRequestOptions.abortSignal property +## 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 -abortSignal?: AbortSignal; +signal?: AbortSignal; ``` From f7b7b6d842e60385ec45e68fdfbea18f902f643f Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 22 May 2024 10:30:50 -0400 Subject: [PATCH 13/28] predendence -> precedence typo fix --- .../files/generative-ai.googleaifilemanager.deletefile.md | 2 +- .../files/generative-ai.googleaifilemanager.getfile.md | 2 +- .../files/generative-ai.googleaifilemanager.listfiles.md | 2 +- docs/reference/files/generative-ai.googleaifilemanager.md | 8 ++++---- .../files/generative-ai.googleaifilemanager.uploadfile.md | 2 +- packages/main/src/files/file-manager.ts | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md b/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md index 209ff4a7..0fae42e6 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.deletefile.md @@ -6,7 +6,7 @@ Delete file with given ID. -Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take predendence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization. +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:** diff --git a/docs/reference/files/generative-ai.googleaifilemanager.getfile.md b/docs/reference/files/generative-ai.googleaifilemanager.getfile.md index 21d23c70..a8a08472 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.getfile.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.getfile.md @@ -6,7 +6,7 @@ Get metadata for file with given ID. -Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take predendence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization. +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:** diff --git a/docs/reference/files/generative-ai.googleaifilemanager.listfiles.md b/docs/reference/files/generative-ai.googleaifilemanager.listfiles.md index a80e44ee..1c229fbb 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.listfiles.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.listfiles.md @@ -6,7 +6,7 @@ List all uploaded files. -Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take predendence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization. +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:** diff --git a/docs/reference/files/generative-ai.googleaifilemanager.md b/docs/reference/files/generative-ai.googleaifilemanager.md index 8aa09f16..e0f3144c 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.md @@ -28,8 +28,8 @@ export declare class GoogleAIFileManager | Method | Modifiers | Description | | --- | --- | --- | -| [deleteFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.deletefile.md) | |

Delete file with given ID.

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

| -| [getFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.getfile.md) | |

Get metadata for file with given ID.

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

| -| [listFiles(listParams, requestOptions)](./generative-ai.googleaifilemanager.listfiles.md) | |

List all uploaded files.

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

| -| [uploadFile(filePath, fileMetadata, requestOptions)](./generative-ai.googleaifilemanager.uploadfile.md) | |

Upload a file.

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

| +| [deleteFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.deletefile.md) | |

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.

| +| [getFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.getfile.md) | |

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.

| +| [listFiles(listParams, requestOptions)](./generative-ai.googleaifilemanager.listfiles.md) | |

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.

| +| [uploadFile(filePath, fileMetadata, requestOptions)](./generative-ai.googleaifilemanager.uploadfile.md) | |

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.

| diff --git a/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md b/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md index 2b12f245..0b29cb68 100644 --- a/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md +++ b/docs/reference/files/generative-ai.googleaifilemanager.uploadfile.md @@ -6,7 +6,7 @@ Upload a file. -Any fields set in the optional [SingleRequestOptions](./generative-ai.singlerequestoptions.md) parameter will take predendence over the [RequestOptions](./generative-ai.requestoptions.md) values provided at the time of the [GoogleAIFileManager](./generative-ai.googleaifilemanager.md) initialization. +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:** diff --git a/packages/main/src/files/file-manager.ts b/packages/main/src/files/file-manager.ts index 3da25e2a..6853dd18 100644 --- a/packages/main/src/files/file-manager.ts +++ b/packages/main/src/files/file-manager.ts @@ -51,7 +51,7 @@ export class GoogleAIFileManager { * Upload a file. * * Any fields set in the optional {@link SingleRequestOptions} parameter will take - * predendence over the {@link RequestOptions} values provided at the time of the + * precedence over the {@link RequestOptions} values provided at the time of the * {@link GoogleAIFileManager} initialization. */ async uploadFile( @@ -106,7 +106,7 @@ export class GoogleAIFileManager { * List all uploaded files. * * Any fields set in the optional {@link SingleRequestOptions} parameter will take - * predendence over the {@link RequestOptions} values provided at the time of the + * precedence over the {@link RequestOptions} values provided at the time of the * {@link GoogleAIFileManager} initialization. */ async listFiles( @@ -137,7 +137,7 @@ export class GoogleAIFileManager { * Get metadata for file with given ID. * * Any fields set in the optional {@link SingleRequestOptions} parameter will take - * predendence over the {@link RequestOptions} values provided at the time of the + * precedence over the {@link RequestOptions} values provided at the time of the * {@link GoogleAIFileManager} initialization. */ async getFile( @@ -163,7 +163,7 @@ export class GoogleAIFileManager { * Delete file with given ID. * * Any fields set in the optional {@link SingleRequestOptions} parameter will take - * predendence over the {@link RequestOptions} values provided at the time of the + * precedence over the {@link RequestOptions} values provided at the time of the * {@link GoogleAIFileManager} initialization. */ async deleteFile( From fbc68fd0e048d9d91e9b5714cd9c938bd0687e7c Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 22 May 2024 10:48:05 -0400 Subject: [PATCH 14/28] tests timeout config in conjunction with signal --- .../node/abort-signal.test.ts | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/main/test-integration/node/abort-signal.test.ts b/packages/main/test-integration/node/abort-signal.test.ts index b30d2d52..9283980e 100644 --- a/packages/main/test-integration/node/abort-signal.test.ts +++ b/packages/main/test-integration/node/abort-signal.test.ts @@ -51,25 +51,55 @@ describe("signal", function () { ); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); - it("file manager listFiles abort test", async () => { + it("file manager listFiles aborted", async () => { const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const signal = AbortSignal.timeout(1); const requestOptions: SingleRequestOptions = { signal }; const promise = fileManager.listFiles(/* listParams= */ {}, requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); - it("file manager getFile abort test", async () => { + it("file manager getFile aborted", async () => { const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const signal = AbortSignal.timeout(1); const requestOptions: SingleRequestOptions = { signal }; const promise = fileManager.getFile("signal.jpg", requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); - it("file manager deleteFile abort test", async () => { + it("file manager deleteFile aborted", async () => { const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const signal = AbortSignal.timeout(1); const requestOptions: SingleRequestOptions = { signal }; const promise = fileManager.deleteFile("signal.jpg", requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); + it("file manager getFile timeout without abort signal", async () => { + const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); + // Ensure the file isn't hosted on the service. + try { + await fileManager.deleteFile("files/signal"); + } catch (error) {} + const requestOptions: SingleRequestOptions = { timeout: 1 }; + // Use getFile, which should fail with a fetch error since the file + // doesn't exist. This should let us discern if the error was + // a timeout abort, or the fetch failure in our expect() below. + const promise = fileManager.getFile("signal.jpg", requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("file manager getFile timeout before singal aborts", async () => { + const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); + // Ensure the file isn't hosted on the service. + try { + await fileManager.deleteFile("files/signal"); + } catch (error) {} + // The AbortSignal timeout is longer than the operation itself, so + // the expected abort should come from the timeout parameter of + // requestOptions. Additionally, regardless of timeouts, this operation + // would normally fail as the file should not be hosted in the service. + // If the timeouts don't work properly then we'd get a fetch error, not + // and abort error. + const signal = AbortSignal.timeout(9000); + const requestOptions: SingleRequestOptions = { timeout: 1, signal }; + const promise = fileManager.getFile("signal.jpg", requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); }); From 1e440f4c8d8ad9db12fdab646cab33c583f51fdd Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 5 Jun 2024 15:20:46 -0400 Subject: [PATCH 15/28] docs gen --- docs/reference/files/generative-ai.md | 1 + docs/reference/main/generative-ai.md | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/reference/files/generative-ai.md b/docs/reference/files/generative-ai.md index af005bfd..ac71b540 100644 --- a/docs/reference/files/generative-ai.md +++ b/docs/reference/files/generative-ai.md @@ -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. | diff --git a/docs/reference/main/generative-ai.md b/docs/reference/main/generative-ai.md index d25ff956..0a4281d2 100644 --- a/docs/reference/main/generative-ai.md +++ b/docs/reference/main/generative-ai.md @@ -72,6 +72,7 @@ | [SafetyRating](./generative-ai.safetyrating.md) | A safety rating associated with a [GenerateContentCandidate](./generative-ai.generatecontentcandidate.md) | | [SafetySetting](./generative-ai.safetysetting.md) | Safety setting that can be sent as part of request parameters. | | [Schema](./generative-ai.schema.md) | Schema is used to define the format of input/output data. Represents a select subset of an OpenAPI 3.0 schema object. More fields may be added in the future as needed. | +| [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | Params passed to atomic asynchronous operations. | | [StartChatParams](./generative-ai.startchatparams.md) | Params for [GenerativeModel.startChat()](./generative-ai.generativemodel.startchat.md). | | [TextPart](./generative-ai.textpart.md) | Content part interface if the part represents a text string. | | [ToolConfig](./generative-ai.toolconfig.md) | Tool config. This config is shared for all tools provided in the request. | From b73cb1a9403d1784b56878a88cce656a673c846b Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Tue, 16 Jul 2024 10:49:35 -0400 Subject: [PATCH 16/28] merge main --- common/api-review/generative-ai-server.api.md | 9 +++++---- common/api-review/generative-ai.api.md | 5 +++++ packages/main/test-integration/node/abort-signal.test.ts | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/common/api-review/generative-ai-server.api.md b/common/api-review/generative-ai-server.api.md index ae98439c..48973bbc 100644 --- a/common/api-review/generative-ai-server.api.md +++ b/common/api-review/generative-ai-server.api.md @@ -354,10 +354,11 @@ export class GoogleAIFileManager { constructor(apiKey: string, _requestOptions?: RequestOptions); // (undocumented) apiKey: string; - deleteFile(fileId: string): Promise; - getFile(fileId: string): Promise; - listFiles(listParams?: ListParams): Promise; - uploadFile(filePath: string, fileMetadata: FileMetadata): Promise; + deleteFile(fileId: string, requestOptions?: SingleRequestOptions): Promise; + getFile(fileId: string, requestOptions?: SingleRequestOptions): Promise; + listFiles(listParams?: ListParams, requestOptions?: SingleRequestOptions): Promise; + // Warning: (ae-forgotten-export) The symbol "SingleRequestOptions" needs to be exported by the entry point index.d.ts + uploadFile(filePath: string, fileMetadata: FileMetadata, requestOptions?: SingleRequestOptions): Promise; } // @public diff --git a/common/api-review/generative-ai.api.md b/common/api-review/generative-ai.api.md index 83f151fc..8323c2c2 100644 --- a/common/api-review/generative-ai.api.md +++ b/common/api-review/generative-ai.api.md @@ -667,6 +667,11 @@ export interface Schema { type?: FunctionDeclarationSchemaType; } +// @public +export interface SingleRequestOptions extends RequestOptions { + signal?: AbortSignal; +} + // @public export interface StartChatParams extends BaseParams { cachedContent?: string; diff --git a/packages/main/test-integration/node/abort-signal.test.ts b/packages/main/test-integration/node/abort-signal.test.ts index 9283980e..80195a41 100644 --- a/packages/main/test-integration/node/abort-signal.test.ts +++ b/packages/main/test-integration/node/abort-signal.test.ts @@ -18,7 +18,7 @@ import { expect, use } from "chai"; import * as chaiAsPromised from "chai-as-promised"; import { SingleRequestOptions } from "../.."; -import { GoogleAIFileManager } from "../../dist/files"; +import { GoogleAIFileManager } from "../../dist/server"; use(chaiAsPromised); From 20b16fbe09488f7d9d8d1e31205ba52562f2502a Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 17 Jul 2024 10:43:47 -0400 Subject: [PATCH 17/28] ChatSession and GenerativeModel implementation --- common/api-review/generative-ai.api.md | 20 +++--- packages/main/src/methods/chat-session.ts | 27 ++++++-- packages/main/src/methods/count-tokens.ts | 6 +- packages/main/src/methods/generate-content.ts | 6 +- packages/main/src/models/generative-model.ts | 67 ++++++++++++++++--- packages/main/src/requests/request.ts | 20 +++--- 6 files changed, 106 insertions(+), 40 deletions(-) diff --git a/common/api-review/generative-ai.api.md b/common/api-review/generative-ai.api.md index 8323c2c2..2275a977 100644 --- a/common/api-review/generative-ai.api.md +++ b/common/api-review/generative-ai.api.md @@ -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; // (undocumented) model: string; // (undocumented) params?: StartChatParams; - // (undocumented) - requestOptions?: RequestOptions; - sendMessage(request: string | Array): Promise; - sendMessageStream(request: string | Array): Promise; + sendMessage(request: string | Array, requestOptions?: SingleRequestOptions): Promise; + sendMessageStream(request: string | Array, requestOptions?: SingleRequestOptions): Promise; } // @public @@ -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; + batchEmbedContents(batchEmbedContentRequest: BatchEmbedContentsRequest, requestOptions?: SingleRequestOptions): Promise; // (undocumented) cachedContent: CachedContent; - countTokens(request: CountTokensRequest | string | Array): Promise; - embedContent(request: EmbedContentRequest | string | Array): Promise; - generateContent(request: GenerateContentRequest | string | Array): Promise; - generateContentStream(request: GenerateContentRequest | string | Array): Promise; + countTokens(request: CountTokensRequest | string | Array, requestOptions?: SingleRequestOptions): Promise; + embedContent(request: EmbedContentRequest | string | Array, requestOptions?: SingleRequestOptions): Promise; + generateContent(request: GenerateContentRequest | string | Array, requestOptions?: SingleRequestOptions): Promise; + generateContentStream(request: GenerateContentRequest | string | Array, requestOptions?: SingleRequestOptions): Promise; // (undocumented) generationConfig: GenerationConfig; // (undocumented) diff --git a/packages/main/src/methods/chat-session.ts b/packages/main/src/methods/chat-session.ts index fd469bfe..2d1c7e6b 100644 --- a/packages/main/src/methods/chat-session.ts +++ b/packages/main/src/methods/chat-session.ts @@ -22,6 +22,7 @@ import { GenerateContentStreamResult, Part, RequestOptions, + SingleRequestOptions, StartChatParams, } from "../../types"; import { formatNewContent } from "../requests/request-helpers"; @@ -49,7 +50,7 @@ export class ChatSession { apiKey: string, public model: string, public params?: StartChatParams, - public requestOptions?: RequestOptions, + private _requestOptions: RequestOptions = {}, ) { this._apiKey = apiKey; if (params?.history) { @@ -70,10 +71,15 @@ export class ChatSession { /** * Sends a chat message and receives a non-streaming - * {@link GenerateContentResult} + * {@link GenerateContentResult}. + * + * Fields set in the optional {@link SingleRequestOptions} parameter will + * take precedence over the {@link RequestOptions} values provided at the + * time of the {@link GoogleAIFileManager} initialization. */ async sendMessage( request: string | Array, + requestOptions: SingleRequestOptions = {}, ): Promise { await this._sendPromise; const newContent = formatNewContent(request); @@ -86,6 +92,10 @@ export class ChatSession { cachedContent: this.params?.cachedContent, contents: [...this._history, newContent], }; + const chatSessionRequestOptions: SingleRequestOptions = { + ...this._requestOptions, + ...requestOptions, + }; let finalResult; // Add onto the chain. this._sendPromise = this._sendPromise @@ -94,7 +104,7 @@ export class ChatSession { this._apiKey, this.model, generateContentRequest, - this.requestOptions, + chatSessionRequestOptions, ), ) .then((result) => { @@ -128,9 +138,14 @@ export class ChatSession { * Sends a chat message and receives the response as a * {@link GenerateContentStreamResult} containing an iterable stream * and a response promise. + * + * Fields set in the optional {@link SingleRequestOptions} parameter will + * take precedence over the {@link RequestOptions} values provided at the + * time of the {@link GoogleAIFileManager} initialization. */ async sendMessageStream( request: string | Array, + requestOptions: SingleRequestOptions = {}, ): Promise { await this._sendPromise; const newContent = formatNewContent(request); @@ -143,11 +158,15 @@ export class ChatSession { cachedContent: this.params?.cachedContent, contents: [...this._history, newContent], }; + const chatSessionRequestOptions: SingleRequestOptions = { + ...this._requestOptions, + ...requestOptions, + }; const streamPromise = generateContentStream( this._apiKey, this.model, generateContentRequest, - this.requestOptions, + chatSessionRequestOptions, ); // Add onto the chain. diff --git a/packages/main/src/methods/count-tokens.ts b/packages/main/src/methods/count-tokens.ts index a8a38e93..49d5ba1c 100644 --- a/packages/main/src/methods/count-tokens.ts +++ b/packages/main/src/methods/count-tokens.ts @@ -18,7 +18,7 @@ import { CountTokensRequest, CountTokensResponse, - RequestOptions, + SingleRequestOptions, } from "../../types"; import { Task, makeModelRequest } from "../requests/request"; @@ -26,7 +26,7 @@ export async function countTokens( apiKey: string, model: string, params: CountTokensRequest, - requestOptions?: RequestOptions, + singleRequestOptions: SingleRequestOptions, ): Promise { const response = await makeModelRequest( model, @@ -34,7 +34,7 @@ export async function countTokens( apiKey, false, JSON.stringify(params), - requestOptions, + singleRequestOptions, ); return response.json(); } diff --git a/packages/main/src/methods/generate-content.ts b/packages/main/src/methods/generate-content.ts index 327cd96e..8c1e1393 100644 --- a/packages/main/src/methods/generate-content.ts +++ b/packages/main/src/methods/generate-content.ts @@ -20,7 +20,7 @@ import { GenerateContentResponse, GenerateContentResult, GenerateContentStreamResult, - RequestOptions, + SingleRequestOptions, } from "../../types"; import { Task, makeModelRequest } from "../requests/request"; import { addHelpers } from "../requests/response-helpers"; @@ -30,7 +30,7 @@ export async function generateContentStream( apiKey: string, model: string, params: GenerateContentRequest, - requestOptions?: RequestOptions, + requestOptions: SingleRequestOptions, ): Promise { const response = await makeModelRequest( model, @@ -47,7 +47,7 @@ export async function generateContent( apiKey: string, model: string, params: GenerateContentRequest, - requestOptions?: RequestOptions, + requestOptions?: SingleRequestOptions, ): Promise { const response = await makeModelRequest( model, diff --git a/packages/main/src/models/generative-model.ts b/packages/main/src/models/generative-model.ts index bbc17601..375d9ddf 100644 --- a/packages/main/src/models/generative-model.ts +++ b/packages/main/src/models/generative-model.ts @@ -36,6 +36,7 @@ import { Part, RequestOptions, SafetySetting, + SingleRequestOptions, StartChatParams, Tool, ToolConfig, @@ -67,7 +68,7 @@ export class GenerativeModel { constructor( public apiKey: string, modelParams: ModelParams, - requestOptions?: RequestOptions, + private _requestOptions: RequestOptions = {}, ) { if (modelParams.model.includes("/")) { // Models may be named "models/model-name" or "tunedModels/model-name" @@ -84,17 +85,25 @@ export class GenerativeModel { modelParams.systemInstruction, ); this.cachedContent = modelParams.cachedContent; - this.requestOptions = requestOptions || {}; } /** * Makes a single non-streaming call to the model * and returns an object containing a single {@link GenerateContentResponse}. + * + * Fields set in the optional {@link SingleRequestOptions} parameter will + * take precedence over the {@link RequestOptions} values provided at the + * time of the {@link GoogleAIFileManager} initialization. */ async generateContent( request: GenerateContentRequest | string | Array, + requestOptions: SingleRequestOptions = {}, ): Promise { const formattedParams = formatGenerateContentInput(request); + const generativeModelRequestOptions: SingleRequestOptions = { + ...this._requestOptions, + ...requestOptions, + }; return generateContent( this.apiKey, this.model, @@ -107,20 +116,29 @@ export class GenerativeModel { cachedContent: this.cachedContent?.name, ...formattedParams, }, - this.requestOptions, + generativeModelRequestOptions, ); } /** - * Makes a single streaming call to the model - * and returns an object containing an iterable stream that iterates - * over all chunks in the streaming response as well as - * a promise that returns the final aggregated response. + * Makes a single streaming call to the model and returns an object + * containing an iterable stream that iterates over all chunks in the + * streaming response as well as a promise that returns the final + * aggregated response. + * + * Fields set in the optional {@link SingleRequestOptions} parameter will + * take precedence over the {@link RequestOptions} values provided at the + * time of the {@link GoogleAIFileManager} initialization. */ async generateContentStream( request: GenerateContentRequest | string | Array, + requestOptions: SingleRequestOptions = {}, ): Promise { const formattedParams = formatGenerateContentInput(request); + const generativeModelRequestOptions: SingleRequestOptions = { + ...this._requestOptions, + ...requestOptions, + }; return generateContentStream( this.apiKey, this.model, @@ -133,7 +151,7 @@ export class GenerativeModel { cachedContent: this.cachedContent?.name, ...formattedParams, }, - this.requestOptions, + generativeModelRequestOptions, ); } @@ -160,9 +178,14 @@ export class GenerativeModel { /** * Counts the tokens in the provided request. + * + * Fields set in the optional {@link SingleRequestOptions} parameter will + * take precedence over the {@link RequestOptions} values provided at the + * time of the {@link GoogleAIFileManager} initialization. */ async countTokens( request: CountTokensRequest | string | Array, + requestOptions: SingleRequestOptions = {}, ): Promise { const formattedParams = formatCountTokensInput(request, { model: this.model, @@ -173,40 +196,62 @@ export class GenerativeModel { systemInstruction: this.systemInstruction, cachedContent: this.cachedContent, }); + const generativeModelRequestOptions: SingleRequestOptions = { + ...this._requestOptions, + ...requestOptions, + }; return countTokens( this.apiKey, this.model, formattedParams, - this.requestOptions, + generativeModelRequestOptions, ); } /** * Embeds the provided content. + * + * Fields set in the optional {@link SingleRequestOptions} parameter will + * take precedence over the {@link RequestOptions} values provided at the + * time of the {@link GoogleAIFileManager} initialization. */ async embedContent( request: EmbedContentRequest | string | Array, + requestOptions: SingleRequestOptions = {}, ): Promise { const formattedParams = formatEmbedContentInput(request); + const generativeModelRequestOptions: SingleRequestOptions = { + ...this._requestOptions, + ...requestOptions, + }; return embedContent( this.apiKey, this.model, formattedParams, - this.requestOptions, + generativeModelRequestOptions, ); } /** * Embeds an array of {@link EmbedContentRequest}s. + * + * Fields set in the optional {@link SingleRequestOptions} parameter will + * take precedence over the {@link RequestOptions} values provided at the + * time of the {@link GoogleAIFileManager} initialization. */ async batchEmbedContents( batchEmbedContentRequest: BatchEmbedContentsRequest, + requestOptions: SingleRequestOptions = {}, ): Promise { + const generativeModelRequestOptions: SingleRequestOptions = { + ...this._requestOptions, + ...requestOptions, + }; return batchEmbedContents( this.apiKey, this.model, batchEmbedContentRequest, - this.requestOptions, + generativeModelRequestOptions, ); } } diff --git a/packages/main/src/requests/request.ts b/packages/main/src/requests/request.ts index 9249aba0..c5d197ad 100644 --- a/packages/main/src/requests/request.ts +++ b/packages/main/src/requests/request.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { RequestOptions } from "../../types"; +import { RequestOptions, SingleRequestOptions } from "../../types"; import { GoogleGenerativeAIError, GoogleGenerativeAIFetchError, @@ -116,7 +116,7 @@ export async function constructModelRequest( apiKey: string, stream: boolean, body: string, - requestOptions?: RequestOptions, + requestOptions: SingleRequestOptions, ): Promise<{ url: string; fetchOptions: RequestInit }> { const url = new RequestUrl(model, task, apiKey, stream, requestOptions); return { @@ -136,7 +136,7 @@ export async function makeModelRequest( apiKey: string, stream: boolean, body: string, - requestOptions?: RequestOptions, + requestOptions: SingleRequestOptions = {}, // Allows this to be stubbed for tests fetchFn = fetch, ): Promise { @@ -217,13 +217,17 @@ async function handleResponseNotOk( * @param requestOptions - The user-defined request options. * @returns The generated request options. */ -function buildFetchOptions(requestOptions?: RequestOptions): RequestInit { +function buildFetchOptions(requestOptions?: SingleRequestOptions): RequestInit { const fetchOptions = {} as RequestInit; + const controller = new AbortController(); if (requestOptions?.timeout >= 0) { - const abortController = new AbortController(); - const signal = abortController.signal; - setTimeout(() => abortController.abort(), requestOptions.timeout); - fetchOptions.signal = signal; + setTimeout(() => controller.abort(), requestOptions.timeout); } + if (requestOptions?.signal) { + requestOptions.signal.addEventListener("abort", () => { + controller.abort(); + }); + } + fetchOptions.signal = controller.signal; return fetchOptions; } From c4c8426411382fb29da7868718a6f18bf2bcda1f Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 17 Jul 2024 14:44:23 -0400 Subject: [PATCH 18/28] remove SRO from some FileManager functions --- packages/main/src/server/file-manager.ts | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/packages/main/src/server/file-manager.ts b/packages/main/src/server/file-manager.ts index f760db6b..b5a7dfd3 100644 --- a/packages/main/src/server/file-manager.ts +++ b/packages/main/src/server/file-manager.ts @@ -49,26 +49,16 @@ export class GoogleAIFileManager { /** * Upload a file. - * - * Any fields set in the optional {@link SingleRequestOptions} parameter will take - * precedence over the {@link RequestOptions} values provided at the time of the - * {@link GoogleAIFileManager} initialization. */ async uploadFile( filePath: string, fileMetadata: FileMetadata, - requestOptions: SingleRequestOptions = {}, ): Promise { const file = readFileSync(filePath); - const filesRequestOptions: SingleRequestOptions = { - ...this._requestOptions, - ...requestOptions, - }; - const url = new FilesRequestUrl( RpcTask.UPLOAD, this.apiKey, - filesRequestOptions, + this._requestOptions, ); const uploadHeaders = getHeaders(url); @@ -161,23 +151,14 @@ export class GoogleAIFileManager { /** * Delete file with given ID. - * - * Any fields set in the optional {@link SingleRequestOptions} parameter will take - * precedence over the {@link RequestOptions} values provided at the time of the - * {@link GoogleAIFileManager} initialization. */ async deleteFile( fileId: string, - requestOptions: SingleRequestOptions = {}, ): Promise { - const filesRequestOptions: SingleRequestOptions = { - ...this._requestOptions, - ...requestOptions, - }; const url = new FilesRequestUrl( RpcTask.DELETE, this.apiKey, - filesRequestOptions, + this._requestOptions, ); url.appendPath(parseFileId(fileId)); const uploadHeaders = getHeaders(url); From c61466af3321a7b65c421c673c3f2bd10f8f0144 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 17 Jul 2024 14:55:16 -0400 Subject: [PATCH 19/28] docs --- common/api-review/generative-ai-server.api.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/api-review/generative-ai-server.api.md b/common/api-review/generative-ai-server.api.md index 48973bbc..456c5273 100644 --- a/common/api-review/generative-ai-server.api.md +++ b/common/api-review/generative-ai-server.api.md @@ -354,11 +354,11 @@ export class GoogleAIFileManager { constructor(apiKey: string, _requestOptions?: RequestOptions); // (undocumented) apiKey: string; - deleteFile(fileId: string, requestOptions?: SingleRequestOptions): Promise; + deleteFile(fileId: string): Promise; getFile(fileId: string, requestOptions?: SingleRequestOptions): Promise; - listFiles(listParams?: ListParams, requestOptions?: SingleRequestOptions): Promise; // Warning: (ae-forgotten-export) The symbol "SingleRequestOptions" needs to be exported by the entry point index.d.ts - uploadFile(filePath: string, fileMetadata: FileMetadata, requestOptions?: SingleRequestOptions): Promise; + listFiles(listParams?: ListParams, requestOptions?: SingleRequestOptions): Promise; + uploadFile(filePath: string, fileMetadata: FileMetadata): Promise; } // @public From 6e26b0cf8a55edf9711a3babc6367c0f54343264 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 17 Jul 2024 16:05:05 -0400 Subject: [PATCH 20/28] format --- packages/main/src/server/file-manager.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/main/src/server/file-manager.ts b/packages/main/src/server/file-manager.ts index b5a7dfd3..c34abb2b 100644 --- a/packages/main/src/server/file-manager.ts +++ b/packages/main/src/server/file-manager.ts @@ -152,9 +152,7 @@ export class GoogleAIFileManager { /** * Delete file with given ID. */ - async deleteFile( - fileId: string, - ): Promise { + async deleteFile(fileId: string): Promise { const url = new FilesRequestUrl( RpcTask.DELETE, this.apiKey, From bec6f015864d15d0bdc2c42f527e9ebd6e6bd0e0 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 17 Jul 2024 16:07:46 -0400 Subject: [PATCH 21/28] GoogleAIFileManager & GenerativeModel tests. --- .../node/abort-signal.test.ts | 185 +++++++++++++----- 1 file changed, 139 insertions(+), 46 deletions(-) diff --git a/packages/main/test-integration/node/abort-signal.test.ts b/packages/main/test-integration/node/abort-signal.test.ts index 80195a41..62ea1fcc 100644 --- a/packages/main/test-integration/node/abort-signal.test.ts +++ b/packages/main/test-integration/node/abort-signal.test.ts @@ -17,7 +17,11 @@ import { expect, use } from "chai"; import * as chaiAsPromised from "chai-as-promised"; -import { SingleRequestOptions } from "../.."; +import { + GoogleGenerativeAI, + RequestOptions, + SingleRequestOptions, +} from "../.."; import { GoogleAIFileManager } from "../../dist/server"; use(chaiAsPromised); @@ -28,78 +32,167 @@ use(chaiAsPromised); describe("signal", function () { this.timeout(60e3); this.slow(10e3); - it("file manager uploadFile abort test", async () => { + /* GoogleAIFileManager */ + it("GoogleAIFileManager getFile() SingleRequestOption timeout", async () => { + // Ensure SingleRequestOptions.timeout takes precendence over the value of + // RequestOptions.timeout configured at construction. Also, a control test + // to ensure that timeout still works without an AbortSignal present. + const requestOptions: RequestOptions = { timeout: 9000 }; + const fileManager = new GoogleAIFileManager( + process.env.GEMINI_API_KEY, + requestOptions, + ); + // Ensure the file isn't hosted on the service. + try { + await fileManager.deleteFile("files/signal"); + } catch (error) {} + const singleRequestOptions: SingleRequestOptions = { timeout: 1 }; + // Use getFile, which should fail with a fetch error since the file + // doesn't exist. This should let us discern if the error was + // a timeout abort, or the fetch failure in our expect() below. + const promise = fileManager.getFile("signal.jpg", singleRequestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("GoogleAIFileManager getFile() aborted", async () => { const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); - const filePathInService = "signal.jpg"; - - // This delete step should cleanup the state of the service for this and - // future executions. + const signal = AbortSignal.timeout(1); + const requestOptions: SingleRequestOptions = { signal }; + const promise = fileManager.getFile("signal.jpg", requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("GoogleAIFileManager getFile() timeout before signal aborts", async () => { + // Ensure the manually configured timeout works in conjunction with the + // AbortSignal timeout. + const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); + // Ensure the file isn't hosted on the service. try { await fileManager.deleteFile("files/signal"); } catch (error) {} - + const signal = AbortSignal.timeout(9000); + const requestOptions: SingleRequestOptions = { timeout: 1, signal }; + const promise = fileManager.getFile("signal.jpg", requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("GoogleAIFileManager listFiles() aborted", async () => { + const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const signal = AbortSignal.timeout(1); - const promise = fileManager.uploadFile( - "test-utils/cat.jpeg", - { - mimeType: "image/jpeg", - name: filePathInService, - }, + const requestOptions: SingleRequestOptions = { signal }; + const promise = fileManager.listFiles(/* listParams= */ {}, requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("GoogleAIFileManager listFiles() timeout before signal aborts", async () => { + const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); + const signal = AbortSignal.timeout(9000); + const requestOptions: SingleRequestOptions = { timeout: 1, signal }; + const promise = fileManager.listFiles(/* listParams= */ {}, requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + + /* GenerativeModel */ + it("GenerativeModel generateContent() SingleRequestOption timeout", async () => { + // Ensure SingleRequestOptions.timeout takes precendence over the value of + // RequestOptions.timeout configured at construction. Also, a control test + // to ensure that timeout still works without an AbortSignal present. + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); + const requestOptions: RequestOptions = { + timeout: 9000, // This is much longer than a generateContent request. + }; + const model = genAI.getGenerativeModel( { - signal, + model: "gemini-1.5-flash-latest", }, + requestOptions, + ); + const singleRequestOptions: SingleRequestOptions = { timeout: 1 }; + const promise = model.generateContent( + "This is not an image", + singleRequestOptions, ); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); - it("file manager listFiles aborted", async () => { - const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); + it("GenerativeModel generateContent() aborted", async () => { + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); + const model = genAI.getGenerativeModel({ + model: "gemini-1.5-flash-latest", + }); const signal = AbortSignal.timeout(1); const requestOptions: SingleRequestOptions = { signal }; - const promise = fileManager.listFiles(/* listParams= */ {}, requestOptions); + const promise = model.generateContent( + "This is not an image", + requestOptions, + ); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("GenerativeModel generateContent() timeout before signal aborts", async () => { + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); + const model = genAI.getGenerativeModel({ + model: "gemini-1.5-flash-latest", + }); + const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); + const signal = AbortSignal.timeout(9000); + const requestOptions: SingleRequestOptions = { timeout: 1, signal }; + const promise = model.generateContent( + "This is not an image", + requestOptions, + ); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); - it("file manager getFile aborted", async () => { + it("GenerativeModel countTokens() aborted", async () => { + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); + const model = genAI.getGenerativeModel({ + model: "gemini-1.5-flash-latest", + }); const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const signal = AbortSignal.timeout(1); const requestOptions: SingleRequestOptions = { signal }; - const promise = fileManager.getFile("signal.jpg", requestOptions); + const promise = model.countTokens("This is not an image", requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); - it("file manager deleteFile aborted", async () => { + it("GenerativeModel embedContent() aborted", async () => { + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); + const model = genAI.getGenerativeModel({ + model: "gemini-1.5-flash-latest", + }); const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const signal = AbortSignal.timeout(1); const requestOptions: SingleRequestOptions = { signal }; - const promise = fileManager.deleteFile("signal.jpg", requestOptions); + const promise = model.embedContent("This is not an image", requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); - it("file manager getFile timeout without abort signal", async () => { + it("GenerativeModel batchEmbedContent() aborted", async () => { + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); + const model = genAI.getGenerativeModel({ + model: "gemini-1.5-flash-latest", + }); const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); - // Ensure the file isn't hosted on the service. - try { - await fileManager.deleteFile("files/signal"); - } catch (error) {} - const requestOptions: SingleRequestOptions = { timeout: 1 }; - // Use getFile, which should fail with a fetch error since the file - // doesn't exist. This should let us discern if the error was - // a timeout abort, or the fetch failure in our expect() below. - const promise = fileManager.getFile("signal.jpg", requestOptions); + const signal = AbortSignal.timeout(1); + const requestOptions: SingleRequestOptions = { signal }; + const content1 = { + content: { role: "user", parts: [{ text: "embed me" }] }, + }; + const content2 = { + content: { role: "user", parts: [{ text: "embed me" }] }, + }; + const promise = model.batchEmbedContents( + { + requests: [content1, content2], + }, + requestOptions, + ); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); - it("file manager getFile timeout before singal aborts", async () => { - const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); - // Ensure the file isn't hosted on the service. - try { - await fileManager.deleteFile("files/signal"); - } catch (error) {} - // The AbortSignal timeout is longer than the operation itself, so - // the expected abort should come from the timeout parameter of - // requestOptions. Additionally, regardless of timeouts, this operation - // would normally fail as the file should not be hosted in the service. - // If the timeouts don't work properly then we'd get a fetch error, not - // and abort error. - const signal = AbortSignal.timeout(9000); - const requestOptions: SingleRequestOptions = { timeout: 1, signal }; - const promise = fileManager.getFile("signal.jpg", requestOptions); + + /* ChatSessionManager */ + it("ChatSession generateContent() aborted", async () => { + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); + const model = genAI.getGenerativeModel({ + model: "gemini-1.5-flash-latest", + }); + const question1 = "What is the capital of Oregon?"; + const chat = model.startChat(); + const signal = AbortSignal.timeout(1); + const requestOptions: SingleRequestOptions = { signal }; + const promise = chat.sendMessage(question1, requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); }); From 5bbbcf5066f60a0bf8856e834e435d2739949904 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 17 Jul 2024 16:43:56 -0400 Subject: [PATCH 22/28] ChatSessionManager tests --- .../node/abort-signal.test.ts | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/packages/main/test-integration/node/abort-signal.test.ts b/packages/main/test-integration/node/abort-signal.test.ts index 62ea1fcc..497961a7 100644 --- a/packages/main/test-integration/node/abort-signal.test.ts +++ b/packages/main/test-integration/node/abort-signal.test.ts @@ -33,7 +33,7 @@ describe("signal", function () { this.timeout(60e3); this.slow(10e3); /* GoogleAIFileManager */ - it("GoogleAIFileManager getFile() SingleRequestOption timeout", async () => { + it("GoogleAIFileManager getFile() SingleRequestOption.timeout", async () => { // Ensure SingleRequestOptions.timeout takes precendence over the value of // RequestOptions.timeout configured at construction. Also, a control test // to ensure that timeout still works without an AbortSignal present. @@ -89,7 +89,7 @@ describe("signal", function () { }); /* GenerativeModel */ - it("GenerativeModel generateContent() SingleRequestOption timeout", async () => { + it("GenerativeModel generateContent() SingleRequestOption.timeout", async () => { // Ensure SingleRequestOptions.timeout takes precendence over the value of // RequestOptions.timeout configured at construction. Also, a control test // to ensure that timeout still works without an AbortSignal present. @@ -183,7 +183,27 @@ describe("signal", function () { }); /* ChatSessionManager */ - it("ChatSession generateContent() aborted", async () => { + it("ChatSessionManager sendMessage() SingleRequestOption.timeout", async () => { + // Ensure SingleRequestOptions.timeout takes precendence over the value of + // RequestOptions.timeout configured at construction. Also, a control test + // to ensure that timeout still works without an AbortSignal present. + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); + const requestOptions: RequestOptions = { + timeout: 9000, // This is much longer than a generateContent request. + }; + const model = genAI.getGenerativeModel( + { + model: "gemini-1.5-flash-latest", + }, + requestOptions, + ); + const question1 = "What is the capital of Oregon?"; + const chat = model.startChat(); + const singleRequestOptions: SingleRequestOptions = { timeout: 1 }; + const promise = chat.sendMessage(question1, singleRequestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("ChatSession sendMessage() aborted", async () => { const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest", @@ -195,4 +215,40 @@ describe("signal", function () { const promise = chat.sendMessage(question1, requestOptions); await expect(promise).to.be.rejectedWith("This operation was aborted"); }); + it("ChatSession sendMessage() timeout before signal aborts", async () => { + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); + const model = genAI.getGenerativeModel({ + model: "gemini-1.5-flash-latest", + }); + const question1 = "What is the capital of Oregon?"; + const chat = model.startChat(); + const signal = AbortSignal.timeout(9000); + const requestOptions: SingleRequestOptions = { timeout: 1, signal }; + const promise = chat.sendMessage(question1, requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("ChatSession sendMessageStream() aborted", async () => { + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); + const model = genAI.getGenerativeModel({ + model: "gemini-1.5-flash-latest", + }); + const question1 = "What is the capital of Oregon?"; + const chat = model.startChat(); + const signal = AbortSignal.timeout(1); + const requestOptions: SingleRequestOptions = { signal }; + const promise = chat.sendMessageStream(question1, requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); + it("ChatSession sendMessageStream() timeout before signal aborts", async () => { + const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); + const model = genAI.getGenerativeModel({ + model: "gemini-1.5-flash-latest", + }); + const question1 = "What is the capital of Oregon?"; + const chat = model.startChat(); + const signal = AbortSignal.timeout(9000); + const requestOptions: SingleRequestOptions = { timeout: 1, signal }; + const promise = chat.sendMessageStream(question1, requestOptions); + await expect(promise).to.be.rejectedWith("This operation was aborted"); + }); }); From 6abb6d44b1986eab32d3802325519ce0ebb06677 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 17 Jul 2024 16:48:45 -0400 Subject: [PATCH 23/28] extra GoogleAIFileManager variables --- packages/main/test-integration/node/abort-signal.test.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/main/test-integration/node/abort-signal.test.ts b/packages/main/test-integration/node/abort-signal.test.ts index 497961a7..d540b2df 100644 --- a/packages/main/test-integration/node/abort-signal.test.ts +++ b/packages/main/test-integration/node/abort-signal.test.ts @@ -128,7 +128,6 @@ describe("signal", function () { const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest", }); - const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const signal = AbortSignal.timeout(9000); const requestOptions: SingleRequestOptions = { timeout: 1, signal }; const promise = model.generateContent( @@ -142,7 +141,6 @@ describe("signal", function () { const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest", }); - const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const signal = AbortSignal.timeout(1); const requestOptions: SingleRequestOptions = { signal }; const promise = model.countTokens("This is not an image", requestOptions); @@ -153,7 +151,6 @@ describe("signal", function () { const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest", }); - const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const signal = AbortSignal.timeout(1); const requestOptions: SingleRequestOptions = { signal }; const promise = model.embedContent("This is not an image", requestOptions); @@ -164,7 +161,6 @@ describe("signal", function () { const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash-latest", }); - const fileManager = new GoogleAIFileManager(process.env.GEMINI_API_KEY); const signal = AbortSignal.timeout(1); const requestOptions: SingleRequestOptions = { signal }; const content1 = { From 4d7121fc4af649e6595051c902620b1f457414d1 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Thu, 18 Jul 2024 16:25:53 -0400 Subject: [PATCH 24/28] Fix utest failure due to signal now appearing in requests --- packages/main/src/requests/request.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/main/src/requests/request.test.ts b/packages/main/src/requests/request.test.ts index 61d39924..9cc6a237 100644 --- a/packages/main/src/requests/request.test.ts +++ b/packages/main/src/requests/request.test.ts @@ -225,6 +225,7 @@ describe("request methods", () => { method: "POST", headers: match.instanceOf(Headers), body: "", + signal: match.instanceOf(AbortSignal), }); expect(response.ok).to.be.true; }); From 5e52c28126463279641bb228a3e8e8966cea6bdd Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Thu, 18 Jul 2024 16:38:30 -0400 Subject: [PATCH 25/28] yarn docs --- .../main/generative-ai.chatsession._constructor_.md | 4 ++-- docs/reference/main/generative-ai.chatsession.md | 7 +++---- .../main/generative-ai.chatsession.requestoptions.md | 11 ----------- .../main/generative-ai.chatsession.sendmessage.md | 7 +++++-- .../generative-ai.chatsession.sendmessagestream.md | 5 ++++- .../generative-ai.generativemodel._constructor_.md | 4 ++-- ...nerative-ai.generativemodel.batchembedcontents.md | 5 ++++- .../generative-ai.generativemodel.counttokens.md | 5 ++++- .../generative-ai.generativemodel.embedcontent.md | 5 ++++- .../generative-ai.generativemodel.generatecontent.md | 5 ++++- ...ative-ai.generativemodel.generatecontentstream.md | 5 ++++- docs/reference/main/generative-ai.generativemodel.md | 12 ++++++------ .../generative-ai.googleaifilemanager.deletefile.md | 2 +- .../generative-ai.googleaifilemanager.getfile.md | 7 +++++-- .../generative-ai.googleaifilemanager.listfiles.md | 7 +++++-- .../server/generative-ai.googleaifilemanager.md | 8 ++++---- .../generative-ai.googleaifilemanager.uploadfile.md | 2 +- 17 files changed, 58 insertions(+), 43 deletions(-) delete mode 100644 docs/reference/main/generative-ai.chatsession.requestoptions.md diff --git a/docs/reference/main/generative-ai.chatsession._constructor_.md b/docs/reference/main/generative-ai.chatsession._constructor_.md index 918fd310..8bd24a6e 100644 --- a/docs/reference/main/generative-ai.chatsession._constructor_.md +++ b/docs/reference/main/generative-ai.chatsession._constructor_.md @@ -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 @@ -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)_ | diff --git a/docs/reference/main/generative-ai.chatsession.md b/docs/reference/main/generative-ai.chatsession.md index 948cd4cd..360a0ef9 100644 --- a/docs/reference/main/generative-ai.chatsession.md +++ b/docs/reference/main/generative-ai.chatsession.md @@ -16,7 +16,7 @@ export declare class ChatSession | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(apiKey, model, params, requestOptions)](./generative-ai.chatsession._constructor_.md) | | Constructs a new instance of the ChatSession class | +| [(constructor)(apiKey, model, params, \_requestOptions)](./generative-ai.chatsession._constructor_.md) | | Constructs a new instance of the ChatSession class | ## Properties @@ -24,13 +24,12 @@ export declare class ChatSession | --- | --- | --- | --- | | [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) | |

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.

| +| [sendMessageStream(request, requestOptions)](./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.

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.

| diff --git a/docs/reference/main/generative-ai.chatsession.requestoptions.md b/docs/reference/main/generative-ai.chatsession.requestoptions.md deleted file mode 100644 index bc7402c4..00000000 --- a/docs/reference/main/generative-ai.chatsession.requestoptions.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [ChatSession](./generative-ai.chatsession.md) > [requestOptions](./generative-ai.chatsession.requestoptions.md) - -## ChatSession.requestOptions property - -**Signature:** - -```typescript -requestOptions?: RequestOptions; -``` diff --git a/docs/reference/main/generative-ai.chatsession.sendmessage.md b/docs/reference/main/generative-ai.chatsession.sendmessage.md index 08a5ff6c..dfa66713 100644 --- a/docs/reference/main/generative-ai.chatsession.sendmessage.md +++ b/docs/reference/main/generative-ai.chatsession.sendmessage.md @@ -4,12 +4,14 @@ ## 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): Promise; +sendMessage(request: string | Array, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,6 +19,7 @@ sendMessage(request: string | Array): Promise> | | +| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/main/generative-ai.chatsession.sendmessagestream.md b/docs/reference/main/generative-ai.chatsession.sendmessagestream.md index e6f7cbe3..ac409f77 100644 --- a/docs/reference/main/generative-ai.chatsession.sendmessagestream.md +++ b/docs/reference/main/generative-ai.chatsession.sendmessagestream.md @@ -6,10 +6,12 @@ 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): Promise; +sendMessageStream(request: string | Array, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,6 +19,7 @@ sendMessageStream(request: string | Array): Promise> | | +| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/main/generative-ai.generativemodel._constructor_.md b/docs/reference/main/generative-ai.generativemodel._constructor_.md index 47030ab7..1a410e65 100644 --- a/docs/reference/main/generative-ai.generativemodel._constructor_.md +++ b/docs/reference/main/generative-ai.generativemodel._constructor_.md @@ -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 @@ -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)_ | diff --git a/docs/reference/main/generative-ai.generativemodel.batchembedcontents.md b/docs/reference/main/generative-ai.generativemodel.batchembedcontents.md index cd3ccadc..76d31f98 100644 --- a/docs/reference/main/generative-ai.generativemodel.batchembedcontents.md +++ b/docs/reference/main/generative-ai.generativemodel.batchembedcontents.md @@ -6,10 +6,12 @@ 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; +batchEmbedContents(batchEmbedContentRequest: BatchEmbedContentsRequest, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,6 +19,7 @@ batchEmbedContents(batchEmbedContentRequest: BatchEmbedContentsRequest): Promise | Parameter | Type | Description | | --- | --- | --- | | batchEmbedContentRequest | [BatchEmbedContentsRequest](./generative-ai.batchembedcontentsrequest.md) | | +| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/main/generative-ai.generativemodel.counttokens.md b/docs/reference/main/generative-ai.generativemodel.counttokens.md index 1e3b982d..d81236a2 100644 --- a/docs/reference/main/generative-ai.generativemodel.counttokens.md +++ b/docs/reference/main/generative-ai.generativemodel.counttokens.md @@ -6,10 +6,12 @@ Counts the tokens in the provided request. +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 -countTokens(request: CountTokensRequest | string | Array): Promise; +countTokens(request: CountTokensRequest | string | Array, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,6 +19,7 @@ countTokens(request: CountTokensRequest | string | Array): Promis | Parameter | Type | Description | | --- | --- | --- | | request | [CountTokensRequest](./generative-ai.counttokensrequest.md) \| string \| Array<string \| [Part](./generative-ai.part.md)> | | +| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/main/generative-ai.generativemodel.embedcontent.md b/docs/reference/main/generative-ai.generativemodel.embedcontent.md index 445d130d..8c2105d8 100644 --- a/docs/reference/main/generative-ai.generativemodel.embedcontent.md +++ b/docs/reference/main/generative-ai.generativemodel.embedcontent.md @@ -6,10 +6,12 @@ Embeds the provided content. +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 -embedContent(request: EmbedContentRequest | string | Array): Promise; +embedContent(request: EmbedContentRequest | string | Array, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,6 +19,7 @@ embedContent(request: EmbedContentRequest | string | Array): Prom | Parameter | Type | Description | | --- | --- | --- | | request | [EmbedContentRequest](./generative-ai.embedcontentrequest.md) \| string \| Array<string \| [Part](./generative-ai.part.md)> | | +| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/main/generative-ai.generativemodel.generatecontent.md b/docs/reference/main/generative-ai.generativemodel.generatecontent.md index 86d0ac70..8cc74496 100644 --- a/docs/reference/main/generative-ai.generativemodel.generatecontent.md +++ b/docs/reference/main/generative-ai.generativemodel.generatecontent.md @@ -6,10 +6,12 @@ Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./generative-ai.generatecontentresponse.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 -generateContent(request: GenerateContentRequest | string | Array): Promise; +generateContent(request: GenerateContentRequest | string | Array, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,6 +19,7 @@ generateContent(request: GenerateContentRequest | string | Array) | Parameter | Type | Description | | --- | --- | --- | | request | [GenerateContentRequest](./generative-ai.generatecontentrequest.md) \| string \| Array<string \| [Part](./generative-ai.part.md)> | | +| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/main/generative-ai.generativemodel.generatecontentstream.md b/docs/reference/main/generative-ai.generativemodel.generatecontentstream.md index 5288ad82..6cfd125c 100644 --- a/docs/reference/main/generative-ai.generativemodel.generatecontentstream.md +++ b/docs/reference/main/generative-ai.generativemodel.generatecontentstream.md @@ -6,10 +6,12 @@ Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response. +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 -generateContentStream(request: GenerateContentRequest | string | Array): Promise; +generateContentStream(request: GenerateContentRequest | string | Array, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,6 +19,7 @@ generateContentStream(request: GenerateContentRequest | string | Array> | | +| requestOptions | [SingleRequestOptions](./generative-ai.singlerequestoptions.md) | _(Optional)_ | **Returns:** diff --git a/docs/reference/main/generative-ai.generativemodel.md b/docs/reference/main/generative-ai.generativemodel.md index f78e6b8a..c822694c 100644 --- a/docs/reference/main/generative-ai.generativemodel.md +++ b/docs/reference/main/generative-ai.generativemodel.md @@ -16,7 +16,7 @@ export declare class GenerativeModel | Constructor | Modifiers | Description | | --- | --- | --- | -| [(constructor)(apiKey, modelParams, requestOptions)](./generative-ai.generativemodel._constructor_.md) | | Constructs a new instance of the GenerativeModel class | +| [(constructor)(apiKey, modelParams, \_requestOptions)](./generative-ai.generativemodel._constructor_.md) | | Constructs a new instance of the GenerativeModel class | ## Properties @@ -36,10 +36,10 @@ export declare class GenerativeModel | Method | Modifiers | Description | | --- | --- | --- | -| [batchEmbedContents(batchEmbedContentRequest)](./generative-ai.generativemodel.batchembedcontents.md) | | Embeds an array of [EmbedContentRequest](./generative-ai.embedcontentrequest.md)s. | -| [countTokens(request)](./generative-ai.generativemodel.counttokens.md) | | Counts the tokens in the provided request. | -| [embedContent(request)](./generative-ai.generativemodel.embedcontent.md) | | Embeds the provided content. | -| [generateContent(request)](./generative-ai.generativemodel.generatecontent.md) | | Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./generative-ai.generatecontentresponse.md). | -| [generateContentStream(request)](./generative-ai.generativemodel.generatecontentstream.md) | | Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response. | +| [batchEmbedContents(batchEmbedContentRequest, requestOptions)](./generative-ai.generativemodel.batchembedcontents.md) | |

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.

| +| [countTokens(request, requestOptions)](./generative-ai.generativemodel.counttokens.md) | |

Counts the tokens in the provided request.

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.

| +| [embedContent(request, requestOptions)](./generative-ai.generativemodel.embedcontent.md) | |

Embeds the provided content.

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.

| +| [generateContent(request, requestOptions)](./generative-ai.generativemodel.generatecontent.md) | |

Makes a single non-streaming call to the model and returns an object containing a single [GenerateContentResponse](./generative-ai.generatecontentresponse.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.

| +| [generateContentStream(request, requestOptions)](./generative-ai.generativemodel.generatecontentstream.md) | |

Makes a single streaming call to the model and returns an object containing an iterable stream that iterates over all chunks in the streaming response as well as a promise that returns the final aggregated response.

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.

| | [startChat(startChatParams)](./generative-ai.generativemodel.startchat.md) | | Gets a new [ChatSession](./generative-ai.chatsession.md) instance which can be used for multi-turn chats. | diff --git a/docs/reference/server/generative-ai.googleaifilemanager.deletefile.md b/docs/reference/server/generative-ai.googleaifilemanager.deletefile.md index e5ecfdad..acaefb74 100644 --- a/docs/reference/server/generative-ai.googleaifilemanager.deletefile.md +++ b/docs/reference/server/generative-ai.googleaifilemanager.deletefile.md @@ -4,7 +4,7 @@ ## GoogleAIFileManager.deleteFile() method -Delete file with given ID +Delete file with given ID. **Signature:** diff --git a/docs/reference/server/generative-ai.googleaifilemanager.getfile.md b/docs/reference/server/generative-ai.googleaifilemanager.getfile.md index 613d6b6c..79f46753 100644 --- a/docs/reference/server/generative-ai.googleaifilemanager.getfile.md +++ b/docs/reference/server/generative-ai.googleaifilemanager.getfile.md @@ -4,12 +4,14 @@ ## GoogleAIFileManager.getFile() method -Get metadata for file with given ID +Get metadata for file with given ID. + +Any fields set in the optional 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; +getFile(fileId: string, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,6 +19,7 @@ getFile(fileId: string): Promise; | Parameter | Type | Description | | --- | --- | --- | | fileId | string | | +| requestOptions | SingleRequestOptions | _(Optional)_ | **Returns:** diff --git a/docs/reference/server/generative-ai.googleaifilemanager.listfiles.md b/docs/reference/server/generative-ai.googleaifilemanager.listfiles.md index ef116fb6..f8449bd0 100644 --- a/docs/reference/server/generative-ai.googleaifilemanager.listfiles.md +++ b/docs/reference/server/generative-ai.googleaifilemanager.listfiles.md @@ -4,12 +4,14 @@ ## GoogleAIFileManager.listFiles() method -List all uploaded files +List all uploaded files. + +Any fields set in the optional 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; +listFiles(listParams?: ListParams, requestOptions?: SingleRequestOptions): Promise; ``` ## Parameters @@ -17,6 +19,7 @@ listFiles(listParams?: ListParams): Promise; | Parameter | Type | Description | | --- | --- | --- | | listParams | [ListParams](./generative-ai.listparams.md) | _(Optional)_ | +| requestOptions | SingleRequestOptions | _(Optional)_ | **Returns:** diff --git a/docs/reference/server/generative-ai.googleaifilemanager.md b/docs/reference/server/generative-ai.googleaifilemanager.md index 655c8d0c..04d22232 100644 --- a/docs/reference/server/generative-ai.googleaifilemanager.md +++ b/docs/reference/server/generative-ai.googleaifilemanager.md @@ -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)](./generative-ai.googleaifilemanager.deletefile.md) | | Delete file with given ID. | +| [getFile(fileId, requestOptions)](./generative-ai.googleaifilemanager.getfile.md) | |

Get metadata for file with given ID.

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

| +| [listFiles(listParams, requestOptions)](./generative-ai.googleaifilemanager.listfiles.md) | |

List all uploaded files.

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

| +| [uploadFile(filePath, fileMetadata)](./generative-ai.googleaifilemanager.uploadfile.md) | | Upload a file. | diff --git a/docs/reference/server/generative-ai.googleaifilemanager.uploadfile.md b/docs/reference/server/generative-ai.googleaifilemanager.uploadfile.md index 90648e90..71e4f76b 100644 --- a/docs/reference/server/generative-ai.googleaifilemanager.uploadfile.md +++ b/docs/reference/server/generative-ai.googleaifilemanager.uploadfile.md @@ -4,7 +4,7 @@ ## GoogleAIFileManager.uploadFile() method -Upload a file +Upload a file. **Signature:** From 0edc918c4ae5bcda7d45b7c5385bf634f8a94da0 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Fri, 19 Jul 2024 10:15:01 -0400 Subject: [PATCH 26/28] AbortSignal in buildFetchOptions only if needed. --- packages/main/src/requests/request.test.ts | 1 - packages/main/src/requests/request.ts | 20 +++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/main/src/requests/request.test.ts b/packages/main/src/requests/request.test.ts index 9cc6a237..61d39924 100644 --- a/packages/main/src/requests/request.test.ts +++ b/packages/main/src/requests/request.test.ts @@ -225,7 +225,6 @@ describe("request methods", () => { method: "POST", headers: match.instanceOf(Headers), body: "", - signal: match.instanceOf(AbortSignal), }); expect(response.ok).to.be.true; }); diff --git a/packages/main/src/requests/request.ts b/packages/main/src/requests/request.ts index c5d197ad..0828b65a 100644 --- a/packages/main/src/requests/request.ts +++ b/packages/main/src/requests/request.ts @@ -219,15 +219,17 @@ async function handleResponseNotOk( */ function buildFetchOptions(requestOptions?: SingleRequestOptions): RequestInit { const fetchOptions = {} as RequestInit; - const controller = new AbortController(); - if (requestOptions?.timeout >= 0) { - setTimeout(() => controller.abort(), requestOptions.timeout); - } - if (requestOptions?.signal) { - requestOptions.signal.addEventListener("abort", () => { - controller.abort(); - }); + if (requestOptions?.signal !== undefined || requestOptions?.timeout >= 0) { + const controller = new AbortController(); + if (requestOptions?.timeout >= 0) { + setTimeout(() => controller.abort(), requestOptions.timeout); + } + if (requestOptions?.signal) { + requestOptions.signal.addEventListener("abort", () => { + controller.abort(); + }); + } + fetchOptions.signal = controller.signal; } - fetchOptions.signal = controller.signal; return fetchOptions; } From 1444eb63be3c474639dc7f98300c7d423557bef1 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Fri, 19 Jul 2024 10:16:45 -0400 Subject: [PATCH 27/28] docs --- docs/reference/main/generative-ai.singlerequestoptions.md | 2 +- .../main/generative-ai.singlerequestoptions.signal.md | 4 +++- packages/main/types/requests.ts | 7 +++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/reference/main/generative-ai.singlerequestoptions.md b/docs/reference/main/generative-ai.singlerequestoptions.md index 2cbda55f..4d9a23d3 100644 --- a/docs/reference/main/generative-ai.singlerequestoptions.md +++ b/docs/reference/main/generative-ai.singlerequestoptions.md @@ -17,5 +17,5 @@ export interface SingleRequestOptions extends RequestOptions | 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. | +| [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.

NOTE: AbortSignal is a client-only operation. Using it to cancel an operation will not cancel the request in the service. You will still be charged usage for any applicable operations.

| diff --git a/docs/reference/main/generative-ai.singlerequestoptions.signal.md b/docs/reference/main/generative-ai.singlerequestoptions.signal.md index 9f0672b7..ac064709 100644 --- a/docs/reference/main/generative-ai.singlerequestoptions.signal.md +++ b/docs/reference/main/generative-ai.singlerequestoptions.signal.md @@ -4,7 +4,9 @@ ## 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. +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. + +NOTE: AbortSignal is a client-only operation. Using it to cancel an operation will not cancel the request in the service. You will still be charged usage for any applicable operations. **Signature:** diff --git a/packages/main/types/requests.ts b/packages/main/types/requests.ts index c266a846..4eec1e9c 100644 --- a/packages/main/types/requests.ts +++ b/packages/main/types/requests.ts @@ -196,8 +196,11 @@ export interface RequestOptions { export interface SingleRequestOptions extends RequestOptions { /** * 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. + * also be aborted due to the expiration of the timeout value, if provided. + * + * NOTE: AbortSignal is a client-only operation. Using it to cancel an + * operation will not cancel the request in the service. You will still + * be charged usage for any applicable operations. */ signal?: AbortSignal; } From ac4b7217f5a95a443b5607449d09f7c716bc9e82 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Fri, 19 Jul 2024 18:46:08 -0400 Subject: [PATCH 28/28] changeset --- .changeset/tough-beds-serve.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tough-beds-serve.md diff --git a/.changeset/tough-beds-serve.md b/.changeset/tough-beds-serve.md new file mode 100644 index 00000000..2b35de93 --- /dev/null +++ b/.changeset/tough-beds-serve.md @@ -0,0 +1,5 @@ +--- +"@google/generative-ai": minor +--- + +Adds `SingleRequestOptions` with `AbortSignal` support to most of the asynchronous methods of `GenerativeModel`, `GoogleAIFileManager` and `ChatSession`.