@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/node/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @license
|
|
29
|
-
* Copyright
|
|
29
|
+
* Copyright 2025 Google LLC
|
|
30
30
|
* SPDX-License-Identifier: Apache-2.0
|
|
31
31
|
*/
|
|
32
32
|
class BaseModule {
|
|
@@ -153,7 +153,7 @@ function getValueByPath(data, keys) {
|
|
|
153
153
|
|
|
154
154
|
/**
|
|
155
155
|
* @license
|
|
156
|
-
* Copyright
|
|
156
|
+
* Copyright 2025 Google LLC
|
|
157
157
|
* SPDX-License-Identifier: Apache-2.0
|
|
158
158
|
*/
|
|
159
159
|
function tModel(apiClient, model) {
|
|
@@ -378,9 +378,6 @@ function processSchema(apiClient, schema) {
|
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
if ('anyOf' in schema) {
|
|
381
|
-
if (!apiClient.isVertexAI()) {
|
|
382
|
-
throw new Error('AnyOf is not supported in the response schema for the Gemini API.');
|
|
383
|
-
}
|
|
384
381
|
if (schema['anyOf'] !== undefined) {
|
|
385
382
|
for (const subSchema of schema['anyOf']) {
|
|
386
383
|
processSchema(apiClient, subSchema);
|
|
@@ -521,14 +518,12 @@ function tFileName(apiClient, fromName) {
|
|
|
521
518
|
|
|
522
519
|
/**
|
|
523
520
|
* @license
|
|
524
|
-
* Copyright
|
|
521
|
+
* Copyright 2025 Google LLC
|
|
525
522
|
* SPDX-License-Identifier: Apache-2.0
|
|
526
523
|
*/
|
|
527
524
|
/**
|
|
528
525
|
* @fileoverview Pagers for the GenAI List APIs.
|
|
529
526
|
*/
|
|
530
|
-
// TODO(b/401555348): Re-enable linting after enforcing strong types.
|
|
531
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
532
527
|
var PagedItem;
|
|
533
528
|
(function (PagedItem) {
|
|
534
529
|
PagedItem["PAGED_ITEM_BATCH_JOBS"] = "batchJobs";
|
|
@@ -543,6 +538,7 @@ var PagedItem;
|
|
|
543
538
|
class Pager {
|
|
544
539
|
constructor(name, request, response, params) {
|
|
545
540
|
this.pageInternal = [];
|
|
541
|
+
this.paramsInternal = {};
|
|
546
542
|
this.requestInternal = request;
|
|
547
543
|
this.init(name, response, params);
|
|
548
544
|
}
|
|
@@ -699,7 +695,7 @@ class Pager {
|
|
|
699
695
|
|
|
700
696
|
/**
|
|
701
697
|
* @license
|
|
702
|
-
* Copyright
|
|
698
|
+
* Copyright 2025 Google LLC
|
|
703
699
|
* SPDX-License-Identifier: Apache-2.0
|
|
704
700
|
*/
|
|
705
701
|
// Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
@@ -935,17 +931,6 @@ function createPartFromBase64(data, mimeType) {
|
|
|
935
931
|
},
|
|
936
932
|
};
|
|
937
933
|
}
|
|
938
|
-
/**
|
|
939
|
-
* Creates a `Part` object from the `startOffset` and `endOffset` of a `VideoMetadata` object.
|
|
940
|
-
*/
|
|
941
|
-
function createPartFromVideoMetadata(startOffset, endOffset) {
|
|
942
|
-
return {
|
|
943
|
-
videoMetadata: {
|
|
944
|
-
startOffset: startOffset,
|
|
945
|
-
endOffset: endOffset,
|
|
946
|
-
},
|
|
947
|
-
};
|
|
948
|
-
}
|
|
949
934
|
/**
|
|
950
935
|
* Creates a `Part` object from the `outcome` and `output` of a `CodeExecutionResult` object.
|
|
951
936
|
*/
|
|
@@ -1288,7 +1273,7 @@ class SessionSendToolResponseParameters {
|
|
|
1288
1273
|
|
|
1289
1274
|
/**
|
|
1290
1275
|
* @license
|
|
1291
|
-
* Copyright
|
|
1276
|
+
* Copyright 2025 Google LLC
|
|
1292
1277
|
* SPDX-License-Identifier: Apache-2.0
|
|
1293
1278
|
*/
|
|
1294
1279
|
class Caches extends BaseModule {
|
|
@@ -1303,7 +1288,7 @@ class Caches extends BaseModule {
|
|
|
1303
1288
|
*
|
|
1304
1289
|
* @example
|
|
1305
1290
|
* ```ts
|
|
1306
|
-
* const cachedContents = await
|
|
1291
|
+
* const cachedContents = await ai.caches.list({config: {'pageSize': 2}});
|
|
1307
1292
|
* for (const cachedContent of cachedContents) {
|
|
1308
1293
|
* console.log(cachedContent);
|
|
1309
1294
|
* }
|
|
@@ -1322,7 +1307,7 @@ class Caches extends BaseModule {
|
|
|
1322
1307
|
* @example
|
|
1323
1308
|
* ```ts
|
|
1324
1309
|
* const contents = ...; // Initialize the content to cache.
|
|
1325
|
-
* const response = await
|
|
1310
|
+
* const response = await ai.caches.create({
|
|
1326
1311
|
* model: 'gemini-2.0-flash',
|
|
1327
1312
|
* config: {
|
|
1328
1313
|
* 'contents': contents,
|
|
@@ -1393,7 +1378,7 @@ class Caches extends BaseModule {
|
|
|
1393
1378
|
*
|
|
1394
1379
|
* @example
|
|
1395
1380
|
* ```ts
|
|
1396
|
-
* await
|
|
1381
|
+
* await ai.caches.get({name: 'gemini-1.5-flash'});
|
|
1397
1382
|
* ```
|
|
1398
1383
|
*/
|
|
1399
1384
|
async get(params) {
|
|
@@ -1456,7 +1441,7 @@ class Caches extends BaseModule {
|
|
|
1456
1441
|
*
|
|
1457
1442
|
* @example
|
|
1458
1443
|
* ```ts
|
|
1459
|
-
* await
|
|
1444
|
+
* await ai.caches.delete({name: 'gemini-1.5-flash'});
|
|
1460
1445
|
* ```
|
|
1461
1446
|
*/
|
|
1462
1447
|
async delete(params) {
|
|
@@ -1483,7 +1468,7 @@ class Caches extends BaseModule {
|
|
|
1483
1468
|
return httpResponse.json();
|
|
1484
1469
|
});
|
|
1485
1470
|
return response.then((apiResponse) => {
|
|
1486
|
-
const resp = deleteCachedContentResponseFromVertex(
|
|
1471
|
+
const resp = deleteCachedContentResponseFromVertex();
|
|
1487
1472
|
const typedResp = new DeleteCachedContentResponse();
|
|
1488
1473
|
Object.assign(typedResp, resp);
|
|
1489
1474
|
return typedResp;
|
|
@@ -1508,7 +1493,7 @@ class Caches extends BaseModule {
|
|
|
1508
1493
|
return httpResponse.json();
|
|
1509
1494
|
});
|
|
1510
1495
|
return response.then((apiResponse) => {
|
|
1511
|
-
const resp = deleteCachedContentResponseFromMldev(
|
|
1496
|
+
const resp = deleteCachedContentResponseFromMldev();
|
|
1512
1497
|
const typedResp = new DeleteCachedContentResponse();
|
|
1513
1498
|
Object.assign(typedResp, resp);
|
|
1514
1499
|
return typedResp;
|
|
@@ -1523,7 +1508,7 @@ class Caches extends BaseModule {
|
|
|
1523
1508
|
*
|
|
1524
1509
|
* @example
|
|
1525
1510
|
* ```ts
|
|
1526
|
-
* const response = await
|
|
1511
|
+
* const response = await ai.caches.update({
|
|
1527
1512
|
* name: 'gemini-1.5-flash',
|
|
1528
1513
|
* config: {'ttl': '7600s'}
|
|
1529
1514
|
* });
|
|
@@ -1781,18 +1766,10 @@ function schemaToVertex$1(apiClient, fromObject) {
|
|
|
1781
1766
|
if (fromPattern != null) {
|
|
1782
1767
|
setValueByPath(toObject, ['pattern'], fromPattern);
|
|
1783
1768
|
}
|
|
1784
|
-
const fromMinimum = getValueByPath(fromObject, ['minimum']);
|
|
1785
|
-
if (fromMinimum != null) {
|
|
1786
|
-
setValueByPath(toObject, ['minimum'], fromMinimum);
|
|
1787
|
-
}
|
|
1788
1769
|
const fromDefault = getValueByPath(fromObject, ['default']);
|
|
1789
1770
|
if (fromDefault != null) {
|
|
1790
1771
|
setValueByPath(toObject, ['default'], fromDefault);
|
|
1791
1772
|
}
|
|
1792
|
-
const fromAnyOf = getValueByPath(fromObject, ['anyOf']);
|
|
1793
|
-
if (fromAnyOf != null) {
|
|
1794
|
-
setValueByPath(toObject, ['anyOf'], fromAnyOf);
|
|
1795
|
-
}
|
|
1796
1773
|
const fromMaxLength = getValueByPath(fromObject, ['maxLength']);
|
|
1797
1774
|
if (fromMaxLength != null) {
|
|
1798
1775
|
setValueByPath(toObject, ['maxLength'], fromMaxLength);
|
|
@@ -1811,16 +1788,16 @@ function schemaToVertex$1(apiClient, fromObject) {
|
|
|
1811
1788
|
if (fromMinProperties != null) {
|
|
1812
1789
|
setValueByPath(toObject, ['minProperties'], fromMinProperties);
|
|
1813
1790
|
}
|
|
1814
|
-
const fromMaximum = getValueByPath(fromObject, ['maximum']);
|
|
1815
|
-
if (fromMaximum != null) {
|
|
1816
|
-
setValueByPath(toObject, ['maximum'], fromMaximum);
|
|
1817
|
-
}
|
|
1818
1791
|
const fromMaxProperties = getValueByPath(fromObject, [
|
|
1819
1792
|
'maxProperties',
|
|
1820
1793
|
]);
|
|
1821
1794
|
if (fromMaxProperties != null) {
|
|
1822
1795
|
setValueByPath(toObject, ['maxProperties'], fromMaxProperties);
|
|
1823
1796
|
}
|
|
1797
|
+
const fromAnyOf = getValueByPath(fromObject, ['anyOf']);
|
|
1798
|
+
if (fromAnyOf != null) {
|
|
1799
|
+
setValueByPath(toObject, ['anyOf'], fromAnyOf);
|
|
1800
|
+
}
|
|
1824
1801
|
const fromDescription = getValueByPath(fromObject, ['description']);
|
|
1825
1802
|
if (fromDescription != null) {
|
|
1826
1803
|
setValueByPath(toObject, ['description'], fromDescription);
|
|
@@ -1841,10 +1818,18 @@ function schemaToVertex$1(apiClient, fromObject) {
|
|
|
1841
1818
|
if (fromMaxItems != null) {
|
|
1842
1819
|
setValueByPath(toObject, ['maxItems'], fromMaxItems);
|
|
1843
1820
|
}
|
|
1821
|
+
const fromMaximum = getValueByPath(fromObject, ['maximum']);
|
|
1822
|
+
if (fromMaximum != null) {
|
|
1823
|
+
setValueByPath(toObject, ['maximum'], fromMaximum);
|
|
1824
|
+
}
|
|
1844
1825
|
const fromMinItems = getValueByPath(fromObject, ['minItems']);
|
|
1845
1826
|
if (fromMinItems != null) {
|
|
1846
1827
|
setValueByPath(toObject, ['minItems'], fromMinItems);
|
|
1847
1828
|
}
|
|
1829
|
+
const fromMinimum = getValueByPath(fromObject, ['minimum']);
|
|
1830
|
+
if (fromMinimum != null) {
|
|
1831
|
+
setValueByPath(toObject, ['minimum'], fromMinimum);
|
|
1832
|
+
}
|
|
1848
1833
|
const fromNullable = getValueByPath(fromObject, ['nullable']);
|
|
1849
1834
|
if (fromNullable != null) {
|
|
1850
1835
|
setValueByPath(toObject, ['nullable'], fromNullable);
|
|
@@ -1908,11 +1893,11 @@ function functionDeclarationToVertex$1(apiClient, fromObject) {
|
|
|
1908
1893
|
}
|
|
1909
1894
|
return toObject;
|
|
1910
1895
|
}
|
|
1911
|
-
function googleSearchToMldev$1(
|
|
1896
|
+
function googleSearchToMldev$1() {
|
|
1912
1897
|
const toObject = {};
|
|
1913
1898
|
return toObject;
|
|
1914
1899
|
}
|
|
1915
|
-
function googleSearchToVertex$1(
|
|
1900
|
+
function googleSearchToVertex$1() {
|
|
1916
1901
|
const toObject = {};
|
|
1917
1902
|
return toObject;
|
|
1918
1903
|
}
|
|
@@ -2411,11 +2396,11 @@ function cachedContentFromVertex(apiClient, fromObject) {
|
|
|
2411
2396
|
}
|
|
2412
2397
|
return toObject;
|
|
2413
2398
|
}
|
|
2414
|
-
function deleteCachedContentResponseFromMldev(
|
|
2399
|
+
function deleteCachedContentResponseFromMldev() {
|
|
2415
2400
|
const toObject = {};
|
|
2416
2401
|
return toObject;
|
|
2417
2402
|
}
|
|
2418
|
-
function deleteCachedContentResponseFromVertex(
|
|
2403
|
+
function deleteCachedContentResponseFromVertex() {
|
|
2419
2404
|
const toObject = {};
|
|
2420
2405
|
return toObject;
|
|
2421
2406
|
}
|
|
@@ -2527,7 +2512,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
2527
2512
|
|
|
2528
2513
|
/**
|
|
2529
2514
|
* @license
|
|
2530
|
-
* Copyright
|
|
2515
|
+
* Copyright 2025 Google LLC
|
|
2531
2516
|
* SPDX-License-Identifier: Apache-2.0
|
|
2532
2517
|
*/
|
|
2533
2518
|
/**
|
|
@@ -2632,16 +2617,35 @@ class Chats {
|
|
|
2632
2617
|
/**
|
|
2633
2618
|
* Creates a new chat session.
|
|
2634
2619
|
*
|
|
2620
|
+
* @remarks
|
|
2621
|
+
* The config in the params will be used for all requests within the chat
|
|
2622
|
+
* session unless overridden by a per-request `config` in
|
|
2623
|
+
* {@link ./types.SendMessageParameters}.
|
|
2624
|
+
*
|
|
2635
2625
|
* @param params - Parameters for creating a chat session.
|
|
2636
2626
|
* @returns A new chat session.
|
|
2627
|
+
*
|
|
2628
|
+
* @example
|
|
2629
|
+
* ```ts
|
|
2630
|
+
* const chat = ai.chats.create({
|
|
2631
|
+
* model: 'gemini-2.0-flash'
|
|
2632
|
+
* config: {
|
|
2633
|
+
* temperature: 0.5,
|
|
2634
|
+
* maxOutputTokens: 1024,
|
|
2635
|
+
* }
|
|
2636
|
+
* });
|
|
2637
|
+
* ```
|
|
2637
2638
|
*/
|
|
2638
2639
|
create(params) {
|
|
2639
2640
|
return new Chat(this.apiClient, this.modelsModule, params.model, params.config, params.history);
|
|
2640
2641
|
}
|
|
2641
2642
|
}
|
|
2642
2643
|
/**
|
|
2643
|
-
* Chat session that enables sending messages
|
|
2644
|
-
*
|
|
2644
|
+
* Chat session that enables sending messages to the model with previous
|
|
2645
|
+
* conversation context.
|
|
2646
|
+
*
|
|
2647
|
+
* @remarks
|
|
2648
|
+
* The session maintains all the turns between user and model.
|
|
2645
2649
|
*/
|
|
2646
2650
|
class Chat {
|
|
2647
2651
|
constructor(apiClient, modelsModule, model, config = {}, history = []) {
|
|
@@ -2665,6 +2669,15 @@ class Chat {
|
|
|
2665
2669
|
* @see {@link Chat#sendMessageStream} for streaming method.
|
|
2666
2670
|
* @param params - parameters for sending messages within a chat session.
|
|
2667
2671
|
* @returns The model's response.
|
|
2672
|
+
*
|
|
2673
|
+
* @example
|
|
2674
|
+
* ```ts
|
|
2675
|
+
* const chat = ai.chats.create({model: 'gemini-2.0-flash'});
|
|
2676
|
+
* const response = await chat.sendMessage({
|
|
2677
|
+
* message: 'Why is the sky blue?'
|
|
2678
|
+
* });
|
|
2679
|
+
* console.log(response.text);
|
|
2680
|
+
* ```
|
|
2668
2681
|
*/
|
|
2669
2682
|
async sendMessage(params) {
|
|
2670
2683
|
var _a;
|
|
@@ -2696,6 +2709,17 @@ class Chat {
|
|
|
2696
2709
|
* @see {@link Chat#sendMessage} for non-streaming method.
|
|
2697
2710
|
* @param params - parameters for sending the message.
|
|
2698
2711
|
* @return The model's response.
|
|
2712
|
+
*
|
|
2713
|
+
* @example
|
|
2714
|
+
* ```ts
|
|
2715
|
+
* const chat = ai.chats.create({model: 'gemini-2.0-flash'});
|
|
2716
|
+
* const response = await chat.sendMessageStream({
|
|
2717
|
+
* message: 'Why is the sky blue?'
|
|
2718
|
+
* });
|
|
2719
|
+
* for await (const chunk of response) {
|
|
2720
|
+
* console.log(chunk.text);
|
|
2721
|
+
* }
|
|
2722
|
+
* ```
|
|
2699
2723
|
*/
|
|
2700
2724
|
async sendMessageStream(params) {
|
|
2701
2725
|
var _a;
|
|
@@ -2787,7 +2811,7 @@ class Chat {
|
|
|
2787
2811
|
|
|
2788
2812
|
/**
|
|
2789
2813
|
* @license
|
|
2790
|
-
* Copyright
|
|
2814
|
+
* Copyright 2025 Google LLC
|
|
2791
2815
|
* SPDX-License-Identifier: Apache-2.0
|
|
2792
2816
|
*/
|
|
2793
2817
|
class Models extends BaseModule {
|
|
@@ -2817,14 +2841,12 @@ class Models extends BaseModule {
|
|
|
2817
2841
|
*
|
|
2818
2842
|
* Some models support multimodal input and output.
|
|
2819
2843
|
*
|
|
2820
|
-
* @param
|
|
2821
|
-
* @param contents - The input contents to use for generating content.
|
|
2822
|
-
* @param [config] - The configuration for generating content.
|
|
2844
|
+
* @param params - The parameters for generating content.
|
|
2823
2845
|
* @return The response from generating content.
|
|
2824
2846
|
*
|
|
2825
2847
|
* @example
|
|
2826
2848
|
* ```ts
|
|
2827
|
-
* const response = await
|
|
2849
|
+
* const response = await ai.models.generateContent({
|
|
2828
2850
|
* model: 'gemini-2.0-flash',
|
|
2829
2851
|
* contents: 'why is the sky blue?',
|
|
2830
2852
|
* config: {
|
|
@@ -2861,14 +2883,12 @@ class Models extends BaseModule {
|
|
|
2861
2883
|
*
|
|
2862
2884
|
* Some models support multimodal input and output.
|
|
2863
2885
|
*
|
|
2864
|
-
* @param
|
|
2865
|
-
* @param contents - The input contents to use for generating content.
|
|
2866
|
-
* @param [config] - The configuration for generating content.
|
|
2886
|
+
* @param params - The parameters for generating content with streaming response.
|
|
2867
2887
|
* @return The response from generating content.
|
|
2868
2888
|
*
|
|
2869
2889
|
* @example
|
|
2870
2890
|
* ```ts
|
|
2871
|
-
* const response = await
|
|
2891
|
+
* const response = await ai.models.generateContentStream({
|
|
2872
2892
|
* model: 'gemini-2.0-flash',
|
|
2873
2893
|
* contents: 'why is the sky blue?',
|
|
2874
2894
|
* config: {
|
|
@@ -3027,14 +3047,12 @@ class Models extends BaseModule {
|
|
|
3027
3047
|
/**
|
|
3028
3048
|
* Calculates embeddings for the given contents. Only text is supported.
|
|
3029
3049
|
*
|
|
3030
|
-
* @param
|
|
3031
|
-
* @param contents - The contents to embed.
|
|
3032
|
-
* @param [config] - The config for embedding contents.
|
|
3050
|
+
* @param params - The parameters for embedding contents.
|
|
3033
3051
|
* @return The response from the API.
|
|
3034
3052
|
*
|
|
3035
3053
|
* @example
|
|
3036
3054
|
* ```ts
|
|
3037
|
-
* const response = await
|
|
3055
|
+
* const response = await ai.models.embedContent({
|
|
3038
3056
|
* model: 'text-embedding-004',
|
|
3039
3057
|
* contents: [
|
|
3040
3058
|
* 'What is your name?',
|
|
@@ -3106,14 +3124,12 @@ class Models extends BaseModule {
|
|
|
3106
3124
|
/**
|
|
3107
3125
|
* Generates an image based on a text description and configuration.
|
|
3108
3126
|
*
|
|
3109
|
-
* @param
|
|
3110
|
-
* @param prompt - A text description of the image to generate.
|
|
3111
|
-
* @param [config] - The config for image generation.
|
|
3127
|
+
* @param params - The parameters for generating images.
|
|
3112
3128
|
* @return The response from the API.
|
|
3113
3129
|
*
|
|
3114
3130
|
* @example
|
|
3115
3131
|
* ```ts
|
|
3116
|
-
* const response = await
|
|
3132
|
+
* const response = await ai.models.generateImages({
|
|
3117
3133
|
* model: 'imagen-3.0-generate-002',
|
|
3118
3134
|
* prompt: 'Robot holding a red skateboard',
|
|
3119
3135
|
* config: {
|
|
@@ -3184,14 +3200,12 @@ class Models extends BaseModule {
|
|
|
3184
3200
|
* Counts the number of tokens in the given contents. Multimodal input is
|
|
3185
3201
|
* supported for Gemini models.
|
|
3186
3202
|
*
|
|
3187
|
-
* @param
|
|
3188
|
-
* @param contents - The contents to count tokens for.
|
|
3189
|
-
* @param [config] - The config for counting tokens.
|
|
3203
|
+
* @param params - The parameters for counting tokens.
|
|
3190
3204
|
* @return The response from the API.
|
|
3191
3205
|
*
|
|
3192
3206
|
* @example
|
|
3193
3207
|
* ```ts
|
|
3194
|
-
* const response = await
|
|
3208
|
+
* const response = await ai.models.countTokens({
|
|
3195
3209
|
* model: 'gemini-2.0-flash',
|
|
3196
3210
|
* contents: 'The quick brown fox jumps over the lazy dog.'
|
|
3197
3211
|
* });
|
|
@@ -3260,14 +3274,12 @@ class Models extends BaseModule {
|
|
|
3260
3274
|
*
|
|
3261
3275
|
* This method is not supported by the Gemini Developer API.
|
|
3262
3276
|
*
|
|
3263
|
-
* @param
|
|
3264
|
-
* @param contents - The content to compute tokens for.
|
|
3265
|
-
* @param [config] - The config for computing tokens.
|
|
3277
|
+
* @param params - The parameters for computing tokens.
|
|
3266
3278
|
* @return The response from the API.
|
|
3267
3279
|
*
|
|
3268
3280
|
* @example
|
|
3269
3281
|
* ```ts
|
|
3270
|
-
* const response = await
|
|
3282
|
+
* const response = await ai.models.computeTokens({
|
|
3271
3283
|
* model: 'gemini-2.0-flash',
|
|
3272
3284
|
* contents: 'What is your name?'
|
|
3273
3285
|
* });
|
|
@@ -3275,7 +3287,7 @@ class Models extends BaseModule {
|
|
|
3275
3287
|
* ```
|
|
3276
3288
|
*/
|
|
3277
3289
|
async computeTokens(params) {
|
|
3278
|
-
var _a
|
|
3290
|
+
var _a;
|
|
3279
3291
|
let response;
|
|
3280
3292
|
let path = '';
|
|
3281
3293
|
let queryParams = {};
|
|
@@ -3305,29 +3317,7 @@ class Models extends BaseModule {
|
|
|
3305
3317
|
});
|
|
3306
3318
|
}
|
|
3307
3319
|
else {
|
|
3308
|
-
|
|
3309
|
-
path = formatMap('None', body['_url']);
|
|
3310
|
-
queryParams = body['_query'];
|
|
3311
|
-
delete body['config'];
|
|
3312
|
-
delete body['_url'];
|
|
3313
|
-
delete body['_query'];
|
|
3314
|
-
response = this.apiClient
|
|
3315
|
-
.request({
|
|
3316
|
-
path: path,
|
|
3317
|
-
queryParams: queryParams,
|
|
3318
|
-
body: JSON.stringify(body),
|
|
3319
|
-
httpMethod: 'POST',
|
|
3320
|
-
httpOptions: (_b = params.config) === null || _b === void 0 ? void 0 : _b.httpOptions,
|
|
3321
|
-
})
|
|
3322
|
-
.then((httpResponse) => {
|
|
3323
|
-
return httpResponse.json();
|
|
3324
|
-
});
|
|
3325
|
-
return response.then((apiResponse) => {
|
|
3326
|
-
const resp = computeTokensResponseFromMldev(this.apiClient, apiResponse);
|
|
3327
|
-
const typedResp = new ComputeTokensResponse();
|
|
3328
|
-
Object.assign(typedResp, resp);
|
|
3329
|
-
return typedResp;
|
|
3330
|
-
});
|
|
3320
|
+
throw new Error('This method is only supported by the Vertex AI.');
|
|
3331
3321
|
}
|
|
3332
3322
|
}
|
|
3333
3323
|
}
|
|
@@ -3472,15 +3462,9 @@ function schemaToMldev(apiClient, fromObject) {
|
|
|
3472
3462
|
if (getValueByPath(fromObject, ['pattern']) !== undefined) {
|
|
3473
3463
|
throw new Error('pattern parameter is not supported in Gemini API.');
|
|
3474
3464
|
}
|
|
3475
|
-
if (getValueByPath(fromObject, ['minimum']) !== undefined) {
|
|
3476
|
-
throw new Error('minimum parameter is not supported in Gemini API.');
|
|
3477
|
-
}
|
|
3478
3465
|
if (getValueByPath(fromObject, ['default']) !== undefined) {
|
|
3479
3466
|
throw new Error('default parameter is not supported in Gemini API.');
|
|
3480
3467
|
}
|
|
3481
|
-
if (getValueByPath(fromObject, ['anyOf']) !== undefined) {
|
|
3482
|
-
throw new Error('anyOf parameter is not supported in Gemini API.');
|
|
3483
|
-
}
|
|
3484
3468
|
if (getValueByPath(fromObject, ['maxLength']) !== undefined) {
|
|
3485
3469
|
throw new Error('maxLength parameter is not supported in Gemini API.');
|
|
3486
3470
|
}
|
|
@@ -3493,12 +3477,13 @@ function schemaToMldev(apiClient, fromObject) {
|
|
|
3493
3477
|
if (getValueByPath(fromObject, ['minProperties']) !== undefined) {
|
|
3494
3478
|
throw new Error('minProperties parameter is not supported in Gemini API.');
|
|
3495
3479
|
}
|
|
3496
|
-
if (getValueByPath(fromObject, ['maximum']) !== undefined) {
|
|
3497
|
-
throw new Error('maximum parameter is not supported in Gemini API.');
|
|
3498
|
-
}
|
|
3499
3480
|
if (getValueByPath(fromObject, ['maxProperties']) !== undefined) {
|
|
3500
3481
|
throw new Error('maxProperties parameter is not supported in Gemini API.');
|
|
3501
3482
|
}
|
|
3483
|
+
const fromAnyOf = getValueByPath(fromObject, ['anyOf']);
|
|
3484
|
+
if (fromAnyOf != null) {
|
|
3485
|
+
setValueByPath(toObject, ['anyOf'], fromAnyOf);
|
|
3486
|
+
}
|
|
3502
3487
|
const fromDescription = getValueByPath(fromObject, ['description']);
|
|
3503
3488
|
if (fromDescription != null) {
|
|
3504
3489
|
setValueByPath(toObject, ['description'], fromDescription);
|
|
@@ -3519,10 +3504,18 @@ function schemaToMldev(apiClient, fromObject) {
|
|
|
3519
3504
|
if (fromMaxItems != null) {
|
|
3520
3505
|
setValueByPath(toObject, ['maxItems'], fromMaxItems);
|
|
3521
3506
|
}
|
|
3507
|
+
const fromMaximum = getValueByPath(fromObject, ['maximum']);
|
|
3508
|
+
if (fromMaximum != null) {
|
|
3509
|
+
setValueByPath(toObject, ['maximum'], fromMaximum);
|
|
3510
|
+
}
|
|
3522
3511
|
const fromMinItems = getValueByPath(fromObject, ['minItems']);
|
|
3523
3512
|
if (fromMinItems != null) {
|
|
3524
3513
|
setValueByPath(toObject, ['minItems'], fromMinItems);
|
|
3525
3514
|
}
|
|
3515
|
+
const fromMinimum = getValueByPath(fromObject, ['minimum']);
|
|
3516
|
+
if (fromMinimum != null) {
|
|
3517
|
+
setValueByPath(toObject, ['minimum'], fromMinimum);
|
|
3518
|
+
}
|
|
3526
3519
|
const fromNullable = getValueByPath(fromObject, ['nullable']);
|
|
3527
3520
|
if (fromNullable != null) {
|
|
3528
3521
|
setValueByPath(toObject, ['nullable'], fromNullable);
|
|
@@ -3557,18 +3550,10 @@ function schemaToVertex(apiClient, fromObject) {
|
|
|
3557
3550
|
if (fromPattern != null) {
|
|
3558
3551
|
setValueByPath(toObject, ['pattern'], fromPattern);
|
|
3559
3552
|
}
|
|
3560
|
-
const fromMinimum = getValueByPath(fromObject, ['minimum']);
|
|
3561
|
-
if (fromMinimum != null) {
|
|
3562
|
-
setValueByPath(toObject, ['minimum'], fromMinimum);
|
|
3563
|
-
}
|
|
3564
3553
|
const fromDefault = getValueByPath(fromObject, ['default']);
|
|
3565
3554
|
if (fromDefault != null) {
|
|
3566
3555
|
setValueByPath(toObject, ['default'], fromDefault);
|
|
3567
3556
|
}
|
|
3568
|
-
const fromAnyOf = getValueByPath(fromObject, ['anyOf']);
|
|
3569
|
-
if (fromAnyOf != null) {
|
|
3570
|
-
setValueByPath(toObject, ['anyOf'], fromAnyOf);
|
|
3571
|
-
}
|
|
3572
3557
|
const fromMaxLength = getValueByPath(fromObject, ['maxLength']);
|
|
3573
3558
|
if (fromMaxLength != null) {
|
|
3574
3559
|
setValueByPath(toObject, ['maxLength'], fromMaxLength);
|
|
@@ -3587,16 +3572,16 @@ function schemaToVertex(apiClient, fromObject) {
|
|
|
3587
3572
|
if (fromMinProperties != null) {
|
|
3588
3573
|
setValueByPath(toObject, ['minProperties'], fromMinProperties);
|
|
3589
3574
|
}
|
|
3590
|
-
const fromMaximum = getValueByPath(fromObject, ['maximum']);
|
|
3591
|
-
if (fromMaximum != null) {
|
|
3592
|
-
setValueByPath(toObject, ['maximum'], fromMaximum);
|
|
3593
|
-
}
|
|
3594
3575
|
const fromMaxProperties = getValueByPath(fromObject, [
|
|
3595
3576
|
'maxProperties',
|
|
3596
3577
|
]);
|
|
3597
3578
|
if (fromMaxProperties != null) {
|
|
3598
3579
|
setValueByPath(toObject, ['maxProperties'], fromMaxProperties);
|
|
3599
3580
|
}
|
|
3581
|
+
const fromAnyOf = getValueByPath(fromObject, ['anyOf']);
|
|
3582
|
+
if (fromAnyOf != null) {
|
|
3583
|
+
setValueByPath(toObject, ['anyOf'], fromAnyOf);
|
|
3584
|
+
}
|
|
3600
3585
|
const fromDescription = getValueByPath(fromObject, ['description']);
|
|
3601
3586
|
if (fromDescription != null) {
|
|
3602
3587
|
setValueByPath(toObject, ['description'], fromDescription);
|
|
@@ -3617,10 +3602,18 @@ function schemaToVertex(apiClient, fromObject) {
|
|
|
3617
3602
|
if (fromMaxItems != null) {
|
|
3618
3603
|
setValueByPath(toObject, ['maxItems'], fromMaxItems);
|
|
3619
3604
|
}
|
|
3605
|
+
const fromMaximum = getValueByPath(fromObject, ['maximum']);
|
|
3606
|
+
if (fromMaximum != null) {
|
|
3607
|
+
setValueByPath(toObject, ['maximum'], fromMaximum);
|
|
3608
|
+
}
|
|
3620
3609
|
const fromMinItems = getValueByPath(fromObject, ['minItems']);
|
|
3621
3610
|
if (fromMinItems != null) {
|
|
3622
3611
|
setValueByPath(toObject, ['minItems'], fromMinItems);
|
|
3623
3612
|
}
|
|
3613
|
+
const fromMinimum = getValueByPath(fromObject, ['minimum']);
|
|
3614
|
+
if (fromMinimum != null) {
|
|
3615
|
+
setValueByPath(toObject, ['minimum'], fromMinimum);
|
|
3616
|
+
}
|
|
3624
3617
|
const fromNullable = getValueByPath(fromObject, ['nullable']);
|
|
3625
3618
|
if (fromNullable != null) {
|
|
3626
3619
|
setValueByPath(toObject, ['nullable'], fromNullable);
|
|
@@ -3715,11 +3708,11 @@ function functionDeclarationToVertex(apiClient, fromObject) {
|
|
|
3715
3708
|
}
|
|
3716
3709
|
return toObject;
|
|
3717
3710
|
}
|
|
3718
|
-
function googleSearchToMldev(
|
|
3711
|
+
function googleSearchToMldev() {
|
|
3719
3712
|
const toObject = {};
|
|
3720
3713
|
return toObject;
|
|
3721
3714
|
}
|
|
3722
|
-
function googleSearchToVertex(
|
|
3715
|
+
function googleSearchToVertex() {
|
|
3723
3716
|
const toObject = {};
|
|
3724
3717
|
return toObject;
|
|
3725
3718
|
}
|
|
@@ -4668,21 +4661,6 @@ function countTokensParametersToVertex(apiClient, fromObject) {
|
|
|
4668
4661
|
}
|
|
4669
4662
|
return toObject;
|
|
4670
4663
|
}
|
|
4671
|
-
function computeTokensParametersToMldev(apiClient, fromObject) {
|
|
4672
|
-
const toObject = {};
|
|
4673
|
-
const fromModel = getValueByPath(fromObject, ['model']);
|
|
4674
|
-
if (fromModel != null) {
|
|
4675
|
-
setValueByPath(toObject, ['_url', 'model'], tModel(apiClient, fromModel));
|
|
4676
|
-
}
|
|
4677
|
-
if (getValueByPath(fromObject, ['contents']) !== undefined) {
|
|
4678
|
-
throw new Error('contents parameter is not supported in Gemini API.');
|
|
4679
|
-
}
|
|
4680
|
-
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
4681
|
-
if (fromConfig != null) {
|
|
4682
|
-
setValueByPath(toObject, ['config'], fromConfig);
|
|
4683
|
-
}
|
|
4684
|
-
return toObject;
|
|
4685
|
-
}
|
|
4686
4664
|
function computeTokensParametersToVertex(apiClient, fromObject) {
|
|
4687
4665
|
const toObject = {};
|
|
4688
4666
|
const fromModel = getValueByPath(fromObject, ['model']);
|
|
@@ -5052,7 +5030,7 @@ function contentEmbeddingFromVertex(apiClient, fromObject) {
|
|
|
5052
5030
|
}
|
|
5053
5031
|
return toObject;
|
|
5054
5032
|
}
|
|
5055
|
-
function embedContentMetadataFromMldev(
|
|
5033
|
+
function embedContentMetadataFromMldev() {
|
|
5056
5034
|
const toObject = {};
|
|
5057
5035
|
return toObject;
|
|
5058
5036
|
}
|
|
@@ -5139,6 +5117,42 @@ function imageFromVertex(apiClient, fromObject) {
|
|
|
5139
5117
|
}
|
|
5140
5118
|
return toObject;
|
|
5141
5119
|
}
|
|
5120
|
+
function safetyAttributesFromMldev(apiClient, fromObject) {
|
|
5121
|
+
const toObject = {};
|
|
5122
|
+
const fromCategories = getValueByPath(fromObject, [
|
|
5123
|
+
'safetyAttributes',
|
|
5124
|
+
'categories',
|
|
5125
|
+
]);
|
|
5126
|
+
if (fromCategories != null) {
|
|
5127
|
+
setValueByPath(toObject, ['categories'], fromCategories);
|
|
5128
|
+
}
|
|
5129
|
+
const fromScores = getValueByPath(fromObject, [
|
|
5130
|
+
'safetyAttributes',
|
|
5131
|
+
'scores',
|
|
5132
|
+
]);
|
|
5133
|
+
if (fromScores != null) {
|
|
5134
|
+
setValueByPath(toObject, ['scores'], fromScores);
|
|
5135
|
+
}
|
|
5136
|
+
return toObject;
|
|
5137
|
+
}
|
|
5138
|
+
function safetyAttributesFromVertex(apiClient, fromObject) {
|
|
5139
|
+
const toObject = {};
|
|
5140
|
+
const fromCategories = getValueByPath(fromObject, [
|
|
5141
|
+
'safetyAttributes',
|
|
5142
|
+
'categories',
|
|
5143
|
+
]);
|
|
5144
|
+
if (fromCategories != null) {
|
|
5145
|
+
setValueByPath(toObject, ['categories'], fromCategories);
|
|
5146
|
+
}
|
|
5147
|
+
const fromScores = getValueByPath(fromObject, [
|
|
5148
|
+
'safetyAttributes',
|
|
5149
|
+
'scores',
|
|
5150
|
+
]);
|
|
5151
|
+
if (fromScores != null) {
|
|
5152
|
+
setValueByPath(toObject, ['scores'], fromScores);
|
|
5153
|
+
}
|
|
5154
|
+
return toObject;
|
|
5155
|
+
}
|
|
5142
5156
|
function generatedImageFromMldev(apiClient, fromObject) {
|
|
5143
5157
|
const toObject = {};
|
|
5144
5158
|
const fromImage = getValueByPath(fromObject, ['_self']);
|
|
@@ -5151,6 +5165,10 @@ function generatedImageFromMldev(apiClient, fromObject) {
|
|
|
5151
5165
|
if (fromRaiFilteredReason != null) {
|
|
5152
5166
|
setValueByPath(toObject, ['raiFilteredReason'], fromRaiFilteredReason);
|
|
5153
5167
|
}
|
|
5168
|
+
const fromSafetyAttributes = getValueByPath(fromObject, ['_self']);
|
|
5169
|
+
if (fromSafetyAttributes != null) {
|
|
5170
|
+
setValueByPath(toObject, ['safetyAttributes'], safetyAttributesFromMldev(apiClient, fromSafetyAttributes));
|
|
5171
|
+
}
|
|
5154
5172
|
return toObject;
|
|
5155
5173
|
}
|
|
5156
5174
|
function generatedImageFromVertex(apiClient, fromObject) {
|
|
@@ -5165,6 +5183,10 @@ function generatedImageFromVertex(apiClient, fromObject) {
|
|
|
5165
5183
|
if (fromRaiFilteredReason != null) {
|
|
5166
5184
|
setValueByPath(toObject, ['raiFilteredReason'], fromRaiFilteredReason);
|
|
5167
5185
|
}
|
|
5186
|
+
const fromSafetyAttributes = getValueByPath(fromObject, ['_self']);
|
|
5187
|
+
if (fromSafetyAttributes != null) {
|
|
5188
|
+
setValueByPath(toObject, ['safetyAttributes'], safetyAttributesFromVertex(apiClient, fromSafetyAttributes));
|
|
5189
|
+
}
|
|
5168
5190
|
const fromEnhancedPrompt = getValueByPath(fromObject, ['prompt']);
|
|
5169
5191
|
if (fromEnhancedPrompt != null) {
|
|
5170
5192
|
setValueByPath(toObject, ['enhancedPrompt'], fromEnhancedPrompt);
|
|
@@ -5227,14 +5249,6 @@ function countTokensResponseFromVertex(apiClient, fromObject) {
|
|
|
5227
5249
|
}
|
|
5228
5250
|
return toObject;
|
|
5229
5251
|
}
|
|
5230
|
-
function computeTokensResponseFromMldev(apiClient, fromObject) {
|
|
5231
|
-
const toObject = {};
|
|
5232
|
-
const fromTokensInfo = getValueByPath(fromObject, ['tokensInfo']);
|
|
5233
|
-
if (fromTokensInfo != null) {
|
|
5234
|
-
setValueByPath(toObject, ['tokensInfo'], fromTokensInfo);
|
|
5235
|
-
}
|
|
5236
|
-
return toObject;
|
|
5237
|
-
}
|
|
5238
5252
|
function computeTokensResponseFromVertex(apiClient, fromObject) {
|
|
5239
5253
|
const toObject = {};
|
|
5240
5254
|
const fromTokensInfo = getValueByPath(fromObject, ['tokensInfo']);
|
|
@@ -5246,7 +5260,7 @@ function computeTokensResponseFromVertex(apiClient, fromObject) {
|
|
|
5246
5260
|
|
|
5247
5261
|
/**
|
|
5248
5262
|
* @license
|
|
5249
|
-
* Copyright
|
|
5263
|
+
* Copyright 2025 Google LLC
|
|
5250
5264
|
* SPDX-License-Identifier: Apache-2.0
|
|
5251
5265
|
*/
|
|
5252
5266
|
const FUNCTION_RESPONSE_REQUIRES_ID = 'FunctionResponse request must have an `id` field from the response of a ToolCall.FunctionalCalls in Google AI.';
|
|
@@ -5507,6 +5521,12 @@ function liveServerMessageFromVertex(apiClient, fromObject) {
|
|
|
5507
5521
|
/**
|
|
5508
5522
|
* Handles incoming messages from the WebSocket.
|
|
5509
5523
|
*
|
|
5524
|
+
* @remarks
|
|
5525
|
+
* This function is responsible for parsing incoming messages, transforming them
|
|
5526
|
+
* into LiveServerMessages, and then calling the onmessage callback. Note that
|
|
5527
|
+
* the first message which is received from the server is a setupComplete
|
|
5528
|
+
* message.
|
|
5529
|
+
*
|
|
5510
5530
|
* @param apiClient The ApiClient instance.
|
|
5511
5531
|
* @param onmessage The user-provided onmessage callback (if any).
|
|
5512
5532
|
* @param event The MessageEvent from the WebSocket.
|
|
@@ -5544,20 +5564,14 @@ class Live {
|
|
|
5544
5564
|
Establishes a connection to the specified model with the given
|
|
5545
5565
|
configuration and returns a Session object representing that connection.
|
|
5546
5566
|
|
|
5547
|
-
> [!CAUTION] This SDK does not yet support the live API for **Google Vertex AI**.
|
|
5548
|
-
|
|
5549
5567
|
@experimental
|
|
5550
5568
|
|
|
5551
|
-
@param
|
|
5552
|
-
@
|
|
5553
|
-
@param callbacks - Optional callbacks for websocket events. If not
|
|
5554
|
-
provided, default no-op callbacks will be used. Generally, prefer to
|
|
5555
|
-
provide explicit callbacks to allow for proper handling of websocket
|
|
5556
|
-
events (e.g. connection errors).
|
|
5569
|
+
@param params - The parameters for establishing a connection to the model.
|
|
5570
|
+
@return A live session.
|
|
5557
5571
|
|
|
5558
5572
|
@example
|
|
5559
5573
|
```ts
|
|
5560
|
-
const session = await
|
|
5574
|
+
const session = await ai.live.connect({
|
|
5561
5575
|
model: 'gemini-2.0-flash-exp',
|
|
5562
5576
|
config: {
|
|
5563
5577
|
responseModalities: [Modality.AUDIO],
|
|
@@ -5581,9 +5595,6 @@ class Live {
|
|
|
5581
5595
|
*/
|
|
5582
5596
|
async connect(params) {
|
|
5583
5597
|
var _a, _b;
|
|
5584
|
-
if (this.apiClient.isVertexAI()) {
|
|
5585
|
-
throw new Error('This SDK does not yet support the live API for **Google Vertex AI**.');
|
|
5586
|
-
}
|
|
5587
5598
|
const websocketBaseUrl = this.apiClient.getWebsocketBaseUrl();
|
|
5588
5599
|
const apiVersion = this.apiClient.getApiVersion();
|
|
5589
5600
|
let url;
|
|
@@ -5659,8 +5670,7 @@ class Session {
|
|
|
5659
5670
|
if (params.turns !== null && params.turns !== undefined) {
|
|
5660
5671
|
let contents = [];
|
|
5661
5672
|
try {
|
|
5662
|
-
contents =
|
|
5663
|
-
tContents(apiClient, params.turns);
|
|
5673
|
+
contents = tContents(apiClient, params.turns);
|
|
5664
5674
|
if (apiClient.isVertexAI()) {
|
|
5665
5675
|
contents = contents.map((item) => contentToVertex(apiClient, item));
|
|
5666
5676
|
}
|
|
@@ -5700,8 +5710,10 @@ class Session {
|
|
|
5700
5710
|
throw new Error('functionResponses is required.');
|
|
5701
5711
|
}
|
|
5702
5712
|
for (const functionResponse of functionResponses) {
|
|
5703
|
-
if (typeof functionResponse !== 'object' ||
|
|
5704
|
-
|
|
5713
|
+
if (typeof functionResponse !== 'object' ||
|
|
5714
|
+
functionResponse === null ||
|
|
5715
|
+
!('name' in functionResponse) ||
|
|
5716
|
+
!('response' in functionResponse)) {
|
|
5705
5717
|
throw new Error(`Could not parse function response, type '${typeof functionResponse}'.`);
|
|
5706
5718
|
}
|
|
5707
5719
|
if (!apiClient.isVertexAI() && !('id' in functionResponse)) {
|
|
@@ -5709,7 +5721,7 @@ class Session {
|
|
|
5709
5721
|
}
|
|
5710
5722
|
}
|
|
5711
5723
|
const clientMessage = {
|
|
5712
|
-
toolResponse: { functionResponses: functionResponses }
|
|
5724
|
+
toolResponse: { functionResponses: functionResponses },
|
|
5713
5725
|
};
|
|
5714
5726
|
return clientMessage;
|
|
5715
5727
|
}
|
|
@@ -5827,7 +5839,7 @@ class Session {
|
|
|
5827
5839
|
|
|
5828
5840
|
@example
|
|
5829
5841
|
```ts
|
|
5830
|
-
const session = await
|
|
5842
|
+
const session = await ai.live.connect({
|
|
5831
5843
|
model: 'gemini-2.0-flash-exp',
|
|
5832
5844
|
config: {
|
|
5833
5845
|
responseModalities: [Modality.AUDIO],
|
|
@@ -5864,13 +5876,13 @@ function mapToHeaders(map) {
|
|
|
5864
5876
|
|
|
5865
5877
|
/**
|
|
5866
5878
|
* @license
|
|
5867
|
-
* Copyright
|
|
5879
|
+
* Copyright 2025 Google LLC
|
|
5868
5880
|
* SPDX-License-Identifier: Apache-2.0
|
|
5869
5881
|
*/
|
|
5870
5882
|
const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
5871
5883
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
5872
5884
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
5873
|
-
const SDK_VERSION = '0.
|
|
5885
|
+
const SDK_VERSION = '0.4.0'; // x-release-please-version
|
|
5874
5886
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
5875
5887
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
5876
5888
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -6082,7 +6094,7 @@ class ApiClient {
|
|
|
6082
6094
|
async unaryApiCall(url, requestInit, httpMethod) {
|
|
6083
6095
|
return this.apiCall(url.toString(), Object.assign(Object.assign({}, requestInit), { method: httpMethod }))
|
|
6084
6096
|
.then(async (response) => {
|
|
6085
|
-
await throwErrorIfNotOK(response
|
|
6097
|
+
await throwErrorIfNotOK(response);
|
|
6086
6098
|
return new HttpResponse(response);
|
|
6087
6099
|
})
|
|
6088
6100
|
.catch((e) => {
|
|
@@ -6097,7 +6109,7 @@ class ApiClient {
|
|
|
6097
6109
|
async streamApiCall(url, requestInit, httpMethod) {
|
|
6098
6110
|
return this.apiCall(url.toString(), Object.assign(Object.assign({}, requestInit), { method: httpMethod }))
|
|
6099
6111
|
.then(async (response) => {
|
|
6100
|
-
await throwErrorIfNotOK(response
|
|
6112
|
+
await throwErrorIfNotOK(response);
|
|
6101
6113
|
return this.processStreamResponse(response);
|
|
6102
6114
|
})
|
|
6103
6115
|
.catch((e) => {
|
|
@@ -6242,7 +6254,7 @@ class ApiClient {
|
|
|
6242
6254
|
return uploadUrl;
|
|
6243
6255
|
}
|
|
6244
6256
|
}
|
|
6245
|
-
async function throwErrorIfNotOK(response
|
|
6257
|
+
async function throwErrorIfNotOK(response) {
|
|
6246
6258
|
var _a;
|
|
6247
6259
|
if (response === undefined) {
|
|
6248
6260
|
throw new ServerError('response is undefined');
|
|
@@ -6278,7 +6290,7 @@ async function throwErrorIfNotOK(response, url, requestInit) {
|
|
|
6278
6290
|
|
|
6279
6291
|
/**
|
|
6280
6292
|
* @license
|
|
6281
|
-
* Copyright
|
|
6293
|
+
* Copyright 2025 Google LLC
|
|
6282
6294
|
* SPDX-License-Identifier: Apache-2.0
|
|
6283
6295
|
*/
|
|
6284
6296
|
class Files extends BaseModule {
|
|
@@ -6296,7 +6308,7 @@ class Files extends BaseModule {
|
|
|
6296
6308
|
* size of each page is 10.
|
|
6297
6309
|
*
|
|
6298
6310
|
* ```ts
|
|
6299
|
-
* const listResponse = await
|
|
6311
|
+
* const listResponse = await ai.files.list({config: {'pageSize': 10}});
|
|
6300
6312
|
* for await (const file of listResponse) {
|
|
6301
6313
|
* console.log(file.name);
|
|
6302
6314
|
* }
|
|
@@ -6329,63 +6341,43 @@ class Files extends BaseModule {
|
|
|
6329
6341
|
*
|
|
6330
6342
|
* This section can contain multiple paragraphs and code examples.
|
|
6331
6343
|
*
|
|
6332
|
-
* @param
|
|
6333
|
-
*
|
|
6334
|
-
*
|
|
6344
|
+
* @param params - Optional parameters specified in the
|
|
6345
|
+
* `common.UploadFileParameters` interface.
|
|
6346
|
+
* Optional @see {@link common.UploadFileParameters}
|
|
6335
6347
|
* @return A promise that resolves to a `types.File` object.
|
|
6336
6348
|
* @throws An error if called on a Vertex AI client.
|
|
6337
6349
|
* @throws An error if the `mimeType` is not provided and can not be inferred,
|
|
6338
|
-
* the `mimeType` can be provided in the `config` parameter.
|
|
6350
|
+
* the `mimeType` can be provided in the `params.config` parameter.
|
|
6339
6351
|
* @throws An error occurs if a suitable upload location cannot be established.
|
|
6340
6352
|
*
|
|
6341
6353
|
* @example
|
|
6342
6354
|
* The following code uploads a file to Gemini API.
|
|
6343
6355
|
*
|
|
6344
6356
|
* ```ts
|
|
6345
|
-
* const file = await
|
|
6357
|
+
* const file = await ai.files.upload({file: 'file.txt', config: {
|
|
6346
6358
|
* mimeType: 'text/plain',
|
|
6347
|
-
* });
|
|
6359
|
+
* }});
|
|
6348
6360
|
* console.log(file.name);
|
|
6349
6361
|
* ```
|
|
6350
6362
|
*/
|
|
6351
|
-
async upload(
|
|
6363
|
+
async upload(params) {
|
|
6352
6364
|
if (this.apiClient.isVertexAI()) {
|
|
6353
6365
|
throw new Error('Vertex AI does not support uploading files. You can share files through a GCS bucket.');
|
|
6354
6366
|
}
|
|
6355
|
-
return this.apiClient
|
|
6367
|
+
return this.apiClient
|
|
6368
|
+
.uploadFile(params.file, params.config)
|
|
6369
|
+
.then((response) => {
|
|
6356
6370
|
const file = fileFromMldev(this.apiClient, response);
|
|
6357
6371
|
return file;
|
|
6358
6372
|
});
|
|
6359
6373
|
}
|
|
6360
6374
|
async listInternal(params) {
|
|
6361
|
-
var _a
|
|
6375
|
+
var _a;
|
|
6362
6376
|
let response;
|
|
6363
6377
|
let path = '';
|
|
6364
6378
|
let queryParams = {};
|
|
6365
6379
|
if (this.apiClient.isVertexAI()) {
|
|
6366
|
-
|
|
6367
|
-
path = formatMap('None', body['_url']);
|
|
6368
|
-
queryParams = body['_query'];
|
|
6369
|
-
delete body['config'];
|
|
6370
|
-
delete body['_url'];
|
|
6371
|
-
delete body['_query'];
|
|
6372
|
-
response = this.apiClient
|
|
6373
|
-
.request({
|
|
6374
|
-
path: path,
|
|
6375
|
-
queryParams: queryParams,
|
|
6376
|
-
body: JSON.stringify(body),
|
|
6377
|
-
httpMethod: 'GET',
|
|
6378
|
-
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
6379
|
-
})
|
|
6380
|
-
.then((httpResponse) => {
|
|
6381
|
-
return httpResponse.json();
|
|
6382
|
-
});
|
|
6383
|
-
return response.then((apiResponse) => {
|
|
6384
|
-
const resp = listFilesResponseFromVertex(this.apiClient);
|
|
6385
|
-
const typedResp = new ListFilesResponse();
|
|
6386
|
-
Object.assign(typedResp, resp);
|
|
6387
|
-
return typedResp;
|
|
6388
|
-
});
|
|
6380
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
6389
6381
|
}
|
|
6390
6382
|
else {
|
|
6391
6383
|
const body = listFilesParametersToMldev(this.apiClient, params);
|
|
@@ -6400,7 +6392,7 @@ class Files extends BaseModule {
|
|
|
6400
6392
|
queryParams: queryParams,
|
|
6401
6393
|
body: JSON.stringify(body),
|
|
6402
6394
|
httpMethod: 'GET',
|
|
6403
|
-
httpOptions: (
|
|
6395
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
6404
6396
|
})
|
|
6405
6397
|
.then((httpResponse) => {
|
|
6406
6398
|
return httpResponse.json();
|
|
@@ -6414,34 +6406,12 @@ class Files extends BaseModule {
|
|
|
6414
6406
|
}
|
|
6415
6407
|
}
|
|
6416
6408
|
async createInternal(params) {
|
|
6417
|
-
var _a
|
|
6409
|
+
var _a;
|
|
6418
6410
|
let response;
|
|
6419
6411
|
let path = '';
|
|
6420
6412
|
let queryParams = {};
|
|
6421
6413
|
if (this.apiClient.isVertexAI()) {
|
|
6422
|
-
|
|
6423
|
-
path = formatMap('', body['_url']);
|
|
6424
|
-
queryParams = body['_query'];
|
|
6425
|
-
delete body['config'];
|
|
6426
|
-
delete body['_url'];
|
|
6427
|
-
delete body['_query'];
|
|
6428
|
-
response = this.apiClient
|
|
6429
|
-
.request({
|
|
6430
|
-
path: path,
|
|
6431
|
-
queryParams: queryParams,
|
|
6432
|
-
body: JSON.stringify(body),
|
|
6433
|
-
httpMethod: 'POST',
|
|
6434
|
-
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
6435
|
-
})
|
|
6436
|
-
.then((httpResponse) => {
|
|
6437
|
-
return httpResponse.json();
|
|
6438
|
-
});
|
|
6439
|
-
return response.then((apiResponse) => {
|
|
6440
|
-
const resp = createFileResponseFromVertex(this.apiClient, apiResponse);
|
|
6441
|
-
const typedResp = new CreateFileResponse();
|
|
6442
|
-
Object.assign(typedResp, resp);
|
|
6443
|
-
return typedResp;
|
|
6444
|
-
});
|
|
6414
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
6445
6415
|
}
|
|
6446
6416
|
else {
|
|
6447
6417
|
const body = createFileParametersToMldev(this.apiClient, params);
|
|
@@ -6456,7 +6426,7 @@ class Files extends BaseModule {
|
|
|
6456
6426
|
queryParams: queryParams,
|
|
6457
6427
|
body: JSON.stringify(body),
|
|
6458
6428
|
httpMethod: 'POST',
|
|
6459
|
-
httpOptions: (
|
|
6429
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
6460
6430
|
})
|
|
6461
6431
|
.then((httpResponse) => {
|
|
6462
6432
|
return httpResponse.json();
|
|
@@ -6480,37 +6450,17 @@ class Files extends BaseModule {
|
|
|
6480
6450
|
* const config: GetFileParameters = {
|
|
6481
6451
|
* name: fileName,
|
|
6482
6452
|
* };
|
|
6483
|
-
* file = await
|
|
6453
|
+
* file = await ai.files.get(config);
|
|
6484
6454
|
* console.log(file.name);
|
|
6485
6455
|
* ```
|
|
6486
6456
|
*/
|
|
6487
6457
|
async get(params) {
|
|
6488
|
-
var _a
|
|
6458
|
+
var _a;
|
|
6489
6459
|
let response;
|
|
6490
6460
|
let path = '';
|
|
6491
6461
|
let queryParams = {};
|
|
6492
6462
|
if (this.apiClient.isVertexAI()) {
|
|
6493
|
-
|
|
6494
|
-
path = formatMap('None', body['_url']);
|
|
6495
|
-
queryParams = body['_query'];
|
|
6496
|
-
delete body['config'];
|
|
6497
|
-
delete body['_url'];
|
|
6498
|
-
delete body['_query'];
|
|
6499
|
-
response = this.apiClient
|
|
6500
|
-
.request({
|
|
6501
|
-
path: path,
|
|
6502
|
-
queryParams: queryParams,
|
|
6503
|
-
body: JSON.stringify(body),
|
|
6504
|
-
httpMethod: 'GET',
|
|
6505
|
-
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
6506
|
-
})
|
|
6507
|
-
.then((httpResponse) => {
|
|
6508
|
-
return httpResponse.json();
|
|
6509
|
-
});
|
|
6510
|
-
return response.then((apiResponse) => {
|
|
6511
|
-
const resp = fileFromVertex(this.apiClient);
|
|
6512
|
-
return resp;
|
|
6513
|
-
});
|
|
6463
|
+
throw new Error('This method is only supported by the Gemini Developer API.');
|
|
6514
6464
|
}
|
|
6515
6465
|
else {
|
|
6516
6466
|
const body = getFileParametersToMldev(this.apiClient, params);
|
|
@@ -6525,7 +6475,7 @@ class Files extends BaseModule {
|
|
|
6525
6475
|
queryParams: queryParams,
|
|
6526
6476
|
body: JSON.stringify(body),
|
|
6527
6477
|
httpMethod: 'GET',
|
|
6528
|
-
httpOptions: (
|
|
6478
|
+
httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
|
|
6529
6479
|
})
|
|
6530
6480
|
.then((httpResponse) => {
|
|
6531
6481
|
return httpResponse.json();
|
|
@@ -6557,13 +6507,6 @@ function listFilesParametersToMldev(apiClient, fromObject) {
|
|
|
6557
6507
|
}
|
|
6558
6508
|
return toObject;
|
|
6559
6509
|
}
|
|
6560
|
-
function listFilesParametersToVertex(apiClient, fromObject) {
|
|
6561
|
-
const toObject = {};
|
|
6562
|
-
if (getValueByPath(fromObject, ['config']) !== undefined) {
|
|
6563
|
-
throw new Error('config parameter is not supported in Vertex AI.');
|
|
6564
|
-
}
|
|
6565
|
-
return toObject;
|
|
6566
|
-
}
|
|
6567
6510
|
function fileStatusToMldev(apiClient, fromObject) {
|
|
6568
6511
|
const toObject = {};
|
|
6569
6512
|
const fromDetails = getValueByPath(fromObject, ['details']);
|
|
@@ -6656,16 +6599,6 @@ function createFileParametersToMldev(apiClient, fromObject) {
|
|
|
6656
6599
|
}
|
|
6657
6600
|
return toObject;
|
|
6658
6601
|
}
|
|
6659
|
-
function createFileParametersToVertex(apiClient, fromObject) {
|
|
6660
|
-
const toObject = {};
|
|
6661
|
-
if (getValueByPath(fromObject, ['file']) !== undefined) {
|
|
6662
|
-
throw new Error('file parameter is not supported in Vertex AI.');
|
|
6663
|
-
}
|
|
6664
|
-
if (getValueByPath(fromObject, ['config']) !== undefined) {
|
|
6665
|
-
throw new Error('config parameter is not supported in Vertex AI.');
|
|
6666
|
-
}
|
|
6667
|
-
return toObject;
|
|
6668
|
-
}
|
|
6669
6602
|
function getFileParametersToMldev(apiClient, fromObject) {
|
|
6670
6603
|
const toObject = {};
|
|
6671
6604
|
const fromName = getValueByPath(fromObject, ['name']);
|
|
@@ -6678,16 +6611,6 @@ function getFileParametersToMldev(apiClient, fromObject) {
|
|
|
6678
6611
|
}
|
|
6679
6612
|
return toObject;
|
|
6680
6613
|
}
|
|
6681
|
-
function getFileParametersToVertex(apiClient, fromObject) {
|
|
6682
|
-
const toObject = {};
|
|
6683
|
-
if (getValueByPath(fromObject, ['name']) !== undefined) {
|
|
6684
|
-
throw new Error('name parameter is not supported in Vertex AI.');
|
|
6685
|
-
}
|
|
6686
|
-
if (getValueByPath(fromObject, ['config']) !== undefined) {
|
|
6687
|
-
throw new Error('config parameter is not supported in Vertex AI.');
|
|
6688
|
-
}
|
|
6689
|
-
return toObject;
|
|
6690
|
-
}
|
|
6691
6614
|
function fileStatusFromMldev(apiClient, fromObject) {
|
|
6692
6615
|
const toObject = {};
|
|
6693
6616
|
const fromDetails = getValueByPath(fromObject, ['details']);
|
|
@@ -6768,10 +6691,6 @@ function fileFromMldev(apiClient, fromObject) {
|
|
|
6768
6691
|
}
|
|
6769
6692
|
return toObject;
|
|
6770
6693
|
}
|
|
6771
|
-
function fileFromVertex(apiClient, fromObject) {
|
|
6772
|
-
const toObject = {};
|
|
6773
|
-
return toObject;
|
|
6774
|
-
}
|
|
6775
6694
|
function listFilesResponseFromMldev(apiClient, fromObject) {
|
|
6776
6695
|
const toObject = {};
|
|
6777
6696
|
const fromNextPageToken = getValueByPath(fromObject, [
|
|
@@ -6793,10 +6712,6 @@ function listFilesResponseFromMldev(apiClient, fromObject) {
|
|
|
6793
6712
|
}
|
|
6794
6713
|
return toObject;
|
|
6795
6714
|
}
|
|
6796
|
-
function listFilesResponseFromVertex(apiClient, fromObject) {
|
|
6797
|
-
const toObject = {};
|
|
6798
|
-
return toObject;
|
|
6799
|
-
}
|
|
6800
6715
|
function createFileResponseFromMldev(apiClient, fromObject) {
|
|
6801
6716
|
const toObject = {};
|
|
6802
6717
|
const fromHttpHeaders = getValueByPath(fromObject, ['httpHeaders']);
|
|
@@ -6805,14 +6720,6 @@ function createFileResponseFromMldev(apiClient, fromObject) {
|
|
|
6805
6720
|
}
|
|
6806
6721
|
return toObject;
|
|
6807
6722
|
}
|
|
6808
|
-
function createFileResponseFromVertex(apiClient, fromObject) {
|
|
6809
|
-
const toObject = {};
|
|
6810
|
-
const fromHttpHeaders = getValueByPath(fromObject, ['httpHeaders']);
|
|
6811
|
-
if (fromHttpHeaders != null) {
|
|
6812
|
-
setValueByPath(toObject, ['httpHeaders'], fromHttpHeaders);
|
|
6813
|
-
}
|
|
6814
|
-
return toObject;
|
|
6815
|
-
}
|
|
6816
6723
|
|
|
6817
6724
|
/**
|
|
6818
6725
|
* @license
|
|
@@ -6904,7 +6811,7 @@ class NodeWebSocket {
|
|
|
6904
6811
|
this.callbacks = callbacks;
|
|
6905
6812
|
}
|
|
6906
6813
|
connect() {
|
|
6907
|
-
this.ws = new NodeWs__namespace.WebSocket(this.url, this.headers);
|
|
6814
|
+
this.ws = new NodeWs__namespace.WebSocket(this.url, { headers: this.headers });
|
|
6908
6815
|
this.ws.onopen = this.callbacks.onopen;
|
|
6909
6816
|
this.ws.onerror = this.callbacks.onerror;
|
|
6910
6817
|
this.ws.onclose = this.callbacks.onclose;
|
|
@@ -7181,7 +7088,7 @@ class NodeUploader {
|
|
|
7181
7088
|
|
|
7182
7089
|
/**
|
|
7183
7090
|
* @license
|
|
7184
|
-
* Copyright
|
|
7091
|
+
* Copyright 2025 Google LLC
|
|
7185
7092
|
* SPDX-License-Identifier: Apache-2.0
|
|
7186
7093
|
*/
|
|
7187
7094
|
const LANGUAGE_LABEL_PREFIX = 'gl-node/';
|
|
@@ -7194,23 +7101,21 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
|
|
|
7194
7101
|
*
|
|
7195
7102
|
* The {@link GoogleGenAIOptions.vertexai} value determines which of the API services to use.
|
|
7196
7103
|
*
|
|
7197
|
-
* When using the Gemini API, a {@link GoogleGenAIOptions.apiKey} must be set,
|
|
7198
|
-
* when using Vertex AI {@link GoogleGenAIOptions.project}
|
|
7199
|
-
* and {@link GoogleGenAIOptions.location} must be set,
|
|
7200
|
-
* and the {@link GoogleGenAIOptions.vertexai} must be set to `true`.
|
|
7104
|
+
* When using the Gemini API, a {@link GoogleGenAIOptions.apiKey} must also be set,
|
|
7105
|
+
* when using Vertex AI {@link GoogleGenAIOptions.project} and {@link GoogleGenAIOptions.location} must also be set.
|
|
7201
7106
|
*
|
|
7202
7107
|
* @example
|
|
7203
7108
|
* Initializing the SDK for using the Gemini API:
|
|
7204
7109
|
* ```ts
|
|
7205
7110
|
* import {GoogleGenAI} from '@google/genai';
|
|
7206
|
-
* const ai =
|
|
7111
|
+
* const ai = new GoogleGenAI({apiKey: 'GEMINI_API_KEY'});
|
|
7207
7112
|
* ```
|
|
7208
7113
|
*
|
|
7209
7114
|
* @example
|
|
7210
7115
|
* Initializing the SDK for using the Vertex AI API:
|
|
7211
7116
|
* ```ts
|
|
7212
7117
|
* import {GoogleGenAI} from '@google/genai';
|
|
7213
|
-
* const ai =
|
|
7118
|
+
* const ai = new GoogleGenAI({
|
|
7214
7119
|
* vertexai: true,
|
|
7215
7120
|
* project: 'PROJECT_ID',
|
|
7216
7121
|
* location: 'PROJECT_LOCATION'
|
|
@@ -7220,7 +7125,7 @@ const LANGUAGE_LABEL_PREFIX = 'gl-node/';
|
|
|
7220
7125
|
*/
|
|
7221
7126
|
class GoogleGenAI {
|
|
7222
7127
|
constructor(options) {
|
|
7223
|
-
var _a, _b, _c, _d, _e
|
|
7128
|
+
var _a, _b, _c, _d, _e;
|
|
7224
7129
|
this.vertexai =
|
|
7225
7130
|
(_b = (_a = options.vertexai) !== null && _a !== void 0 ? _a : getBooleanEnv('GOOGLE_GENAI_USE_VERTEXAI')) !== null && _b !== void 0 ? _b : false;
|
|
7226
7131
|
// The tests currently assume that an API key is never set if vertexai is true.
|
|
@@ -7232,7 +7137,7 @@ class GoogleGenAI {
|
|
|
7232
7137
|
this.project = (_d = options.project) !== null && _d !== void 0 ? _d : getEnv('GOOGLE_CLOUD_PROJECT');
|
|
7233
7138
|
this.location = (_e = options.location) !== null && _e !== void 0 ? _e : getEnv('GOOGLE_CLOUD_LOCATION');
|
|
7234
7139
|
this.apiVersion = options.apiVersion;
|
|
7235
|
-
const auth =
|
|
7140
|
+
const auth = new NodeAuth({
|
|
7236
7141
|
apiKey: this.apiKey,
|
|
7237
7142
|
googleAuthOptions: options.googleAuthOptions,
|
|
7238
7143
|
});
|
|
@@ -7301,7 +7206,6 @@ exports.createPartFromFunctionCall = createPartFromFunctionCall;
|
|
|
7301
7206
|
exports.createPartFromFunctionResponse = createPartFromFunctionResponse;
|
|
7302
7207
|
exports.createPartFromText = createPartFromText;
|
|
7303
7208
|
exports.createPartFromUri = createPartFromUri;
|
|
7304
|
-
exports.createPartFromVideoMetadata = createPartFromVideoMetadata;
|
|
7305
7209
|
exports.createUserContent = createUserContent;
|
|
7306
7210
|
exports.toolToMldev = toolToMldev$1;
|
|
7307
7211
|
exports.toolToVertex = toolToVertex$1;
|