@google/genai 1.14.0 → 1.15.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/README.md +24 -0
- package/dist/genai.d.ts +138 -0
- package/dist/index.cjs +264 -4
- package/dist/index.mjs +264 -5
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +264 -4
- package/dist/node/index.mjs +264 -5
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +138 -0
- package/dist/web/index.mjs +264 -5
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +138 -0
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -925,6 +925,15 @@ exports.EditMode = void 0;
|
|
|
925
925
|
EditMode["EDIT_MODE_BGSWAP"] = "EDIT_MODE_BGSWAP";
|
|
926
926
|
EditMode["EDIT_MODE_PRODUCT_IMAGE"] = "EDIT_MODE_PRODUCT_IMAGE";
|
|
927
927
|
})(exports.EditMode || (exports.EditMode = {}));
|
|
928
|
+
/** Enum that represents the segmentation mode. */
|
|
929
|
+
exports.SegmentMode = void 0;
|
|
930
|
+
(function (SegmentMode) {
|
|
931
|
+
SegmentMode["FOREGROUND"] = "FOREGROUND";
|
|
932
|
+
SegmentMode["BACKGROUND"] = "BACKGROUND";
|
|
933
|
+
SegmentMode["PROMPT"] = "PROMPT";
|
|
934
|
+
SegmentMode["SEMANTIC"] = "SEMANTIC";
|
|
935
|
+
SegmentMode["INTERACTIVE"] = "INTERACTIVE";
|
|
936
|
+
})(exports.SegmentMode || (exports.SegmentMode = {}));
|
|
928
937
|
/** Enum that controls the compression quality of the generated videos. */
|
|
929
938
|
exports.VideoCompressionQuality = void 0;
|
|
930
939
|
(function (VideoCompressionQuality) {
|
|
@@ -1571,6 +1580,9 @@ class UpscaleImageResponse {
|
|
|
1571
1580
|
/** The output images response. */
|
|
1572
1581
|
class RecontextImageResponse {
|
|
1573
1582
|
}
|
|
1583
|
+
/** The output images response. */
|
|
1584
|
+
class SegmentImageResponse {
|
|
1585
|
+
}
|
|
1574
1586
|
class ListModelsResponse {
|
|
1575
1587
|
}
|
|
1576
1588
|
class DeleteModelResponse {
|
|
@@ -4309,6 +4321,7 @@ class Batches extends BaseModule {
|
|
|
4309
4321
|
* ```
|
|
4310
4322
|
*/
|
|
4311
4323
|
this.create = async (params) => {
|
|
4324
|
+
var _a, _b;
|
|
4312
4325
|
if (this.apiClient.isVertexAI()) {
|
|
4313
4326
|
const timestamp = Date.now();
|
|
4314
4327
|
const timestampStr = timestamp.toString();
|
|
@@ -4333,6 +4346,55 @@ class Batches extends BaseModule {
|
|
|
4333
4346
|
}
|
|
4334
4347
|
}
|
|
4335
4348
|
}
|
|
4349
|
+
else {
|
|
4350
|
+
if (Array.isArray(params.src) ||
|
|
4351
|
+
(typeof params.src !== 'string' && params.src.inlinedRequests)) {
|
|
4352
|
+
// Move system instruction to httpOptions extraBody.
|
|
4353
|
+
let path = '';
|
|
4354
|
+
let queryParams = {};
|
|
4355
|
+
const body = createBatchJobParametersToMldev(this.apiClient, params);
|
|
4356
|
+
path = formatMap('{model}:batchGenerateContent', body['_url']);
|
|
4357
|
+
queryParams = body['_query'];
|
|
4358
|
+
// Move system instruction to 'request':
|
|
4359
|
+
// {'systemInstruction': system_instruction}
|
|
4360
|
+
const batch = body['batch'];
|
|
4361
|
+
const inputConfig = batch['inputConfig'];
|
|
4362
|
+
const requestsWrapper = inputConfig['requests'];
|
|
4363
|
+
const requests = requestsWrapper['requests'];
|
|
4364
|
+
const newRequests = [];
|
|
4365
|
+
for (const request of requests) {
|
|
4366
|
+
const requestDict = request;
|
|
4367
|
+
if (requestDict['systemInstruction']) {
|
|
4368
|
+
const systemInstructionValue = requestDict['systemInstruction'];
|
|
4369
|
+
delete requestDict['systemInstruction'];
|
|
4370
|
+
const requestContent = requestDict['request'];
|
|
4371
|
+
requestContent['systemInstruction'] = systemInstructionValue;
|
|
4372
|
+
requestDict['request'] = requestContent;
|
|
4373
|
+
}
|
|
4374
|
+
newRequests.push(requestDict);
|
|
4375
|
+
}
|
|
4376
|
+
requestsWrapper['requests'] = newRequests;
|
|
4377
|
+
delete body['config'];
|
|
4378
|
+
delete body['_url'];
|
|
4379
|
+
delete body['_query'];
|
|
4380
|
+
const response = this.apiClient
|
|
4381
|
+
.request({
|
|
4382
|
+
path: path,
|
|
4383
|
+
queryParams: queryParams,
|
|
4384
|
+
body: JSON.stringify(body),
|
|
4385
|
+
httpMethod: 'POST',
|
|
4386
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
4387
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
4388
|
+
})
|
|
4389
|
+
.then((httpResponse) => {
|
|
4390
|
+
return httpResponse.json();
|
|
4391
|
+
});
|
|
4392
|
+
return response.then((apiResponse) => {
|
|
4393
|
+
const resp = batchJobFromMldev(apiResponse);
|
|
4394
|
+
return resp;
|
|
4395
|
+
});
|
|
4396
|
+
}
|
|
4397
|
+
}
|
|
4336
4398
|
return await this.createInternal(params);
|
|
4337
4399
|
};
|
|
4338
4400
|
/**
|
|
@@ -6243,9 +6305,6 @@ function isValidContent(content) {
|
|
|
6243
6305
|
if (part === undefined || Object.keys(part).length === 0) {
|
|
6244
6306
|
return false;
|
|
6245
6307
|
}
|
|
6246
|
-
if (!part.thought && part.text !== undefined && part.text === '') {
|
|
6247
|
-
return false;
|
|
6248
|
-
}
|
|
6249
6308
|
}
|
|
6250
6309
|
return true;
|
|
6251
6310
|
}
|
|
@@ -10450,6 +10509,9 @@ function generateVideosConfigToMldev(fromObject, parentObject) {
|
|
|
10450
10509
|
if (getValueByPath(fromObject, ['lastFrame']) !== undefined) {
|
|
10451
10510
|
throw new Error('lastFrame parameter is not supported in Gemini API.');
|
|
10452
10511
|
}
|
|
10512
|
+
if (getValueByPath(fromObject, ['referenceImages']) !== undefined) {
|
|
10513
|
+
throw new Error('referenceImages parameter is not supported in Gemini API.');
|
|
10514
|
+
}
|
|
10453
10515
|
if (getValueByPath(fromObject, ['compressionQuality']) !== undefined) {
|
|
10454
10516
|
throw new Error('compressionQuality parameter is not supported in Gemini API.');
|
|
10455
10517
|
}
|
|
@@ -11760,6 +11822,78 @@ function recontextImageParametersToVertex(apiClient, fromObject) {
|
|
|
11760
11822
|
}
|
|
11761
11823
|
return toObject;
|
|
11762
11824
|
}
|
|
11825
|
+
function scribbleImageToVertex(fromObject) {
|
|
11826
|
+
const toObject = {};
|
|
11827
|
+
const fromImage = getValueByPath(fromObject, ['image']);
|
|
11828
|
+
if (fromImage != null) {
|
|
11829
|
+
setValueByPath(toObject, ['image'], imageToVertex(fromImage));
|
|
11830
|
+
}
|
|
11831
|
+
return toObject;
|
|
11832
|
+
}
|
|
11833
|
+
function segmentImageSourceToVertex(fromObject, parentObject) {
|
|
11834
|
+
const toObject = {};
|
|
11835
|
+
const fromPrompt = getValueByPath(fromObject, ['prompt']);
|
|
11836
|
+
if (parentObject !== undefined && fromPrompt != null) {
|
|
11837
|
+
setValueByPath(parentObject, ['instances[0]', 'prompt'], fromPrompt);
|
|
11838
|
+
}
|
|
11839
|
+
const fromImage = getValueByPath(fromObject, ['image']);
|
|
11840
|
+
if (parentObject !== undefined && fromImage != null) {
|
|
11841
|
+
setValueByPath(parentObject, ['instances[0]', 'image'], imageToVertex(fromImage));
|
|
11842
|
+
}
|
|
11843
|
+
const fromScribbleImage = getValueByPath(fromObject, [
|
|
11844
|
+
'scribbleImage',
|
|
11845
|
+
]);
|
|
11846
|
+
if (parentObject !== undefined && fromScribbleImage != null) {
|
|
11847
|
+
setValueByPath(parentObject, ['instances[0]', 'scribble'], scribbleImageToVertex(fromScribbleImage));
|
|
11848
|
+
}
|
|
11849
|
+
return toObject;
|
|
11850
|
+
}
|
|
11851
|
+
function segmentImageConfigToVertex(fromObject, parentObject) {
|
|
11852
|
+
const toObject = {};
|
|
11853
|
+
const fromMode = getValueByPath(fromObject, ['mode']);
|
|
11854
|
+
if (parentObject !== undefined && fromMode != null) {
|
|
11855
|
+
setValueByPath(parentObject, ['parameters', 'mode'], fromMode);
|
|
11856
|
+
}
|
|
11857
|
+
const fromMaxPredictions = getValueByPath(fromObject, [
|
|
11858
|
+
'maxPredictions',
|
|
11859
|
+
]);
|
|
11860
|
+
if (parentObject !== undefined && fromMaxPredictions != null) {
|
|
11861
|
+
setValueByPath(parentObject, ['parameters', 'maxPredictions'], fromMaxPredictions);
|
|
11862
|
+
}
|
|
11863
|
+
const fromConfidenceThreshold = getValueByPath(fromObject, [
|
|
11864
|
+
'confidenceThreshold',
|
|
11865
|
+
]);
|
|
11866
|
+
if (parentObject !== undefined && fromConfidenceThreshold != null) {
|
|
11867
|
+
setValueByPath(parentObject, ['parameters', 'confidenceThreshold'], fromConfidenceThreshold);
|
|
11868
|
+
}
|
|
11869
|
+
const fromMaskDilation = getValueByPath(fromObject, ['maskDilation']);
|
|
11870
|
+
if (parentObject !== undefined && fromMaskDilation != null) {
|
|
11871
|
+
setValueByPath(parentObject, ['parameters', 'maskDilation'], fromMaskDilation);
|
|
11872
|
+
}
|
|
11873
|
+
const fromBinaryColorThreshold = getValueByPath(fromObject, [
|
|
11874
|
+
'binaryColorThreshold',
|
|
11875
|
+
]);
|
|
11876
|
+
if (parentObject !== undefined && fromBinaryColorThreshold != null) {
|
|
11877
|
+
setValueByPath(parentObject, ['parameters', 'binaryColorThreshold'], fromBinaryColorThreshold);
|
|
11878
|
+
}
|
|
11879
|
+
return toObject;
|
|
11880
|
+
}
|
|
11881
|
+
function segmentImageParametersToVertex(apiClient, fromObject) {
|
|
11882
|
+
const toObject = {};
|
|
11883
|
+
const fromModel = getValueByPath(fromObject, ['model']);
|
|
11884
|
+
if (fromModel != null) {
|
|
11885
|
+
setValueByPath(toObject, ['_url', 'model'], tModel(apiClient, fromModel));
|
|
11886
|
+
}
|
|
11887
|
+
const fromSource = getValueByPath(fromObject, ['source']);
|
|
11888
|
+
if (fromSource != null) {
|
|
11889
|
+
setValueByPath(toObject, ['config'], segmentImageSourceToVertex(fromSource, toObject));
|
|
11890
|
+
}
|
|
11891
|
+
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
11892
|
+
if (fromConfig != null) {
|
|
11893
|
+
setValueByPath(toObject, ['config'], segmentImageConfigToVertex(fromConfig, toObject));
|
|
11894
|
+
}
|
|
11895
|
+
return toObject;
|
|
11896
|
+
}
|
|
11763
11897
|
function getModelParametersToVertex(apiClient, fromObject) {
|
|
11764
11898
|
const toObject = {};
|
|
11765
11899
|
const fromModel = getValueByPath(fromObject, ['model']);
|
|
@@ -11928,6 +12062,20 @@ function videoToVertex(fromObject) {
|
|
|
11928
12062
|
}
|
|
11929
12063
|
return toObject;
|
|
11930
12064
|
}
|
|
12065
|
+
function videoGenerationReferenceImageToVertex(fromObject) {
|
|
12066
|
+
const toObject = {};
|
|
12067
|
+
const fromImage = getValueByPath(fromObject, ['image']);
|
|
12068
|
+
if (fromImage != null) {
|
|
12069
|
+
setValueByPath(toObject, ['image'], imageToVertex(fromImage));
|
|
12070
|
+
}
|
|
12071
|
+
const fromReferenceType = getValueByPath(fromObject, [
|
|
12072
|
+
'referenceType',
|
|
12073
|
+
]);
|
|
12074
|
+
if (fromReferenceType != null) {
|
|
12075
|
+
setValueByPath(toObject, ['referenceType'], fromReferenceType);
|
|
12076
|
+
}
|
|
12077
|
+
return toObject;
|
|
12078
|
+
}
|
|
11931
12079
|
function generateVideosConfigToVertex(fromObject, parentObject) {
|
|
11932
12080
|
const toObject = {};
|
|
11933
12081
|
const fromNumberOfVideos = getValueByPath(fromObject, [
|
|
@@ -11994,6 +12142,18 @@ function generateVideosConfigToVertex(fromObject, parentObject) {
|
|
|
11994
12142
|
if (parentObject !== undefined && fromLastFrame != null) {
|
|
11995
12143
|
setValueByPath(parentObject, ['instances[0]', 'lastFrame'], imageToVertex(fromLastFrame));
|
|
11996
12144
|
}
|
|
12145
|
+
const fromReferenceImages = getValueByPath(fromObject, [
|
|
12146
|
+
'referenceImages',
|
|
12147
|
+
]);
|
|
12148
|
+
if (parentObject !== undefined && fromReferenceImages != null) {
|
|
12149
|
+
let transformedList = fromReferenceImages;
|
|
12150
|
+
if (Array.isArray(transformedList)) {
|
|
12151
|
+
transformedList = transformedList.map((item) => {
|
|
12152
|
+
return videoGenerationReferenceImageToVertex(item);
|
|
12153
|
+
});
|
|
12154
|
+
}
|
|
12155
|
+
setValueByPath(parentObject, ['instances[0]', 'referenceImages'], transformedList);
|
|
12156
|
+
}
|
|
11997
12157
|
const fromCompressionQuality = getValueByPath(fromObject, [
|
|
11998
12158
|
'compressionQuality',
|
|
11999
12159
|
]);
|
|
@@ -13043,6 +13203,50 @@ function recontextImageResponseFromVertex(fromObject) {
|
|
|
13043
13203
|
}
|
|
13044
13204
|
return toObject;
|
|
13045
13205
|
}
|
|
13206
|
+
function entityLabelFromVertex(fromObject) {
|
|
13207
|
+
const toObject = {};
|
|
13208
|
+
const fromLabel = getValueByPath(fromObject, ['label']);
|
|
13209
|
+
if (fromLabel != null) {
|
|
13210
|
+
setValueByPath(toObject, ['label'], fromLabel);
|
|
13211
|
+
}
|
|
13212
|
+
const fromScore = getValueByPath(fromObject, ['score']);
|
|
13213
|
+
if (fromScore != null) {
|
|
13214
|
+
setValueByPath(toObject, ['score'], fromScore);
|
|
13215
|
+
}
|
|
13216
|
+
return toObject;
|
|
13217
|
+
}
|
|
13218
|
+
function generatedImageMaskFromVertex(fromObject) {
|
|
13219
|
+
const toObject = {};
|
|
13220
|
+
const fromMask = getValueByPath(fromObject, ['_self']);
|
|
13221
|
+
if (fromMask != null) {
|
|
13222
|
+
setValueByPath(toObject, ['mask'], imageFromVertex(fromMask));
|
|
13223
|
+
}
|
|
13224
|
+
const fromLabels = getValueByPath(fromObject, ['labels']);
|
|
13225
|
+
if (fromLabels != null) {
|
|
13226
|
+
let transformedList = fromLabels;
|
|
13227
|
+
if (Array.isArray(transformedList)) {
|
|
13228
|
+
transformedList = transformedList.map((item) => {
|
|
13229
|
+
return entityLabelFromVertex(item);
|
|
13230
|
+
});
|
|
13231
|
+
}
|
|
13232
|
+
setValueByPath(toObject, ['labels'], transformedList);
|
|
13233
|
+
}
|
|
13234
|
+
return toObject;
|
|
13235
|
+
}
|
|
13236
|
+
function segmentImageResponseFromVertex(fromObject) {
|
|
13237
|
+
const toObject = {};
|
|
13238
|
+
const fromGeneratedMasks = getValueByPath(fromObject, ['predictions']);
|
|
13239
|
+
if (fromGeneratedMasks != null) {
|
|
13240
|
+
let transformedList = fromGeneratedMasks;
|
|
13241
|
+
if (Array.isArray(transformedList)) {
|
|
13242
|
+
transformedList = transformedList.map((item) => {
|
|
13243
|
+
return generatedImageMaskFromVertex(item);
|
|
13244
|
+
});
|
|
13245
|
+
}
|
|
13246
|
+
setValueByPath(toObject, ['generatedMasks'], transformedList);
|
|
13247
|
+
}
|
|
13248
|
+
return toObject;
|
|
13249
|
+
}
|
|
13046
13250
|
function endpointFromVertex(fromObject) {
|
|
13047
13251
|
const toObject = {};
|
|
13048
13252
|
const fromName = getValueByPath(fromObject, ['endpoint']);
|
|
@@ -13290,7 +13494,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
13290
13494
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
13291
13495
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
13292
13496
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
13293
|
-
const SDK_VERSION = '1.
|
|
13497
|
+
const SDK_VERSION = '1.15.0'; // x-release-please-version
|
|
13294
13498
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
13295
13499
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
13296
13500
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -15733,6 +15937,61 @@ class Models extends BaseModule {
|
|
|
15733
15937
|
throw new Error('This method is only supported by the Vertex AI.');
|
|
15734
15938
|
}
|
|
15735
15939
|
}
|
|
15940
|
+
/**
|
|
15941
|
+
* Segments an image, creating a mask of a specified area.
|
|
15942
|
+
*
|
|
15943
|
+
* @param params - The parameters for segmenting an image.
|
|
15944
|
+
* @return The response from the API.
|
|
15945
|
+
*
|
|
15946
|
+
* @example
|
|
15947
|
+
* ```ts
|
|
15948
|
+
* const response = await ai.models.segmentImage({
|
|
15949
|
+
* model: 'image-segmentation-001',
|
|
15950
|
+
* source: {
|
|
15951
|
+
* image: image,
|
|
15952
|
+
* },
|
|
15953
|
+
* config: {
|
|
15954
|
+
* mode: 'foreground',
|
|
15955
|
+
* },
|
|
15956
|
+
* });
|
|
15957
|
+
* console.log(response?.generatedMasks?.[0]?.mask?.imageBytes);
|
|
15958
|
+
* ```
|
|
15959
|
+
*/
|
|
15960
|
+
async segmentImage(params) {
|
|
15961
|
+
var _a, _b;
|
|
15962
|
+
let response;
|
|
15963
|
+
let path = '';
|
|
15964
|
+
let queryParams = {};
|
|
15965
|
+
if (this.apiClient.isVertexAI()) {
|
|
15966
|
+
const body = segmentImageParametersToVertex(this.apiClient, params);
|
|
15967
|
+
path = formatMap('{model}:predict', body['_url']);
|
|
15968
|
+
queryParams = body['_query'];
|
|
15969
|
+
delete body['config'];
|
|
15970
|
+
delete body['_url'];
|
|
15971
|
+
delete body['_query'];
|
|
15972
|
+
response = this.apiClient
|
|
15973
|
+
.request({
|
|
15974
|
+
path: path,
|
|
15975
|
+
queryParams: queryParams,
|
|
15976
|
+
body: JSON.stringify(body),
|
|
15977
|
+
httpMethod: 'POST',
|
|
15978
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
15979
|
+
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
15980
|
+
})
|
|
15981
|
+
.then((httpResponse) => {
|
|
15982
|
+
return httpResponse.json();
|
|
15983
|
+
});
|
|
15984
|
+
return response.then((apiResponse) => {
|
|
15985
|
+
const resp = segmentImageResponseFromVertex(apiResponse);
|
|
15986
|
+
const typedResp = new SegmentImageResponse();
|
|
15987
|
+
Object.assign(typedResp, resp);
|
|
15988
|
+
return typedResp;
|
|
15989
|
+
});
|
|
15990
|
+
}
|
|
15991
|
+
else {
|
|
15992
|
+
throw new Error('This method is only supported by the Vertex AI.');
|
|
15993
|
+
}
|
|
15994
|
+
}
|
|
15736
15995
|
/**
|
|
15737
15996
|
* Fetches information about a model by name.
|
|
15738
15997
|
*
|
|
@@ -18856,6 +19115,7 @@ exports.Pager = Pager;
|
|
|
18856
19115
|
exports.RawReferenceImage = RawReferenceImage;
|
|
18857
19116
|
exports.RecontextImageResponse = RecontextImageResponse;
|
|
18858
19117
|
exports.ReplayResponse = ReplayResponse;
|
|
19118
|
+
exports.SegmentImageResponse = SegmentImageResponse;
|
|
18859
19119
|
exports.Session = Session;
|
|
18860
19120
|
exports.StyleReferenceImage = StyleReferenceImage;
|
|
18861
19121
|
exports.SubjectReferenceImage = SubjectReferenceImage;
|