@google/genai 1.41.0 → 1.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/genai.d.ts +66 -11
- package/dist/index.cjs +213 -34
- package/dist/index.mjs +214 -35
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +213 -34
- package/dist/node/index.mjs +214 -35
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/node.d.ts +66 -11
- package/dist/tokenizer/node.cjs +12 -0
- package/dist/tokenizer/node.mjs +12 -0
- package/dist/tokenizer/node.mjs.map +1 -1
- package/dist/web/index.mjs +214 -35
- package/dist/web/index.mjs.map +1 -1
- package/dist/web/web.d.ts +66 -11
- package/package.json +2 -2
package/dist/genai.d.ts
CHANGED
|
@@ -1730,12 +1730,12 @@ export declare interface Content {
|
|
|
1730
1730
|
declare type Content_2 = TextContent | ImageContent | AudioContent | DocumentContent | VideoContent | ThoughtContent | FunctionCallContent | FunctionResultContent | CodeExecutionCallContent | CodeExecutionResultContent | URLContextCallContent | URLContextResultContent | GoogleSearchCallContent | GoogleSearchResultContent | MCPServerToolCallContent | MCPServerToolResultContent | FileSearchCallContent | FileSearchResultContent;
|
|
1731
1731
|
|
|
1732
1732
|
declare interface ContentDelta {
|
|
1733
|
+
event_type: 'content.delta';
|
|
1733
1734
|
delta?: ContentDelta.TextDelta | ContentDelta.ImageDelta | ContentDelta.AudioDelta | ContentDelta.DocumentDelta | ContentDelta.VideoDelta | ContentDelta.ThoughtSummaryDelta | ContentDelta.ThoughtSignatureDelta | ContentDelta.FunctionCallDelta | ContentDelta.FunctionResultDelta | ContentDelta.CodeExecutionCallDelta | ContentDelta.CodeExecutionResultDelta | ContentDelta.URLContextCallDelta | ContentDelta.URLContextResultDelta | ContentDelta.GoogleSearchCallDelta | ContentDelta.GoogleSearchResultDelta | ContentDelta.MCPServerToolCallDelta | ContentDelta.MCPServerToolResultDelta | ContentDelta.FileSearchCallDelta | ContentDelta.FileSearchResultDelta;
|
|
1734
1735
|
/**
|
|
1735
1736
|
* The event_id token to be used to resume the interaction stream, from this event.
|
|
1736
1737
|
*/
|
|
1737
1738
|
event_id?: string;
|
|
1738
|
-
event_type?: 'content.delta';
|
|
1739
1739
|
index?: number;
|
|
1740
1740
|
}
|
|
1741
1741
|
|
|
@@ -2001,6 +2001,7 @@ export declare class ContentReferenceImage {
|
|
|
2001
2001
|
}
|
|
2002
2002
|
|
|
2003
2003
|
declare interface ContentStart {
|
|
2004
|
+
event_type: 'content.start';
|
|
2004
2005
|
/**
|
|
2005
2006
|
* The content of the response.
|
|
2006
2007
|
*/
|
|
@@ -2009,16 +2010,15 @@ declare interface ContentStart {
|
|
|
2009
2010
|
* The event_id token to be used to resume the interaction stream, from this event.
|
|
2010
2011
|
*/
|
|
2011
2012
|
event_id?: string;
|
|
2012
|
-
event_type?: 'content.start';
|
|
2013
2013
|
index?: number;
|
|
2014
2014
|
}
|
|
2015
2015
|
|
|
2016
2016
|
declare interface ContentStop {
|
|
2017
|
+
event_type: 'content.stop';
|
|
2017
2018
|
/**
|
|
2018
2019
|
* The event_id token to be used to resume the interaction stream, from this event.
|
|
2019
2020
|
*/
|
|
2020
2021
|
event_id?: string;
|
|
2021
|
-
event_type?: 'content.stop';
|
|
2022
2022
|
index?: number;
|
|
2023
2023
|
}
|
|
2024
2024
|
|
|
@@ -2582,11 +2582,11 @@ export declare interface DatasetStats {
|
|
|
2582
2582
|
* Configuration for the Deep Research agent.
|
|
2583
2583
|
*/
|
|
2584
2584
|
declare interface DeepResearchAgentConfig {
|
|
2585
|
+
type: 'deep-research';
|
|
2585
2586
|
/**
|
|
2586
2587
|
* Whether to include thought summaries in the response.
|
|
2587
2588
|
*/
|
|
2588
2589
|
thinking_summaries?: 'auto' | 'none';
|
|
2589
|
-
type?: 'deep-research';
|
|
2590
2590
|
}
|
|
2591
2591
|
|
|
2592
2592
|
/** Optional parameters for models.get method. */
|
|
@@ -2922,7 +2922,7 @@ export declare interface DownloadFileParameters {
|
|
|
2922
2922
|
* Configuration for dynamic agents.
|
|
2923
2923
|
*/
|
|
2924
2924
|
declare interface DynamicAgentConfig {
|
|
2925
|
-
type
|
|
2925
|
+
type: 'dynamic';
|
|
2926
2926
|
[k: string]: unknown;
|
|
2927
2927
|
}
|
|
2928
2928
|
|
|
@@ -3098,6 +3098,25 @@ export declare interface EmbedContentParameters {
|
|
|
3098
3098
|
config?: EmbedContentConfig;
|
|
3099
3099
|
}
|
|
3100
3100
|
|
|
3101
|
+
/** Parameters for the _embed_content method. */
|
|
3102
|
+
export declare interface EmbedContentParametersPrivate {
|
|
3103
|
+
/** ID of the model to use. For a list of models, see `Google models
|
|
3104
|
+
<https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models>`_. */
|
|
3105
|
+
model: string;
|
|
3106
|
+
/** The content to embed. Only the `parts.text` fields will be counted.
|
|
3107
|
+
*/
|
|
3108
|
+
contents?: ContentListUnion;
|
|
3109
|
+
/** The single content to embed. Only the `parts.text` fields will be counted.
|
|
3110
|
+
*/
|
|
3111
|
+
content?: ContentUnion;
|
|
3112
|
+
/** The Vertex embedding API to use.
|
|
3113
|
+
*/
|
|
3114
|
+
embeddingApiType?: EmbeddingApiType;
|
|
3115
|
+
/** Configuration that contains optional parameters.
|
|
3116
|
+
*/
|
|
3117
|
+
config?: EmbedContentConfig;
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3101
3120
|
/** Response for the embed_content method. */
|
|
3102
3121
|
export declare class EmbedContentResponse {
|
|
3103
3122
|
/** Used to retain the full HTTP response. */
|
|
@@ -3111,6 +3130,18 @@ export declare class EmbedContentResponse {
|
|
|
3111
3130
|
metadata?: EmbedContentMetadata;
|
|
3112
3131
|
}
|
|
3113
3132
|
|
|
3133
|
+
/** Enum representing the Vertex embedding API to use. */
|
|
3134
|
+
export declare enum EmbeddingApiType {
|
|
3135
|
+
/**
|
|
3136
|
+
* predict API endpoint (default)
|
|
3137
|
+
*/
|
|
3138
|
+
PREDICT = "PREDICT",
|
|
3139
|
+
/**
|
|
3140
|
+
* embedContent API Endpoint
|
|
3141
|
+
*/
|
|
3142
|
+
EMBED_CONTENT = "EMBED_CONTENT"
|
|
3143
|
+
}
|
|
3144
|
+
|
|
3114
3145
|
export declare interface EmbeddingsBatchJobSource {
|
|
3115
3146
|
/** The Gemini Developer API's file resource name of the input data
|
|
3116
3147
|
(e.g. "files/12345").
|
|
@@ -3180,6 +3211,7 @@ export declare enum Environment {
|
|
|
3180
3211
|
}
|
|
3181
3212
|
|
|
3182
3213
|
declare interface ErrorEvent_2 {
|
|
3214
|
+
event_type: 'error';
|
|
3183
3215
|
/**
|
|
3184
3216
|
* Error message from an interaction.
|
|
3185
3217
|
*/
|
|
@@ -3188,7 +3220,6 @@ declare interface ErrorEvent_2 {
|
|
|
3188
3220
|
* The event_id token to be used to resume the interaction stream, from this event.
|
|
3189
3221
|
*/
|
|
3190
3222
|
event_id?: string;
|
|
3191
|
-
event_type?: 'error';
|
|
3192
3223
|
}
|
|
3193
3224
|
|
|
3194
3225
|
declare namespace ErrorEvent_2 {
|
|
@@ -5761,11 +5792,11 @@ declare interface InteractionCancelParams {
|
|
|
5761
5792
|
}
|
|
5762
5793
|
|
|
5763
5794
|
declare interface InteractionCompleteEvent {
|
|
5795
|
+
event_type: 'interaction.complete';
|
|
5764
5796
|
/**
|
|
5765
5797
|
* The event_id token to be used to resume the interaction stream, from this event.
|
|
5766
5798
|
*/
|
|
5767
5799
|
event_id?: string;
|
|
5768
|
-
event_type?: 'interaction.complete';
|
|
5769
5800
|
/**
|
|
5770
5801
|
* The Interaction resource.
|
|
5771
5802
|
*/
|
|
@@ -5907,11 +5938,11 @@ declare namespace InteractionsAPI {
|
|
|
5907
5938
|
declare type InteractionSSEEvent = InteractionStartEvent | InteractionCompleteEvent | InteractionStatusUpdate | ContentStart | ContentDelta | ContentStop | ErrorEvent_2;
|
|
5908
5939
|
|
|
5909
5940
|
declare interface InteractionStartEvent {
|
|
5941
|
+
event_type: 'interaction.start';
|
|
5910
5942
|
/**
|
|
5911
5943
|
* The event_id token to be used to resume the interaction stream, from this event.
|
|
5912
5944
|
*/
|
|
5913
5945
|
event_id?: string;
|
|
5914
|
-
event_type?: 'interaction.start';
|
|
5915
5946
|
/**
|
|
5916
5947
|
* The Interaction resource.
|
|
5917
5948
|
*/
|
|
@@ -5919,11 +5950,11 @@ declare interface InteractionStartEvent {
|
|
|
5919
5950
|
}
|
|
5920
5951
|
|
|
5921
5952
|
declare interface InteractionStatusUpdate {
|
|
5953
|
+
event_type: 'interaction.status_update';
|
|
5922
5954
|
/**
|
|
5923
5955
|
* The event_id token to be used to resume the interaction stream, from this event.
|
|
5924
5956
|
*/
|
|
5925
5957
|
event_id?: string;
|
|
5926
|
-
event_type?: 'interaction.status_update';
|
|
5927
5958
|
interaction_id?: string;
|
|
5928
5959
|
status?: 'in_progress' | 'requires_action' | 'completed' | 'failed' | 'cancelled' | 'incomplete';
|
|
5929
5960
|
}
|
|
@@ -7316,6 +7347,28 @@ export declare interface ModelArmorConfig {
|
|
|
7316
7347
|
export declare class Models extends BaseModule {
|
|
7317
7348
|
private readonly apiClient;
|
|
7318
7349
|
constructor(apiClient: ApiClient);
|
|
7350
|
+
/**
|
|
7351
|
+
* Calculates embeddings for the given contents.
|
|
7352
|
+
*
|
|
7353
|
+
* @param params - The parameters for embedding contents.
|
|
7354
|
+
* @return The response from the API.
|
|
7355
|
+
*
|
|
7356
|
+
* @example
|
|
7357
|
+
* ```ts
|
|
7358
|
+
* const response = await ai.models.embedContent({
|
|
7359
|
+
* model: 'text-embedding-004',
|
|
7360
|
+
* contents: [
|
|
7361
|
+
* 'What is your name?',
|
|
7362
|
+
* 'What is your favorite color?',
|
|
7363
|
+
* ],
|
|
7364
|
+
* config: {
|
|
7365
|
+
* outputDimensionality: 64,
|
|
7366
|
+
* },
|
|
7367
|
+
* });
|
|
7368
|
+
* console.log(response);
|
|
7369
|
+
* ```
|
|
7370
|
+
*/
|
|
7371
|
+
embedContent: (params: types.EmbedContentParameters) => Promise<types.EmbedContentResponse>;
|
|
7319
7372
|
/**
|
|
7320
7373
|
* Makes an API request to generate content with a given model.
|
|
7321
7374
|
*
|
|
@@ -7526,7 +7579,7 @@ export declare class Models extends BaseModule {
|
|
|
7526
7579
|
* console.log(response);
|
|
7527
7580
|
* ```
|
|
7528
7581
|
*/
|
|
7529
|
-
|
|
7582
|
+
private embedContentInternal;
|
|
7530
7583
|
/**
|
|
7531
7584
|
* Private method for generating images.
|
|
7532
7585
|
*/
|
|
@@ -10019,6 +10072,7 @@ declare namespace types {
|
|
|
10019
10072
|
ResourceScope,
|
|
10020
10073
|
FeatureSelectionPreference,
|
|
10021
10074
|
Environment,
|
|
10075
|
+
EmbeddingApiType,
|
|
10022
10076
|
SafetyFilterLevel,
|
|
10023
10077
|
PersonGeneration,
|
|
10024
10078
|
ImagePromptLanguage,
|
|
@@ -10151,7 +10205,7 @@ declare namespace types {
|
|
|
10151
10205
|
ReferenceImage,
|
|
10152
10206
|
EditImageParameters,
|
|
10153
10207
|
EmbedContentConfig,
|
|
10154
|
-
|
|
10208
|
+
EmbedContentParametersPrivate,
|
|
10155
10209
|
ContentEmbeddingStatistics,
|
|
10156
10210
|
ContentEmbedding,
|
|
10157
10211
|
EmbedContentMetadata,
|
|
@@ -10419,6 +10473,7 @@ declare namespace types {
|
|
|
10419
10473
|
CountTokensResult,
|
|
10420
10474
|
ComputeTokensResult,
|
|
10421
10475
|
CreateTuningJobParameters,
|
|
10476
|
+
EmbedContentParameters,
|
|
10422
10477
|
UploadToFileSearchStoreResponse,
|
|
10423
10478
|
UploadToFileSearchStoreOperation,
|
|
10424
10479
|
BlobImageUnion,
|
package/dist/index.cjs
CHANGED
|
@@ -1330,6 +1330,18 @@ exports.Environment = void 0;
|
|
|
1330
1330
|
*/
|
|
1331
1331
|
Environment["ENVIRONMENT_BROWSER"] = "ENVIRONMENT_BROWSER";
|
|
1332
1332
|
})(exports.Environment || (exports.Environment = {}));
|
|
1333
|
+
/** Enum representing the Vertex embedding API to use. */
|
|
1334
|
+
exports.EmbeddingApiType = void 0;
|
|
1335
|
+
(function (EmbeddingApiType) {
|
|
1336
|
+
/**
|
|
1337
|
+
* predict API endpoint (default)
|
|
1338
|
+
*/
|
|
1339
|
+
EmbeddingApiType["PREDICT"] = "PREDICT";
|
|
1340
|
+
/**
|
|
1341
|
+
* embedContent API Endpoint
|
|
1342
|
+
*/
|
|
1343
|
+
EmbeddingApiType["EMBED_CONTENT"] = "EMBED_CONTENT";
|
|
1344
|
+
})(exports.EmbeddingApiType || (exports.EmbeddingApiType = {}));
|
|
1333
1345
|
/** Enum that controls the safety filter level for objectionable content. */
|
|
1334
1346
|
exports.SafetyFilterLevel = void 0;
|
|
1335
1347
|
(function (SafetyFilterLevel) {
|
|
@@ -3361,6 +3373,10 @@ function tJobState(state) {
|
|
|
3361
3373
|
return stateString;
|
|
3362
3374
|
}
|
|
3363
3375
|
}
|
|
3376
|
+
function tIsVertexEmbedContentModel(model) {
|
|
3377
|
+
return ((model.includes('gemini') && model !== 'gemini-embedding-001') ||
|
|
3378
|
+
model.includes('maas'));
|
|
3379
|
+
}
|
|
3364
3380
|
|
|
3365
3381
|
/**
|
|
3366
3382
|
* @license
|
|
@@ -6933,7 +6949,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
|
|
|
6933
6949
|
const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
|
|
6934
6950
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
6935
6951
|
const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
|
|
6936
|
-
const SDK_VERSION = '1.
|
|
6952
|
+
const SDK_VERSION = '1.42.0'; // x-release-please-version
|
|
6937
6953
|
const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
|
|
6938
6954
|
const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
|
|
6939
6955
|
const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
|
|
@@ -10661,6 +10677,13 @@ class BaseGeminiNextGenAPIClient {
|
|
|
10661
10677
|
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))) {
|
|
10662
10678
|
return { bodyHeaders: undefined, body: ReadableStreamFrom(body) };
|
|
10663
10679
|
}
|
|
10680
|
+
else if (typeof body === 'object' &&
|
|
10681
|
+
headers.values.get('content-type') === 'application/x-www-form-urlencoded') {
|
|
10682
|
+
return {
|
|
10683
|
+
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
10684
|
+
body: this.stringifyQuery(body),
|
|
10685
|
+
};
|
|
10686
|
+
}
|
|
10664
10687
|
else {
|
|
10665
10688
|
return this.encoder({ body, headers });
|
|
10666
10689
|
}
|
|
@@ -12164,33 +12187,103 @@ function embedContentConfigToMldev(fromObject, parentObject, _rootObject) {
|
|
|
12164
12187
|
}
|
|
12165
12188
|
return toObject;
|
|
12166
12189
|
}
|
|
12167
|
-
function embedContentConfigToVertex(fromObject, parentObject,
|
|
12190
|
+
function embedContentConfigToVertex(fromObject, parentObject, rootObject) {
|
|
12168
12191
|
const toObject = {};
|
|
12169
|
-
|
|
12170
|
-
|
|
12171
|
-
|
|
12192
|
+
let discriminatorTaskType = getValueByPath(rootObject, [
|
|
12193
|
+
'embeddingApiType',
|
|
12194
|
+
]);
|
|
12195
|
+
if (discriminatorTaskType === undefined) {
|
|
12196
|
+
discriminatorTaskType = 'PREDICT';
|
|
12172
12197
|
}
|
|
12173
|
-
|
|
12174
|
-
|
|
12175
|
-
|
|
12198
|
+
if (discriminatorTaskType === 'PREDICT') {
|
|
12199
|
+
const fromTaskType = getValueByPath(fromObject, ['taskType']);
|
|
12200
|
+
if (parentObject !== undefined && fromTaskType != null) {
|
|
12201
|
+
setValueByPath(parentObject, ['instances[]', 'task_type'], fromTaskType);
|
|
12202
|
+
}
|
|
12176
12203
|
}
|
|
12177
|
-
|
|
12178
|
-
'
|
|
12204
|
+
else if (discriminatorTaskType === 'EMBED_CONTENT') {
|
|
12205
|
+
const fromTaskType = getValueByPath(fromObject, ['taskType']);
|
|
12206
|
+
if (parentObject !== undefined && fromTaskType != null) {
|
|
12207
|
+
setValueByPath(parentObject, ['taskType'], fromTaskType);
|
|
12208
|
+
}
|
|
12209
|
+
}
|
|
12210
|
+
let discriminatorTitle = getValueByPath(rootObject, [
|
|
12211
|
+
'embeddingApiType',
|
|
12179
12212
|
]);
|
|
12180
|
-
if (
|
|
12181
|
-
|
|
12213
|
+
if (discriminatorTitle === undefined) {
|
|
12214
|
+
discriminatorTitle = 'PREDICT';
|
|
12182
12215
|
}
|
|
12183
|
-
|
|
12184
|
-
|
|
12185
|
-
|
|
12216
|
+
if (discriminatorTitle === 'PREDICT') {
|
|
12217
|
+
const fromTitle = getValueByPath(fromObject, ['title']);
|
|
12218
|
+
if (parentObject !== undefined && fromTitle != null) {
|
|
12219
|
+
setValueByPath(parentObject, ['instances[]', 'title'], fromTitle);
|
|
12220
|
+
}
|
|
12221
|
+
}
|
|
12222
|
+
else if (discriminatorTitle === 'EMBED_CONTENT') {
|
|
12223
|
+
const fromTitle = getValueByPath(fromObject, ['title']);
|
|
12224
|
+
if (parentObject !== undefined && fromTitle != null) {
|
|
12225
|
+
setValueByPath(parentObject, ['title'], fromTitle);
|
|
12226
|
+
}
|
|
12227
|
+
}
|
|
12228
|
+
let discriminatorOutputDimensionality = getValueByPath(rootObject, [
|
|
12229
|
+
'embeddingApiType',
|
|
12230
|
+
]);
|
|
12231
|
+
if (discriminatorOutputDimensionality === undefined) {
|
|
12232
|
+
discriminatorOutputDimensionality = 'PREDICT';
|
|
12233
|
+
}
|
|
12234
|
+
if (discriminatorOutputDimensionality === 'PREDICT') {
|
|
12235
|
+
const fromOutputDimensionality = getValueByPath(fromObject, [
|
|
12236
|
+
'outputDimensionality',
|
|
12237
|
+
]);
|
|
12238
|
+
if (parentObject !== undefined && fromOutputDimensionality != null) {
|
|
12239
|
+
setValueByPath(parentObject, ['parameters', 'outputDimensionality'], fromOutputDimensionality);
|
|
12240
|
+
}
|
|
12241
|
+
}
|
|
12242
|
+
else if (discriminatorOutputDimensionality === 'EMBED_CONTENT') {
|
|
12243
|
+
const fromOutputDimensionality = getValueByPath(fromObject, [
|
|
12244
|
+
'outputDimensionality',
|
|
12245
|
+
]);
|
|
12246
|
+
if (parentObject !== undefined && fromOutputDimensionality != null) {
|
|
12247
|
+
setValueByPath(parentObject, ['outputDimensionality'], fromOutputDimensionality);
|
|
12248
|
+
}
|
|
12186
12249
|
}
|
|
12187
|
-
|
|
12188
|
-
|
|
12189
|
-
|
|
12250
|
+
let discriminatorMimeType = getValueByPath(rootObject, [
|
|
12251
|
+
'embeddingApiType',
|
|
12252
|
+
]);
|
|
12253
|
+
if (discriminatorMimeType === undefined) {
|
|
12254
|
+
discriminatorMimeType = 'PREDICT';
|
|
12255
|
+
}
|
|
12256
|
+
if (discriminatorMimeType === 'PREDICT') {
|
|
12257
|
+
const fromMimeType = getValueByPath(fromObject, ['mimeType']);
|
|
12258
|
+
if (parentObject !== undefined && fromMimeType != null) {
|
|
12259
|
+
setValueByPath(parentObject, ['instances[]', 'mimeType'], fromMimeType);
|
|
12260
|
+
}
|
|
12261
|
+
}
|
|
12262
|
+
let discriminatorAutoTruncate = getValueByPath(rootObject, [
|
|
12263
|
+
'embeddingApiType',
|
|
12264
|
+
]);
|
|
12265
|
+
if (discriminatorAutoTruncate === undefined) {
|
|
12266
|
+
discriminatorAutoTruncate = 'PREDICT';
|
|
12267
|
+
}
|
|
12268
|
+
if (discriminatorAutoTruncate === 'PREDICT') {
|
|
12269
|
+
const fromAutoTruncate = getValueByPath(fromObject, [
|
|
12270
|
+
'autoTruncate',
|
|
12271
|
+
]);
|
|
12272
|
+
if (parentObject !== undefined && fromAutoTruncate != null) {
|
|
12273
|
+
setValueByPath(parentObject, ['parameters', 'autoTruncate'], fromAutoTruncate);
|
|
12274
|
+
}
|
|
12275
|
+
}
|
|
12276
|
+
else if (discriminatorAutoTruncate === 'EMBED_CONTENT') {
|
|
12277
|
+
const fromAutoTruncate = getValueByPath(fromObject, [
|
|
12278
|
+
'autoTruncate',
|
|
12279
|
+
]);
|
|
12280
|
+
if (parentObject !== undefined && fromAutoTruncate != null) {
|
|
12281
|
+
setValueByPath(parentObject, ['autoTruncate'], fromAutoTruncate);
|
|
12282
|
+
}
|
|
12190
12283
|
}
|
|
12191
12284
|
return toObject;
|
|
12192
12285
|
}
|
|
12193
|
-
function
|
|
12286
|
+
function embedContentParametersPrivateToMldev(apiClient, fromObject, rootObject) {
|
|
12194
12287
|
const toObject = {};
|
|
12195
12288
|
const fromModel = getValueByPath(fromObject, ['model']);
|
|
12196
12289
|
if (fromModel != null) {
|
|
@@ -12206,6 +12299,10 @@ function embedContentParametersToMldev(apiClient, fromObject, rootObject) {
|
|
|
12206
12299
|
}
|
|
12207
12300
|
setValueByPath(toObject, ['requests[]', 'content'], transformedList);
|
|
12208
12301
|
}
|
|
12302
|
+
const fromContent = getValueByPath(fromObject, ['content']);
|
|
12303
|
+
if (fromContent != null) {
|
|
12304
|
+
contentToMldev$1(tContent(fromContent));
|
|
12305
|
+
}
|
|
12209
12306
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
12210
12307
|
if (fromConfig != null) {
|
|
12211
12308
|
embedContentConfigToMldev(fromConfig, toObject);
|
|
@@ -12216,25 +12313,45 @@ function embedContentParametersToMldev(apiClient, fromObject, rootObject) {
|
|
|
12216
12313
|
}
|
|
12217
12314
|
return toObject;
|
|
12218
12315
|
}
|
|
12219
|
-
function
|
|
12316
|
+
function embedContentParametersPrivateToVertex(apiClient, fromObject, rootObject) {
|
|
12220
12317
|
const toObject = {};
|
|
12221
12318
|
const fromModel = getValueByPath(fromObject, ['model']);
|
|
12222
12319
|
if (fromModel != null) {
|
|
12223
12320
|
setValueByPath(toObject, ['_url', 'model'], tModel(apiClient, fromModel));
|
|
12224
12321
|
}
|
|
12225
|
-
|
|
12226
|
-
|
|
12227
|
-
|
|
12228
|
-
|
|
12229
|
-
|
|
12230
|
-
|
|
12231
|
-
|
|
12322
|
+
let discriminatorContents = getValueByPath(rootObject, [
|
|
12323
|
+
'embeddingApiType',
|
|
12324
|
+
]);
|
|
12325
|
+
if (discriminatorContents === undefined) {
|
|
12326
|
+
discriminatorContents = 'PREDICT';
|
|
12327
|
+
}
|
|
12328
|
+
if (discriminatorContents === 'PREDICT') {
|
|
12329
|
+
const fromContents = getValueByPath(fromObject, ['contents']);
|
|
12330
|
+
if (fromContents != null) {
|
|
12331
|
+
let transformedList = tContentsForEmbed(apiClient, fromContents);
|
|
12332
|
+
if (Array.isArray(transformedList)) {
|
|
12333
|
+
transformedList = transformedList.map((item) => {
|
|
12334
|
+
return item;
|
|
12335
|
+
});
|
|
12336
|
+
}
|
|
12337
|
+
setValueByPath(toObject, ['instances[]', 'content'], transformedList);
|
|
12338
|
+
}
|
|
12339
|
+
}
|
|
12340
|
+
let discriminatorContent = getValueByPath(rootObject, [
|
|
12341
|
+
'embeddingApiType',
|
|
12342
|
+
]);
|
|
12343
|
+
if (discriminatorContent === undefined) {
|
|
12344
|
+
discriminatorContent = 'PREDICT';
|
|
12345
|
+
}
|
|
12346
|
+
if (discriminatorContent === 'EMBED_CONTENT') {
|
|
12347
|
+
const fromContent = getValueByPath(fromObject, ['content']);
|
|
12348
|
+
if (fromContent != null) {
|
|
12349
|
+
setValueByPath(toObject, ['content'], tContent(fromContent));
|
|
12232
12350
|
}
|
|
12233
|
-
setValueByPath(toObject, ['instances[]', 'content'], transformedList);
|
|
12234
12351
|
}
|
|
12235
12352
|
const fromConfig = getValueByPath(fromObject, ['config']);
|
|
12236
12353
|
if (fromConfig != null) {
|
|
12237
|
-
embedContentConfigToVertex(fromConfig, toObject);
|
|
12354
|
+
embedContentConfigToVertex(fromConfig, toObject, rootObject);
|
|
12238
12355
|
}
|
|
12239
12356
|
return toObject;
|
|
12240
12357
|
}
|
|
@@ -12287,6 +12404,24 @@ function embedContentResponseFromVertex(fromObject, rootObject) {
|
|
|
12287
12404
|
if (fromMetadata != null) {
|
|
12288
12405
|
setValueByPath(toObject, ['metadata'], fromMetadata);
|
|
12289
12406
|
}
|
|
12407
|
+
if (rootObject &&
|
|
12408
|
+
getValueByPath(rootObject, ['embeddingApiType']) === 'EMBED_CONTENT') {
|
|
12409
|
+
const embedding = getValueByPath(fromObject, ['embedding']);
|
|
12410
|
+
const usageMetadata = getValueByPath(fromObject, ['usageMetadata']);
|
|
12411
|
+
const truncated = getValueByPath(fromObject, ['truncated']);
|
|
12412
|
+
if (embedding) {
|
|
12413
|
+
const stats = {};
|
|
12414
|
+
if (usageMetadata &&
|
|
12415
|
+
usageMetadata['promptTokenCount']) {
|
|
12416
|
+
stats.tokenCount = usageMetadata['promptTokenCount'];
|
|
12417
|
+
}
|
|
12418
|
+
if (truncated) {
|
|
12419
|
+
stats.truncated = truncated;
|
|
12420
|
+
}
|
|
12421
|
+
embedding.statistics = stats;
|
|
12422
|
+
setValueByPath(toObject, ['embeddings'], [embedding]);
|
|
12423
|
+
}
|
|
12424
|
+
}
|
|
12290
12425
|
return toObject;
|
|
12291
12426
|
}
|
|
12292
12427
|
function endpointFromVertex(fromObject, _rootObject) {
|
|
@@ -15835,6 +15970,47 @@ class Models extends BaseModule {
|
|
|
15835
15970
|
constructor(apiClient) {
|
|
15836
15971
|
super();
|
|
15837
15972
|
this.apiClient = apiClient;
|
|
15973
|
+
/**
|
|
15974
|
+
* Calculates embeddings for the given contents.
|
|
15975
|
+
*
|
|
15976
|
+
* @param params - The parameters for embedding contents.
|
|
15977
|
+
* @return The response from the API.
|
|
15978
|
+
*
|
|
15979
|
+
* @example
|
|
15980
|
+
* ```ts
|
|
15981
|
+
* const response = await ai.models.embedContent({
|
|
15982
|
+
* model: 'text-embedding-004',
|
|
15983
|
+
* contents: [
|
|
15984
|
+
* 'What is your name?',
|
|
15985
|
+
* 'What is your favorite color?',
|
|
15986
|
+
* ],
|
|
15987
|
+
* config: {
|
|
15988
|
+
* outputDimensionality: 64,
|
|
15989
|
+
* },
|
|
15990
|
+
* });
|
|
15991
|
+
* console.log(response);
|
|
15992
|
+
* ```
|
|
15993
|
+
*/
|
|
15994
|
+
this.embedContent = async (params) => {
|
|
15995
|
+
if (!this.apiClient.isVertexAI()) {
|
|
15996
|
+
return await this.embedContentInternal(params);
|
|
15997
|
+
}
|
|
15998
|
+
const isVertexEmbedContentModel = (params.model.includes('gemini') &&
|
|
15999
|
+
params.model !== 'gemini-embedding-001') ||
|
|
16000
|
+
params.model.includes('maas');
|
|
16001
|
+
if (isVertexEmbedContentModel) {
|
|
16002
|
+
const contents = tContents(params.contents);
|
|
16003
|
+
if (contents.length > 1) {
|
|
16004
|
+
throw new Error('The embedContent API for this model only supports one content at a time.');
|
|
16005
|
+
}
|
|
16006
|
+
const paramsPrivate = Object.assign(Object.assign({}, params), { content: contents[0], embeddingApiType: exports.EmbeddingApiType.EMBED_CONTENT });
|
|
16007
|
+
return await this.embedContentInternal(paramsPrivate);
|
|
16008
|
+
}
|
|
16009
|
+
else {
|
|
16010
|
+
const paramsPrivate = Object.assign(Object.assign({}, params), { embeddingApiType: exports.EmbeddingApiType.PREDICT });
|
|
16011
|
+
return await this.embedContentInternal(paramsPrivate);
|
|
16012
|
+
}
|
|
16013
|
+
};
|
|
15838
16014
|
/**
|
|
15839
16015
|
* Makes an API request to generate content with a given model.
|
|
15840
16016
|
*
|
|
@@ -16522,14 +16698,17 @@ class Models extends BaseModule {
|
|
|
16522
16698
|
* console.log(response);
|
|
16523
16699
|
* ```
|
|
16524
16700
|
*/
|
|
16525
|
-
async
|
|
16701
|
+
async embedContentInternal(params) {
|
|
16526
16702
|
var _a, _b, _c, _d;
|
|
16527
16703
|
let response;
|
|
16528
16704
|
let path = '';
|
|
16529
16705
|
let queryParams = {};
|
|
16530
16706
|
if (this.apiClient.isVertexAI()) {
|
|
16531
|
-
const body =
|
|
16532
|
-
|
|
16707
|
+
const body = embedContentParametersPrivateToVertex(this.apiClient, params, params);
|
|
16708
|
+
const endpointUrl = tIsVertexEmbedContentModel(params.model)
|
|
16709
|
+
? '{model}:embedContent'
|
|
16710
|
+
: '{model}:predict';
|
|
16711
|
+
path = formatMap(endpointUrl, body['_url']);
|
|
16533
16712
|
queryParams = body['_query'];
|
|
16534
16713
|
delete body['_url'];
|
|
16535
16714
|
delete body['_query'];
|
|
@@ -16552,14 +16731,14 @@ class Models extends BaseModule {
|
|
|
16552
16731
|
});
|
|
16553
16732
|
});
|
|
16554
16733
|
return response.then((apiResponse) => {
|
|
16555
|
-
const resp = embedContentResponseFromVertex(apiResponse);
|
|
16734
|
+
const resp = embedContentResponseFromVertex(apiResponse, params);
|
|
16556
16735
|
const typedResp = new EmbedContentResponse();
|
|
16557
16736
|
Object.assign(typedResp, resp);
|
|
16558
16737
|
return typedResp;
|
|
16559
16738
|
});
|
|
16560
16739
|
}
|
|
16561
16740
|
else {
|
|
16562
|
-
const body =
|
|
16741
|
+
const body = embedContentParametersPrivateToMldev(this.apiClient, params);
|
|
16563
16742
|
path = formatMap('{model}:batchEmbedContents', body['_url']);
|
|
16564
16743
|
queryParams = body['_query'];
|
|
16565
16744
|
delete body['_url'];
|