@google/genai 1.40.0 → 1.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/genai.d.ts +89 -21
- package/dist/index.cjs +263 -37
- package/dist/index.mjs +264 -38
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +262 -37
- package/dist/node/index.mjs +263 -38
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +89 -21
- package/dist/tokenizer/node.cjs +12 -0
- package/dist/tokenizer/node.d.ts +9 -0
- package/dist/tokenizer/node.mjs +12 -0
- package/dist/tokenizer/node.mjs.map +1 -1
- package/dist/web/index.mjs +264 -38
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +89 -21
- package/package.json +3 -2
package/dist/node/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import pRetry, { AbortError } from 'p-retry';
|
|
1
2
|
import { GoogleAuth } from 'google-auth-library';
|
|
2
3
|
import { createWriteStream } from 'fs';
|
|
3
4
|
import * as fs from 'fs/promises';
|
|
@@ -1365,6 +1366,18 @@ var Environment;
|
|
|
1365
1366
|
*/
|
|
1366
1367
|
Environment["ENVIRONMENT_BROWSER"] = "ENVIRONMENT_BROWSER";
|
|
1367
1368
|
})(Environment || (Environment = {}));
|
|
1369
|
+
/** Enum representing the Vertex embedding API to use. */
|
|
1370
|
+
var EmbeddingApiType;
|
|
1371
|
+
(function (EmbeddingApiType) {
|
|
1372
|
+
/**
|
|
1373
|
+
* predict API endpoint (default)
|
|
1374
|
+
*/
|
|
1375
|
+
EmbeddingApiType["PREDICT"] = "PREDICT";
|
|
1376
|
+
/**
|
|
1377
|
+
* embedContent API Endpoint
|
|
1378
|
+
*/
|
|
1379
|
+
EmbeddingApiType["EMBED_CONTENT"] = "EMBED_CONTENT";
|
|
1380
|
+
})(EmbeddingApiType || (EmbeddingApiType = {}));
|
|
1368
1381
|
/** Enum that controls the safety filter level for objectionable content. */
|
|
1369
1382
|
var SafetyFilterLevel;
|
|
1370
1383
|
(function (SafetyFilterLevel) {
|
|
@@ -3396,6 +3409,10 @@ function tJobState(state) {
|
|
|
3396
3409
|
return stateString;
|
|
3397
3410
|
}
|
|
3398
3411
|
}
|
|
3412
|
+
function tIsVertexEmbedContentModel(model) {
|
|
3413
|
+
return ((model.includes('gemini') && model !== 'gemini-embedding-001') ||
|
|
3414
|
+
model.includes('maas'));
|
|
3415
|
+
}
|
|
3399
3416
|
|
|
3400
3417
|
/**
|
|
3401
3418
|
* @license
|
|
@@ -8637,33 +8654,103 @@ function embedContentConfigToMldev(fromObject, parentObject, _rootObject) {
|
|
|
8637
8654
|
}
|
|
8638
8655
|
return toObject;
|
|
8639
8656
|
}
|
|
8640
|
-
function embedContentConfigToVertex(fromObject, parentObject,
|
|
8657
|
+
function embedContentConfigToVertex(fromObject, parentObject, rootObject) {
|
|
8641
8658
|
const toObject = {};
|
|
8642
|
-
|
|
8643
|
-
|
|
8644
|
-
|
|
8659
|
+
let discriminatorTaskType = getValueByPath(rootObject, [
|
|
8660
|
+
'embeddingApiType',
|
|
8661
|
+
]);
|
|
8662
|
+
if (discriminatorTaskType === undefined) {
|
|
8663
|
+
discriminatorTaskType = 'PREDICT';
|
|
8645
8664
|
}
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
|
|
8665
|
+
if (discriminatorTaskType === 'PREDICT') {
|
|
8666
|
+
const fromTaskType = getValueByPath(fromObject, ['taskType']);
|
|
8667
|
+
if (parentObject !== undefined && fromTaskType != null) {
|
|
8668
|
+
setValueByPath(parentObject, ['instances[]', 'task_type'], fromTaskType);
|
|
8669
|
+
}
|
|
8649
8670
|
}
|
|
8650
|
-
|
|
8651
|
-
'
|
|
8671
|
+
else if (discriminatorTaskType === 'EMBED_CONTENT') {
|
|
8672
|
+
const fromTaskType = getValueByPath(fromObject, ['taskType']);
|
|
8673
|
+
if (parentObject !== undefined && fromTaskType != null) {
|
|
8674
|
+
setValueByPath(parentObject, ['taskType'], fromTaskType);
|
|
8675
|
+
}
|
|
8676
|
+
}
|
|
8677
|
+
let discriminatorTitle = getValueByPath(rootObject, [
|
|
8678
|
+
'embeddingApiType',
|
|
8652
8679
|
]);
|
|
8653
|
-
if (
|
|
8654
|
-
|
|
8680
|
+
if (discriminatorTitle === undefined) {
|
|
8681
|
+
discriminatorTitle = 'PREDICT';
|
|
8655
8682
|
}
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8683
|
+
if (discriminatorTitle === 'PREDICT') {
|
|
8684
|
+
const fromTitle = getValueByPath(fromObject, ['title']);
|
|
8685
|
+
if (parentObject !== undefined && fromTitle != null) {
|
|
8686
|
+
setValueByPath(parentObject, ['instances[]', 'title'], fromTitle);
|
|
8687
|
+
}
|
|
8659
8688
|
}
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8689
|
+
else if (discriminatorTitle === 'EMBED_CONTENT') {
|
|
8690
|
+
const fromTitle = getValueByPath(fromObject, ['title']);
|
|
8691
|
+
if (parentObject !== undefined && fromTitle != null) {
|
|
8692
|
+
setValueByPath(parentObject, ['title'], fromTitle);
|
|
8693
|
+
}
|
|
8694
|
+
}
|
|
8695
|
+
let discriminatorOutputDimensionality = getValueByPath(rootObject, [
|
|
8696
|
+
'embeddingApiType',
|
|
8697
|
+
]);
|
|
8698
|
+
if (discriminatorOutputDimensionality === undefined) {
|
|
8699
|
+
discriminatorOutputDimensionality = 'PREDICT';
|
|
8700
|
+
}
|
|
8701
|
+
if (discriminatorOutputDimensionality === 'PREDICT') {
|
|
8702
|
+
const fromOutputDimensionality = getValueByPath(fromObject, [
|
|
8703
|
+
'outputDimensionality',
|
|
8704
|
+
]);
|
|
8705
|
+
if (parentObject !== undefined && fromOutputDimensionality != null) {
|
|
8706
|
+
setValueByPath(parentObject, ['parameters', 'outputDimensionality'], fromOutputDimensionality);
|
|
8707
|
+
}
|
|
8708
|
+
}
|
|
8709
|
+
else if (discriminatorOutputDimensionality === 'EMBED_CONTENT') {
|
|
8710
|
+
const fromOutputDimensionality = getValueByPath(fromObject, [
|
|
8711
|
+
'outputDimensionality',
|
|
8712
|
+
]);
|
|
8713
|
+
if (parentObject !== undefined && fromOutputDimensionality != null) {
|
|
8714
|
+
setValueByPath(parentObject, ['outputDimensionality'], fromOutputDimensionality);
|
|
8715
|
+
}
|
|
8716
|
+
}
|
|
8717
|
+
let discriminatorMimeType = getValueByPath(rootObject, [
|
|
8718
|
+
'embeddingApiType',
|
|
8719
|
+
]);
|
|
8720
|
+
if (discriminatorMimeType === undefined) {
|
|
8721
|
+
discriminatorMimeType = 'PREDICT';
|
|
8722
|
+
}
|
|
8723
|
+
if (discriminatorMimeType === 'PREDICT') {
|
|
8724
|
+
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
8725
|
+
if (parentObject !== undefined && fromMimeType != null) {
|
|
8726
|
+
setValueByPath(parentObject, ['instances[]', 'mimeType'], fromMimeType);
|
|
8727
|
+
}
|
|
8728
|
+
}
|
|
8729
|
+
let discriminatorAutoTruncate = getValueByPath(rootObject, [
|
|
8730
|
+
'embeddingApiType',
|
|
8731
|
+
]);
|
|
8732
|
+
if (discriminatorAutoTruncate === undefined) {
|
|
8733
|
+
discriminatorAutoTruncate = 'PREDICT';
|
|
8734
|
+
}
|
|
8735
|
+
if (discriminatorAutoTruncate === 'PREDICT') {
|
|
8736
|
+
const fromAutoTruncate = getValueByPath(fromObject, [
|
|
8737
|
+
'autoTruncate',
|
|
8738
|
+
]);
|
|
8739
|
+
if (parentObject !== undefined && fromAutoTruncate != null) {
|
|
8740
|
+
setValueByPath(parentObject, ['parameters', 'autoTruncate'], fromAutoTruncate);
|
|
8741
|
+
}
|
|
8742
|
+
}
|
|
8743
|
+
else if (discriminatorAutoTruncate === 'EMBED_CONTENT') {
|
|
8744
|
+
const fromAutoTruncate = getValueByPath(fromObject, [
|
|
8745
|
+
'autoTruncate',
|
|
8746
|
+
]);
|
|
8747
|
+
if (parentObject !== undefined && fromAutoTruncate != null) {
|
|
8748
|
+
setValueByPath(parentObject, ['autoTruncate'], fromAutoTruncate);
|
|
8749
|
+
}
|
|
8663
8750
|
}
|
|
8664
8751
|
return toObject;
|
|
8665
8752
|
}
|
|
8666
|
-
function
|
|
8753
|
+
function embedContentParametersPrivateToMldev(apiClient, fromObject, rootObject) {
|
|
8667
8754
|
const toObject = {};
|
|
8668
8755
|
const fromModel = getValueByPath(fromObject, ['model']);
|
|
8669
8756
|
if (fromModel != null) {
|
|
@@ -8679,6 +8766,10 @@ function embedContentParametersToMldev(apiClient, fromObject, rootObject) {
|
|
|
8679
8766
|
}
|
|
8680
8767
|
setValueByPath(toObject, ['requests[]', 'content'], transformedList);
|
|
8681
8768
|
}
|
|
8769
|
+
const fromContent = getValueByPath(fromObject, ['content']);
|
|
8770
|
+
if (fromContent != null) {
|
|
8771
|
+
contentToMldev$1(tContent(fromContent));
|
|
8772
|
+
}
|
|
8682
8773
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
8683
8774
|
if (fromConfig != null) {
|
|
8684
8775
|
embedContentConfigToMldev(fromConfig, toObject);
|
|
@@ -8689,25 +8780,45 @@ function embedContentParametersToMldev(apiClient, fromObject, rootObject) {
|
|
|
8689
8780
|
}
|
|
8690
8781
|
return toObject;
|
|
8691
8782
|
}
|
|
8692
|
-
function
|
|
8783
|
+
function embedContentParametersPrivateToVertex(apiClient, fromObject, rootObject) {
|
|
8693
8784
|
const toObject = {};
|
|
8694
8785
|
const fromModel = getValueByPath(fromObject, ['model']);
|
|
8695
8786
|
if (fromModel != null) {
|
|
8696
8787
|
setValueByPath(toObject, ['_url', 'model'], tModel(apiClient, fromModel));
|
|
8697
8788
|
}
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8789
|
+
let discriminatorContents = getValueByPath(rootObject, [
|
|
8790
|
+
'embeddingApiType',
|
|
8791
|
+
]);
|
|
8792
|
+
if (discriminatorContents === undefined) {
|
|
8793
|
+
discriminatorContents = 'PREDICT';
|
|
8794
|
+
}
|
|
8795
|
+
if (discriminatorContents === 'PREDICT') {
|
|
8796
|
+
const fromContents = getValueByPath(fromObject, ['contents']);
|
|
8797
|
+
if (fromContents != null) {
|
|
8798
|
+
let transformedList = tContentsForEmbed(apiClient, fromContents);
|
|
8799
|
+
if (Array.isArray(transformedList)) {
|
|
8800
|
+
transformedList = transformedList.map((item) => {
|
|
8801
|
+
return item;
|
|
8802
|
+
});
|
|
8803
|
+
}
|
|
8804
|
+
setValueByPath(toObject, ['instances[]', 'content'], transformedList);
|
|
8805
|
+
}
|
|
8806
|
+
}
|
|
8807
|
+
let discriminatorContent = getValueByPath(rootObject, [
|
|
8808
|
+
'embeddingApiType',
|
|
8809
|
+
]);
|
|
8810
|
+
if (discriminatorContent === undefined) {
|
|
8811
|
+
discriminatorContent = 'PREDICT';
|
|
8812
|
+
}
|
|
8813
|
+
if (discriminatorContent === 'EMBED_CONTENT') {
|
|
8814
|
+
const fromContent = getValueByPath(fromObject, ['content']);
|
|
8815
|
+
if (fromContent != null) {
|
|
8816
|
+
setValueByPath(toObject, ['content'], tContent(fromContent));
|
|
8705
8817
|
}
|
|
8706
|
-
setValueByPath(toObject, ['instances[]', 'content'], transformedList);
|
|
8707
8818
|
}
|
|
8708
8819
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
8709
8820
|
if (fromConfig != null) {
|
|
8710
|
-
embedContentConfigToVertex(fromConfig, toObject);
|
|
8821
|
+
embedContentConfigToVertex(fromConfig, toObject, rootObject);
|
|
8711
8822
|
}
|
|
8712
8823
|
return toObject;
|
|
8713
8824
|
}
|
|
@@ -8760,6 +8871,24 @@ function embedContentResponseFromVertex(fromObject, rootObject) {
|
|
|
8760
8871
|
if (fromMetadata != null) {
|
|
8761
8872
|
setValueByPath(toObject, ['metadata'], fromMetadata);
|
|
8762
8873
|
}
|
|
8874
|
+
if (rootObject &&
|
|
8875
|
+
getValueByPath(rootObject, ['embeddingApiType']) === 'EMBED_CONTENT') {
|
|
8876
|
+
const embedding = getValueByPath(fromObject, ['embedding']);
|
|
8877
|
+
const usageMetadata = getValueByPath(fromObject, ['usageMetadata']);
|
|
8878
|
+
const truncated = getValueByPath(fromObject, ['truncated']);
|
|
8879
|
+
if (embedding) {
|
|
8880
|
+
const stats = {};
|
|
8881
|
+
if (usageMetadata &&
|
|
8882
|
+
usageMetadata['promptTokenCount']) {
|
|
8883
|
+
stats.tokenCount = usageMetadata['promptTokenCount'];
|
|
8884
|
+
}
|
|
8885
|
+
if (truncated) {
|
|
8886
|
+
stats.truncated = truncated;
|
|
8887
|
+
}
|
|
8888
|
+
embedding.statistics = stats;
|
|
8889
|
+
setValueByPath(toObject, ['embeddings'], [embedding]);
|
|
8890
|
+
}
|
|
8891
|
+
}
|
|
8763
8892
|
return toObject;
|
|
8764
8893
|
}
|
|
8765
8894
|
function endpointFromVertex(fromObject, _rootObject) {
|
|
@@ -11617,10 +11746,22 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
11617
11746
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
11618
11747
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
11619
11748
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
11620
|
-
const SDK_VERSION = '1.
|
|
11749
|
+
const SDK_VERSION = '1.42.0'; // x-release-please-version
|
|
11621
11750
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
11622
11751
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
11623
11752
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
11753
|
+
// Default retry options.
|
|
11754
|
+
// The config is based on https://cloud.google.com/storage/docs/retry-strategy.
|
|
11755
|
+
const DEFAULT_RETRY_ATTEMPTS = 5; // Including the initial call
|
|
11756
|
+
// LINT.IfChange
|
|
11757
|
+
const DEFAULT_RETRY_HTTP_STATUS_CODES = [
|
|
11758
|
+
408, // Request timeout
|
|
11759
|
+
429, // Too many requests
|
|
11760
|
+
500, // Internal server error
|
|
11761
|
+
502, // Bad gateway
|
|
11762
|
+
503, // Service unavailable
|
|
11763
|
+
504, // Gateway timeout
|
|
11764
|
+
];
|
|
11624
11765
|
/**
|
|
11625
11766
|
* The ApiClient class is used to send requests to the Gemini API or Vertex AI
|
|
11626
11767
|
* endpoints.
|
|
@@ -12005,8 +12146,25 @@ class ApiClient {
|
|
|
12005
12146
|
});
|
|
12006
12147
|
}
|
|
12007
12148
|
async apiCall(url, requestInit) {
|
|
12008
|
-
|
|
12009
|
-
|
|
12149
|
+
var _a;
|
|
12150
|
+
if (!this.clientOptions.httpOptions ||
|
|
12151
|
+
!this.clientOptions.httpOptions.retryOptions) {
|
|
12152
|
+
return fetch(url, requestInit);
|
|
12153
|
+
}
|
|
12154
|
+
const retryOptions = this.clientOptions.httpOptions.retryOptions;
|
|
12155
|
+
const runFetch = async () => {
|
|
12156
|
+
const response = await fetch(url, requestInit);
|
|
12157
|
+
if (response.ok) {
|
|
12158
|
+
return response;
|
|
12159
|
+
}
|
|
12160
|
+
if (DEFAULT_RETRY_HTTP_STATUS_CODES.includes(response.status)) {
|
|
12161
|
+
throw new Error(`Retryable HTTP Error: ${response.statusText}`);
|
|
12162
|
+
}
|
|
12163
|
+
throw new AbortError(`Non-retryable exception ${response.statusText} sending request`);
|
|
12164
|
+
};
|
|
12165
|
+
return pRetry(runFetch, {
|
|
12166
|
+
// Retry attempts is one less than the number of total attempts.
|
|
12167
|
+
retries: ((_a = retryOptions.attempts) !== null && _a !== void 0 ? _a : DEFAULT_RETRY_ATTEMPTS) - 1,
|
|
12010
12168
|
});
|
|
12011
12169
|
}
|
|
12012
12170
|
getDefaultHeaders() {
|
|
@@ -13189,6 +13347,47 @@ class Models extends BaseModule {
|
|
|
13189
13347
|
constructor(apiClient) {
|
|
13190
13348
|
super();
|
|
13191
13349
|
this.apiClient = apiClient;
|
|
13350
|
+
/**
|
|
13351
|
+
* Calculates embeddings for the given contents.
|
|
13352
|
+
*
|
|
13353
|
+
* @param params - The parameters for embedding contents.
|
|
13354
|
+
* @return The response from the API.
|
|
13355
|
+
*
|
|
13356
|
+
* @example
|
|
13357
|
+
* ```ts
|
|
13358
|
+
* const response = await ai.models.embedContent({
|
|
13359
|
+
* model: 'text-embedding-004',
|
|
13360
|
+
* contents: [
|
|
13361
|
+
* 'What is your name?',
|
|
13362
|
+
* 'What is your favorite color?',
|
|
13363
|
+
* ],
|
|
13364
|
+
* config: {
|
|
13365
|
+
* outputDimensionality: 64,
|
|
13366
|
+
* },
|
|
13367
|
+
* });
|
|
13368
|
+
* console.log(response);
|
|
13369
|
+
* ```
|
|
13370
|
+
*/
|
|
13371
|
+
this.embedContent = async (params) => {
|
|
13372
|
+
if (!this.apiClient.isVertexAI()) {
|
|
13373
|
+
return await this.embedContentInternal(params);
|
|
13374
|
+
}
|
|
13375
|
+
const isVertexEmbedContentModel = (params.model.includes('gemini') &&
|
|
13376
|
+
params.model !== 'gemini-embedding-001') ||
|
|
13377
|
+
params.model.includes('maas');
|
|
13378
|
+
if (isVertexEmbedContentModel) {
|
|
13379
|
+
const contents = tContents(params.contents);
|
|
13380
|
+
if (contents.length > 1) {
|
|
13381
|
+
throw new Error('The embedContent API for this model only supports one content at a time.');
|
|
13382
|
+
}
|
|
13383
|
+
const paramsPrivate = Object.assign(Object.assign({}, params), { content: contents[0], embeddingApiType: EmbeddingApiType.EMBED_CONTENT });
|
|
13384
|
+
return await this.embedContentInternal(paramsPrivate);
|
|
13385
|
+
}
|
|
13386
|
+
else {
|
|
13387
|
+
const paramsPrivate = Object.assign(Object.assign({}, params), { embeddingApiType: EmbeddingApiType.PREDICT });
|
|
13388
|
+
return await this.embedContentInternal(paramsPrivate);
|
|
13389
|
+
}
|
|
13390
|
+
};
|
|
13192
13391
|
/**
|
|
13193
13392
|
* Makes an API request to generate content with a given model.
|
|
13194
13393
|
*
|
|
@@ -13876,14 +14075,17 @@ class Models extends BaseModule {
|
|
|
13876
14075
|
* console.log(response);
|
|
13877
14076
|
* ```
|
|
13878
14077
|
*/
|
|
13879
|
-
async
|
|
14078
|
+
async embedContentInternal(params) {
|
|
13880
14079
|
var _a, _b, _c, _d;
|
|
13881
14080
|
let response;
|
|
13882
14081
|
let path = '';
|
|
13883
14082
|
let queryParams = {};
|
|
13884
14083
|
if (this.apiClient.isVertexAI()) {
|
|
13885
|
-
const body =
|
|
13886
|
-
|
|
14084
|
+
const body = embedContentParametersPrivateToVertex(this.apiClient, params, params);
|
|
14085
|
+
const endpointUrl = tIsVertexEmbedContentModel(params.model)
|
|
14086
|
+
? '{model}:embedContent'
|
|
14087
|
+
: '{model}:predict';
|
|
14088
|
+
path = formatMap(endpointUrl, body['_url']);
|
|
13887
14089
|
queryParams = body['_query'];
|
|
13888
14090
|
delete body['_url'];
|
|
13889
14091
|
delete body['_query'];
|
|
@@ -13906,14 +14108,14 @@ class Models extends BaseModule {
|
|
|
13906
14108
|
});
|
|
13907
14109
|
});
|
|
13908
14110
|
return response.then((apiResponse) => {
|
|
13909
|
-
const resp = embedContentResponseFromVertex(apiResponse);
|
|
14111
|
+
const resp = embedContentResponseFromVertex(apiResponse, params);
|
|
13910
14112
|
const typedResp = new EmbedContentResponse();
|
|
13911
14113
|
Object.assign(typedResp, resp);
|
|
13912
14114
|
return typedResp;
|
|
13913
14115
|
});
|
|
13914
14116
|
}
|
|
13915
14117
|
else {
|
|
13916
|
-
const body =
|
|
14118
|
+
const body = embedContentParametersPrivateToMldev(this.apiClient, params);
|
|
13917
14119
|
path = formatMap('{model}:batchEmbedContents', body['_url']);
|
|
13918
14120
|
queryParams = body['_query'];
|
|
13919
14121
|
delete body['_url'];
|
|
@@ -17854,7 +18056,7 @@ class BaseGeminiNextGenAPIClient {
|
|
|
17854
18056
|
}
|
|
17855
18057
|
async fetchWithTimeout(url, init, ms, controller) {
|
|
17856
18058
|
const _b = init || {}, { signal, method } = _b, options = __rest(_b, ["signal", "method"]);
|
|
17857
|
-
const abort =
|
|
18059
|
+
const abort = this._makeAbort(controller);
|
|
17858
18060
|
if (signal)
|
|
17859
18061
|
signal.addEventListener('abort', abort, { once: true });
|
|
17860
18062
|
const timeout = setTimeout(abort, ms);
|
|
@@ -17970,6 +18172,11 @@ class BaseGeminiNextGenAPIClient {
|
|
|
17970
18172
|
this.validateHeaders(headers);
|
|
17971
18173
|
return headers.values;
|
|
17972
18174
|
}
|
|
18175
|
+
_makeAbort(controller) {
|
|
18176
|
+
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
|
18177
|
+
// would capture all request options, and cause a memory leak.
|
|
18178
|
+
return () => controller.abort();
|
|
18179
|
+
}
|
|
17973
18180
|
buildBody({ options: { body, headers: rawHeaders } }) {
|
|
17974
18181
|
if (!body) {
|
|
17975
18182
|
return { bodyHeaders: undefined, body: undefined };
|
|
@@ -17998,6 +18205,13 @@ class BaseGeminiNextGenAPIClient {
|
|
|
17998
18205
|
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))) {
|
|
17999
18206
|
return { bodyHeaders: undefined, body: ReadableStreamFrom(body) };
|
|
18000
18207
|
}
|
|
18208
|
+
else if (typeof body === 'object' &&
|
|
18209
|
+
headers.values.get('content-type') === 'application/x-www-form-urlencoded') {
|
|
18210
|
+
return {
|
|
18211
|
+
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
18212
|
+
body: this.stringifyQuery(body),
|
|
18213
|
+
};
|
|
18214
|
+
}
|
|
18001
18215
|
else {
|
|
18002
18216
|
return this.encoder({ body, headers });
|
|
18003
18217
|
}
|
|
@@ -18319,6 +18533,9 @@ function createTuningJobConfigToMldev(fromObject, parentObject, _rootObject) {
|
|
|
18319
18533
|
if (getValueByPath(fromObject, ['outputUri']) !== undefined) {
|
|
18320
18534
|
throw new Error('outputUri parameter is not supported in Gemini API.');
|
|
18321
18535
|
}
|
|
18536
|
+
if (getValueByPath(fromObject, ['encryptionSpec']) !== undefined) {
|
|
18537
|
+
throw new Error('encryptionSpec parameter is not supported in Gemini API.');
|
|
18538
|
+
}
|
|
18322
18539
|
return toObject;
|
|
18323
18540
|
}
|
|
18324
18541
|
function createTuningJobConfigToVertex(fromObject, parentObject, rootObject) {
|
|
@@ -18554,6 +18771,12 @@ function createTuningJobConfigToVertex(fromObject, parentObject, rootObject) {
|
|
|
18554
18771
|
if (parentObject !== undefined && fromOutputUri != null) {
|
|
18555
18772
|
setValueByPath(parentObject, ['outputUri'], fromOutputUri);
|
|
18556
18773
|
}
|
|
18774
|
+
const fromEncryptionSpec = getValueByPath(fromObject, [
|
|
18775
|
+
'encryptionSpec',
|
|
18776
|
+
]);
|
|
18777
|
+
if (parentObject !== undefined && fromEncryptionSpec != null) {
|
|
18778
|
+
setValueByPath(parentObject, ['encryptionSpec'], fromEncryptionSpec);
|
|
18779
|
+
}
|
|
18557
18780
|
return toObject;
|
|
18558
18781
|
}
|
|
18559
18782
|
function createTuningJobParametersPrivateToMldev(fromObject, rootObject) {
|
|
@@ -19806,6 +20029,7 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
|
|
|
19806
20029
|
*/
|
|
19807
20030
|
class GoogleGenAI {
|
|
19808
20031
|
get interactions() {
|
|
20032
|
+
var _a;
|
|
19809
20033
|
if (this._interactions !== undefined) {
|
|
19810
20034
|
return this._interactions;
|
|
19811
20035
|
}
|
|
@@ -19822,6 +20046,7 @@ class GoogleGenAI {
|
|
|
19822
20046
|
clientAdapter: this.apiClient,
|
|
19823
20047
|
defaultHeaders: this.apiClient.getDefaultHeaders(),
|
|
19824
20048
|
timeout: httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.timeout,
|
|
20049
|
+
maxRetries: (_a = httpOpts === null || httpOpts === void 0 ? void 0 : httpOpts.retryOptions) === null || _a === void 0 ? void 0 : _a.attempts,
|
|
19825
20050
|
});
|
|
19826
20051
|
this._interactions = nextGenClient.interactions;
|
|
19827
20052
|
return this._interactions;
|
|
@@ -19936,5 +20161,5 @@ function getApiKeyFromEnv() {
|
|
|
19936
20161
|
return envGoogleApiKey || envGeminiApiKey || undefined;
|
|
19937
20162
|
}
|
|
19938
20163
|
|
|
19939
|
-
export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, CancelTuningJobResponse, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DocumentState, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpElementLocation, HttpResponse, ImagePromptLanguage, ImportFileOperation, ImportFileResponse, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListDocumentsResponse, ListFileSearchStoresResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PartMediaResolutionLevel, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, RegisterFilesResponse, ReplayResponse, ResourceScope, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, ThinkingLevel, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VadSignalType, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, VoiceActivityType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
|
|
20164
|
+
export { ActivityHandling, AdapterSize, ApiError, ApiSpec, AuthType, Batches, Behavior, BlockedReason, Caches, CancelTuningJobResponse, Chat, Chats, ComputeTokensResponse, ContentReferenceImage, ControlReferenceImage, ControlReferenceType, CountTokensResponse, CreateFileResponse, DeleteCachedContentResponse, DeleteFileResponse, DeleteModelResponse, DocumentState, DynamicRetrievalConfigMode, EditImageResponse, EditMode, EmbedContentResponse, EmbeddingApiType, EndSensitivity, Environment, FeatureSelectionPreference, FileSource, FileState, Files, FinishReason, FunctionCallingConfigMode, FunctionResponse, FunctionResponseBlob, FunctionResponseFileData, FunctionResponsePart, FunctionResponseScheduling, GenerateContentResponse, GenerateContentResponsePromptFeedback, GenerateContentResponseUsageMetadata, GenerateImagesResponse, GenerateVideosOperation, GenerateVideosResponse, GoogleGenAI, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, HttpElementLocation, HttpResponse, ImagePromptLanguage, ImportFileOperation, ImportFileResponse, InlinedEmbedContentResponse, InlinedResponse, JobState, Language, ListBatchJobsResponse, ListCachedContentsResponse, ListDocumentsResponse, ListFileSearchStoresResponse, ListFilesResponse, ListModelsResponse, ListTuningJobsResponse, Live, LiveClientToolResponse, LiveMusicPlaybackControl, LiveMusicServerMessage, LiveSendToolResponseParameters, LiveServerMessage, MaskReferenceImage, MaskReferenceMode, MediaModality, MediaResolution, Modality, Models, MusicGenerationMode, Operations, Outcome, PagedItem, Pager, PartMediaResolutionLevel, PersonGeneration, PhishBlockThreshold, RawReferenceImage, RecontextImageResponse, RegisterFilesResponse, ReplayResponse, ResourceScope, SafetyFilterLevel, Scale, SegmentImageResponse, SegmentMode, Session, SingleEmbedContentResponse, StartSensitivity, StyleReferenceImage, SubjectReferenceImage, SubjectReferenceType, ThinkingLevel, Tokens, TrafficType, TuningMethod, TuningMode, TuningTask, TurnCompleteReason, TurnCoverage, Type, UploadToFileSearchStoreOperation, UploadToFileSearchStoreResponse, UploadToFileSearchStoreResumableResponse, UpscaleImageResponse, UrlRetrievalStatus, VadSignalType, VideoCompressionQuality, VideoGenerationMaskMode, VideoGenerationReferenceType, VoiceActivityType, createFunctionResponsePartFromBase64, createFunctionResponsePartFromUri, createModelContent, createPartFromBase64, createPartFromCodeExecutionResult, createPartFromExecutableCode, createPartFromFunctionCall, createPartFromFunctionResponse, createPartFromText, createPartFromUri, createUserContent, mcpToTool, setDefaultBaseUrls };
|
|
19940
20165
|
//# sourceMappingURL=index.mjs.map
|