@google/genai 1.24.0 → 1.25.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 +0 -1
- package/dist/index.cjs +120 -72
- package/dist/index.mjs +120 -72
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +120 -72
- package/dist/node/index.mjs +120 -72
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +0 -1
- package/dist/web/index.mjs +120 -72
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +0 -1
- package/package.json +1 -1
package/dist/node/node.d.ts
CHANGED
|
@@ -467,7 +467,6 @@ export declare class Batches extends BaseModule {
|
|
|
467
467
|
*/
|
|
468
468
|
list: (params?: types.ListBatchJobsParameters) => Promise<Pager<types.BatchJob>>;
|
|
469
469
|
private createInlinedGenerateContentRequest;
|
|
470
|
-
private createInlinedEmbedContentRequest;
|
|
471
470
|
private getGcsUri;
|
|
472
471
|
private getBigqueryUri;
|
|
473
472
|
private formatDestination;
|
package/dist/web/index.mjs
CHANGED
|
@@ -193,6 +193,98 @@ function getValueByPath(data, keys, defaultValue = undefined) {
|
|
|
193
193
|
throw error;
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Moves values from source paths to destination paths.
|
|
198
|
+
*
|
|
199
|
+
* Examples:
|
|
200
|
+
* moveValueByPath(
|
|
201
|
+
* {'requests': [{'content': v1}, {'content': v2}]},
|
|
202
|
+
* {'requests[].*': 'requests[].request.*'}
|
|
203
|
+
* )
|
|
204
|
+
* -> {'requests': [{'request': {'content': v1}}, {'request': {'content': v2}}]}
|
|
205
|
+
*/
|
|
206
|
+
function moveValueByPath(data, paths) {
|
|
207
|
+
for (const [sourcePath, destPath] of Object.entries(paths)) {
|
|
208
|
+
const sourceKeys = sourcePath.split('.');
|
|
209
|
+
const destKeys = destPath.split('.');
|
|
210
|
+
// Determine keys to exclude from wildcard to avoid cyclic references
|
|
211
|
+
const excludeKeys = new Set();
|
|
212
|
+
let wildcardIdx = -1;
|
|
213
|
+
for (let i = 0; i < sourceKeys.length; i++) {
|
|
214
|
+
if (sourceKeys[i] === '*') {
|
|
215
|
+
wildcardIdx = i;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (wildcardIdx !== -1 && destKeys.length > wildcardIdx) {
|
|
220
|
+
// Extract the intermediate key between source and dest paths
|
|
221
|
+
// Example: source=['requests[]', '*'], dest=['requests[]', 'request', '*']
|
|
222
|
+
// We want to exclude 'request'
|
|
223
|
+
for (let i = wildcardIdx; i < destKeys.length; i++) {
|
|
224
|
+
const key = destKeys[i];
|
|
225
|
+
if (key !== '*' && !key.endsWith('[]') && !key.endsWith('[0]')) {
|
|
226
|
+
excludeKeys.add(key);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
_moveValueRecursive(data, sourceKeys, destKeys, 0, excludeKeys);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Recursively moves values from source path to destination path.
|
|
235
|
+
*/
|
|
236
|
+
function _moveValueRecursive(data, sourceKeys, destKeys, keyIdx, excludeKeys) {
|
|
237
|
+
if (keyIdx >= sourceKeys.length) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (typeof data !== 'object' || data === null) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const key = sourceKeys[keyIdx];
|
|
244
|
+
if (key.endsWith('[]')) {
|
|
245
|
+
const keyName = key.slice(0, -2);
|
|
246
|
+
const dataRecord = data;
|
|
247
|
+
if (keyName in dataRecord && Array.isArray(dataRecord[keyName])) {
|
|
248
|
+
for (const item of dataRecord[keyName]) {
|
|
249
|
+
_moveValueRecursive(item, sourceKeys, destKeys, keyIdx + 1, excludeKeys);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
else if (key === '*') {
|
|
254
|
+
// wildcard - move all fields
|
|
255
|
+
if (typeof data === 'object' && data !== null && !Array.isArray(data)) {
|
|
256
|
+
const dataRecord = data;
|
|
257
|
+
const keysToMove = Object.keys(dataRecord).filter((k) => !k.startsWith('_') && !excludeKeys.has(k));
|
|
258
|
+
const valuesToMove = {};
|
|
259
|
+
for (const k of keysToMove) {
|
|
260
|
+
valuesToMove[k] = dataRecord[k];
|
|
261
|
+
}
|
|
262
|
+
// Set values at destination
|
|
263
|
+
for (const [k, v] of Object.entries(valuesToMove)) {
|
|
264
|
+
const newDestKeys = [];
|
|
265
|
+
for (const dk of destKeys.slice(keyIdx)) {
|
|
266
|
+
if (dk === '*') {
|
|
267
|
+
newDestKeys.push(k);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
newDestKeys.push(dk);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
setValueByPath(dataRecord, newDestKeys, v);
|
|
274
|
+
}
|
|
275
|
+
for (const k of keysToMove) {
|
|
276
|
+
delete dataRecord[k];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
// Navigate to next level
|
|
282
|
+
const dataRecord = data;
|
|
283
|
+
if (key in dataRecord) {
|
|
284
|
+
_moveValueRecursive(dataRecord[key], sourceKeys, destKeys, keyIdx + 1, excludeKeys);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
196
288
|
|
|
197
289
|
/**
|
|
198
290
|
* @license
|
|
@@ -334,7 +426,7 @@ function generateVideosResponseFromVertex$1(fromObject) {
|
|
|
334
426
|
}
|
|
335
427
|
function generatedVideoFromMldev$1(fromObject) {
|
|
336
428
|
const toObject = {};
|
|
337
|
-
const fromVideo = getValueByPath(fromObject, ['
|
|
429
|
+
const fromVideo = getValueByPath(fromObject, ['video']);
|
|
338
430
|
if (fromVideo != null) {
|
|
339
431
|
setValueByPath(toObject, ['video'], videoFromMldev$1(fromVideo));
|
|
340
432
|
}
|
|
@@ -370,14 +462,11 @@ function getOperationParametersToVertex(fromObject) {
|
|
|
370
462
|
}
|
|
371
463
|
function videoFromMldev$1(fromObject) {
|
|
372
464
|
const toObject = {};
|
|
373
|
-
const fromUri = getValueByPath(fromObject, ['
|
|
465
|
+
const fromUri = getValueByPath(fromObject, ['uri']);
|
|
374
466
|
if (fromUri != null) {
|
|
375
467
|
setValueByPath(toObject, ['uri'], fromUri);
|
|
376
468
|
}
|
|
377
|
-
const fromVideoBytes = getValueByPath(fromObject, [
|
|
378
|
-
'video',
|
|
379
|
-
'encodedVideo',
|
|
380
|
-
]);
|
|
469
|
+
const fromVideoBytes = getValueByPath(fromObject, ['encodedVideo']);
|
|
381
470
|
if (fromVideoBytes != null) {
|
|
382
471
|
setValueByPath(toObject, ['videoBytes'], tBytes$1(fromVideoBytes));
|
|
383
472
|
}
|
|
@@ -3510,6 +3599,7 @@ function embedContentBatchToMldev(apiClient, fromObject) {
|
|
|
3510
3599
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
3511
3600
|
if (fromConfig != null) {
|
|
3512
3601
|
setValueByPath(toObject, ['_self'], embedContentConfigToMldev$1(fromConfig, toObject));
|
|
3602
|
+
moveValueByPath(toObject, { 'requests[].*': 'requests[].request.*' });
|
|
3513
3603
|
}
|
|
3514
3604
|
return toObject;
|
|
3515
3605
|
}
|
|
@@ -4291,38 +4381,11 @@ class Batches extends BaseModule {
|
|
|
4291
4381
|
* ```
|
|
4292
4382
|
*/
|
|
4293
4383
|
this.createEmbeddings = async (params) => {
|
|
4294
|
-
var _a, _b;
|
|
4295
4384
|
console.warn('batches.createEmbeddings() is experimental and may change without notice.');
|
|
4296
4385
|
if (this.apiClient.isVertexAI()) {
|
|
4297
4386
|
throw new Error('Vertex AI does not support batches.createEmbeddings.');
|
|
4298
4387
|
}
|
|
4299
|
-
|
|
4300
|
-
const src = params.src;
|
|
4301
|
-
const is_inlined = src.inlinedRequests !== undefined;
|
|
4302
|
-
if (!is_inlined) {
|
|
4303
|
-
return this.createEmbeddingsInternal(params); // Fixed typo here
|
|
4304
|
-
}
|
|
4305
|
-
// Inlined embed content requests handling
|
|
4306
|
-
const result = this.createInlinedEmbedContentRequest(params);
|
|
4307
|
-
const path = result.path;
|
|
4308
|
-
const requestBody = result.body;
|
|
4309
|
-
const queryParams = createEmbeddingsBatchJobParametersToMldev(this.apiClient, params)['_query'] || {};
|
|
4310
|
-
const response = this.apiClient
|
|
4311
|
-
.request({
|
|
4312
|
-
path: path,
|
|
4313
|
-
queryParams: queryParams,
|
|
4314
|
-
body: JSON.stringify(requestBody),
|
|
4315
|
-
httpMethod: 'POST',
|
|
4316
|
-
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
4317
|
-
abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
|
|
4318
|
-
})
|
|
4319
|
-
.then((httpResponse) => {
|
|
4320
|
-
return httpResponse.json();
|
|
4321
|
-
});
|
|
4322
|
-
return response.then((apiResponse) => {
|
|
4323
|
-
const resp = batchJobFromMldev(apiResponse);
|
|
4324
|
-
return resp;
|
|
4325
|
-
});
|
|
4388
|
+
return this.createEmbeddingsInternal(params);
|
|
4326
4389
|
};
|
|
4327
4390
|
/**
|
|
4328
4391
|
* Lists batch job configurations.
|
|
@@ -4370,35 +4433,6 @@ class Batches extends BaseModule {
|
|
|
4370
4433
|
delete body['_query'];
|
|
4371
4434
|
return { path, body };
|
|
4372
4435
|
}
|
|
4373
|
-
// Helper function to handle inlined embedding requests
|
|
4374
|
-
createInlinedEmbedContentRequest(params) {
|
|
4375
|
-
const body = createEmbeddingsBatchJobParametersToMldev(this.apiClient, // Use instance apiClient
|
|
4376
|
-
params);
|
|
4377
|
-
const urlParams = body['_url'];
|
|
4378
|
-
const path = formatMap('{model}:asyncBatchEmbedContent', urlParams);
|
|
4379
|
-
const batch = body['batch'];
|
|
4380
|
-
const inputConfig = batch['inputConfig'];
|
|
4381
|
-
const requestsWrapper = inputConfig['requests'];
|
|
4382
|
-
const requests = requestsWrapper['requests'];
|
|
4383
|
-
const newRequests = [];
|
|
4384
|
-
delete requestsWrapper['config']; // Remove top-level config
|
|
4385
|
-
for (const request of requests) {
|
|
4386
|
-
const requestDict = Object.assign({}, request); // Clone
|
|
4387
|
-
const innerRequest = requestDict['request'];
|
|
4388
|
-
for (const key in requestDict) {
|
|
4389
|
-
if (key !== 'request') {
|
|
4390
|
-
innerRequest[key] = requestDict[key];
|
|
4391
|
-
delete requestDict[key];
|
|
4392
|
-
}
|
|
4393
|
-
}
|
|
4394
|
-
newRequests.push(requestDict);
|
|
4395
|
-
}
|
|
4396
|
-
requestsWrapper['requests'] = newRequests;
|
|
4397
|
-
delete body['config'];
|
|
4398
|
-
delete body['_url'];
|
|
4399
|
-
delete body['_query'];
|
|
4400
|
-
return { path, body };
|
|
4401
|
-
}
|
|
4402
4436
|
// Helper function to get the first GCS URI
|
|
4403
4437
|
getGcsUri(src) {
|
|
4404
4438
|
if (typeof src === 'string') {
|
|
@@ -9273,7 +9307,7 @@ function generatedImageMaskFromVertex(fromObject) {
|
|
|
9273
9307
|
}
|
|
9274
9308
|
function generatedVideoFromMldev(fromObject) {
|
|
9275
9309
|
const toObject = {};
|
|
9276
|
-
const fromVideo = getValueByPath(fromObject, ['
|
|
9310
|
+
const fromVideo = getValueByPath(fromObject, ['video']);
|
|
9277
9311
|
if (fromVideo != null) {
|
|
9278
9312
|
setValueByPath(toObject, ['video'], videoFromMldev(fromVideo));
|
|
9279
9313
|
}
|
|
@@ -10419,14 +10453,11 @@ function upscaleImageResponseFromVertex(fromObject) {
|
|
|
10419
10453
|
}
|
|
10420
10454
|
function videoFromMldev(fromObject) {
|
|
10421
10455
|
const toObject = {};
|
|
10422
|
-
const fromUri = getValueByPath(fromObject, ['
|
|
10456
|
+
const fromUri = getValueByPath(fromObject, ['uri']);
|
|
10423
10457
|
if (fromUri != null) {
|
|
10424
10458
|
setValueByPath(toObject, ['uri'], fromUri);
|
|
10425
10459
|
}
|
|
10426
|
-
const fromVideoBytes = getValueByPath(fromObject, [
|
|
10427
|
-
'video',
|
|
10428
|
-
'encodedVideo',
|
|
10429
|
-
]);
|
|
10460
|
+
const fromVideoBytes = getValueByPath(fromObject, ['encodedVideo']);
|
|
10430
10461
|
if (fromVideoBytes != null) {
|
|
10431
10462
|
setValueByPath(toObject, ['videoBytes'], tBytes(fromVideoBytes));
|
|
10432
10463
|
}
|
|
@@ -10498,11 +10529,11 @@ function videoToMldev(fromObject) {
|
|
|
10498
10529
|
const toObject = {};
|
|
10499
10530
|
const fromUri = getValueByPath(fromObject, ['uri']);
|
|
10500
10531
|
if (fromUri != null) {
|
|
10501
|
-
setValueByPath(toObject, ['
|
|
10532
|
+
setValueByPath(toObject, ['uri'], fromUri);
|
|
10502
10533
|
}
|
|
10503
10534
|
const fromVideoBytes = getValueByPath(fromObject, ['videoBytes']);
|
|
10504
10535
|
if (fromVideoBytes != null) {
|
|
10505
|
-
setValueByPath(toObject, ['
|
|
10536
|
+
setValueByPath(toObject, ['encodedVideo'], tBytes(fromVideoBytes));
|
|
10506
10537
|
}
|
|
10507
10538
|
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
10508
10539
|
if (fromMimeType != null) {
|
|
@@ -10536,7 +10567,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
10536
10567
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
10537
10568
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
10538
10569
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
10539
|
-
const SDK_VERSION = '1.
|
|
10570
|
+
const SDK_VERSION = '1.25.0'; // x-release-please-version
|
|
10540
10571
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
10541
10572
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
10542
10573
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -12314,9 +12345,26 @@ class Models extends BaseModule {
|
|
|
12314
12345
|
* ```
|
|
12315
12346
|
*/
|
|
12316
12347
|
this.generateVideos = async (params) => {
|
|
12348
|
+
var _a, _b, _c, _d, _e, _f;
|
|
12317
12349
|
if ((params.prompt || params.image || params.video) && params.source) {
|
|
12318
12350
|
throw new Error('Source and prompt/image/video are mutually exclusive. Please only use source.');
|
|
12319
12351
|
}
|
|
12352
|
+
// Gemini API does not support video bytes.
|
|
12353
|
+
if (!this.apiClient.isVertexAI()) {
|
|
12354
|
+
if (((_a = params.video) === null || _a === void 0 ? void 0 : _a.uri) && ((_b = params.video) === null || _b === void 0 ? void 0 : _b.videoBytes)) {
|
|
12355
|
+
params.video = {
|
|
12356
|
+
uri: params.video.uri,
|
|
12357
|
+
mimeType: params.video.mimeType,
|
|
12358
|
+
};
|
|
12359
|
+
}
|
|
12360
|
+
else if (((_d = (_c = params.source) === null || _c === void 0 ? void 0 : _c.video) === null || _d === void 0 ? void 0 : _d.uri) &&
|
|
12361
|
+
((_f = (_e = params.source) === null || _e === void 0 ? void 0 : _e.video) === null || _f === void 0 ? void 0 : _f.videoBytes)) {
|
|
12362
|
+
params.source.video = {
|
|
12363
|
+
uri: params.source.video.uri,
|
|
12364
|
+
mimeType: params.source.video.mimeType,
|
|
12365
|
+
};
|
|
12366
|
+
}
|
|
12367
|
+
}
|
|
12320
12368
|
return await this.generateVideosInternal(params);
|
|
12321
12369
|
};
|
|
12322
12370
|
}
|