@google/genai 1.12.0 → 1.13.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.
@@ -472,6 +472,14 @@ exports.UrlRetrievalStatus = void 0;
472
472
  * Url retrieval is failed due to error.
473
473
  */
474
474
  UrlRetrievalStatus["URL_RETRIEVAL_STATUS_ERROR"] = "URL_RETRIEVAL_STATUS_ERROR";
475
+ /**
476
+ * Url retrieval is failed because the content is behind paywall.
477
+ */
478
+ UrlRetrievalStatus["URL_RETRIEVAL_STATUS_PAYWALL"] = "URL_RETRIEVAL_STATUS_PAYWALL";
479
+ /**
480
+ * Url retrieval is failed because the content is unsafe.
481
+ */
482
+ UrlRetrievalStatus["URL_RETRIEVAL_STATUS_UNSAFE"] = "URL_RETRIEVAL_STATUS_UNSAFE";
475
483
  })(exports.UrlRetrievalStatus || (exports.UrlRetrievalStatus = {}));
476
484
  /** Output only. The reason why the model stopped generating tokens.
477
485
 
@@ -1098,6 +1106,29 @@ exports.Scale = void 0;
1098
1106
  */
1099
1107
  Scale["B_MAJOR_A_FLAT_MINOR"] = "B_MAJOR_A_FLAT_MINOR";
1100
1108
  })(exports.Scale || (exports.Scale = {}));
1109
+ /** The mode of music generation. */
1110
+ exports.MusicGenerationMode = void 0;
1111
+ (function (MusicGenerationMode) {
1112
+ /**
1113
+ * Rely on the server default generation mode.
1114
+ */
1115
+ MusicGenerationMode["MUSIC_GENERATION_MODE_UNSPECIFIED"] = "MUSIC_GENERATION_MODE_UNSPECIFIED";
1116
+ /**
1117
+ * Steer text prompts to regions of latent space with higher quality
1118
+ music.
1119
+ */
1120
+ MusicGenerationMode["QUALITY"] = "QUALITY";
1121
+ /**
1122
+ * Steer text prompts to regions of latent space with a larger
1123
+ diversity of music.
1124
+ */
1125
+ MusicGenerationMode["DIVERSITY"] = "DIVERSITY";
1126
+ /**
1127
+ * Steer text prompts to regions of latent space more likely to
1128
+ generate music with vocals.
1129
+ */
1130
+ MusicGenerationMode["VOCALIZATION"] = "VOCALIZATION";
1131
+ })(exports.MusicGenerationMode || (exports.MusicGenerationMode = {}));
1101
1132
  /** The playback control signal to apply to the music generation. */
1102
1133
  exports.LiveMusicPlaybackControl = void 0;
