@google/genai 0.2.0 → 0.4.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 +1 -1
- package/dist/genai.d.ts +141 -83
- package/dist/index.js +201 -295
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +202 -295
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.js +209 -305
- package/dist/node/index.js.map +1 -1
- package/dist/node/node.d.ts +145 -89
- package/dist/web/index.mjs +207 -297
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +143 -85
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @license
|
|
5
|
-
* Copyright
|
|
5
|
+
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
8
|
class BaseModule {
|
|
@@ -129,7 +129,7 @@ function getValueByPath(data, keys) {
|
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
131
|
* @license
|
|
132
|
-
* Copyright
|
|
132
|
+
* Copyright 2025 Google LLC
|
|
133
133
|
* SPDX-License-Identifier: Apache-2.0
|
|
134
134
|
*/
|
|
135
135
|
function tModel(apiClient, model) {
|
|
@@ -354,9 +354,6 @@ function processSchema(apiClient, schema) {
|
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
if ('anyOf' in schema) {
|
|
357
|
-
if (!apiClient.isVertexAI()) {
|
|
358
|
-
throw new Error('AnyOf is not supported in the response schema for the Gemini API.');
|
|
359
|
-
}
|
|
360
357
|
if (schema['anyOf'] !== undefined) {
|
|
361
358
|
for (const subSchema of schema['anyOf']) {
|
|
362
359
|
processSchema(apiClient, subSchema);
|
|
@@ -497,14 +494,12 @@ function tFileName(apiClient, fromName) {
|
|
|
497
494
|
|
|
498
495
|
/**
|
|
499
496
|
* @license
|
|
500
|
-
* Copyright
|
|
497
|
+
* Copyright 2025 Google LLC
|
|
501
498
|
* SPDX-License-Identifier: Apache-2.0
|
|
502
499
|
*/
|
|
503
500
|
/**
|
|
504
501
|
* @fileoverview Pagers for the GenAI List APIs.
|
|
505
502
|
*/
|
|
506
|
-
// TODO(b/401555348): Re-enable linting after enforcing strong types.
|
|
507
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
508
503
|
var PagedItem;
|
|
509
504
|
(function (PagedItem) {
|
|
510
505
|
PagedItem["PAGED_ITEM_BATCH_JOBS"] = "batchJobs";
|
|
@@ -519,6 +514,7 @@ var PagedItem;
|
|
|
519
514
|
class Pager {
|
|
520
515
|
constructor(name, request, response, params) {
|
|
521
516
|
this.pageInternal = [];
|
|
517
|
+
this.paramsInternal = {};
|
|
522
518
|
this.requestInternal = request;
|
|
523
519
|
this.init(name, response, params);
|
|
524
520
|
}
|
|
@@ -675,7 +671,7 @@ class Pager {
|
|
|
675
671
|
|
|
676
672
|
/**
|
|
677
673
|
* @license
|
|
678
|
-
* Copyright
|
|
674
|
+
* Copyright 2025 Google LLC
|
|
679
675
|
* SPDX-License-Identifier: Apache-2.0
|
|
680
676
|
*/
|
|
681
677
|
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
@@ -911,17 +907,6 @@ function createPartFromBase64(data, mimeType) {
|
|
|
911
907
|
},
|
|
912
908
|
};
|
|
913
909
|
}
|
|
914
|
-
/**
|
|
915
|
-
* Creates a `Part` object from the `startOffset` and `endOffset` of a `VideoMetadata` object.
|
|
916
|
-
*/
|
|
917
|
-
function createPartFromVideoMetadata(startOffset, endOffset) {
|
|
918
|
-
return {
|
|
919
|
-
videoMetadata: {
|
|
920
|
-
startOffset: startOffset,
|
|
921
|
-
endOffset: endOffset,
|
|
922
|
-
},
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
910
|
/**
|
|
926
911
|
* Creates a `Part` object from the `outcome` and `output` of a `CodeExecutionResult` object.
|
|
927
912
|
*/
|
|
@@ -1264,7 +1249,7 @@ class SessionSendToolResponseParameters {
|
|
|
1264
1249
|
|
|
1265
1250
|
/**
|
|
1266
1251
|
* @license
|
|
1267
|
-
* Copyright
|
|
1252
|
+
* Copyright 2025 Google LLC
|
|
1268
1253
|
* SPDX-License-Identifier: Apache-2.0
|
|
1269
1254
|
*/
|
|
1270
1255
|
class Caches extends BaseModule {
|
|
@@ -1279,7 +1264,7 @@ class Caches extends BaseModule {
|
|
|
1279
1264
|
*
|
|
1280
1265
|
* @example
|
|
1281
1266
|
* ```ts
|
|
1282
|
-
* const cachedContents = await
|
|
1267
|
+
* const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
|
|
1283
1268
|
* for (const cachedContent of cachedContents) {
|
|
1284
1269
|
* console.log(cachedContent);
|
|
1285
1270
|
* }
|
|
@@ -1298,7 +1283,7 @@ class Caches extends BaseModule {
|
|
|
1298
1283
|
* @example
|
|
1299
1284
|
* ```ts
|
|
1300
1285
|
* const contents = ...; // Initialize the content to cache.
|
|
1301
|
-
* const response = await
|
|
1286
|
+
* const response = await ai.caches.create({
|
|
1302
1287
|
* model: 'gemini-2.0-flash',
|
|
1303
1288
|
* config: {
|
|
1304
1289
|
* 'contents': contents,
|
|
@@ -1369,7 +1354,7 @@ class Caches extends BaseModule {
|
|
|
1369
1354
|
*
|
|
1370
1355
|
* @example
|
|
1371
1356
|
* ```ts
|
|
1372
|
-
* await
|
|
1357
|
+
* await ai.caches.get({name: 'gemini-1.5-flash'});
|
|
1373
1358
|
* ```
|
|
1374
1359
|
*/
|
|
1375
1360
|
async get(params) {
|
|
@@ -1432,7 +1417,7 @@ class Caches extends BaseModule {
|
|
|
1432
1417
|
*
|
|
1433
1418
|
* @example
|
|
1434
1419
|
* ```ts
|
|
1435
|
-
* await
|
|
1420
|
+
* await ai.caches.delete({name: 'gemini-1.5-flash'});
|
|
1436
1421
|
* ```
|
|
1437
1422
|
*/
|
|
1438
1423
|
async delete(params) {
|
|
@@ -1459,7 +1444,7 @@ class Caches extends BaseModule {
|
|
|
1459
1444
|
return httpResponse.json();
|
|
1460
1445
|
});
|
|
1461
1446
|
return response.then((apiResponse) => {
|
|
1462
|
-
const resp = deleteCachedContentResponseFromVertex(
|
|
1447
|
+
const resp = deleteCachedContentResponseFromVertex();
|
|
1463
1448
|
const typedResp = new DeleteCachedContentResponse();
|
|
1464
1449
|
Object.assign(typedResp, resp);
|
|
1465
1450
|
return typedResp;
|
|
@@ -1484,7 +1469,7 @@ class Caches extends BaseModule {
|
|
|
1484
1469
|
return httpResponse.json();
|
|
1485
1470
|
});
|
|
1486
1471
|
return response.then((apiResponse) => {
|
|
1487
|
-
const resp = deleteCachedContentResponseFromMldev(
|
|
1472
|
+
const resp = deleteCachedContentResponseFromMldev();
|
|
1488
1473
|
const typedResp = new DeleteCachedContentResponse();
|
|
1489
1474
|
Object.assign(typedResp, resp);
|
|
1490
1475
|
return typedResp;
|
|
@@ -1499,7 +1484,7 @@ class Caches extends BaseModule {
|
|
|
1499
1484
|
*
|
|
1500
1485
|
* @example
|
|
1501
1486
|
* ```ts
|
|
1502
|
-
* const response = await
|
|
1487
|
+
* const response = await ai.caches.update({
|
|
1503
1488
|
* name: 'gemini-1.5-flash',
|
|
1504
1489
|
* config: {'ttl': '7600s'}
|
|
1505
1490
|
* });
|
|
@@ -1757,18 +1742,10 @@ function schemaToVertex$1(apiClient, fromObject) {
|
|
|
1757
1742
|
if (fromPattern != null) {
|
|
1758
1743
|
setValueByPath(toObject, ['pattern'], fromPattern);
|
|
1759
1744
|
}
|
|
1760
|
-
const fromMinimum = getValueByPath(fromObject, ['minimum']);
|
|
1761
|
-
if (fromMinimum != null) {
|
|
1762
|
-
setValueByPath(toObject, ['minimum'], fromMinimum);
|
|
1763
|
-
}
|
|
1764
1745
|
const fromDefault = getValueByPath(fromObject, ['default']);
|
|
1765
1746
|
if (fromDefault != null) {
|
|
1766
1747
|
setValueByPath(toObject, ['default'], fromDefault);
|
|
1767
1748
|
}
|
|
1768
|
-
const fromAnyOf = getValueByPath(fromObject, ['anyOf']);
|
|
1769
|
-
if (fromAnyOf != null) {
|
|
1770
|
-
setValueByPath(toObject, ['anyOf'], fromAnyOf);
|
|
1771
|
-
}
|
|
1772
1749
|
const fromMaxLength = getValueByPath(fromObject, ['maxLength']);
|
|
1773
1750
|
if (fromMaxLength != null) {
|
|
1774
1751
|
setValueByPath(toObject, ['maxLength'], fromMaxLength);
|
|
@@ -1787,16 +1764,16 @@ function schemaToVertex$1(apiClient, fromObject) {
|
|
|
1787
1764
|
if (fromMinProperties != null) {
|
|
1788
1765
|
setValueByPath(toObject, ['minProperties'], fromMinProperties);
|
|
1789
1766
|
}
|
|
1790
|
-
const fromMaximum = getValueByPath(fromObject, ['maximum']);
|
|
1791
|
-
if (fromMaximum != null) {
|
|
1792
|
-
setValueByPath(toObject, ['maximum'], fromMaximum);
|
|
1793
|
-
}
|
|
1794
1767
|
const fromMaxProperties = getValueByPath(fromObject, [
|
|
1795
1768
|
'maxProperties',
|
|
1796
1769
|
]);
|
|
1797
1770
|
if (fromMaxProperties != null) {
|
|
1798
1771
|
setValueByPath(toObject, ['maxProperties'], fromMaxProperties);
|
|
1799
1772
|
}
|
|
1773
|
+
const fromAnyOf = getValueByPath(fromObject, ['anyOf']);
|
|
1774
|
+
if (fromAnyOf != null) {
|
|
1775
|
+
setValueByPath(toObject, ['anyOf'], fromAnyOf);
|
|
1776
|
+
}
|
|
1800
1777
|
const fromDescription = getValueByPath(fromObject, ['description']);
|
|
1801
1778
|
if (fromDescription != null) {
|
|
1802
1779
|
setValueByPath(toObject, ['description'], fromDescription);
|
|
@@ -1817,10 +1794,18 @@ function schemaToVertex$1(apiClient, fromObject) {
|
|
|
1817
1794
|
if (fromMaxItems != null) {
|
|
1818
1795
|
setValueByPath(toObject, ['maxItems'], fromMaxItems);
|
|
1819
1796
|
}
|
|
1797
|
+
const fromMaximum = getValueByPath(fromObject, ['maximum']);
|
|
1798
|
+
if (fromMaximum != null) {
|
|
1799
|
+
setValueByPath(toObject, ['maximum'], fromMaximum);
|
|
1800
|
+
}
|
|
1820
1801
|
const fromMinItems = getValueByPath(fromObject, ['minItems']);
|
|
1821
1802
|
if (fromMinItems != null) {
|
|
1822
1803
|
setValueByPath(toObject, ['minItems'], fromMinItems);
|
|
1823
1804
|
}
|
|
1805
|
+
const fromMinimum = getValueByPath(fromObject, ['minimum']);
|
|
1806
|
+
if (fromMinimum != null) {
|
|
1807
|
+
setValueByPath(toObject, ['minimum'], fromMinimum);
|
|
1808
|
+
}
|
|
1824
1809
|
const fromNullable = getValueByPath(fromObject, ['nullable']);
|
|
1825
1810
|
if (fromNullable != null) {
|
|
1826
1811
|
setValueByPath(toObject, ['nullable'], fromNullable);
|
|
@@ -1884,11 +1869,11 @@ function functionDeclarationToVertex$1(apiClient, fromObject) {
|
|
|
1884
1869
|
}
|
|
1885
1870
|
return toObject;
|
|
1886
1871
|
}
|
|
1887
|
-
function googleSearchToMldev$1(
|
|
1872
|
+
function googleSearchToMldev$1() {
|
|
1888
1873
|
const toObject = {};
|
|
1889
1874
|
return toObject;
|
|
1890
1875
|
}
|
|
1891
|
-
function googleSearchToVertex$1(
|
|
1876
|
+
function googleSearchToVertex$1() {
|
|
1892
1877
|
const toObject = {};
|
|
1893
1878
|
return toObject;
|
|
1894
1879
|
}
|
|
@@ -2387,11 +2372,11 @@ function cachedContentFromVertex(apiClient, fromObject) {
|
|
|
2387
2372
|
}
|
|
2388
2373
|
return toObject;
|
|
2389
2374
|
}
|
|
2390
|
-
function deleteCachedContentResponseFromMldev(
|
|
2375
|
+
function deleteCachedContentResponseFromMldev() {
|
|
2391
2376
|
const toObject = {};
|
|
2392
2377
|
return toObject;
|
|
2393
2378
|
}
|
|
2394
|
-
function deleteCachedContentResponseFromVertex(
|
|
2379
|
+
function deleteCachedContentResponseFromVertex() {
|
|
2395
2380
|
const toObject = {};
|
|
2396
2381
|
return toObject;
|
|
2397
2382
|
}
|
|
@@ -2503,7 +2488,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
2503
2488
|
|
|
2504
2489
|
/**
|
|
2505
2490
|
* @license
|
|
2506
|
-
* Copyright
|
|
2491
|
+
* Copyright 2025 Google LLC
|
|
2507
2492
|
* SPDX-License-Identifier: Apache-2.0
|
|
2508
2493
|
*/
|
|
2509
2494
|
/**
|
|
@@ -2608,16 +2593,35 @@ class Chats {
|
|
|
2608
2593
|
/**
|
|
2609
2594
|
* Creates a new chat session.
|
|
2610
2595
|
*
|
|
2596
|
+
* @remarks
|
|
2597
|
+
* The config in the params will be used for all requests within the chat
|
|
2598
|
+
* session unless overridden by a per-request `config` in
|
|
2599
|
+
* {@link ./types.SendMessageParameters}.
|
|
2600
|
+
*
|
|
2611
2601
|
* @param params - Parameters for creating a chat session.
|
|
2612
2602
|
* @returns A new chat session.
|
|
2603
|
+
*
|
|
2604
|
+
* @example
|
|
2605
|
+
* ```ts
|
|
2606
|
+
* const chat = ai.chats.create({
|
|
2607
|
+
* model: 'gemini-2.0-flash'
|
|
2608
|
+
* config: {
|
|
2609
|
+
* temperature: 0.5,
|
|
2610
|
+
* maxOutputTokens: 1024,
|
|
2611
|
+
* }
|
|
2612
|
+
* });
|
|
2613
|
+
* ```
|
|
2613
2614
|
*/
|
|
2614
2615
|
create(params) {
|
|
2615
2616
|
return new Chat(this.apiClient, this.modelsModule, params.model, params.config, params.history);
|
|
2616
2617
|
}
|
|
2617
2618
|
}
|
|
2618
2619
|
/**
|
|
2619
|
-
* Chat session that enables sending messages
|
|
2620
|
-
*
|
|
2620
|
+
* Chat session that enables sending messages to the model with previous
|
|
2621
|
+
* conversation context.
|
|
2622
|
+
*
|
|
2623
|
+
* @remarks
|
|
2624
|
+
* The session maintains all the turns between user and model.
|
|
2621
2625
|
*/
|
|
2622
2626
|
class Chat {
|
|
2623
2627
|
constructor(apiClient, modelsModule, model, config = {}, history = []) {
|
|
@@ -2641,6 +2645,15 @@ class Chat {
|
|
|
2641
2645
|
* @see {@link Chat#sendMessageStream} for streaming method.
|
|
2642
2646
|
* @param params - parameters for sending messages within a chat session.
|
|
2643
2647
|
* @returns The model's response.
|
|
2648
|
+
*
|
|
2649
|
+
* @example
|
|
2650
|
+
* ```ts
|
|
2651
|
+
* const chat = ai.chats.create({model: 'gemini-2.0-flash'});
|
|
2652
|
+
* const response = await chat.sendMessage({
|
|
2653
|
+
* message: 'Why is the sky blue?'
|
|
2654
|
+
* });
|
|
2655
|
+
* console.log(response.text);
|
|
2656
|
+
* ```
|
|
2644
2657
|
*/
|
|
2645
2658
|
async sendMessage(params) {
|
|
2646
2659
|
var _a;
|
|
@@ -2672,6 +2685,17 @@ class Chat {
|
|
|
2672
2685
|
* @see {@link Chat#sendMessage} for non-streaming method.
|
|
2673
2686
|
* @param params - parameters for sending the message.
|
|
2674
2687
|
* @return The model's response.
|
|
2688
|
+
*
|
|
2689
|
+
* @example
|
|
2690
|
+
* ```ts
|
|
2691
|
+
* const chat = ai.chats.create({model: 'gemini-2.0-flash'});
|
|
2692
|
+
* const response = await chat.sendMessageStream({
|
|
2693
|
+
* message: 'Why is the sky blue?'
|
|
2694
|
+
* });
|
|
2695
|
+
* for await (const chunk of response) {
|
|
2696
|
+
* console.log(chunk.text);
|
|
2697
|
+
* }
|
|
2698
|
+
* ```
|
|
2675
2699
|
*/
|
|
2676
2700
|
async sendMessageStream(params) {
|
|
2677
2701
|
var _a;
|
|
@@ -2763,13 +2787,13 @@ class Chat {
|
|
|
2763
2787
|
|
|
2764
2788
|
/**
|
|
2765
2789
|
* @license
|
|
2766
|
-
* Copyright
|
|
2790
|
+
* Copyright 2025 Google LLC
|
|
2767
2791
|
* SPDX-License-Identifier: Apache-2.0
|
|
2768
2792
|
*/
|
|
2769
2793
|
const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
2770
2794
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
2771
2795
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
2772
|
-
const SDK_VERSION = '0.
|
|
2796
|
+
const SDK_VERSION = '0.4.0'; // x-release-please-version
|
|
2773
2797
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
2774
2798
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
2775
2799
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -2981,7 +3005,7 @@ class ApiClient {
|
|
|
2981
3005
|
async unaryApiCall(url, requestInit, httpMethod) {
|
|
2982
3006
|
return this.apiCall(url.toString(), Object.assign(Object.assign({}, requestInit), { method: httpMethod }))
|
|
2983
3007
|
.then(async (response) => {
|
|
2984
|
-
await throwErrorIfNotOK(response
|
|
3008
|
+
await throwErrorIfNotOK(response);
|
|
2985
3009
|
return new HttpResponse(response);
|
|
2986
3010
|
})
|
|
2987
3011
|
.catch((e) => {
|
|
@@ -2996,7 +3020,7 @@ class ApiClient {
|
|
|
2996
3020
|
async streamApiCall(url, requestInit, httpMethod) {
|
|
2997
3021
|
return this.apiCall(url.toString(), Object.assign(Object.assign({}, requestInit), { method: httpMethod }))
|
|
2998
3022
|
.then(async (response) => {
|
|
2999
|
-
await throwErrorIfNotOK(response
|
|
3023
|
+
await throwErrorIfNotOK(response);
|
|
3000
3024
|
return this.processStreamResponse(response);
|
|
3001
3025
|
})
|
|
3002
3026
|
.catch((e) => {
|
|
@@ -3141,7 +3165,7 @@ class ApiClient {
|
|
|
3141
3165
|
return uploadUrl;
|
|
3142
3166
|
}
|
|
3143
3167
|
}
|
|
3144
|
-
async function throwErrorIfNotOK(response
|
|
3168
|
+
async function throwErrorIfNotOK(response) {
|
|
3145
3169
|
var _a;
|
|
3146
3170
|
if (response === undefined) {
|
|
3147
3171
|
throw new ServerError('response is undefined');
|
|
@@ -3263,7 +3287,7 @@ class CrossWebSocketFactory {
|
|
|
3263
3287
|
|
|
3264
3288
|
/**
|
|
3265
3289
|
* @license
|
|
3266
|
-
* Copyright
|
|
3290
|
+
* Copyright 2025 Google LLC
|
|
3267
3291
|
* SPDX-License-Identifier: Apache-2.0
|
|
3268
3292
|
*/
|
|
3269
3293
|
class Files extends BaseModule {
|
|
@@ -3281,7 +3305,7 @@ class Files extends BaseModule {
|
|
|
3281
3305
|
* size of each page is 10.
|
|
3282
3306
|
*
|
|
3283
3307
|
* ```ts
|
|
3284
|
-
* const listResponse = await
|
|
3308
|
+
* const listResponse = await ai.files.list({config: {'pageSize': 10}});
|
|
3285
3309
|
* for await (const file of listResponse) {
|
|
3286
3310
|
* console.log(file.name);
|
|
3287
3311
|
* }
|
|
@@ -3314,63 +3338,43 @@ class Files extends BaseModule {
|
|
|
3314
3338
|
*
|
|
3315
3339
|
* This section can contain multiple paragraphs and code examples.
|
|
3316
3340
|
*
|
|
3317
|
-
* @param
|
|
3318
|
-
*
|
|
3319
|
-
*
|
|
3341
|
+
* @param params - Optional parameters specified in the
|
|
3342
|
+
* `common.UploadFileParameters` interface.
|
|
3343
|
+
* Optional @see {@link common.UploadFileParameters}
|
|
3320
3344
|
* @return A promise that resolves to a `types.File` object.
|
|
3321
3345
|
* @throws An error if called on a Vertex AI client.
|
|
3322
3346
|
* @throws An error if the `mimeType` is not provided and can not be inferred,
|
|
3323
|
-
* the `mimeType` can be provided in the `config` parameter.
|
|
3347
|
+
* the `mimeType` can be provided in the `params.config` parameter.
|
|
3324
3348
|
* @throws An error occurs if a suitable upload location cannot be established.
|
|
3325
3349
|
*
|
|
3326
3350
|
* @example
|
|
3327
3351
|
* The following code uploads a file to Gemini API.
|
|
3328
3352
|
*
|
|
3329
3353
|
* ```ts
|
|
3330
|
-
* const file = await
|
|
3354
|
+
* const file = await ai.files.upload({file: 'file.txt', config: {
|
|
3331
3355
|
* mimeType: 'text/plain',
|
|
3332
|
-
* });
|
|
3356
|
+
* }});
|
|
3333
3357
|
* console.log(file.name);
|
|
3334
3358
|
* ```
|
|
3335
3359
|
*/
|
|
3336
|
-
async upload(
|
|
3360
|
+
async upload(params) {
|
|
3337
3361
|
if (this.apiClient.isVertexAI()) {
|
|
3338
3362
|
throw new Error('Vertex AI does not support uploading files. You can share files through a GCS bucket.');
|
|
3339
3363
|
}
|
|
3340
|
-
return this.apiClient
|
|
3364
|
+
return this.apiClient
|
|
3365
|
+
.uploadFile(params.file, params.config)
|
|
3366
|
+
.then((response) => {
|
|
3341
3367
|
const file = fileFromMldev(this.apiClient, response);
|
|
3342
3368
|
return file;
|
|
3343
3369
|
});
|
|
3344
3370
|
}
|
|
3345
3371
|
async listInternal(params) {
|
|
3346
|
-
var _a
|
|
3372
|
+
var _a;
|
|
3347
3373
|
let response;
|
|
3348
3374
|
let path = '';
|
|
3349
3375
|
let queryParams = {};
|
|
3350
3376
|
if (this.apiClient.isVertexAI()) {
|
|
3351
|
-
|
|
3352
|
-
path = formatMap('None', body['_url']);
|
|
3353
|
-
queryParams = body['_query'];
|
|
3354
|
-
delete body['config'];
|
|
3355
|
-
delete body['_url'];
|
|
3356
|
-
delete body['_query'];
|
|
3357
|
-
response = this.apiClient
|
|
3358
|
-
.request({
|
|
3359
|
-
path: path,
|
|
3360
|
-
queryParams: queryParams,
|
|
3361
|
-
body: JSON.stringify(body),
|
|
3362
|
-
httpMethod: 'GET',
|
|
3363
|
-
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
3364
|
-
})
|
|
3365
|
-
.then((httpResponse) => {
|
|
3366
|
-
return httpResponse.json();
|
|
3367
|
-
});
|
|
3368
|
-
return response.then((apiResponse) => {
|
|
3369
|
-
const resp = listFilesResponseFromVertex(this.apiClient);
|
|
3370
|
-
const typedResp = new ListFilesResponse();
|
|
3371
|
-
Object.assign(typedResp, resp);
|
|
3372
|
-
return typedResp;
|
|
3373
|
-
});
|
|
3377
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
3374
3378
|
}
|
|
3375
3379
|
else {
|
|
3376
3380
|
const body = listFilesParametersToMldev(this.apiClient, params);
|
|
@@ -3385,7 +3389,7 @@ class Files extends BaseModule {
|
|
|
3385
3389
|
queryParams: queryParams,
|
|
3386
3390
|
body: JSON.stringify(body),
|
|
3387
3391
|
httpMethod: 'GET',
|
|
3388
|
-
httpOptions: (
|
|
3392
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
3389
3393
|
})
|
|
3390
3394
|
.then((httpResponse) => {
|
|
3391
3395
|
return httpResponse.json();
|
|
@@ -3399,34 +3403,12 @@ class Files extends BaseModule {
|
|
|
3399
3403
|
}
|
|
3400
3404
|
}
|
|
3401
3405
|
async createInternal(params) {
|
|
3402
|
-
var _a
|
|
3406
|
+
var _a;
|
|
3403
3407
|
let response;
|
|
3404
3408
|
let path = '';
|
|
3405
3409
|
let queryParams = {};
|
|
3406
3410
|
if (this.apiClient.isVertexAI()) {
|
|
3407
|
-
|
|
3408
|
-
path = formatMap('', body['_url']);
|
|
3409
|
-
queryParams = body['_query'];
|
|
3410
|
-
delete body['config'];
|
|
3411
|
-
delete body['_url'];
|
|
3412
|
-
delete body['_query'];
|
|
3413
|
-
response = this.apiClient
|
|
3414
|
-
.request({
|
|
3415
|
-
path: path,
|
|
3416
|
-
queryParams: queryParams,
|
|
3417
|
-
body: JSON.stringify(body),
|
|
3418
|
-
httpMethod: 'POST',
|
|
3419
|
-
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
3420
|
-
})
|
|
3421
|
-
.then((httpResponse) => {
|
|
3422
|
-
return httpResponse.json();
|
|
3423
|
-
});
|
|
3424
|
-
return response.then((apiResponse) => {
|
|
3425
|
-
const resp = createFileResponseFromVertex(this.apiClient, apiResponse);
|
|
3426
|
-
const typedResp = new CreateFileResponse();
|
|
3427
|
-
Object.assign(typedResp, resp);
|
|
3428
|
-
return typedResp;
|
|
3429
|
-
});
|
|
3411
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
3430
3412
|
}
|
|
3431
3413
|
else {
|
|
3432
3414
|
const body = createFileParametersToMldev(this.apiClient, params);
|
|
@@ -3441,7 +3423,7 @@ class Files extends BaseModule {
|
|
|
3441
3423
|
queryParams: queryParams,
|
|
3442
3424
|
body: JSON.stringify(body),
|
|
3443
3425
|
httpMethod: 'POST',
|
|
3444
|
-
httpOptions: (
|
|
3426
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
3445
3427
|
})
|
|
3446
3428
|
.then((httpResponse) => {
|
|
3447
3429
|
return httpResponse.json();
|
|
@@ -3465,37 +3447,17 @@ class Files extends BaseModule {
|
|
|
3465
3447
|
* const config: GetFileParameters = {
|
|
3466
3448
|
* name: fileName,
|
|
3467
3449
|
* };
|
|
3468
|
-
* file = await
|
|
3450
|
+
* file = await ai.files.get(config);
|
|
3469
3451
|
* console.log(file.name);
|
|
3470
3452
|
* ```
|
|
3471
3453
|
*/
|
|
3472
3454
|
async get(params) {
|
|
3473
|
-
var _a
|
|
3455
|
+
var _a;
|
|
3474
3456
|
let response;
|
|
3475
3457
|
let path = '';
|
|
3476
3458
|
let queryParams = {};
|
|
3477
3459
|
if (this.apiClient.isVertexAI()) {
|
|
3478
|
-
|
|
3479
|
-
path = formatMap('None', body['_url']);
|
|
3480
|
-
queryParams = body['_query'];
|
|
3481
|
-
delete body['config'];
|
|
3482
|
-
delete body['_url'];
|
|
3483
|
-
delete body['_query'];
|
|
3484
|
-
response = this.apiClient
|
|
3485
|
-
.request({
|
|
3486
|
-
path: path,
|
|
3487
|
-
queryParams: queryParams,
|
|
3488
|
-
body: JSON.stringify(body),
|
|
3489
|
-
httpMethod: 'GET',
|
|
3490
|
-
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
3491
|
-
})
|
|
3492
|
-
.then((httpResponse) => {
|
|
3493
|
-
return httpResponse.json();
|
|
3494
|
-
});
|
|
3495
|
-
return response.then((apiResponse) => {
|
|
3496
|
-
const resp = fileFromVertex(this.apiClient);
|
|
3497
|
-
return resp;
|
|
3498
|
-
});
|
|
3460
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
3499
3461
|
}
|
|
3500
3462
|
else {
|
|
3501
3463
|
const body = getFileParametersToMldev(this.apiClient, params);
|
|
@@ -3510,7 +3472,7 @@ class Files extends BaseModule {
|
|
|
3510
3472
|
queryParams: queryParams,
|
|
3511
3473
|
body: JSON.stringify(body),
|
|
3512
3474
|
httpMethod: 'GET',
|
|
3513
|
-
httpOptions: (
|
|
3475
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
3514
3476
|
})
|
|
3515
3477
|
.then((httpResponse) => {
|
|
3516
3478
|
return httpResponse.json();
|
|
@@ -3542,13 +3504,6 @@ function listFilesParametersToMldev(apiClient, fromObject) {
|
|
|
3542
3504
|
}
|
|
3543
3505
|
return toObject;
|
|
3544
3506
|
}
|
|
3545
|
-
function listFilesParametersToVertex(apiClient, fromObject) {
|
|
3546
|
-
const toObject = {};
|
|
3547
|
-
if (getValueByPath(fromObject, ['config']) !== undefined) {
|
|
3548
|
-
throw new Error('config parameter is not supported in Vertex AI.');
|
|
3549
|
-
}
|
|
3550
|
-
return toObject;
|
|
3551
|
-
}
|
|
3552
3507
|
function fileStatusToMldev(apiClient, fromObject) {
|
|
3553
3508
|
const toObject = {};
|
|
3554
3509
|
const fromDetails = getValueByPath(fromObject, ['details']);
|
|
@@ -3641,16 +3596,6 @@ function createFileParametersToMldev(apiClient, fromObject) {
|
|
|
3641
3596
|
}
|
|
3642
3597
|
return toObject;
|
|
3643
3598
|
}
|
|
3644
|
-
function createFileParametersToVertex(apiClient, fromObject) {
|
|
3645
|
-
const toObject = {};
|
|
3646
|
-
if (getValueByPath(fromObject, ['file']) !== undefined) {
|
|
3647
|
-
throw new Error('file parameter is not supported in Vertex AI.');
|
|
3648
|
-
}
|
|
3649
|
-
if (getValueByPath(fromObject, ['config']) !== undefined) {
|
|
3650
|
-
throw new Error('config parameter is not supported in Vertex AI.');
|
|
3651
|
-
}
|
|
3652
|
-
return toObject;
|
|
3653
|
-
}
|
|
3654
3599
|
function getFileParametersToMldev(apiClient, fromObject) {
|
|
3655
3600
|
const toObject = {};
|
|
3656
3601
|
const fromName = getValueByPath(fromObject, ['name']);
|
|
@@ -3663,16 +3608,6 @@ function getFileParametersToMldev(apiClient, fromObject) {
|
|
|
3663
3608
|
}
|
|
3664
3609
|
return toObject;
|
|
3665
3610
|
}
|
|
3666
|
-
function getFileParametersToVertex(apiClient, fromObject) {
|
|
3667
|
-
const toObject = {};
|
|
3668
|
-
if (getValueByPath(fromObject, ['name']) !== undefined) {
|
|
3669
|
-
throw new Error('name parameter is not supported in Vertex AI.');
|
|
3670
|
-
}
|
|
3671
|
-
if (getValueByPath(fromObject, ['config']) !== undefined) {
|
|
3672
|
-
throw new Error('config parameter is not supported in Vertex AI.');
|
|
3673
|
-
}
|
|
3674
|
-
return toObject;
|
|
3675
|
-
}
|
|
3676
3611
|
function fileStatusFromMldev(apiClient, fromObject) {
|
|
3677
3612
|
const toObject = {};
|
|
3678
3613
|
const fromDetails = getValueByPath(fromObject, ['details']);
|
|
@@ -3753,10 +3688,6 @@ function fileFromMldev(apiClient, fromObject) {
|
|
|
3753
3688
|
}
|
|
3754
3689
|
return toObject;
|
|
3755
3690
|
}
|
|
3756
|
-
function fileFromVertex(apiClient, fromObject) {
|
|
3757
|
-
const toObject = {};
|
|
3758
|
-
return toObject;
|
|
3759
|
-
}
|
|
3760
3691
|
function listFilesResponseFromMldev(apiClient, fromObject) {
|
|
3761
3692
|
const toObject = {};
|
|
3762
3693
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
@@ -3778,10 +3709,6 @@ function listFilesResponseFromMldev(apiClient, fromObject) {
|
|
|
3778
3709
|
}
|
|
3779
3710
|
return toObject;
|
|
3780
3711
|
}
|
|
3781
|
-
function listFilesResponseFromVertex(apiClient, fromObject) {
|
|
3782
|
-
const toObject = {};
|
|
3783
|
-
return toObject;
|
|
3784
|
-
}
|
|
3785
3712
|
function createFileResponseFromMldev(apiClient, fromObject) {
|
|
3786
3713
|
const toObject = {};
|
|
3787
3714
|
const fromHttpHeaders = getValueByPath(fromObject, ['httpHeaders']);
|
|
@@ -3790,18 +3717,10 @@ function createFileResponseFromMldev(apiClient, fromObject) {
|
|
|
3790
3717
|
}
|
|
3791
3718
|
return toObject;
|
|
3792
3719
|
}
|
|
3793
|
-
function createFileResponseFromVertex(apiClient, fromObject) {
|
|
3794
|
-
const toObject = {};
|
|
3795
|
-
const fromHttpHeaders = getValueByPath(fromObject, ['httpHeaders']);
|
|
3796
|
-
if (fromHttpHeaders != null) {
|
|
3797
|
-
setValueByPath(toObject, ['httpHeaders'], fromHttpHeaders);
|
|
3798
|
-
}
|
|
3799
|
-
return toObject;
|
|
3800
|
-
}
|
|
3801
3720
|
|
|
3802
3721
|
/**
|
|
3803
3722
|
* @license
|
|
3804
|
-
* Copyright
|
|
3723
|
+
* Copyright 2025 Google LLC
|
|
3805
3724
|
* SPDX-License-Identifier: Apache-2.0
|
|
3806
3725
|
*/
|
|
3807
3726
|
class Models extends BaseModule {
|
|
@@ -3831,14 +3750,12 @@ class Models extends BaseModule {
|
|
|
3831
3750
|
*
|
|
3832
3751
|
* Some models support multimodal input and output.
|
|
3833
3752
|
*
|
|
3834
|
-
* @param
|
|
3835
|
-
* @param contents - The input contents to use for generating content.
|
|
3836
|
-
* @param [config] - The configuration for generating content.
|
|
3753
|
+
* @param params - The parameters for generating content.
|
|
3837
3754
|
* @return The response from generating content.
|
|
3838
3755
|
*
|
|
3839
3756
|
* @example
|
|
3840
3757
|
* ```ts
|
|
3841
|
-
* const response = await
|
|
3758
|
+
* const response = await ai.models.generateContent({
|
|
3842
3759
|
* model: 'gemini-2.0-flash',
|
|
3843
3760
|
* contents: 'why is the sky blue?',
|
|
3844
3761
|
* config: {
|
|
@@ -3875,14 +3792,12 @@ class Models extends BaseModule {
|
|
|
3875
3792
|
*
|
|
3876
3793
|
* Some models support multimodal input and output.
|
|
3877
3794
|
*
|
|
3878
|
-
* @param
|
|
3879
|
-
* @param contents - The input contents to use for generating content.
|
|
3880
|
-
* @param [config] - The configuration for generating content.
|
|
3795
|
+
* @param params - The parameters for generating content with streaming response.
|
|
3881
3796
|
* @return The response from generating content.
|
|
3882
3797
|
*
|
|
3883
3798
|
* @example
|
|
3884
3799
|
* ```ts
|
|
3885
|
-
* const response = await
|
|
3800
|
+
* const response = await ai.models.generateContentStream({
|
|
3886
3801
|
* model: 'gemini-2.0-flash',
|
|
3887
3802
|
* contents: 'why is the sky blue?',
|
|
3888
3803
|
* config: {
|
|
@@ -4041,14 +3956,12 @@ class Models extends BaseModule {
|
|
|
4041
3956
|
/**
|
|
4042
3957
|
* Calculates embeddings for the given contents. Only text is supported.
|
|
4043
3958
|
*
|
|
4044
|
-
* @param
|
|
4045
|
-
* @param contents - The contents to embed.
|
|
4046
|
-
* @param [config] - The config for embedding contents.
|
|
3959
|
+
* @param params - The parameters for embedding contents.
|
|
4047
3960
|
* @return The response from the API.
|
|
4048
3961
|
*
|
|
4049
3962
|
* @example
|
|
4050
3963
|
* ```ts
|
|
4051
|
-
* const response = await
|
|
3964
|
+
* const response = await ai.models.embedContent({
|
|
4052
3965
|
* model: 'text-embedding-004',
|
|
4053
3966
|
* contents: [
|
|
4054
3967
|
* 'What is your name?',
|
|
@@ -4120,14 +4033,12 @@ class Models extends BaseModule {
|
|
|
4120
4033
|
/**
|
|
4121
4034
|
* Generates an image based on a text description and configuration.
|
|
4122
4035
|
*
|
|
4123
|
-
* @param
|
|
4124
|
-
* @param prompt - A text description of the image to generate.
|
|
4125
|
-
* @param [config] - The config for image generation.
|
|
4036
|
+
* @param params - The parameters for generating images.
|
|
4126
4037
|
* @return The response from the API.
|
|
4127
4038
|
*
|
|
4128
4039
|
* @example
|
|
4129
4040
|
* ```ts
|
|
4130
|
-
* const response = await
|
|
4041
|
+
* const response = await ai.models.generateImages({
|
|
4131
4042
|
* model: 'imagen-3.0-generate-002',
|
|
4132
4043
|
* prompt: 'Robot holding a red skateboard',
|
|
4133
4044
|
* config: {
|
|
@@ -4198,14 +4109,12 @@ class Models extends BaseModule {
|
|
|
4198
4109
|
* Counts the number of tokens in the given contents. Multimodal input is
|
|
4199
4110
|
* supported for Gemini models.
|
|
4200
4111
|
*
|
|
4201
|
-
* @param
|
|
4202
|
-
* @param contents - The contents to count tokens for.
|
|
4203
|
-
* @param [config] - The config for counting tokens.
|
|
4112
|
+
* @param params - The parameters for counting tokens.
|
|
4204
4113
|
* @return The response from the API.
|
|
4205
4114
|
*
|
|
4206
4115
|
* @example
|
|
4207
4116
|
* ```ts
|
|
4208
|
-
* const response = await
|
|
4117
|
+
* const response = await ai.models.countTokens({
|
|
4209
4118
|
* model: 'gemini-2.0-flash',
|
|
4210
4119
|
* contents: 'The quick brown fox jumps over the lazy dog.'
|
|
4211
4120
|
* });
|
|
@@ -4274,14 +4183,12 @@ class Models extends BaseModule {
|
|
|
4274
4183
|
*
|
|
4275
4184
|
* This method is not supported by the Gemini Developer API.
|
|
4276
4185
|
*
|
|
4277
|
-
* @param
|
|
4278
|
-
* @param contents - The content to compute tokens for.
|
|
4279
|
-
* @param [config] - The config for computing tokens.
|
|
4186
|
+
* @param params - The parameters for computing tokens.
|
|
4280
4187
|
* @return The response from the API.
|
|
4281
4188
|
*
|
|
4282
4189
|
* @example
|
|
4283
4190
|
* ```ts
|
|
4284
|
-
* const response = await
|
|
4191
|
+
* const response = await ai.models.computeTokens({
|
|
4285
4192
|
* model: 'gemini-2.0-flash',
|
|
4286
4193
|
* contents: 'What is your name?'
|
|
4287
4194
|
* });
|
|
@@ -4289,7 +4196,7 @@ class Models extends BaseModule {
|
|
|
4289
4196
|
* ```
|
|
4290
4197
|
*/
|
|
4291
4198
|
async computeTokens(params) {
|
|
4292
|
-
var _a
|
|
4199
|
+
var _a;
|
|
4293
4200
|
let response;
|
|
4294
4201
|
let path = '';
|
|
4295
4202
|
let queryParams = {};
|
|
@@ -4319,29 +4226,7 @@ class Models extends BaseModule {
|
|
|
4319
4226
|
});
|
|
4320
4227
|
}
|
|
4321
4228
|
else {
|
|
4322
|
-
|
|
4323
|
-
path = formatMap('None', body['_url']);
|
|
4324
|
-
queryParams = body['_query'];
|
|
4325
|
-
delete body['config'];
|
|
4326
|
-
delete body['_url'];
|
|
4327
|
-
delete body['_query'];
|
|
4328
|
-
response = this.apiClient
|
|
4329
|
-
.request({
|
|
4330
|
-
path: path,
|
|
4331
|
-
queryParams: queryParams,
|
|
4332
|
-
body: JSON.stringify(body),
|
|
4333
|
-
httpMethod: 'POST',
|
|
4334
|
-
httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
|
|
4335
|
-
})
|
|
4336
|
-
.then((httpResponse) => {
|
|
4337
|
-
return httpResponse.json();
|
|
4338
|
-
});
|
|
4339
|
-
return response.then((apiResponse) => {
|
|
4340
|
-
const resp = computeTokensResponseFromMldev(this.apiClient, apiResponse);
|
|
4341
|
-
const typedResp = new ComputeTokensResponse();
|
|
4342
|
-
Object.assign(typedResp, resp);
|
|
4343
|
-
return typedResp;
|
|
4344
|
-
});
|
|
4229
|
+
throw new Error('This method is only supported by the Vertex AI.');
|
|
4345
4230
|
}
|
|
4346
4231
|
}
|
|
4347
4232
|
}
|
|
@@ -4486,15 +4371,9 @@ function schemaToMldev(apiClient, fromObject) {
|
|
|
4486
4371
|
if (getValueByPath(fromObject, ['pattern']) !== undefined) {
|
|
4487
4372
|
throw new Error('pattern parameter is not supported in Gemini API.');
|
|
4488
4373
|
}
|
|
4489
|
-
if (getValueByPath(fromObject, ['minimum']) !== undefined) {
|
|
4490
|
-
throw new Error('minimum parameter is not supported in Gemini API.');
|
|
4491
|
-
}
|
|
4492
4374
|
if (getValueByPath(fromObject, ['default']) !== undefined) {
|
|
4493
4375
|
throw new Error('default parameter is not supported in Gemini API.');
|
|
4494
4376
|
}
|
|
4495
|
-
if (getValueByPath(fromObject, ['anyOf']) !== undefined) {
|
|
4496
|
-
throw new Error('anyOf parameter is not supported in Gemini API.');
|
|
4497
|
-
}
|
|
4498
4377
|
if (getValueByPath(fromObject, ['maxLength']) !== undefined) {
|
|
4499
4378
|
throw new Error('maxLength parameter is not supported in Gemini API.');
|
|
4500
4379
|
}
|
|
@@ -4507,12 +4386,13 @@ function schemaToMldev(apiClient, fromObject) {
|
|
|
4507
4386
|
if (getValueByPath(fromObject, ['minProperties']) !== undefined) {
|
|
4508
4387
|
throw new Error('minProperties parameter is not supported in Gemini API.');
|
|
4509
4388
|
}
|
|
4510
|
-
if (getValueByPath(fromObject, ['maximum']) !== undefined) {
|
|
4511
|
-
throw new Error('maximum parameter is not supported in Gemini API.');
|
|
4512
|
-
}
|
|
4513
4389
|
if (getValueByPath(fromObject, ['maxProperties']) !== undefined) {
|
|
4514
4390
|
throw new Error('maxProperties parameter is not supported in Gemini API.');
|
|
4515
4391
|
}
|
|
4392
|
+
const fromAnyOf = getValueByPath(fromObject, ['anyOf']);
|
|
4393
|
+
if (fromAnyOf != null) {
|
|
4394
|
+
setValueByPath(toObject, ['anyOf'], fromAnyOf);
|
|
4395
|
+
}
|
|
4516
4396
|
const fromDescription = getValueByPath(fromObject, ['description']);
|
|
4517
4397
|
if (fromDescription != null) {
|
|
4518
4398
|
setValueByPath(toObject, ['description'], fromDescription);
|
|
@@ -4533,10 +4413,18 @@ function schemaToMldev(apiClient, fromObject) {
|
|
|
4533
4413
|
if (fromMaxItems != null) {
|
|
4534
4414
|
setValueByPath(toObject, ['maxItems'], fromMaxItems);
|
|
4535
4415
|
}
|
|
4416
|
+
const fromMaximum = getValueByPath(fromObject, ['maximum']);
|
|
4417
|
+
if (fromMaximum != null) {
|
|
4418
|
+
setValueByPath(toObject, ['maximum'], fromMaximum);
|
|
4419
|
+
}
|
|
4536
4420
|
const fromMinItems = getValueByPath(fromObject, ['minItems']);
|
|
4537
4421
|
if (fromMinItems != null) {
|
|
4538
4422
|
setValueByPath(toObject, ['minItems'], fromMinItems);
|
|
4539
4423
|
}
|
|
4424
|
+
const fromMinimum = getValueByPath(fromObject, ['minimum']);
|
|
4425
|
+
if (fromMinimum != null) {
|
|
4426
|
+
setValueByPath(toObject, ['minimum'], fromMinimum);
|
|
4427
|
+
}
|
|
4540
4428
|
const fromNullable = getValueByPath(fromObject, ['nullable']);
|
|
4541
4429
|
if (fromNullable != null) {
|
|
4542
4430
|
setValueByPath(toObject, ['nullable'], fromNullable);
|
|
@@ -4571,18 +4459,10 @@ function schemaToVertex(apiClient, fromObject) {
|
|
|
4571
4459
|
if (fromPattern != null) {
|
|
4572
4460
|
setValueByPath(toObject, ['pattern'], fromPattern);
|
|
4573
4461
|
}
|
|
4574
|
-
const fromMinimum = getValueByPath(fromObject, ['minimum']);
|
|
4575
|
-
if (fromMinimum != null) {
|
|
4576
|
-
setValueByPath(toObject, ['minimum'], fromMinimum);
|
|
4577
|
-
}
|
|
4578
4462
|
const fromDefault = getValueByPath(fromObject, ['default']);
|
|
4579
4463
|
if (fromDefault != null) {
|
|
4580
4464
|
setValueByPath(toObject, ['default'], fromDefault);
|
|
4581
4465
|
}
|
|
4582
|
-
const fromAnyOf = getValueByPath(fromObject, ['anyOf']);
|
|
4583
|
-
if (fromAnyOf != null) {
|
|
4584
|
-
setValueByPath(toObject, ['anyOf'], fromAnyOf);
|
|
4585
|
-
}
|
|
4586
4466
|
const fromMaxLength = getValueByPath(fromObject, ['maxLength']);
|
|
4587
4467
|
if (fromMaxLength != null) {
|
|
4588
4468
|
setValueByPath(toObject, ['maxLength'], fromMaxLength);
|
|
@@ -4601,16 +4481,16 @@ function schemaToVertex(apiClient, fromObject) {
|
|
|
4601
4481
|
if (fromMinProperties != null) {
|
|
4602
4482
|
setValueByPath(toObject, ['minProperties'], fromMinProperties);
|
|
4603
4483
|
}
|
|
4604
|
-
const fromMaximum = getValueByPath(fromObject, ['maximum']);
|
|
4605
|
-
if (fromMaximum != null) {
|
|
4606
|
-
setValueByPath(toObject, ['maximum'], fromMaximum);
|
|
4607
|
-
}
|
|
4608
4484
|
const fromMaxProperties = getValueByPath(fromObject, [
|
|
4609
4485
|
'maxProperties',
|
|
4610
4486
|
]);
|
|
4611
4487
|
if (fromMaxProperties != null) {
|
|
4612
4488
|
setValueByPath(toObject, ['maxProperties'], fromMaxProperties);
|
|
4613
4489
|
}
|
|
4490
|
+
const fromAnyOf = getValueByPath(fromObject, ['anyOf']);
|
|
4491
|
+
if (fromAnyOf != null) {
|
|
4492
|
+
setValueByPath(toObject, ['anyOf'], fromAnyOf);
|
|
4493
|
+
}
|
|
4614
4494
|
const fromDescription = getValueByPath(fromObject, ['description']);
|
|
4615
4495
|
if (fromDescription != null) {
|
|
4616
4496
|
setValueByPath(toObject, ['description'], fromDescription);
|
|
@@ -4631,10 +4511,18 @@ function schemaToVertex(apiClient, fromObject) {
|
|
|
4631
4511
|
if (fromMaxItems != null) {
|
|
4632
4512
|
setValueByPath(toObject, ['maxItems'], fromMaxItems);
|
|
4633
4513
|
}
|
|
4514
|
+
const fromMaximum = getValueByPath(fromObject, ['maximum']);
|
|
4515
|
+
if (fromMaximum != null) {
|
|
4516
|
+
setValueByPath(toObject, ['maximum'], fromMaximum);
|
|
4517
|
+
}
|
|
4634
4518
|
const fromMinItems = getValueByPath(fromObject, ['minItems']);
|
|
4635
4519
|
if (fromMinItems != null) {
|
|
4636
4520
|
setValueByPath(toObject, ['minItems'], fromMinItems);
|
|
4637
4521
|
}
|
|
4522
|
+
const fromMinimum = getValueByPath(fromObject, ['minimum']);
|
|
4523
|
+
if (fromMinimum != null) {
|
|
4524
|
+
setValueByPath(toObject, ['minimum'], fromMinimum);
|
|
4525
|
+
}
|
|
4638
4526
|
const fromNullable = getValueByPath(fromObject, ['nullable']);
|
|
4639
4527
|
if (fromNullable != null) {
|
|
4640
4528
|
setValueByPath(toObject, ['nullable'], fromNullable);
|
|
@@ -4729,11 +4617,11 @@ function functionDeclarationToVertex(apiClient, fromObject) {
|
|
|
4729
4617
|
}
|
|
4730
4618
|
return toObject;
|
|
4731
4619
|
}
|
|
4732
|
-
function googleSearchToMldev(
|
|
4620
|
+
function googleSearchToMldev() {
|
|
4733
4621
|
const toObject = {};
|
|
4734
4622
|
return toObject;
|
|
4735
4623
|
}
|
|
4736
|
-
function googleSearchToVertex(
|
|
4624
|
+
function googleSearchToVertex() {
|
|
4737
4625
|
const toObject = {};
|
|
4738
4626
|
return toObject;
|
|
4739
4627
|
}
|
|
@@ -5682,21 +5570,6 @@ function countTokensParametersToVertex(apiClient, fromObject) {
|
|
|
5682
5570
|
}
|
|
5683
5571
|
return toObject;
|
|
5684
5572
|
}
|
|
5685
|
-
function computeTokensParametersToMldev(apiClient, fromObject) {
|
|
5686
|
-
const toObject = {};
|
|
5687
|
-
const fromModel = getValueByPath(fromObject, ['model']);
|
|
5688
|
-
if (fromModel != null) {
|
|
5689
|
-
setValueByPath(toObject, ['_url', 'model'], tModel(apiClient, fromModel));
|
|
5690
|
-
}
|
|
5691
|
-
if (getValueByPath(fromObject, ['contents']) !== undefined) {
|
|
5692
|
-
throw new Error('contents parameter is not supported in Gemini API.');
|
|
5693
|
-
}
|
|
5694
|
-
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
5695
|
-
if (fromConfig != null) {
|
|
5696
|
-
setValueByPath(toObject, ['config'], fromConfig);
|
|
5697
|
-
}
|
|
5698
|
-
return toObject;
|
|
5699
|
-
}
|
|
5700
5573
|
function computeTokensParametersToVertex(apiClient, fromObject) {
|
|
5701
5574
|
const toObject = {};
|
|
5702
5575
|
const fromModel = getValueByPath(fromObject, ['model']);
|
|
@@ -6066,7 +5939,7 @@ function contentEmbeddingFromVertex(apiClient, fromObject) {
|
|
|
6066
5939
|
}
|
|
6067
5940
|
return toObject;
|
|
6068
5941
|
}
|
|
6069
|
-
function embedContentMetadataFromMldev(
|
|
5942
|
+
function embedContentMetadataFromMldev() {
|
|
6070
5943
|
const toObject = {};
|
|
6071
5944
|
return toObject;
|
|
6072
5945
|
}
|
|
@@ -6153,6 +6026,42 @@ function imageFromVertex(apiClient, fromObject) {
|
|
|
6153
6026
|
}
|
|
6154
6027
|
return toObject;
|
|
6155
6028
|
}
|
|
6029
|
+
function safetyAttributesFromMldev(apiClient, fromObject) {
|
|
6030
|
+
const toObject = {};
|
|
6031
|
+
const fromCategories = getValueByPath(fromObject, [
|
|
6032
|
+
'safetyAttributes',
|
|
6033
|
+
'categories',
|
|
6034
|
+
]);
|
|
6035
|
+
if (fromCategories != null) {
|
|
6036
|
+
setValueByPath(toObject, ['categories'], fromCategories);
|
|
6037
|
+
}
|
|
6038
|
+
const fromScores = getValueByPath(fromObject, [
|
|
6039
|
+
'safetyAttributes',
|
|
6040
|
+
'scores',
|
|
6041
|
+
]);
|
|
6042
|
+
if (fromScores != null) {
|
|
6043
|
+
setValueByPath(toObject, ['scores'], fromScores);
|
|
6044
|
+
}
|
|
6045
|
+
return toObject;
|
|
6046
|
+
}
|
|
6047
|
+
function safetyAttributesFromVertex(apiClient, fromObject) {
|
|
6048
|
+
const toObject = {};
|
|
6049
|
+
const fromCategories = getValueByPath(fromObject, [
|
|
6050
|
+
'safetyAttributes',
|
|
6051
|
+
'categories',
|
|
6052
|
+
]);
|
|
6053
|
+
if (fromCategories != null) {
|
|
6054
|
+
setValueByPath(toObject, ['categories'], fromCategories);
|
|
6055
|
+
}
|
|
6056
|
+
const fromScores = getValueByPath(fromObject, [
|
|
6057
|
+
'safetyAttributes',
|
|
6058
|
+
'scores',
|
|
6059
|
+
]);
|
|
6060
|
+
if (fromScores != null) {
|
|
6061
|
+
setValueByPath(toObject, ['scores'], fromScores);
|
|
6062
|
+
}
|
|
6063
|
+
return toObject;
|
|
6064
|
+
}
|
|
6156
6065
|
function generatedImageFromMldev(apiClient, fromObject) {
|
|
6157
6066
|
const toObject = {};
|
|
6158
6067
|
const fromImage = getValueByPath(fromObject, ['_self']);
|
|
@@ -6165,6 +6074,10 @@ function generatedImageFromMldev(apiClient, fromObject) {
|
|
|
6165
6074
|
if (fromRaiFilteredReason != null) {
|
|
6166
6075
|
setValueByPath(toObject, ['raiFilteredReason'], fromRaiFilteredReason);
|
|
6167
6076
|
}
|
|
6077
|
+
const fromSafetyAttributes = getValueByPath(fromObject, ['_self']);
|
|
6078
|
+
if (fromSafetyAttributes != null) {
|
|
6079
|
+
setValueByPath(toObject, ['safetyAttributes'], safetyAttributesFromMldev(apiClient, fromSafetyAttributes));
|
|
6080
|
+
}
|
|
6168
6081
|
return toObject;
|
|
6169
6082
|
}
|
|
6170
6083
|
function generatedImageFromVertex(apiClient, fromObject) {
|
|
@@ -6179,6 +6092,10 @@ function generatedImageFromVertex(apiClient, fromObject) {
|
|
|
6179
6092
|
if (fromRaiFilteredReason != null) {
|
|
6180
6093
|
setValueByPath(toObject, ['raiFilteredReason'], fromRaiFilteredReason);
|
|
6181
6094
|
}
|
|
6095
|
+
const fromSafetyAttributes = getValueByPath(fromObject, ['_self']);
|
|
6096
|
+
if (fromSafetyAttributes != null) {
|
|
6097
|
+
setValueByPath(toObject, ['safetyAttributes'], safetyAttributesFromVertex(apiClient, fromSafetyAttributes));
|
|
6098
|
+
}
|
|
6182
6099
|
const fromEnhancedPrompt = getValueByPath(fromObject, ['prompt']);
|
|
6183
6100
|
if (fromEnhancedPrompt != null) {
|
|
6184
6101
|
setValueByPath(toObject, ['enhancedPrompt'], fromEnhancedPrompt);
|
|
@@ -6241,14 +6158,6 @@ function countTokensResponseFromVertex(apiClient, fromObject) {
|
|
|
6241
6158
|
}
|
|
6242
6159
|
return toObject;
|
|
6243
6160
|
}
|
|
6244
|
-
function computeTokensResponseFromMldev(apiClient, fromObject) {
|
|
6245
|
-
const toObject = {};
|
|
6246
|
-
const fromTokensInfo = getValueByPath(fromObject, ['tokensInfo']);
|
|
6247
|
-
if (fromTokensInfo != null) {
|
|
6248
|
-
setValueByPath(toObject, ['tokensInfo'], fromTokensInfo);
|
|
6249
|
-
}
|
|
6250
|
-
return toObject;
|
|
6251
|
-
}
|
|
6252
6161
|
function computeTokensResponseFromVertex(apiClient, fromObject) {
|
|
6253
6162
|
const toObject = {};
|
|
6254
6163
|
const fromTokensInfo = getValueByPath(fromObject, ['tokensInfo']);
|
|
@@ -6260,7 +6169,7 @@ function computeTokensResponseFromVertex(apiClient, fromObject) {
|
|
|
6260
6169
|
|
|
6261
6170
|
/**
|
|
6262
6171
|
* @license
|
|
6263
|
-
* Copyright
|
|
6172
|
+
* Copyright 2025 Google LLC
|
|
6264
6173
|
* SPDX-License-Identifier: Apache-2.0
|
|
6265
6174
|
*/
|
|
6266
6175
|
const FUNCTION_RESPONSE_REQUIRES_ID = 'FunctionResponse request must have an `id` field from the response of a ToolCall.FunctionalCalls in Google AI.';
|
|
@@ -6521,6 +6430,12 @@ function liveServerMessageFromVertex(apiClient, fromObject) {
|
|
|
6521
6430
|
/**
|
|
6522
6431
|
* Handles incoming messages from the WebSocket.
|
|
6523
6432
|
*
|
|
6433
|
+
* @remarks
|
|
6434
|
+
* This function is responsible for parsing incoming messages, transforming them
|
|
6435
|
+
* into LiveServerMessages, and then calling the onmessage callback. Note that
|
|
6436
|
+
* the first message which is received from the server is a setupComplete
|
|
6437
|
+
* message.
|
|
6438
|
+
*
|
|
6524
6439
|
* @param apiClient The ApiClient instance.
|
|
6525
6440
|
* @param onmessage The user-provided onmessage callback (if any).
|
|
6526
6441
|
* @param event The MessageEvent from the WebSocket.
|
|
@@ -6558,20 +6473,14 @@ class Live {
|
|
|
6558
6473
|
Establishes a connection to the specified model with the given
|
|
6559
6474
|
configuration and returns a Session object representing that connection.
|
|
6560
6475
|
|
|
6561
|
-
> [!CAUTION] This SDK does not yet support the live API for **Google Vertex AI**.
|
|
6562
|
-
|
|
6563
6476
|
@experimental
|
|
6564
6477
|
|
|
6565
|
-
@param
|
|
6566
|
-
@
|
|
6567
|
-
@param callbacks - Optional callbacks for websocket events. If not
|
|
6568
|
-
provided, default no-op callbacks will be used. Generally, prefer to
|
|
6569
|
-
provide explicit callbacks to allow for proper handling of websocket
|
|
6570
|
-
events (e.g. connection errors).
|
|
6478
|
+
@param params - The parameters for establishing a connection to the model.
|
|
6479
|
+
@return A live session.
|
|
6571
6480
|
|
|
6572
6481
|
@example
|
|
6573
6482
|
```ts
|
|
6574
|
-
const session = await
|
|
6483
|
+
const session = await ai.live.connect({
|
|
6575
6484
|
model: 'gemini-2.0-flash-exp',
|
|
6576
6485
|
config: {
|
|
6577
6486
|
responseModalities: [Modality.AUDIO],
|
|
@@ -6595,9 +6504,6 @@ class Live {
|
|
|
6595
6504
|
*/
|
|
6596
6505
|
async connect(params) {
|
|
6597
6506
|
var _a, _b;
|
|
6598
|
-
if (this.apiClient.isVertexAI()) {
|
|
6599
|
-
throw new Error('This SDK does not yet support the live API for **Google Vertex AI**.');
|
|
6600
|
-
}
|
|
6601
6507
|
const websocketBaseUrl = this.apiClient.getWebsocketBaseUrl();
|
|
6602
6508
|
const apiVersion = this.apiClient.getApiVersion();
|
|
6603
6509
|
let url;
|
|
@@ -6673,8 +6579,7 @@ class Session {
|
|
|
6673
6579
|
if (params.turns !== null && params.turns !== undefined) {
|
|
6674
6580
|
let contents = [];
|
|
6675
6581
|
try {
|
|
6676
|
-
contents =
|
|
6677
|
-
tContents(apiClient, params.turns);
|
|
6582
|
+
contents = tContents(apiClient, params.turns);
|
|
6678
6583
|
if (apiClient.isVertexAI()) {
|
|
6679
6584
|
contents = contents.map((item) => contentToVertex(apiClient, item));
|
|
6680
6585
|
}
|
|
@@ -6714,8 +6619,10 @@ class Session {
|
|
|
6714
6619
|
throw new Error('functionResponses is required.');
|
|
6715
6620
|
}
|
|
6716
6621
|
for (const functionResponse of functionResponses) {
|
|
6717
|
-
if (typeof functionResponse !== 'object' ||
|
|
6718
|
-
|
|
6622
|
+
if (typeof functionResponse !== 'object' ||
|
|
6623
|
+
functionResponse === null ||
|
|
6624
|
+
!('name' in functionResponse) ||
|
|
6625
|
+
!('response' in functionResponse)) {
|
|
6719
6626
|
throw new Error(`Could not parse function response, type '${typeof functionResponse}'.`);
|
|
6720
6627
|
}
|
|
6721
6628
|
if (!apiClient.isVertexAI() && !('id' in functionResponse)) {
|
|
@@ -6723,7 +6630,7 @@ class Session {
|
|
|
6723
6630
|
}
|
|
6724
6631
|
}
|
|
6725
6632
|
const clientMessage = {
|
|
6726
|
-
toolResponse: { functionResponses: functionResponses }
|
|
6633
|
+
toolResponse: { functionResponses: functionResponses },
|
|
6727
6634
|
};
|
|
6728
6635
|
return clientMessage;
|
|
6729
6636
|
}
|
|
@@ -6841,7 +6748,7 @@ class Session {
|
|
|
6841
6748
|
|
|
6842
6749
|
@example
|
|
6843
6750
|
```ts
|
|
6844
|
-
const session = await
|
|
6751
|
+
const session = await ai.live.connect({
|
|
6845
6752
|
model: 'gemini-2.0-flash-exp',
|
|
6846
6753
|
config: {
|
|
6847
6754
|
responseModalities: [Modality.AUDIO],
|
|
@@ -6992,7 +6899,6 @@ exports.createPartFromFunctionCall = createPartFromFunctionCall;
|
|
|
6992
6899
|
exports.createPartFromFunctionResponse = createPartFromFunctionResponse;
|
|
6993
6900
|
exports.createPartFromText = createPartFromText;
|
|
6994
6901
|
exports.createPartFromUri = createPartFromUri;
|
|
6995
|
-
exports.createPartFromVideoMetadata = createPartFromVideoMetadata;
|
|
6996
6902
|
exports.createUserContent = createUserContent;
|
|
6997
6903
|
exports.toolToMldev = toolToMldev$1;
|
|
6998
6904
|
exports.toolToVertex = toolToVertex$1;
|