1103
1134
  (function (LiveMusicPlaybackControl) {
@@ -1521,6 +1552,9 @@ class EditImageResponse {
1521
1552
  }
1522
1553
  class UpscaleImageResponse {
1523
1554
  }
1555
+ /** The output images response. */
1556
+ class RecontextImageResponse {
1557
+ }
1524
1558
  class ListModelsResponse {
1525
1559
  }
1526
1560
  class DeleteModelResponse {
@@ -3726,6 +3760,10 @@ function generateContentResponseFromMldev$1(fromObject) {
3726
3760
  if (fromPromptFeedback != null) {
3727
3761
  setValueByPath(toObject, ['promptFeedback'], fromPromptFeedback);
3728
3762
  }
3763
+ const fromResponseId = getValueByPath(fromObject, ['responseId']);
3764
+ if (fromResponseId != null) {
3765
+ setValueByPath(toObject, ['responseId'], fromResponseId);
3766
+ }
3729
3767
  const fromUsageMetadata = getValueByPath(fromObject, [
3730
3768
  'usageMetadata',
3731
3769
  ]);
@@ -3859,6 +3897,12 @@ function listBatchJobsResponseFromMldev(fromObject) {
3859
3897
  }
3860
3898
  function deleteResourceJobFromMldev(fromObject) {
3861
3899
  const toObject = {};
3900
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
3901
+ 'sdkHttpResponse',
3902
+ ]);
3903
+ if (fromSdkHttpResponse != null) {
3904
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
3905
+ }
3862
3906
  const fromName = getValueByPath(fromObject, ['name']);
3863
3907
  if (fromName != null) {
3864
3908
  setValueByPath(toObject, ['name'], fromName);
@@ -4008,6 +4052,12 @@ function listBatchJobsResponseFromVertex(fromObject) {
4008
4052
  }
4009
4053
  function deleteResourceJobFromVertex(fromObject) {
4010
4054
  const toObject = {};
4055
+ const fromSdkHttpResponse = getValueByPath(fromObject, [
4056
+ 'sdkHttpResponse',
4057
+ ]);
4058
+ if (fromSdkHttpResponse != null) {
4059
+ setValueByPath(toObject, ['sdkHttpResponse'], fromSdkHttpResponse);
4060
+ }
4011
4061
  const fromName = getValueByPath(fromObject, ['name']);
4012
4062
  if (fromName != null) {
4013
4063
  setValueByPath(toObject, ['name'], fromName);
@@ -4553,7 +4603,13 @@ class Batches extends BaseModule {
4553
4603
  abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
4554
4604
  })
4555
4605
  .then((httpResponse) => {
4556
- return httpResponse.json();
4606
+ return httpResponse.json().then((jsonResponse) => {
4607
+ const response = jsonResponse;
4608
+ response.sdkHttpResponse = {
4609
+ headers: httpResponse.headers,
4610
+ };
4611
+ return response;
4612
+ });
4557
4613
  });
4558
4614
  return response.then((apiResponse) => {
4559
4615
  const resp = deleteResourceJobFromVertex(apiResponse);
@@ -4577,7 +4633,13 @@ class Batches extends BaseModule {
4577
4633
  abortSignal: (_d = params.config) === null || _d === void 0 ? void 0 : _d.abortSignal,
4578
4634
  })
4579
4635
  .then((httpResponse) => {
4580
- return httpResponse.json();
4636
+ return httpResponse.json().then((jsonResponse) => {
4637
+ const response = jsonResponse;
4638
+ response.sdkHttpResponse = {
4639
+ headers: httpResponse.headers,
4640
+ };
4641
+ return response;
4642
+ });
4581
4643
  });
4582
4644
  return response.then((apiResponse) => {
4583
4645
  const resp = deleteResourceJobFromMldev(apiResponse);
@@ -7638,6 +7700,12 @@ function liveMusicGenerationConfigToMldev(fromObject) {
7638
7700
  if (fromOnlyBassAndDrums != null) {
7639
7701
  setValueByPath(toObject, ['onlyBassAndDrums'], fromOnlyBassAndDrums);
7640
7702
  }
7703
+ const fromMusicGenerationMode = getValueByPath(fromObject, [
7704
+ 'musicGenerationMode',
7705
+ ]);
7706
+ if (fromMusicGenerationMode != null) {
7707
+ setValueByPath(toObject, ['musicGenerationMode'], fromMusicGenerationMode);
7708
+ }
7641
7709
  return toObject;
7642
7710
  }
7643
7711
  function liveMusicSetConfigParametersToMldev(fromObject) {
@@ -8796,6 +8864,12 @@ function liveMusicGenerationConfigFromMldev(fromObject) {
8796
8864
  if (fromOnlyBassAndDrums != null) {
8797
8865
  setValueByPath(toObject, ['onlyBassAndDrums'], fromOnlyBassAndDrums);
8798
8866
  }
8867
+ const fromMusicGenerationMode = getValueByPath(fromObject, [
8868
+ 'musicGenerationMode',
8869
+ ]);
8870
+ if (fromMusicGenerationMode != null) {
8871
+ setValueByPath(toObject, ['musicGenerationMode'], fromMusicGenerationMode);
8872
+ }
8799
8873
  return toObject;
8800
8874
  }
8801
8875
  function liveMusicSourceMetadataFromMldev(fromObject) {
@@ -10062,8 +10136,9 @@ function generateImagesConfigToMldev(fromObject, parentObject) {
10062
10136
  if (getValueByPath(fromObject, ['addWatermark']) !== undefined) {
10063
10137
  throw new Error('addWatermark parameter is not supported in Gemini API.');
10064
10138
  }
10065
- if (getValueByPath(fromObject, ['imageSize']) !== undefined) {
10066
- throw new Error('imageSize parameter is not supported in Gemini API.');
10139
+ const fromImageSize = getValueByPath(fromObject, ['imageSize']);
10140
+ if (parentObject !== undefined && fromImageSize != null) {
10141
+ setValueByPath(parentObject, ['parameters', 'sampleImageSize'], fromImageSize);
10067
10142
  }
10068
10143
  if (getValueByPath(fromObject, ['enhancePrompt']) !== undefined) {
10069
10144
  throw new Error('enhancePrompt parameter is not supported in Gemini API.');
@@ -11465,6 +11540,106 @@ function upscaleImageAPIParametersInternalToVertex(apiClient, fromObject) {
11465
11540
  }
11466
11541
  return toObject;
11467
11542
  }
11543
+ function productImageToVertex(fromObject) {
11544
+ const toObject = {};
11545
+ const fromProductImage = getValueByPath(fromObject, ['productImage']);
11546
+ if (fromProductImage != null) {
11547
+ setValueByPath(toObject, ['image'], imageToVertex(fromProductImage));
11548
+ }
11549
+ return toObject;
11550
+ }
11551
+ function recontextImageSourceToVertex(fromObject, parentObject) {
11552
+ const toObject = {};
11553
+ const fromPrompt = getValueByPath(fromObject, ['prompt']);
11554
+ if (parentObject !== undefined && fromPrompt != null) {
11555
+ setValueByPath(parentObject, ['instances[0]', 'prompt'], fromPrompt);
11556
+ }
11557
+ const fromPersonImage = getValueByPath(fromObject, ['personImage']);
11558
+ if (parentObject !== undefined && fromPersonImage != null) {
11559
+ setValueByPath(parentObject, ['instances[0]', 'personImage', 'image'], imageToVertex(fromPersonImage));
11560
+ }
11561
+ const fromProductImages = getValueByPath(fromObject, [
11562
+ 'productImages',
11563
+ ]);
11564
+ if (parentObject !== undefined && fromProductImages != null) {
11565
+ let transformedList = fromProductImages;
11566
+ if (Array.isArray(transformedList)) {
11567
+ transformedList = transformedList.map((item) => {
11568
+ return productImageToVertex(item);
11569
+ });
11570
+ }
11571
+ setValueByPath(parentObject, ['instances[0]', 'productImages'], transformedList);
11572
+ }
11573
+ return toObject;
11574
+ }
11575
+ function recontextImageConfigToVertex(fromObject, parentObject) {
11576
+ const toObject = {};
11577
+ const fromNumberOfImages = getValueByPath(fromObject, [
11578
+ 'numberOfImages',
11579
+ ]);
11580
+ if (parentObject !== undefined && fromNumberOfImages != null) {
11581
+ setValueByPath(parentObject, ['parameters', 'sampleCount'], fromNumberOfImages);
11582
+ }
11583
+ const fromBaseSteps = getValueByPath(fromObject, ['baseSteps']);
11584
+ if (parentObject !== undefined && fromBaseSteps != null) {
11585
+ setValueByPath(parentObject, ['parameters', 'editConfig', 'baseSteps'], fromBaseSteps);
11586
+ }
11587
+ const fromOutputGcsUri = getValueByPath(fromObject, ['outputGcsUri']);
11588
+ if (parentObject !== undefined && fromOutputGcsUri != null) {
11589
+ setValueByPath(parentObject, ['parameters', 'storageUri'], fromOutputGcsUri);
11590
+ }
11591
+ const fromSeed = getValueByPath(fromObject, ['seed']);
11592
+ if (parentObject !== undefined && fromSeed != null) {
11593
+ setValueByPath(parentObject, ['parameters', 'seed'], fromSeed);
11594
+ }
11595
+ const fromSafetyFilterLevel = getValueByPath(fromObject, [
11596
+ 'safetyFilterLevel',
11597
+ ]);
11598
+ if (parentObject !== undefined && fromSafetyFilterLevel != null) {
11599
+ setValueByPath(parentObject, ['parameters', 'safetySetting'], fromSafetyFilterLevel);
11600
+ }
11601
+ const fromPersonGeneration = getValueByPath(fromObject, [
11602
+ 'personGeneration',
11603
+ ]);
11604
+ if (parentObject !== undefined && fromPersonGeneration != null) {
11605
+ setValueByPath(parentObject, ['parameters', 'personGeneration'], fromPersonGeneration);
11606
+ }
11607
+ const fromOutputMimeType = getValueByPath(fromObject, [
11608
+ 'outputMimeType',
11609
+ ]);
11610
+ if (parentObject !== undefined && fromOutputMimeType != null) {
11611
+ setValueByPath(parentObject, ['parameters', 'outputOptions', 'mimeType'], fromOutputMimeType);
11612
+ }
11613
+ const fromOutputCompressionQuality = getValueByPath(fromObject, [
11614
+ 'outputCompressionQuality',
11615
+ ]);
11616
+ if (parentObject !== undefined && fromOutputCompressionQuality != null) {
11617
+ setValueByPath(parentObject, ['parameters', 'outputOptions', 'compressionQuality'], fromOutputCompressionQuality);
11618
+ }
11619
+ const fromEnhancePrompt = getValueByPath(fromObject, [
11620
+ 'enhancePrompt',
11621
+ ]);
11622
+ if (parentObject !== undefined && fromEnhancePrompt != null) {
11623
+ setValueByPath(parentObject, ['parameters', 'enhancePrompt'], fromEnhancePrompt);
11624
+ }
11625
+ return toObject;
11626
+ }
11627
+ function recontextImageParametersToVertex(apiClient, fromObject) {
11628
+ const toObject = {};
11629
+ const fromModel = getValueByPath(fromObject, ['model']);
11630
+ if (fromModel != null) {
11631
+ setValueByPath(toObject, ['_url', 'model'], tModel(apiClient, fromModel));
11632
+ }
11633
+ const fromSource = getValueByPath(fromObject, ['source']);
11634
+ if (fromSource != null) {
11635
+ setValueByPath(toObject, ['config'], recontextImageSourceToVertex(fromSource, toObject));
11636
+ }
11637
+ const fromConfig = getValueByPath(fromObject, ['config']);
11638
+ if (fromConfig != null) {
11639
+ setValueByPath(toObject, ['config'], recontextImageConfigToVertex(fromConfig, toObject));
11640
+ }
11641
+ return toObject;
11642
+ }
11468
11643
  function getModelParametersToVertex(apiClient, fromObject) {
11469
11644
  const toObject = {};
11470
11645
  const fromModel = getValueByPath(fromObject, ['model']);
@@ -11961,6 +12136,10 @@ function generateContentResponseFromMldev(fromObject) {
11961
12136
  if (fromPromptFeedback != null) {
11962
12137
  setValueByPath(toObject, ['promptFeedback'], fromPromptFeedback);
11963
12138
  }
12139
+ const fromResponseId = getValueByPath(fromObject, ['responseId']);
12140
+ if (fromResponseId != null) {
12141
+ setValueByPath(toObject, ['responseId'], fromResponseId);
12142
+ }
11964
12143
  const fromUsageMetadata = getValueByPath(fromObject, [
11965
12144
  'usageMetadata',
11966
12145
  ]);
@@ -12511,10 +12690,6 @@ function generateContentResponseFromVertex(fromObject) {
12511
12690
  if (fromCreateTime != null) {
12512
12691
  setValueByPath(toObject, ['createTime'], fromCreateTime);
12513
12692
  }
12514
- const fromResponseId = getValueByPath(fromObject, ['responseId']);
12515
- if (fromResponseId != null) {
12516
- setValueByPath(toObject, ['responseId'], fromResponseId);
12517
- }
12518
12693
  const fromModelVersion = getValueByPath(fromObject, ['modelVersion']);
12519
12694
  if (fromModelVersion != null) {
12520
12695
  setValueByPath(toObject, ['modelVersion'], fromModelVersion);
@@ -12525,6 +12700,10 @@ function generateContentResponseFromVertex(fromObject) {
12525
12700
  if (fromPromptFeedback != null) {
12526
12701
  setValueByPath(toObject, ['promptFeedback'], fromPromptFeedback);
12527
12702
  }
12703
+ const fromResponseId = getValueByPath(fromObject, ['responseId']);
12704
+ if (fromResponseId != null) {
12705
+ setValueByPath(toObject, ['responseId'], fromResponseId);
12706
+ }
12528
12707
  const fromUsageMetadata = getValueByPath(fromObject, [
12529
12708
  'usageMetadata',
12530
12709
  ]);
@@ -12728,6 +12907,22 @@ function upscaleImageResponseFromVertex(fromObject) {
12728
12907
  }
12729
12908
  return toObject;
12730
12909
  }
12910
+ function recontextImageResponseFromVertex(fromObject) {
12911
+ const toObject = {};
12912
+ const fromGeneratedImages = getValueByPath(fromObject, [
12913
+ 'predictions',
12914
+ ]);
12915
+ if (fromGeneratedImages != null) {
12916
+ let transformedList = fromGeneratedImages;
12917
+ if (Array.isArray(transformedList)) {
12918
+ transformedList = transformedList.map((item) => {
12919
+ return generatedImageFromVertex(item);
12920
+ });
12921
+ }
12922
+ setValueByPath(toObject, ['generatedImages'], transformedList);
12923
+ }
12924
+ return toObject;
12925
+ }
12731
12926
  function endpointFromVertex(fromObject) {
12732
12927
  const toObject = {};
12733
12928
  const fromName = getValueByPath(fromObject, ['endpoint']);
@@ -12975,7 +13170,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
12975
13170
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
12976
13171
  const USER_AGENT_HEADER = 'User-Agent';
12977
13172
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
12978
- const SDK_VERSION = '1.12.0'; // x-release-please-version
13173
+ const SDK_VERSION = '1.13.0'; // x-release-please-version
12979
13174
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
12980
13175
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
12981
13176
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -15345,6 +15540,79 @@ class Models extends BaseModule {
15345
15540
  throw new Error('This method is only supported by the Vertex AI.');
15346
15541
  }
15347
15542
  }
15543
+ /**
15544
+ * Recontextualizes an image.
15545
+ *
15546
+ * There are two types of recontextualization currently supported:
15547
+ * 1) Imagen Product Recontext - Generate images of products in new scenes
15548
+ * and contexts.
15549
+ * 2) Virtual Try-On: Generate images of persons modeling fashion products.
15550
+ *
15551
+ * @param params - The parameters for recontextualizing an image.
15552
+ * @return The response from the API.
15553
+ *
15554
+ * @example
15555
+ * ```ts
15556
+ * const response1 = await ai.models.recontextImage({
15557
+ * model: 'imagen-product-recontext-preview-06-30',
15558
+ * source: {
15559
+ * prompt: 'In a modern kitchen setting.',
15560
+ * productImages: [productImage],
15561
+ * },
15562
+ * config: {
15563
+ * numberOfImages: 1,
15564
+ * },
15565
+ * });
15566
+ * console.log(response1?.generatedImages?.[0]?.image?.imageBytes);
15567
+ *
15568
+ * const response2 = await ai.models.recontextImage({
15569
+ * model: 'virtual-try-on-preview-08-04',
15570
+ * source: {
15571
+ * personImage: personImage,
15572
+ * productImages: [productImage],
15573
+ * },
15574
+ * config: {
15575
+ * numberOfImages: 1,
15576
+ * },
15577
+ * });
15578
+ * console.log(response2?.generatedImages?.[0]?.image?.imageBytes);
15579
+ * ```
15580
+ */
15581
+ async recontextImage(params) {
15582
+ var _a, _b;
15583
+ let response;
15584
+ let path = '';
15585
+ let queryParams = {};
15586
+ if (this.apiClient.isVertexAI()) {
15587
+ const body = recontextImageParametersToVertex(this.apiClient, params);
15588
+ path = formatMap('{model}:predict', body['_url']);
15589
+ queryParams = body['_query'];
15590
+ delete body['config'];
15591
+ delete body['_url'];
15592
+ delete body['_query'];
15593
+ response = this.apiClient
15594
+ .request({
15595
+ path: path,
15596
+ queryParams: queryParams,
15597
+ body: JSON.stringify(body),
15598
+ httpMethod: 'POST',
15599
+ httpOptions: (_a = params.config) === null || _a === void 0 ? void 0 : _a.httpOptions,
15600
+ abortSignal: (_b = params.config) === null || _b === void 0 ? void 0 : _b.abortSignal,
15601
+ })
15602
+ .then((httpResponse) => {
15603
+ return httpResponse.json();
15604
+ });
15605
+ return response.then((apiResponse) => {
15606
+ const resp = recontextImageResponseFromVertex(apiResponse);
15607
+ const typedResp = new RecontextImageResponse();
15608
+ Object.assign(typedResp, resp);
15609
+ return typedResp;
15610
+ });
15611
+ }
15612
+ else {
15613
+ throw new Error('This method is only supported by the Vertex AI.');
15614
+ }
15615
+ }
15348
15616
  /**
15349
15617
  * Fetches information about a model by name.
15350
15618
  *
@@ -18423,6 +18691,7 @@ exports.Models = Models;
18423
18691
  exports.Operations = Operations;
18424
18692
  exports.Pager = Pager;
18425
18693
  exports.RawReferenceImage = RawReferenceImage;
18694
+ exports.RecontextImageResponse = RecontextImageResponse;
18426
18695
  exports.ReplayResponse = ReplayResponse;
18427
18696
  exports.Session = Session;
18428
18697
  exports.StyleReferenceImage = StyleReferenceImage;