From 611adde2f1989e66b6e5d029f7d077e7630ada71 Mon Sep 17 00:00:00 2001 From: Wanlin Du Date: Mon, 23 Jun 2025 11:29:58 -0700 Subject: [PATCH 1/8] feat: expose the responseJsonSchema in GenerateContentConfig PiperOrigin-RevId: 774859088 --- models.go | 10 ++++++++++ types.go | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/models.go b/models.go index 57d1cdac..32cf8521 100644 --- a/models.go +++ b/models.go @@ -833,6 +833,11 @@ func generateContentConfigToMldev(ac *apiClient, fromObject map[string]any, pare setValueByPath(toObject, []string{"responseSchema"}, fromResponseSchema) } + fromResponseJsonSchema := getValueByPath(fromObject, []string{"responseJsonSchema"}) + if fromResponseJsonSchema != nil { + setValueByPath(toObject, []string{"responseJsonSchema"}, fromResponseJsonSchema) + } + if getValueByPath(fromObject, []string{"routingConfig"}) != nil { return nil, fmt.Errorf("routingConfig parameter is not supported in Gemini API") } @@ -2326,6 +2331,11 @@ func generateContentConfigToVertex(ac *apiClient, fromObject map[string]any, par setValueByPath(toObject, []string{"responseSchema"}, fromResponseSchema) } + fromResponseJsonSchema := getValueByPath(fromObject, []string{"responseJsonSchema"}) + if fromResponseJsonSchema != nil { + setValueByPath(toObject, []string{"responseJsonSchema"}, fromResponseJsonSchema) + } + fromRoutingConfig := getValueByPath(fromObject, []string{"routingConfig"}) if fromRoutingConfig != nil { setValueByPath(toObject, []string{"routingConfig"}, fromRoutingConfig) diff --git a/types.go b/types.go index 43fe4f5f..cb177ba4 100644 --- a/types.go +++ b/types.go @@ -1463,6 +1463,22 @@ type GenerateContentConfig struct { // If set, a compatible response_mime_type must also be set. // Compatible mimetypes: `application/json`: Schema for JSON response. ResponseSchema *Schema `json:"responseSchema,omitempty"` + // Optional. Output schema of the generated response. + // This is an alternative to `response_schema` that accepts [JSON + // Schema](https://json-schema.org/). If set, `response_schema` must be + // omitted, but `response_mime_type` is required. While the full JSON Schema + // may be sent, not all features are supported. Specifically, only the + // following properties are supported: - `$id` - `$defs` - `$ref` - `$anchor` + // - `type` - `format` - `title` - `description` - `enum` (for strings and + // numbers) - `items` - `prefixItems` - `minItems` - `maxItems` - `minimum` - + // `maximum` - `anyOf` - `oneOf` (interpreted the same as `anyOf`) - + // `properties` - `additionalProperties` - `required` The non-standard + // `propertyOrdering` property may also be set. Cyclic references are + // unrolled to a limited degree and, as such, may only be used within + // non-required properties. (Nullable properties are not sufficient.) If + // `$ref` is set on a sub-schema, no other properties, except for than those + // starting as a `$`, may be set. + ResponseJsonSchema any `json:"responseJsonSchema,omitempty"` // Optional. Configuration for model router requests. RoutingConfig *GenerationConfigRoutingConfig `json:"routingConfig,omitempty"` // Optional. Configuration for model selection. From 9d901666db4f77e7605bb65e0dcd194b9a7fb887 Mon Sep 17 00:00:00 2001 From: Kaituo Huang Date: Tue, 24 Jun 2025 13:07:11 -0700 Subject: [PATCH 2/8] docs: improve generate images documentation * add docs for person generation config * add aspect ratio supported values PiperOrigin-RevId: 775352393 --- types.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/types.go b/types.go index cb177ba4..5d4cce08 100644 --- a/types.go +++ b/types.go @@ -354,9 +354,12 @@ const ( type PersonGeneration string const ( - PersonGenerationDontAllow PersonGeneration = "DONT_ALLOW" + // Block generation of images of people. + PersonGenerationDontAllow PersonGeneration = "DONT_ALLOW" + // Generate images of adults, but not children. PersonGenerationAllowAdult PersonGeneration = "ALLOW_ADULT" - PersonGenerationAllowAll PersonGeneration = "ALLOW_ALL" + // Generate images that include adults and children. + PersonGenerationAllowAll PersonGeneration = "ALLOW_ALL" ) // Enum that specifies the language of the text in the prompt. @@ -2037,7 +2040,8 @@ type GenerateImagesConfig struct { // Optional. Number of images to generate. // If empty, the system will choose a default value (currently 4). NumberOfImages int32 `json:"numberOfImages,omitempty"` - // Optional. Aspect ratio of the generated images. + // Optional. Aspect ratio of the generated images. Supported values are + // "1:1", "3:4", "4:3", "9:16", and "16:9". AspectRatio string `json:"aspectRatio,omitempty"` // Optional. Controls how much the model adheres to the text prompt. Large // values increase output and prompt alignment, but may compromise image @@ -2248,7 +2252,8 @@ type EditImageConfig struct { // Optional. Number of images to generate. // If empty, the system will choose a default value (currently 4). NumberOfImages int32 `json:"numberOfImages,omitempty"` - // Optional. Aspect ratio of the generated images. + // Optional. Aspect ratio of the generated images. Supported values are + // "1:1", "3:4", "4:3", "9:16", and "16:9". AspectRatio string `json:"aspectRatio,omitempty"` // Optional. Controls how much the model adheres to the text prompt. Large // values increase output and prompt alignment, but may compromise image From 6b9e07fee4864b54690e84ee9b67cf8a588d89d9 Mon Sep 17 00:00:00 2001 From: Matthew Tang Date: Tue, 24 Jun 2025 16:59:40 -0700 Subject: [PATCH 3/8] feat: Add enhance_input_image and image_preservation_factor fields for upscale_image PiperOrigin-RevId: 775438709 --- examples/models/upscale_image/image.go | 6 ++++-- go.mod | 4 +--- models.go | 12 ++++++++++++ types.go | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/examples/models/upscale_image/image.go b/examples/models/upscale_image/image.go index 95886e41..4ea77a7a 100644 --- a/examples/models/upscale_image/image.go +++ b/examples/models/upscale_image/image.go @@ -67,8 +67,10 @@ func run(ctx context.Context) { &genai.Image{ImageBytes: data}, /*upscaleFactor=*/ "x2", &genai.UpscaleImageConfig{ - IncludeRAIReason: true, - OutputMIMEType: "image/jpeg", + IncludeRAIReason: true, + OutputMIMEType: "image/jpeg", + EnhanceInputImage: true, + ImagePreservationFactor: genai.Ptr[float32](0.6), }) if err != nil { log.Fatal(err) diff --git a/go.mod b/go.mod index fe178a41..76bf7def 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,7 @@ module google.golang.org/genai go 1.23 -retract ( - v1.11.0 // Retracted due to breaking change on GenerateVideos -) +retract v1.11.0 // Retracted due to breaking change on GenerateVideos require ( cloud.google.com/go v0.116.0 diff --git a/models.go b/models.go index 32cf8521..fb7f64b0 100644 --- a/models.go +++ b/models.go @@ -2965,6 +2965,16 @@ func upscaleImageAPIConfigToVertex(ac *apiClient, fromObject map[string]any, par setValueByPath(parentObject, []string{"parameters", "outputOptions", "compressionQuality"}, fromOutputCompressionQuality) } + fromEnhanceInputImage := getValueByPath(fromObject, []string{"enhanceInputImage"}) + if fromEnhanceInputImage != nil { + setValueByPath(parentObject, []string{"parameters", "upscaleConfig", "enhanceInputImage"}, fromEnhanceInputImage) + } + + fromImagePreservationFactor := getValueByPath(fromObject, []string{"imagePreservationFactor"}) + if fromImagePreservationFactor != nil { + setValueByPath(parentObject, []string{"parameters", "upscaleConfig", "imagePreservationFactor"}, fromImagePreservationFactor) + } + fromNumberOfImages := getValueByPath(fromObject, []string{"numberOfImages"}) if fromNumberOfImages != nil { setValueByPath(parentObject, []string{"parameters", "sampleCount"}, fromNumberOfImages) @@ -5915,6 +5925,8 @@ func (m Models) UpscaleImage(ctx context.Context, model string, image *Image, up apiConfig.OutputMIMEType = config.OutputMIMEType apiConfig.OutputCompressionQuality = config.OutputCompressionQuality apiConfig.IncludeRAIReason = config.IncludeRAIReason + apiConfig.EnhanceInputImage = config.EnhanceInputImage + apiConfig.ImagePreservationFactor = config.ImagePreservationFactor } return m.upscaleImage(ctx, model, image, upscaleFactor, apiConfig) diff --git a/types.go b/types.go index 5d4cce08..d9229736 100644 --- a/types.go +++ b/types.go @@ -2306,6 +2306,15 @@ type upscaleImageAPIConfig struct { // Optional. The level of compression if the ``output_mime_type`` is // ``image/jpeg``. OutputCompressionQuality *int32 `json:"outputCompressionQuality,omitempty"` + // Optional. Whether to add an image enhancing step before upscaling. + // It is expected to suppress the noise and JPEG compression artifacts + // from the input image. + EnhanceInputImage bool `json:"enhanceInputImage,omitempty"` + // Optional. With a higher image preservation factor, the original image + // pixels are more respected. With a lower image preservation factor, the + // output image will have be more different from the input image, but + // with finer details and less noise. + ImagePreservationFactor *float32 `json:"imagePreservationFactor,omitempty"` // Optional. NumberOfImages int32 `json:"numberOfImages,omitempty"` // Optional. @@ -3201,6 +3210,15 @@ type UpscaleImageConfig struct { OutputMIMEType string `json:"outputMimeType,omitempty"` // Optional. The level of compression if the OutputMIMEType is image/jpeg. OutputCompressionQuality *int32 `json:"outputCompressionQuality,omitempty"` + // Optional. Whether to add an image enhancing step before upscaling. + // It is expected to suppress the noise and JPEG compression artifacts + // from the input image. + EnhanceInputImage bool `json:"enhanceInputImage,omitempty"` + // Optional. With a higher image preservation factor, the original image + // pixels are more respected. With a lower image preservation factor, the + // output image will have be more different from the input image, but + // with finer details and less noise. + ImagePreservationFactor *float32 `json:"imagePreservationFactor,omitempty"` } // A raw reference image. From 061e5674e1744d3bdaade62d3fb8f94c65e77c4c Mon Sep 17 00:00:00 2001 From: Matthew Tang Date: Wed, 25 Jun 2025 11:25:47 -0700 Subject: [PATCH 4/8] feat: Add compressionQuality enum for generate_videos PiperOrigin-RevId: 775769513 --- models.go | 9 +++++++++ types.go | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/models.go b/models.go index fb7f64b0..831bbad2 100644 --- a/models.go +++ b/models.go @@ -1463,6 +1463,10 @@ func generateVideosConfigToMldev(ac *apiClient, fromObject map[string]any, paren return nil, fmt.Errorf("lastFrame parameter is not supported in Gemini API") } + if getValueByPath(fromObject, []string{"compressionQuality"}) != nil { + return nil, fmt.Errorf("compressionQuality parameter is not supported in Gemini API") + } + return toObject, nil } @@ -3377,6 +3381,11 @@ func generateVideosConfigToVertex(ac *apiClient, fromObject map[string]any, pare setValueByPath(parentObject, []string{"instances[0]", "lastFrame"}, fromLastFrame) } + fromCompressionQuality := getValueByPath(fromObject, []string{"compressionQuality"}) + if fromCompressionQuality != nil { + setValueByPath(parentObject, []string{"parameters", "compressionQuality"}, fromCompressionQuality) + } + return toObject, nil } diff --git a/types.go b/types.go index d9229736..fc619e19 100644 --- a/types.go +++ b/types.go @@ -418,6 +418,18 @@ const ( EditModeProductImage EditMode = "EDIT_MODE_PRODUCT_IMAGE" ) +// Enum that controls the compression quality of the generated videos. +type VideoCompressionQuality string + +const ( + // Optimized video compression quality. This will produce videos + // with a compressed, smaller file size. + VideoCompressionQualityOptimized VideoCompressionQuality = "OPTIMIZED" + // Lossless video compression quality. This will produce videos + // with a larger file size. + VideoCompressionQualityLossless VideoCompressionQuality = "LOSSLESS" +) + // State for the lifecycle of a File. type FileState string @@ -2665,6 +2677,8 @@ type GenerateVideosConfig struct { // Optional. Image to use as the last frame of generated videos. Only supported for // image to video use cases. LastFrame *Image `json:"lastFrame,omitempty"` + // Optional. Compression quality of the generated videos. + CompressionQuality VideoCompressionQuality `json:"compressionQuality,omitempty"` } // A generated video. From dcae33f83abfbad8b3cd14930ca0514a61a217d8 Mon Sep 17 00:00:00 2001 From: Amy Wu Date: Wed, 25 Jun 2025 13:07:30 -0700 Subject: [PATCH 5/8] feat: Batches support in Go PiperOrigin-RevId: 775807892 --- batches.go | 3083 +++++++++++++++++++++++++ client.go | 3 + examples/batches/README.md | 26 + examples/batches/create_get_cancel.go | 138 ++ main_test.go | 6 + transformer.go | 50 + types.go | 173 ++ 7 files changed, 3479 insertions(+) create mode 100644 batches.go create mode 100644 examples/batches/README.md create mode 100644 examples/batches/create_get_cancel.go diff --git a/batches.go b/batches.go new file mode 100644 index 00000000..56b1bf72 --- /dev/null +++ b/batches.go @@ -0,0 +1,3083 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by the Google Gen AI SDK generator DO NOT EDIT. + +package genai + +import ( + "context" + "fmt" + "iter" + "net/http" +) + +func inlinedRequestToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromModel := getValueByPath(fromObject, []string{"model"}) + if fromModel != nil { + fromModel, err = tModel(ac, fromModel) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"request", "model"}, fromModel) + } + + fromContents := getValueByPath(fromObject, []string{"contents"}) + if fromContents != nil { + fromContents, err = tContents(ac, fromContents) + if err != nil { + return nil, err + } + + fromContents, err = applyConverterToSlice(ac, fromContents.([]any), contentToMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"request", "contents"}, fromContents) + } + + fromConfig := getValueByPath(fromObject, []string{"config"}) + if fromConfig != nil { + fromConfig, err = generateContentConfigToMldev(ac, fromConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"request", "generationConfig"}, fromConfig) + } + + return toObject, nil +} + +func batchJobSourceToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + if getValueByPath(fromObject, []string{"format"}) != nil { + return nil, fmt.Errorf("format parameter is not supported in Gemini API") + } + + if getValueByPath(fromObject, []string{"gcsUri"}) != nil { + return nil, fmt.Errorf("gcsUri parameter is not supported in Gemini API") + } + + if getValueByPath(fromObject, []string{"bigqueryUri"}) != nil { + return nil, fmt.Errorf("bigqueryUri parameter is not supported in Gemini API") + } + + fromFileName := getValueByPath(fromObject, []string{"fileName"}) + if fromFileName != nil { + setValueByPath(toObject, []string{"fileName"}, fromFileName) + } + + fromInlinedRequests := getValueByPath(fromObject, []string{"inlinedRequests"}) + if fromInlinedRequests != nil { + fromInlinedRequests, err = applyConverterToSlice(ac, fromInlinedRequests.([]any), inlinedRequestToMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"requests", "requests"}, fromInlinedRequests) + } + + return toObject, nil +} + +func citationMetadataToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromCitations := getValueByPath(fromObject, []string{"citations"}) + if fromCitations != nil { + setValueByPath(toObject, []string{"citationSources"}, fromCitations) + } + + return toObject, nil +} + +func urlMetadataToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromRetrievedUrl := getValueByPath(fromObject, []string{"retrievedUrl"}) + if fromRetrievedUrl != nil { + setValueByPath(toObject, []string{"retrievedUrl"}, fromRetrievedUrl) + } + + fromUrlRetrievalStatus := getValueByPath(fromObject, []string{"urlRetrievalStatus"}) + if fromUrlRetrievalStatus != nil { + setValueByPath(toObject, []string{"urlRetrievalStatus"}, fromUrlRetrievalStatus) + } + + return toObject, nil +} + +func urlContextMetadataToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromUrlMetadata := getValueByPath(fromObject, []string{"urlMetadata"}) + if fromUrlMetadata != nil { + fromUrlMetadata, err = applyConverterToSlice(ac, fromUrlMetadata.([]any), urlMetadataToMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"urlMetadata"}, fromUrlMetadata) + } + + return toObject, nil +} + +func candidateToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromContent := getValueByPath(fromObject, []string{"content"}) + if fromContent != nil { + fromContent, err = contentToMldev(ac, fromContent.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"content"}, fromContent) + } + + fromCitationMetadata := getValueByPath(fromObject, []string{"citationMetadata"}) + if fromCitationMetadata != nil { + fromCitationMetadata, err = citationMetadataToMldev(ac, fromCitationMetadata.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"citationMetadata"}, fromCitationMetadata) + } + + if getValueByPath(fromObject, []string{"finishMessage"}) != nil { + return nil, fmt.Errorf("finishMessage parameter is not supported in Gemini API") + } + + fromTokenCount := getValueByPath(fromObject, []string{"tokenCount"}) + if fromTokenCount != nil { + setValueByPath(toObject, []string{"tokenCount"}, fromTokenCount) + } + + fromFinishReason := getValueByPath(fromObject, []string{"finishReason"}) + if fromFinishReason != nil { + setValueByPath(toObject, []string{"finishReason"}, fromFinishReason) + } + + fromUrlContextMetadata := getValueByPath(fromObject, []string{"urlContextMetadata"}) + if fromUrlContextMetadata != nil { + fromUrlContextMetadata, err = urlContextMetadataToMldev(ac, fromUrlContextMetadata.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"urlContextMetadata"}, fromUrlContextMetadata) + } + + fromAvgLogprobs := getValueByPath(fromObject, []string{"avgLogprobs"}) + if fromAvgLogprobs != nil { + setValueByPath(toObject, []string{"avgLogprobs"}, fromAvgLogprobs) + } + + fromGroundingMetadata := getValueByPath(fromObject, []string{"groundingMetadata"}) + if fromGroundingMetadata != nil { + setValueByPath(toObject, []string{"groundingMetadata"}, fromGroundingMetadata) + } + + fromIndex := getValueByPath(fromObject, []string{"index"}) + if fromIndex != nil { + setValueByPath(toObject, []string{"index"}, fromIndex) + } + + fromLogprobsResult := getValueByPath(fromObject, []string{"logprobsResult"}) + if fromLogprobsResult != nil { + setValueByPath(toObject, []string{"logprobsResult"}, fromLogprobsResult) + } + + fromSafetyRatings := getValueByPath(fromObject, []string{"safetyRatings"}) + if fromSafetyRatings != nil { + setValueByPath(toObject, []string{"safetyRatings"}, fromSafetyRatings) + } + + return toObject, nil +} + +func generateContentResponseToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromCandidates := getValueByPath(fromObject, []string{"candidates"}) + if fromCandidates != nil { + fromCandidates, err = applyConverterToSlice(ac, fromCandidates.([]any), candidateToMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"candidates"}, fromCandidates) + } + + if getValueByPath(fromObject, []string{"createTime"}) != nil { + return nil, fmt.Errorf("createTime parameter is not supported in Gemini API") + } + + if getValueByPath(fromObject, []string{"responseId"}) != nil { + return nil, fmt.Errorf("responseId parameter is not supported in Gemini API") + } + + fromModelVersion := getValueByPath(fromObject, []string{"modelVersion"}) + if fromModelVersion != nil { + setValueByPath(toObject, []string{"modelVersion"}, fromModelVersion) + } + + fromPromptFeedback := getValueByPath(fromObject, []string{"promptFeedback"}) + if fromPromptFeedback != nil { + setValueByPath(toObject, []string{"promptFeedback"}, fromPromptFeedback) + } + + fromUsageMetadata := getValueByPath(fromObject, []string{"usageMetadata"}) + if fromUsageMetadata != nil { + setValueByPath(toObject, []string{"usageMetadata"}, fromUsageMetadata) + } + + return toObject, nil +} + +func jobErrorToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + if getValueByPath(fromObject, []string{"details"}) != nil { + return nil, fmt.Errorf("details parameter is not supported in Gemini API") + } + + if getValueByPath(fromObject, []string{"code"}) != nil { + return nil, fmt.Errorf("code parameter is not supported in Gemini API") + } + + if getValueByPath(fromObject, []string{"message"}) != nil { + return nil, fmt.Errorf("message parameter is not supported in Gemini API") + } + + return toObject, nil +} + +func inlinedResponseToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromResponse := getValueByPath(fromObject, []string{"response"}) + if fromResponse != nil { + fromResponse, err = generateContentResponseToMldev(ac, fromResponse.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"response"}, fromResponse) + } + + fromError := getValueByPath(fromObject, []string{"error"}) + if fromError != nil { + fromError, err = jobErrorToMldev(ac, fromError.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"error"}, fromError) + } + + return toObject, nil +} + +func batchJobDestinationToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + if getValueByPath(fromObject, []string{"format"}) != nil { + return nil, fmt.Errorf("format parameter is not supported in Gemini API") + } + + if getValueByPath(fromObject, []string{"gcsUri"}) != nil { + return nil, fmt.Errorf("gcsUri parameter is not supported in Gemini API") + } + + if getValueByPath(fromObject, []string{"bigqueryUri"}) != nil { + return nil, fmt.Errorf("bigqueryUri parameter is not supported in Gemini API") + } + + fromFileName := getValueByPath(fromObject, []string{"fileName"}) + if fromFileName != nil { + setValueByPath(toObject, []string{"responsesFile"}, fromFileName) + } + + fromInlinedResponses := getValueByPath(fromObject, []string{"inlinedResponses"}) + if fromInlinedResponses != nil { + fromInlinedResponses, err = applyConverterToSlice(ac, fromInlinedResponses.([]any), inlinedResponseToMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"inlinedResponses", "inlinedResponses"}, fromInlinedResponses) + } + + return toObject, nil +} + +func createBatchJobConfigToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromDisplayName := getValueByPath(fromObject, []string{"displayName"}) + if fromDisplayName != nil { + setValueByPath(parentObject, []string{"batch", "displayName"}, fromDisplayName) + } + + if getValueByPath(fromObject, []string{"dest"}) != nil { + return nil, fmt.Errorf("dest parameter is not supported in Gemini API") + } + + return toObject, nil +} + +func createBatchJobParametersToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromModel := getValueByPath(fromObject, []string{"model"}) + if fromModel != nil { + fromModel, err = tModel(ac, fromModel) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"_url", "model"}, fromModel) + } + + fromSrc := getValueByPath(fromObject, []string{"src"}) + if fromSrc != nil { + fromSrc, err = tBatchJobSource(ac, fromSrc) + if err != nil { + return nil, err + } + + fromSrc, err = batchJobSourceToMldev(ac, fromSrc.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"batch", "inputConfig"}, fromSrc) + } + + fromConfig := getValueByPath(fromObject, []string{"config"}) + if fromConfig != nil { + fromConfig, err = createBatchJobConfigToMldev(ac, fromConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"config"}, fromConfig) + } + + return toObject, nil +} + +func getBatchJobParametersToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromName := getValueByPath(fromObject, []string{"name"}) + if fromName != nil { + fromName, err = tBatchJobName(ac, fromName) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"_url", "name"}, fromName) + } + + fromConfig := getValueByPath(fromObject, []string{"config"}) + if fromConfig != nil { + setValueByPath(toObject, []string{"config"}, fromConfig) + } + + return toObject, nil +} + +func cancelBatchJobParametersToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromName := getValueByPath(fromObject, []string{"name"}) + if fromName != nil { + fromName, err = tBatchJobName(ac, fromName) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"_url", "name"}, fromName) + } + + fromConfig := getValueByPath(fromObject, []string{"config"}) + if fromConfig != nil { + setValueByPath(toObject, []string{"config"}, fromConfig) + } + + return toObject, nil +} + +func listBatchJobsConfigToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromPageSize := getValueByPath(fromObject, []string{"pageSize"}) + if fromPageSize != nil { + setValueByPath(parentObject, []string{"_query", "pageSize"}, fromPageSize) + } + + fromPageToken := getValueByPath(fromObject, []string{"pageToken"}) + if fromPageToken != nil { + setValueByPath(parentObject, []string{"_query", "pageToken"}, fromPageToken) + } + + if getValueByPath(fromObject, []string{"filter"}) != nil { + return nil, fmt.Errorf("filter parameter is not supported in Gemini API") + } + + return toObject, nil +} + +func listBatchJobsParametersToMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromConfig := getValueByPath(fromObject, []string{"config"}) + if fromConfig != nil { + fromConfig, err = listBatchJobsConfigToMldev(ac, fromConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"config"}, fromConfig) + } + + return toObject, nil +} + +func inlinedRequestToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + if getValueByPath(fromObject, []string{"model"}) != nil { + return nil, fmt.Errorf("model parameter is not supported in Vertex AI") + } + + if getValueByPath(fromObject, []string{"contents"}) != nil { + return nil, fmt.Errorf("contents parameter is not supported in Vertex AI") + } + + if getValueByPath(fromObject, []string{"config"}) != nil { + return nil, fmt.Errorf("config parameter is not supported in Vertex AI") + } + + return toObject, nil +} + +func batchJobSourceToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromFormat := getValueByPath(fromObject, []string{"format"}) + if fromFormat != nil { + setValueByPath(toObject, []string{"instancesFormat"}, fromFormat) + } + + fromGcsUri := getValueByPath(fromObject, []string{"gcsUri"}) + if fromGcsUri != nil { + setValueByPath(toObject, []string{"gcsSource", "uris"}, fromGcsUri) + } + + fromBigqueryUri := getValueByPath(fromObject, []string{"bigqueryUri"}) + if fromBigqueryUri != nil { + setValueByPath(toObject, []string{"bigquerySource", "inputUri"}, fromBigqueryUri) + } + + if getValueByPath(fromObject, []string{"fileName"}) != nil { + return nil, fmt.Errorf("fileName parameter is not supported in Vertex AI") + } + + if getValueByPath(fromObject, []string{"inlinedRequests"}) != nil { + return nil, fmt.Errorf("inlinedRequests parameter is not supported in Vertex AI") + } + + return toObject, nil +} + +func citationMetadataToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromCitations := getValueByPath(fromObject, []string{"citations"}) + if fromCitations != nil { + setValueByPath(toObject, []string{"citations"}, fromCitations) + } + + return toObject, nil +} + +func urlMetadataToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromRetrievedUrl := getValueByPath(fromObject, []string{"retrievedUrl"}) + if fromRetrievedUrl != nil { + setValueByPath(toObject, []string{"retrievedUrl"}, fromRetrievedUrl) + } + + fromUrlRetrievalStatus := getValueByPath(fromObject, []string{"urlRetrievalStatus"}) + if fromUrlRetrievalStatus != nil { + setValueByPath(toObject, []string{"urlRetrievalStatus"}, fromUrlRetrievalStatus) + } + + return toObject, nil +} + +func urlContextMetadataToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromUrlMetadata := getValueByPath(fromObject, []string{"urlMetadata"}) + if fromUrlMetadata != nil { + fromUrlMetadata, err = applyConverterToSlice(ac, fromUrlMetadata.([]any), urlMetadataToVertex) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"urlMetadata"}, fromUrlMetadata) + } + + return toObject, nil +} + +func candidateToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromContent := getValueByPath(fromObject, []string{"content"}) + if fromContent != nil { + fromContent, err = contentToVertex(ac, fromContent.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"content"}, fromContent) + } + + fromCitationMetadata := getValueByPath(fromObject, []string{"citationMetadata"}) + if fromCitationMetadata != nil { + fromCitationMetadata, err = citationMetadataToVertex(ac, fromCitationMetadata.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"citationMetadata"}, fromCitationMetadata) + } + + fromFinishMessage := getValueByPath(fromObject, []string{"finishMessage"}) + if fromFinishMessage != nil { + setValueByPath(toObject, []string{"finishMessage"}, fromFinishMessage) + } + + if getValueByPath(fromObject, []string{"tokenCount"}) != nil { + return nil, fmt.Errorf("tokenCount parameter is not supported in Vertex AI") + } + + fromFinishReason := getValueByPath(fromObject, []string{"finishReason"}) + if fromFinishReason != nil { + setValueByPath(toObject, []string{"finishReason"}, fromFinishReason) + } + + fromUrlContextMetadata := getValueByPath(fromObject, []string{"urlContextMetadata"}) + if fromUrlContextMetadata != nil { + fromUrlContextMetadata, err = urlContextMetadataToVertex(ac, fromUrlContextMetadata.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"urlContextMetadata"}, fromUrlContextMetadata) + } + + fromAvgLogprobs := getValueByPath(fromObject, []string{"avgLogprobs"}) + if fromAvgLogprobs != nil { + setValueByPath(toObject, []string{"avgLogprobs"}, fromAvgLogprobs) + } + + fromGroundingMetadata := getValueByPath(fromObject, []string{"groundingMetadata"}) + if fromGroundingMetadata != nil { + setValueByPath(toObject, []string{"groundingMetadata"}, fromGroundingMetadata) + } + + fromIndex := getValueByPath(fromObject, []string{"index"}) + if fromIndex != nil { + setValueByPath(toObject, []string{"index"}, fromIndex) + } + + fromLogprobsResult := getValueByPath(fromObject, []string{"logprobsResult"}) + if fromLogprobsResult != nil { + setValueByPath(toObject, []string{"logprobsResult"}, fromLogprobsResult) + } + + fromSafetyRatings := getValueByPath(fromObject, []string{"safetyRatings"}) + if fromSafetyRatings != nil { + setValueByPath(toObject, []string{"safetyRatings"}, fromSafetyRatings) + } + + return toObject, nil +} + +func generateContentResponseToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromCandidates := getValueByPath(fromObject, []string{"candidates"}) + if fromCandidates != nil { + fromCandidates, err = applyConverterToSlice(ac, fromCandidates.([]any), candidateToVertex) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"candidates"}, fromCandidates) + } + + fromCreateTime := getValueByPath(fromObject, []string{"createTime"}) + if fromCreateTime != nil { + setValueByPath(toObject, []string{"createTime"}, fromCreateTime) + } + + fromResponseId := getValueByPath(fromObject, []string{"responseId"}) + if fromResponseId != nil { + setValueByPath(toObject, []string{"responseId"}, fromResponseId) + } + + fromModelVersion := getValueByPath(fromObject, []string{"modelVersion"}) + if fromModelVersion != nil { + setValueByPath(toObject, []string{"modelVersion"}, fromModelVersion) + } + + fromPromptFeedback := getValueByPath(fromObject, []string{"promptFeedback"}) + if fromPromptFeedback != nil { + setValueByPath(toObject, []string{"promptFeedback"}, fromPromptFeedback) + } + + fromUsageMetadata := getValueByPath(fromObject, []string{"usageMetadata"}) + if fromUsageMetadata != nil { + setValueByPath(toObject, []string{"usageMetadata"}, fromUsageMetadata) + } + + return toObject, nil +} + +func jobErrorToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromDetails := getValueByPath(fromObject, []string{"details"}) + if fromDetails != nil { + setValueByPath(toObject, []string{"details"}, fromDetails) + } + + fromCode := getValueByPath(fromObject, []string{"code"}) + if fromCode != nil { + setValueByPath(toObject, []string{"code"}, fromCode) + } + + fromMessage := getValueByPath(fromObject, []string{"message"}) + if fromMessage != nil { + setValueByPath(toObject, []string{"message"}, fromMessage) + } + + return toObject, nil +} + +func inlinedResponseToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + if getValueByPath(fromObject, []string{"response"}) != nil { + return nil, fmt.Errorf("response parameter is not supported in Vertex AI") + } + + if getValueByPath(fromObject, []string{"error"}) != nil { + return nil, fmt.Errorf("error parameter is not supported in Vertex AI") + } + + return toObject, nil +} + +func batchJobDestinationToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromFormat := getValueByPath(fromObject, []string{"format"}) + if fromFormat != nil { + setValueByPath(toObject, []string{"predictionsFormat"}, fromFormat) + } + + fromGcsUri := getValueByPath(fromObject, []string{"gcsUri"}) + if fromGcsUri != nil { + setValueByPath(toObject, []string{"gcsDestination", "outputUriPrefix"}, fromGcsUri) + } + + fromBigqueryUri := getValueByPath(fromObject, []string{"bigqueryUri"}) + if fromBigqueryUri != nil { + setValueByPath(toObject, []string{"bigqueryDestination", "outputUri"}, fromBigqueryUri) + } + + if getValueByPath(fromObject, []string{"fileName"}) != nil { + return nil, fmt.Errorf("fileName parameter is not supported in Vertex AI") + } + + if getValueByPath(fromObject, []string{"inlinedResponses"}) != nil { + return nil, fmt.Errorf("inlinedResponses parameter is not supported in Vertex AI") + } + + return toObject, nil +} + +func createBatchJobConfigToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromDisplayName := getValueByPath(fromObject, []string{"displayName"}) + if fromDisplayName != nil { + setValueByPath(parentObject, []string{"displayName"}, fromDisplayName) + } + + fromDest := getValueByPath(fromObject, []string{"dest"}) + if fromDest != nil { + fromDest, err = tBatchJobDestination(ac, fromDest) + if err != nil { + return nil, err + } + + fromDest, err = batchJobDestinationToVertex(ac, fromDest.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(parentObject, []string{"outputConfig"}, fromDest) + } + + return toObject, nil +} + +func createBatchJobParametersToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromModel := getValueByPath(fromObject, []string{"model"}) + if fromModel != nil { + fromModel, err = tModel(ac, fromModel) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"model"}, fromModel) + } + + fromSrc := getValueByPath(fromObject, []string{"src"}) + if fromSrc != nil { + fromSrc, err = tBatchJobSource(ac, fromSrc) + if err != nil { + return nil, err + } + + fromSrc, err = batchJobSourceToVertex(ac, fromSrc.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"inputConfig"}, fromSrc) + } + + fromConfig := getValueByPath(fromObject, []string{"config"}) + if fromConfig != nil { + fromConfig, err = createBatchJobConfigToVertex(ac, fromConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"config"}, fromConfig) + } + + return toObject, nil +} + +func getBatchJobParametersToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromName := getValueByPath(fromObject, []string{"name"}) + if fromName != nil { + fromName, err = tBatchJobName(ac, fromName) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"_url", "name"}, fromName) + } + + fromConfig := getValueByPath(fromObject, []string{"config"}) + if fromConfig != nil { + setValueByPath(toObject, []string{"config"}, fromConfig) + } + + return toObject, nil +} + +func cancelBatchJobParametersToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromName := getValueByPath(fromObject, []string{"name"}) + if fromName != nil { + fromName, err = tBatchJobName(ac, fromName) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"_url", "name"}, fromName) + } + + fromConfig := getValueByPath(fromObject, []string{"config"}) + if fromConfig != nil { + setValueByPath(toObject, []string{"config"}, fromConfig) + } + + return toObject, nil +} + +func listBatchJobsConfigToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromPageSize := getValueByPath(fromObject, []string{"pageSize"}) + if fromPageSize != nil { + setValueByPath(parentObject, []string{"_query", "pageSize"}, fromPageSize) + } + + fromPageToken := getValueByPath(fromObject, []string{"pageToken"}) + if fromPageToken != nil { + setValueByPath(parentObject, []string{"_query", "pageToken"}, fromPageToken) + } + + fromFilter := getValueByPath(fromObject, []string{"filter"}) + if fromFilter != nil { + setValueByPath(parentObject, []string{"_query", "filter"}, fromFilter) + } + + return toObject, nil +} + +func listBatchJobsParametersToVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromConfig := getValueByPath(fromObject, []string{"config"}) + if fromConfig != nil { + fromConfig, err = listBatchJobsConfigToVertex(ac, fromConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"config"}, fromConfig) + } + + return toObject, nil +} + +func jobErrorFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func schemaFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromAnyOf := getValueByPath(fromObject, []string{"anyOf"}) + if fromAnyOf != nil { + setValueByPath(toObject, []string{"anyOf"}, fromAnyOf) + } + + fromDefault := getValueByPath(fromObject, []string{"default"}) + if fromDefault != nil { + setValueByPath(toObject, []string{"default"}, fromDefault) + } + + fromDescription := getValueByPath(fromObject, []string{"description"}) + if fromDescription != nil { + setValueByPath(toObject, []string{"description"}, fromDescription) + } + + fromEnum := getValueByPath(fromObject, []string{"enum"}) + if fromEnum != nil { + setValueByPath(toObject, []string{"enum"}, fromEnum) + } + + fromExample := getValueByPath(fromObject, []string{"example"}) + if fromExample != nil { + setValueByPath(toObject, []string{"example"}, fromExample) + } + + fromFormat := getValueByPath(fromObject, []string{"format"}) + if fromFormat != nil { + setValueByPath(toObject, []string{"format"}, fromFormat) + } + + fromItems := getValueByPath(fromObject, []string{"items"}) + if fromItems != nil { + setValueByPath(toObject, []string{"items"}, fromItems) + } + + fromMaxItems := getValueByPath(fromObject, []string{"maxItems"}) + if fromMaxItems != nil { + setValueByPath(toObject, []string{"maxItems"}, fromMaxItems) + } + + fromMaxLength := getValueByPath(fromObject, []string{"maxLength"}) + if fromMaxLength != nil { + setValueByPath(toObject, []string{"maxLength"}, fromMaxLength) + } + + fromMaxProperties := getValueByPath(fromObject, []string{"maxProperties"}) + if fromMaxProperties != nil { + setValueByPath(toObject, []string{"maxProperties"}, fromMaxProperties) + } + + fromMaximum := getValueByPath(fromObject, []string{"maximum"}) + if fromMaximum != nil { + setValueByPath(toObject, []string{"maximum"}, fromMaximum) + } + + fromMinItems := getValueByPath(fromObject, []string{"minItems"}) + if fromMinItems != nil { + setValueByPath(toObject, []string{"minItems"}, fromMinItems) + } + + fromMinLength := getValueByPath(fromObject, []string{"minLength"}) + if fromMinLength != nil { + setValueByPath(toObject, []string{"minLength"}, fromMinLength) + } + + fromMinProperties := getValueByPath(fromObject, []string{"minProperties"}) + if fromMinProperties != nil { + setValueByPath(toObject, []string{"minProperties"}, fromMinProperties) + } + + fromMinimum := getValueByPath(fromObject, []string{"minimum"}) + if fromMinimum != nil { + setValueByPath(toObject, []string{"minimum"}, fromMinimum) + } + + fromNullable := getValueByPath(fromObject, []string{"nullable"}) + if fromNullable != nil { + setValueByPath(toObject, []string{"nullable"}, fromNullable) + } + + fromPattern := getValueByPath(fromObject, []string{"pattern"}) + if fromPattern != nil { + setValueByPath(toObject, []string{"pattern"}, fromPattern) + } + + fromProperties := getValueByPath(fromObject, []string{"properties"}) + if fromProperties != nil { + setValueByPath(toObject, []string{"properties"}, fromProperties) + } + + fromPropertyOrdering := getValueByPath(fromObject, []string{"propertyOrdering"}) + if fromPropertyOrdering != nil { + setValueByPath(toObject, []string{"propertyOrdering"}, fromPropertyOrdering) + } + + fromRequired := getValueByPath(fromObject, []string{"required"}) + if fromRequired != nil { + setValueByPath(toObject, []string{"required"}, fromRequired) + } + + fromTitle := getValueByPath(fromObject, []string{"title"}) + if fromTitle != nil { + setValueByPath(toObject, []string{"title"}, fromTitle) + } + + fromType := getValueByPath(fromObject, []string{"type"}) + if fromType != nil { + setValueByPath(toObject, []string{"type"}, fromType) + } + + return toObject, nil +} + +func modelSelectionConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func safetySettingFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromCategory := getValueByPath(fromObject, []string{"category"}) + if fromCategory != nil { + setValueByPath(toObject, []string{"category"}, fromCategory) + } + + fromThreshold := getValueByPath(fromObject, []string{"threshold"}) + if fromThreshold != nil { + setValueByPath(toObject, []string{"threshold"}, fromThreshold) + } + + return toObject, nil +} + +func functionDeclarationFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromBehavior := getValueByPath(fromObject, []string{"behavior"}) + if fromBehavior != nil { + setValueByPath(toObject, []string{"behavior"}, fromBehavior) + } + + fromDescription := getValueByPath(fromObject, []string{"description"}) + if fromDescription != nil { + setValueByPath(toObject, []string{"description"}, fromDescription) + } + + fromName := getValueByPath(fromObject, []string{"name"}) + if fromName != nil { + setValueByPath(toObject, []string{"name"}, fromName) + } + + fromParameters := getValueByPath(fromObject, []string{"parameters"}) + if fromParameters != nil { + setValueByPath(toObject, []string{"parameters"}, fromParameters) + } + + fromParametersJsonSchema := getValueByPath(fromObject, []string{"parametersJsonSchema"}) + if fromParametersJsonSchema != nil { + setValueByPath(toObject, []string{"parametersJsonSchema"}, fromParametersJsonSchema) + } + + fromResponse := getValueByPath(fromObject, []string{"response"}) + if fromResponse != nil { + setValueByPath(toObject, []string{"response"}, fromResponse) + } + + fromResponseJsonSchema := getValueByPath(fromObject, []string{"responseJsonSchema"}) + if fromResponseJsonSchema != nil { + setValueByPath(toObject, []string{"responseJsonSchema"}, fromResponseJsonSchema) + } + + return toObject, nil +} + +func intervalFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromStartTime := getValueByPath(fromObject, []string{"startTime"}) + if fromStartTime != nil { + setValueByPath(toObject, []string{"startTime"}, fromStartTime) + } + + fromEndTime := getValueByPath(fromObject, []string{"endTime"}) + if fromEndTime != nil { + setValueByPath(toObject, []string{"endTime"}, fromEndTime) + } + + return toObject, nil +} + +func googleSearchFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromTimeRangeFilter := getValueByPath(fromObject, []string{"timeRangeFilter"}) + if fromTimeRangeFilter != nil { + fromTimeRangeFilter, err = intervalFromMldev(ac, fromTimeRangeFilter.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"timeRangeFilter"}, fromTimeRangeFilter) + } + + return toObject, nil +} + +func dynamicRetrievalConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromMode := getValueByPath(fromObject, []string{"mode"}) + if fromMode != nil { + setValueByPath(toObject, []string{"mode"}, fromMode) + } + + fromDynamicThreshold := getValueByPath(fromObject, []string{"dynamicThreshold"}) + if fromDynamicThreshold != nil { + setValueByPath(toObject, []string{"dynamicThreshold"}, fromDynamicThreshold) + } + + return toObject, nil +} + +func googleSearchRetrievalFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromDynamicRetrievalConfig := getValueByPath(fromObject, []string{"dynamicRetrievalConfig"}) + if fromDynamicRetrievalConfig != nil { + fromDynamicRetrievalConfig, err = dynamicRetrievalConfigFromMldev(ac, fromDynamicRetrievalConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"dynamicRetrievalConfig"}, fromDynamicRetrievalConfig) + } + + return toObject, nil +} + +func enterpriseWebSearchFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func apiKeyConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func authConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromAuthType := getValueByPath(fromObject, []string{"authType"}) + if fromAuthType != nil { + setValueByPath(toObject, []string{"authType"}, fromAuthType) + } + + fromGoogleServiceAccountConfig := getValueByPath(fromObject, []string{"googleServiceAccountConfig"}) + if fromGoogleServiceAccountConfig != nil { + setValueByPath(toObject, []string{"googleServiceAccountConfig"}, fromGoogleServiceAccountConfig) + } + + fromHttpBasicAuthConfig := getValueByPath(fromObject, []string{"httpBasicAuthConfig"}) + if fromHttpBasicAuthConfig != nil { + setValueByPath(toObject, []string{"httpBasicAuthConfig"}, fromHttpBasicAuthConfig) + } + + fromOauthConfig := getValueByPath(fromObject, []string{"oauthConfig"}) + if fromOauthConfig != nil { + setValueByPath(toObject, []string{"oauthConfig"}, fromOauthConfig) + } + + fromOidcConfig := getValueByPath(fromObject, []string{"oidcConfig"}) + if fromOidcConfig != nil { + setValueByPath(toObject, []string{"oidcConfig"}, fromOidcConfig) + } + + return toObject, nil +} + +func googleMapsFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func urlContextFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func toolFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromFunctionDeclarations := getValueByPath(fromObject, []string{"functionDeclarations"}) + if fromFunctionDeclarations != nil { + fromFunctionDeclarations, err = applyConverterToSlice(ac, fromFunctionDeclarations.([]any), functionDeclarationFromMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"functionDeclarations"}, fromFunctionDeclarations) + } + + fromGoogleSearch := getValueByPath(fromObject, []string{"googleSearch"}) + if fromGoogleSearch != nil { + fromGoogleSearch, err = googleSearchFromMldev(ac, fromGoogleSearch.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"googleSearch"}, fromGoogleSearch) + } + + fromGoogleSearchRetrieval := getValueByPath(fromObject, []string{"googleSearchRetrieval"}) + if fromGoogleSearchRetrieval != nil { + fromGoogleSearchRetrieval, err = googleSearchRetrievalFromMldev(ac, fromGoogleSearchRetrieval.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"googleSearchRetrieval"}, fromGoogleSearchRetrieval) + } + + fromUrlContext := getValueByPath(fromObject, []string{"urlContext"}) + if fromUrlContext != nil { + fromUrlContext, err = urlContextFromMldev(ac, fromUrlContext.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"urlContext"}, fromUrlContext) + } + + fromCodeExecution := getValueByPath(fromObject, []string{"codeExecution"}) + if fromCodeExecution != nil { + setValueByPath(toObject, []string{"codeExecution"}, fromCodeExecution) + } + + return toObject, nil +} + +func functionCallingConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromMode := getValueByPath(fromObject, []string{"mode"}) + if fromMode != nil { + setValueByPath(toObject, []string{"mode"}, fromMode) + } + + fromAllowedFunctionNames := getValueByPath(fromObject, []string{"allowedFunctionNames"}) + if fromAllowedFunctionNames != nil { + setValueByPath(toObject, []string{"allowedFunctionNames"}, fromAllowedFunctionNames) + } + + return toObject, nil +} + +func latLngFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromLatitude := getValueByPath(fromObject, []string{"latitude"}) + if fromLatitude != nil { + setValueByPath(toObject, []string{"latitude"}, fromLatitude) + } + + fromLongitude := getValueByPath(fromObject, []string{"longitude"}) + if fromLongitude != nil { + setValueByPath(toObject, []string{"longitude"}, fromLongitude) + } + + return toObject, nil +} + +func retrievalConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromLatLng := getValueByPath(fromObject, []string{"latLng"}) + if fromLatLng != nil { + fromLatLng, err = latLngFromMldev(ac, fromLatLng.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"latLng"}, fromLatLng) + } + + fromLanguageCode := getValueByPath(fromObject, []string{"languageCode"}) + if fromLanguageCode != nil { + setValueByPath(toObject, []string{"languageCode"}, fromLanguageCode) + } + + return toObject, nil +} + +func toolConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromFunctionCallingConfig := getValueByPath(fromObject, []string{"functionCallingConfig"}) + if fromFunctionCallingConfig != nil { + fromFunctionCallingConfig, err = functionCallingConfigFromMldev(ac, fromFunctionCallingConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"functionCallingConfig"}, fromFunctionCallingConfig) + } + + fromRetrievalConfig := getValueByPath(fromObject, []string{"retrievalConfig"}) + if fromRetrievalConfig != nil { + fromRetrievalConfig, err = retrievalConfigFromMldev(ac, fromRetrievalConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"retrievalConfig"}, fromRetrievalConfig) + } + + return toObject, nil +} + +func prebuiltVoiceConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromVoiceName := getValueByPath(fromObject, []string{"voiceName"}) + if fromVoiceName != nil { + setValueByPath(toObject, []string{"voiceName"}, fromVoiceName) + } + + return toObject, nil +} + +func voiceConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromPrebuiltVoiceConfig := getValueByPath(fromObject, []string{"prebuiltVoiceConfig"}) + if fromPrebuiltVoiceConfig != nil { + fromPrebuiltVoiceConfig, err = prebuiltVoiceConfigFromMldev(ac, fromPrebuiltVoiceConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"prebuiltVoiceConfig"}, fromPrebuiltVoiceConfig) + } + + return toObject, nil +} + +func speakerVoiceConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromSpeaker := getValueByPath(fromObject, []string{"speaker"}) + if fromSpeaker != nil { + setValueByPath(toObject, []string{"speaker"}, fromSpeaker) + } + + fromVoiceConfig := getValueByPath(fromObject, []string{"voiceConfig"}) + if fromVoiceConfig != nil { + fromVoiceConfig, err = voiceConfigFromMldev(ac, fromVoiceConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"voiceConfig"}, fromVoiceConfig) + } + + return toObject, nil +} + +func multiSpeakerVoiceConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromSpeakerVoiceConfigs := getValueByPath(fromObject, []string{"speakerVoiceConfigs"}) + if fromSpeakerVoiceConfigs != nil { + fromSpeakerVoiceConfigs, err = applyConverterToSlice(ac, fromSpeakerVoiceConfigs.([]any), speakerVoiceConfigFromMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"speakerVoiceConfigs"}, fromSpeakerVoiceConfigs) + } + + return toObject, nil +} + +func speechConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromVoiceConfig := getValueByPath(fromObject, []string{"voiceConfig"}) + if fromVoiceConfig != nil { + fromVoiceConfig, err = voiceConfigFromMldev(ac, fromVoiceConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"voiceConfig"}, fromVoiceConfig) + } + + fromMultiSpeakerVoiceConfig := getValueByPath(fromObject, []string{"multiSpeakerVoiceConfig"}) + if fromMultiSpeakerVoiceConfig != nil { + fromMultiSpeakerVoiceConfig, err = multiSpeakerVoiceConfigFromMldev(ac, fromMultiSpeakerVoiceConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"multiSpeakerVoiceConfig"}, fromMultiSpeakerVoiceConfig) + } + + fromLanguageCode := getValueByPath(fromObject, []string{"languageCode"}) + if fromLanguageCode != nil { + setValueByPath(toObject, []string{"languageCode"}, fromLanguageCode) + } + + return toObject, nil +} + +func thinkingConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromIncludeThoughts := getValueByPath(fromObject, []string{"includeThoughts"}) + if fromIncludeThoughts != nil { + setValueByPath(toObject, []string{"includeThoughts"}, fromIncludeThoughts) + } + + fromThinkingBudget := getValueByPath(fromObject, []string{"thinkingBudget"}) + if fromThinkingBudget != nil { + setValueByPath(toObject, []string{"thinkingBudget"}, fromThinkingBudget) + } + + return toObject, nil +} + +func generateContentConfigFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromSystemInstruction := getValueByPath(fromObject, []string{"systemInstruction"}) + if fromSystemInstruction != nil { + fromSystemInstruction, err = tContent(ac, fromSystemInstruction) + if err != nil { + return nil, err + } + + fromSystemInstruction, err = contentFromMldev(ac, fromSystemInstruction.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"systemInstruction"}, fromSystemInstruction) + } + + fromTemperature := getValueByPath(fromObject, []string{"temperature"}) + if fromTemperature != nil { + setValueByPath(toObject, []string{"temperature"}, fromTemperature) + } + + fromTopP := getValueByPath(fromObject, []string{"topP"}) + if fromTopP != nil { + setValueByPath(toObject, []string{"topP"}, fromTopP) + } + + fromTopK := getValueByPath(fromObject, []string{"topK"}) + if fromTopK != nil { + setValueByPath(toObject, []string{"topK"}, fromTopK) + } + + fromCandidateCount := getValueByPath(fromObject, []string{"candidateCount"}) + if fromCandidateCount != nil { + setValueByPath(toObject, []string{"candidateCount"}, fromCandidateCount) + } + + fromMaxOutputTokens := getValueByPath(fromObject, []string{"maxOutputTokens"}) + if fromMaxOutputTokens != nil { + setValueByPath(toObject, []string{"maxOutputTokens"}, fromMaxOutputTokens) + } + + fromStopSequences := getValueByPath(fromObject, []string{"stopSequences"}) + if fromStopSequences != nil { + setValueByPath(toObject, []string{"stopSequences"}, fromStopSequences) + } + + fromResponseLogprobs := getValueByPath(fromObject, []string{"responseLogprobs"}) + if fromResponseLogprobs != nil { + setValueByPath(toObject, []string{"responseLogprobs"}, fromResponseLogprobs) + } + + fromLogprobs := getValueByPath(fromObject, []string{"logprobs"}) + if fromLogprobs != nil { + setValueByPath(toObject, []string{"logprobs"}, fromLogprobs) + } + + fromPresencePenalty := getValueByPath(fromObject, []string{"presencePenalty"}) + if fromPresencePenalty != nil { + setValueByPath(toObject, []string{"presencePenalty"}, fromPresencePenalty) + } + + fromFrequencyPenalty := getValueByPath(fromObject, []string{"frequencyPenalty"}) + if fromFrequencyPenalty != nil { + setValueByPath(toObject, []string{"frequencyPenalty"}, fromFrequencyPenalty) + } + + fromSeed := getValueByPath(fromObject, []string{"seed"}) + if fromSeed != nil { + setValueByPath(toObject, []string{"seed"}, fromSeed) + } + + fromResponseMimeType := getValueByPath(fromObject, []string{"responseMimeType"}) + if fromResponseMimeType != nil { + setValueByPath(toObject, []string{"responseMimeType"}, fromResponseMimeType) + } + + fromResponseSchema := getValueByPath(fromObject, []string{"responseSchema"}) + if fromResponseSchema != nil { + fromResponseSchema, err = tSchema(ac, fromResponseSchema) + if err != nil { + return nil, err + } + + fromResponseSchema, err = schemaFromMldev(ac, fromResponseSchema.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"responseSchema"}, fromResponseSchema) + } + + fromResponseJsonSchema := getValueByPath(fromObject, []string{"responseJsonSchema"}) + if fromResponseJsonSchema != nil { + setValueByPath(toObject, []string{"responseJsonSchema"}, fromResponseJsonSchema) + } + + fromSafetySettings := getValueByPath(fromObject, []string{"safetySettings"}) + if fromSafetySettings != nil { + fromSafetySettings, err = applyConverterToSlice(ac, fromSafetySettings.([]any), safetySettingFromMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"safetySettings"}, fromSafetySettings) + } + + fromTools := getValueByPath(fromObject, []string{"tools"}) + if fromTools != nil { + fromTools, err = applyItemTransformerToSlice(ac, fromTools.([]any), tTool) + if err != nil { + return nil, err + } + + fromTools, err = tTools(ac, fromTools) + if err != nil { + return nil, err + } + + fromTools, err = applyConverterToSlice(ac, fromTools.([]any), toolFromMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"tools"}, fromTools) + } + + fromToolConfig := getValueByPath(fromObject, []string{"toolConfig"}) + if fromToolConfig != nil { + fromToolConfig, err = toolConfigFromMldev(ac, fromToolConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"toolConfig"}, fromToolConfig) + } + + fromCachedContent := getValueByPath(fromObject, []string{"cachedContent"}) + if fromCachedContent != nil { + fromCachedContent, err = tCachedContentName(ac, fromCachedContent) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"cachedContent"}, fromCachedContent) + } + + fromResponseModalities := getValueByPath(fromObject, []string{"responseModalities"}) + if fromResponseModalities != nil { + setValueByPath(toObject, []string{"responseModalities"}, fromResponseModalities) + } + + fromMediaResolution := getValueByPath(fromObject, []string{"mediaResolution"}) + if fromMediaResolution != nil { + setValueByPath(toObject, []string{"mediaResolution"}, fromMediaResolution) + } + + fromSpeechConfig := getValueByPath(fromObject, []string{"speechConfig"}) + if fromSpeechConfig != nil { + fromSpeechConfig, err = tSpeechConfig(ac, fromSpeechConfig) + if err != nil { + return nil, err + } + + fromSpeechConfig, err = speechConfigFromMldev(ac, fromSpeechConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"speechConfig"}, fromSpeechConfig) + } + + fromThinkingConfig := getValueByPath(fromObject, []string{"thinkingConfig"}) + if fromThinkingConfig != nil { + fromThinkingConfig, err = thinkingConfigFromMldev(ac, fromThinkingConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"thinkingConfig"}, fromThinkingConfig) + } + + return toObject, nil +} + +func inlinedRequestFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromModel := getValueByPath(fromObject, []string{"request", "model"}) + if fromModel != nil { + fromModel, err = tModel(ac, fromModel) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"model"}, fromModel) + } + + fromContents := getValueByPath(fromObject, []string{"request", "contents"}) + if fromContents != nil { + fromContents, err = tContents(ac, fromContents) + if err != nil { + return nil, err + } + + fromContents, err = applyConverterToSlice(ac, fromContents.([]any), contentFromMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"contents"}, fromContents) + } + + fromConfig := getValueByPath(fromObject, []string{"request", "generationConfig"}) + if fromConfig != nil { + fromConfig, err = generateContentConfigFromMldev(ac, fromConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"config"}, fromConfig) + } + + return toObject, nil +} + +func batchJobSourceFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromFileName := getValueByPath(fromObject, []string{"fileName"}) + if fromFileName != nil { + setValueByPath(toObject, []string{"fileName"}, fromFileName) + } + + fromInlinedRequests := getValueByPath(fromObject, []string{"requests", "requests"}) + if fromInlinedRequests != nil { + fromInlinedRequests, err = applyConverterToSlice(ac, fromInlinedRequests.([]any), inlinedRequestFromMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"inlinedRequests"}, fromInlinedRequests) + } + + return toObject, nil +} + +func inlinedResponseFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromResponse := getValueByPath(fromObject, []string{"response"}) + if fromResponse != nil { + fromResponse, err = generateContentResponseFromMldev(ac, fromResponse.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"response"}, fromResponse) + } + + fromError := getValueByPath(fromObject, []string{"error"}) + if fromError != nil { + fromError, err = jobErrorFromMldev(ac, fromError.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"error"}, fromError) + } + + return toObject, nil +} + +func batchJobDestinationFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromFileName := getValueByPath(fromObject, []string{"responsesFile"}) + if fromFileName != nil { + setValueByPath(toObject, []string{"fileName"}, fromFileName) + } + + fromInlinedResponses := getValueByPath(fromObject, []string{"inlinedResponses", "inlinedResponses"}) + if fromInlinedResponses != nil { + fromInlinedResponses, err = applyConverterToSlice(ac, fromInlinedResponses.([]any), inlinedResponseFromMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"inlinedResponses"}, fromInlinedResponses) + } + + return toObject, nil +} + +func batchJobFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromName := getValueByPath(fromObject, []string{"name"}) + if fromName != nil { + setValueByPath(toObject, []string{"name"}, fromName) + } + + fromDisplayName := getValueByPath(fromObject, []string{"metadata", "displayName"}) + if fromDisplayName != nil { + setValueByPath(toObject, []string{"displayName"}, fromDisplayName) + } + + fromState := getValueByPath(fromObject, []string{"metadata", "state"}) + if fromState != nil { + fromState, err = tJobState(ac, fromState) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"state"}, fromState) + } + + fromCreateTime := getValueByPath(fromObject, []string{"metadata", "createTime"}) + if fromCreateTime != nil { + setValueByPath(toObject, []string{"createTime"}, fromCreateTime) + } + + fromEndTime := getValueByPath(fromObject, []string{"metadata", "endTime"}) + if fromEndTime != nil { + setValueByPath(toObject, []string{"endTime"}, fromEndTime) + } + + fromUpdateTime := getValueByPath(fromObject, []string{"metadata", "updateTime"}) + if fromUpdateTime != nil { + setValueByPath(toObject, []string{"updateTime"}, fromUpdateTime) + } + + fromModel := getValueByPath(fromObject, []string{"metadata", "model"}) + if fromModel != nil { + setValueByPath(toObject, []string{"model"}, fromModel) + } + + fromDest := getValueByPath(fromObject, []string{"metadata", "output"}) + if fromDest != nil { + fromDest, err = batchJobDestinationFromMldev(ac, fromDest.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"dest"}, fromDest) + } + + return toObject, nil +} + +func listBatchJobsResponseFromMldev(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromNextPageToken := getValueByPath(fromObject, []string{"nextPageToken"}) + if fromNextPageToken != nil { + setValueByPath(toObject, []string{"nextPageToken"}, fromNextPageToken) + } + + fromBatchJobs := getValueByPath(fromObject, []string{"operations"}) + if fromBatchJobs != nil { + fromBatchJobs, err = applyConverterToSlice(ac, fromBatchJobs.([]any), batchJobFromMldev) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"batchJobs"}, fromBatchJobs) + } + + return toObject, nil +} + +func jobErrorFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromDetails := getValueByPath(fromObject, []string{"details"}) + if fromDetails != nil { + setValueByPath(toObject, []string{"details"}, fromDetails) + } + + fromCode := getValueByPath(fromObject, []string{"code"}) + if fromCode != nil { + setValueByPath(toObject, []string{"code"}, fromCode) + } + + fromMessage := getValueByPath(fromObject, []string{"message"}) + if fromMessage != nil { + setValueByPath(toObject, []string{"message"}, fromMessage) + } + + return toObject, nil +} + +func schemaFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromAnyOf := getValueByPath(fromObject, []string{"anyOf"}) + if fromAnyOf != nil { + setValueByPath(toObject, []string{"anyOf"}, fromAnyOf) + } + + fromDefault := getValueByPath(fromObject, []string{"default"}) + if fromDefault != nil { + setValueByPath(toObject, []string{"default"}, fromDefault) + } + + fromDescription := getValueByPath(fromObject, []string{"description"}) + if fromDescription != nil { + setValueByPath(toObject, []string{"description"}, fromDescription) + } + + fromEnum := getValueByPath(fromObject, []string{"enum"}) + if fromEnum != nil { + setValueByPath(toObject, []string{"enum"}, fromEnum) + } + + fromExample := getValueByPath(fromObject, []string{"example"}) + if fromExample != nil { + setValueByPath(toObject, []string{"example"}, fromExample) + } + + fromFormat := getValueByPath(fromObject, []string{"format"}) + if fromFormat != nil { + setValueByPath(toObject, []string{"format"}, fromFormat) + } + + fromItems := getValueByPath(fromObject, []string{"items"}) + if fromItems != nil { + setValueByPath(toObject, []string{"items"}, fromItems) + } + + fromMaxItems := getValueByPath(fromObject, []string{"maxItems"}) + if fromMaxItems != nil { + setValueByPath(toObject, []string{"maxItems"}, fromMaxItems) + } + + fromMaxLength := getValueByPath(fromObject, []string{"maxLength"}) + if fromMaxLength != nil { + setValueByPath(toObject, []string{"maxLength"}, fromMaxLength) + } + + fromMaxProperties := getValueByPath(fromObject, []string{"maxProperties"}) + if fromMaxProperties != nil { + setValueByPath(toObject, []string{"maxProperties"}, fromMaxProperties) + } + + fromMaximum := getValueByPath(fromObject, []string{"maximum"}) + if fromMaximum != nil { + setValueByPath(toObject, []string{"maximum"}, fromMaximum) + } + + fromMinItems := getValueByPath(fromObject, []string{"minItems"}) + if fromMinItems != nil { + setValueByPath(toObject, []string{"minItems"}, fromMinItems) + } + + fromMinLength := getValueByPath(fromObject, []string{"minLength"}) + if fromMinLength != nil { + setValueByPath(toObject, []string{"minLength"}, fromMinLength) + } + + fromMinProperties := getValueByPath(fromObject, []string{"minProperties"}) + if fromMinProperties != nil { + setValueByPath(toObject, []string{"minProperties"}, fromMinProperties) + } + + fromMinimum := getValueByPath(fromObject, []string{"minimum"}) + if fromMinimum != nil { + setValueByPath(toObject, []string{"minimum"}, fromMinimum) + } + + fromNullable := getValueByPath(fromObject, []string{"nullable"}) + if fromNullable != nil { + setValueByPath(toObject, []string{"nullable"}, fromNullable) + } + + fromPattern := getValueByPath(fromObject, []string{"pattern"}) + if fromPattern != nil { + setValueByPath(toObject, []string{"pattern"}, fromPattern) + } + + fromProperties := getValueByPath(fromObject, []string{"properties"}) + if fromProperties != nil { + setValueByPath(toObject, []string{"properties"}, fromProperties) + } + + fromPropertyOrdering := getValueByPath(fromObject, []string{"propertyOrdering"}) + if fromPropertyOrdering != nil { + setValueByPath(toObject, []string{"propertyOrdering"}, fromPropertyOrdering) + } + + fromRequired := getValueByPath(fromObject, []string{"required"}) + if fromRequired != nil { + setValueByPath(toObject, []string{"required"}, fromRequired) + } + + fromTitle := getValueByPath(fromObject, []string{"title"}) + if fromTitle != nil { + setValueByPath(toObject, []string{"title"}, fromTitle) + } + + fromType := getValueByPath(fromObject, []string{"type"}) + if fromType != nil { + setValueByPath(toObject, []string{"type"}, fromType) + } + + return toObject, nil +} + +func modelSelectionConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromFeatureSelectionPreference := getValueByPath(fromObject, []string{"featureSelectionPreference"}) + if fromFeatureSelectionPreference != nil { + setValueByPath(toObject, []string{"featureSelectionPreference"}, fromFeatureSelectionPreference) + } + + return toObject, nil +} + +func safetySettingFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromMethod := getValueByPath(fromObject, []string{"method"}) + if fromMethod != nil { + setValueByPath(toObject, []string{"method"}, fromMethod) + } + + fromCategory := getValueByPath(fromObject, []string{"category"}) + if fromCategory != nil { + setValueByPath(toObject, []string{"category"}, fromCategory) + } + + fromThreshold := getValueByPath(fromObject, []string{"threshold"}) + if fromThreshold != nil { + setValueByPath(toObject, []string{"threshold"}, fromThreshold) + } + + return toObject, nil +} + +func functionDeclarationFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromDescription := getValueByPath(fromObject, []string{"description"}) + if fromDescription != nil { + setValueByPath(toObject, []string{"description"}, fromDescription) + } + + fromName := getValueByPath(fromObject, []string{"name"}) + if fromName != nil { + setValueByPath(toObject, []string{"name"}, fromName) + } + + fromParameters := getValueByPath(fromObject, []string{"parameters"}) + if fromParameters != nil { + setValueByPath(toObject, []string{"parameters"}, fromParameters) + } + + fromParametersJsonSchema := getValueByPath(fromObject, []string{"parametersJsonSchema"}) + if fromParametersJsonSchema != nil { + setValueByPath(toObject, []string{"parametersJsonSchema"}, fromParametersJsonSchema) + } + + fromResponse := getValueByPath(fromObject, []string{"response"}) + if fromResponse != nil { + setValueByPath(toObject, []string{"response"}, fromResponse) + } + + fromResponseJsonSchema := getValueByPath(fromObject, []string{"responseJsonSchema"}) + if fromResponseJsonSchema != nil { + setValueByPath(toObject, []string{"responseJsonSchema"}, fromResponseJsonSchema) + } + + return toObject, nil +} + +func intervalFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromStartTime := getValueByPath(fromObject, []string{"startTime"}) + if fromStartTime != nil { + setValueByPath(toObject, []string{"startTime"}, fromStartTime) + } + + fromEndTime := getValueByPath(fromObject, []string{"endTime"}) + if fromEndTime != nil { + setValueByPath(toObject, []string{"endTime"}, fromEndTime) + } + + return toObject, nil +} + +func googleSearchFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromTimeRangeFilter := getValueByPath(fromObject, []string{"timeRangeFilter"}) + if fromTimeRangeFilter != nil { + fromTimeRangeFilter, err = intervalFromVertex(ac, fromTimeRangeFilter.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"timeRangeFilter"}, fromTimeRangeFilter) + } + + return toObject, nil +} + +func dynamicRetrievalConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromMode := getValueByPath(fromObject, []string{"mode"}) + if fromMode != nil { + setValueByPath(toObject, []string{"mode"}, fromMode) + } + + fromDynamicThreshold := getValueByPath(fromObject, []string{"dynamicThreshold"}) + if fromDynamicThreshold != nil { + setValueByPath(toObject, []string{"dynamicThreshold"}, fromDynamicThreshold) + } + + return toObject, nil +} + +func googleSearchRetrievalFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromDynamicRetrievalConfig := getValueByPath(fromObject, []string{"dynamicRetrievalConfig"}) + if fromDynamicRetrievalConfig != nil { + fromDynamicRetrievalConfig, err = dynamicRetrievalConfigFromVertex(ac, fromDynamicRetrievalConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"dynamicRetrievalConfig"}, fromDynamicRetrievalConfig) + } + + return toObject, nil +} + +func enterpriseWebSearchFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func apiKeyConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromApiKeyString := getValueByPath(fromObject, []string{"apiKeyString"}) + if fromApiKeyString != nil { + setValueByPath(toObject, []string{"apiKeyString"}, fromApiKeyString) + } + + return toObject, nil +} + +func authConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromApiKeyConfig := getValueByPath(fromObject, []string{"apiKeyConfig"}) + if fromApiKeyConfig != nil { + fromApiKeyConfig, err = apiKeyConfigFromVertex(ac, fromApiKeyConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"apiKeyConfig"}, fromApiKeyConfig) + } + + fromAuthType := getValueByPath(fromObject, []string{"authType"}) + if fromAuthType != nil { + setValueByPath(toObject, []string{"authType"}, fromAuthType) + } + + fromGoogleServiceAccountConfig := getValueByPath(fromObject, []string{"googleServiceAccountConfig"}) + if fromGoogleServiceAccountConfig != nil { + setValueByPath(toObject, []string{"googleServiceAccountConfig"}, fromGoogleServiceAccountConfig) + } + + fromHttpBasicAuthConfig := getValueByPath(fromObject, []string{"httpBasicAuthConfig"}) + if fromHttpBasicAuthConfig != nil { + setValueByPath(toObject, []string{"httpBasicAuthConfig"}, fromHttpBasicAuthConfig) + } + + fromOauthConfig := getValueByPath(fromObject, []string{"oauthConfig"}) + if fromOauthConfig != nil { + setValueByPath(toObject, []string{"oauthConfig"}, fromOauthConfig) + } + + fromOidcConfig := getValueByPath(fromObject, []string{"oidcConfig"}) + if fromOidcConfig != nil { + setValueByPath(toObject, []string{"oidcConfig"}, fromOidcConfig) + } + + return toObject, nil +} + +func googleMapsFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromAuthConfig := getValueByPath(fromObject, []string{"authConfig"}) + if fromAuthConfig != nil { + fromAuthConfig, err = authConfigFromVertex(ac, fromAuthConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"authConfig"}, fromAuthConfig) + } + + return toObject, nil +} + +func urlContextFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func toolFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromFunctionDeclarations := getValueByPath(fromObject, []string{"functionDeclarations"}) + if fromFunctionDeclarations != nil { + fromFunctionDeclarations, err = applyConverterToSlice(ac, fromFunctionDeclarations.([]any), functionDeclarationFromVertex) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"functionDeclarations"}, fromFunctionDeclarations) + } + + fromRetrieval := getValueByPath(fromObject, []string{"retrieval"}) + if fromRetrieval != nil { + setValueByPath(toObject, []string{"retrieval"}, fromRetrieval) + } + + fromGoogleSearch := getValueByPath(fromObject, []string{"googleSearch"}) + if fromGoogleSearch != nil { + fromGoogleSearch, err = googleSearchFromVertex(ac, fromGoogleSearch.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"googleSearch"}, fromGoogleSearch) + } + + fromGoogleSearchRetrieval := getValueByPath(fromObject, []string{"googleSearchRetrieval"}) + if fromGoogleSearchRetrieval != nil { + fromGoogleSearchRetrieval, err = googleSearchRetrievalFromVertex(ac, fromGoogleSearchRetrieval.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"googleSearchRetrieval"}, fromGoogleSearchRetrieval) + } + + fromEnterpriseWebSearch := getValueByPath(fromObject, []string{"enterpriseWebSearch"}) + if fromEnterpriseWebSearch != nil { + fromEnterpriseWebSearch, err = enterpriseWebSearchFromVertex(ac, fromEnterpriseWebSearch.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"enterpriseWebSearch"}, fromEnterpriseWebSearch) + } + + fromGoogleMaps := getValueByPath(fromObject, []string{"googleMaps"}) + if fromGoogleMaps != nil { + fromGoogleMaps, err = googleMapsFromVertex(ac, fromGoogleMaps.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"googleMaps"}, fromGoogleMaps) + } + + fromUrlContext := getValueByPath(fromObject, []string{"urlContext"}) + if fromUrlContext != nil { + fromUrlContext, err = urlContextFromVertex(ac, fromUrlContext.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"urlContext"}, fromUrlContext) + } + + fromCodeExecution := getValueByPath(fromObject, []string{"codeExecution"}) + if fromCodeExecution != nil { + setValueByPath(toObject, []string{"codeExecution"}, fromCodeExecution) + } + + return toObject, nil +} + +func functionCallingConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromMode := getValueByPath(fromObject, []string{"mode"}) + if fromMode != nil { + setValueByPath(toObject, []string{"mode"}, fromMode) + } + + fromAllowedFunctionNames := getValueByPath(fromObject, []string{"allowedFunctionNames"}) + if fromAllowedFunctionNames != nil { + setValueByPath(toObject, []string{"allowedFunctionNames"}, fromAllowedFunctionNames) + } + + return toObject, nil +} + +func latLngFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromLatitude := getValueByPath(fromObject, []string{"latitude"}) + if fromLatitude != nil { + setValueByPath(toObject, []string{"latitude"}, fromLatitude) + } + + fromLongitude := getValueByPath(fromObject, []string{"longitude"}) + if fromLongitude != nil { + setValueByPath(toObject, []string{"longitude"}, fromLongitude) + } + + return toObject, nil +} + +func retrievalConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromLatLng := getValueByPath(fromObject, []string{"latLng"}) + if fromLatLng != nil { + fromLatLng, err = latLngFromVertex(ac, fromLatLng.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"latLng"}, fromLatLng) + } + + fromLanguageCode := getValueByPath(fromObject, []string{"languageCode"}) + if fromLanguageCode != nil { + setValueByPath(toObject, []string{"languageCode"}, fromLanguageCode) + } + + return toObject, nil +} + +func toolConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromFunctionCallingConfig := getValueByPath(fromObject, []string{"functionCallingConfig"}) + if fromFunctionCallingConfig != nil { + fromFunctionCallingConfig, err = functionCallingConfigFromVertex(ac, fromFunctionCallingConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"functionCallingConfig"}, fromFunctionCallingConfig) + } + + fromRetrievalConfig := getValueByPath(fromObject, []string{"retrievalConfig"}) + if fromRetrievalConfig != nil { + fromRetrievalConfig, err = retrievalConfigFromVertex(ac, fromRetrievalConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"retrievalConfig"}, fromRetrievalConfig) + } + + return toObject, nil +} + +func prebuiltVoiceConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromVoiceName := getValueByPath(fromObject, []string{"voiceName"}) + if fromVoiceName != nil { + setValueByPath(toObject, []string{"voiceName"}, fromVoiceName) + } + + return toObject, nil +} + +func voiceConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromPrebuiltVoiceConfig := getValueByPath(fromObject, []string{"prebuiltVoiceConfig"}) + if fromPrebuiltVoiceConfig != nil { + fromPrebuiltVoiceConfig, err = prebuiltVoiceConfigFromVertex(ac, fromPrebuiltVoiceConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"prebuiltVoiceConfig"}, fromPrebuiltVoiceConfig) + } + + return toObject, nil +} + +func speakerVoiceConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func multiSpeakerVoiceConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func speechConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromVoiceConfig := getValueByPath(fromObject, []string{"voiceConfig"}) + if fromVoiceConfig != nil { + fromVoiceConfig, err = voiceConfigFromVertex(ac, fromVoiceConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"voiceConfig"}, fromVoiceConfig) + } + + fromLanguageCode := getValueByPath(fromObject, []string{"languageCode"}) + if fromLanguageCode != nil { + setValueByPath(toObject, []string{"languageCode"}, fromLanguageCode) + } + + return toObject, nil +} + +func thinkingConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromIncludeThoughts := getValueByPath(fromObject, []string{"includeThoughts"}) + if fromIncludeThoughts != nil { + setValueByPath(toObject, []string{"includeThoughts"}, fromIncludeThoughts) + } + + fromThinkingBudget := getValueByPath(fromObject, []string{"thinkingBudget"}) + if fromThinkingBudget != nil { + setValueByPath(toObject, []string{"thinkingBudget"}, fromThinkingBudget) + } + + return toObject, nil +} + +func generateContentConfigFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromSystemInstruction := getValueByPath(fromObject, []string{"systemInstruction"}) + if fromSystemInstruction != nil { + fromSystemInstruction, err = tContent(ac, fromSystemInstruction) + if err != nil { + return nil, err + } + + fromSystemInstruction, err = contentFromVertex(ac, fromSystemInstruction.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"systemInstruction"}, fromSystemInstruction) + } + + fromTemperature := getValueByPath(fromObject, []string{"temperature"}) + if fromTemperature != nil { + setValueByPath(toObject, []string{"temperature"}, fromTemperature) + } + + fromTopP := getValueByPath(fromObject, []string{"topP"}) + if fromTopP != nil { + setValueByPath(toObject, []string{"topP"}, fromTopP) + } + + fromTopK := getValueByPath(fromObject, []string{"topK"}) + if fromTopK != nil { + setValueByPath(toObject, []string{"topK"}, fromTopK) + } + + fromCandidateCount := getValueByPath(fromObject, []string{"candidateCount"}) + if fromCandidateCount != nil { + setValueByPath(toObject, []string{"candidateCount"}, fromCandidateCount) + } + + fromMaxOutputTokens := getValueByPath(fromObject, []string{"maxOutputTokens"}) + if fromMaxOutputTokens != nil { + setValueByPath(toObject, []string{"maxOutputTokens"}, fromMaxOutputTokens) + } + + fromStopSequences := getValueByPath(fromObject, []string{"stopSequences"}) + if fromStopSequences != nil { + setValueByPath(toObject, []string{"stopSequences"}, fromStopSequences) + } + + fromResponseLogprobs := getValueByPath(fromObject, []string{"responseLogprobs"}) + if fromResponseLogprobs != nil { + setValueByPath(toObject, []string{"responseLogprobs"}, fromResponseLogprobs) + } + + fromLogprobs := getValueByPath(fromObject, []string{"logprobs"}) + if fromLogprobs != nil { + setValueByPath(toObject, []string{"logprobs"}, fromLogprobs) + } + + fromPresencePenalty := getValueByPath(fromObject, []string{"presencePenalty"}) + if fromPresencePenalty != nil { + setValueByPath(toObject, []string{"presencePenalty"}, fromPresencePenalty) + } + + fromFrequencyPenalty := getValueByPath(fromObject, []string{"frequencyPenalty"}) + if fromFrequencyPenalty != nil { + setValueByPath(toObject, []string{"frequencyPenalty"}, fromFrequencyPenalty) + } + + fromSeed := getValueByPath(fromObject, []string{"seed"}) + if fromSeed != nil { + setValueByPath(toObject, []string{"seed"}, fromSeed) + } + + fromResponseMimeType := getValueByPath(fromObject, []string{"responseMimeType"}) + if fromResponseMimeType != nil { + setValueByPath(toObject, []string{"responseMimeType"}, fromResponseMimeType) + } + + fromResponseSchema := getValueByPath(fromObject, []string{"responseSchema"}) + if fromResponseSchema != nil { + fromResponseSchema, err = tSchema(ac, fromResponseSchema) + if err != nil { + return nil, err + } + + fromResponseSchema, err = schemaFromVertex(ac, fromResponseSchema.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"responseSchema"}, fromResponseSchema) + } + + fromResponseJsonSchema := getValueByPath(fromObject, []string{"responseJsonSchema"}) + if fromResponseJsonSchema != nil { + setValueByPath(toObject, []string{"responseJsonSchema"}, fromResponseJsonSchema) + } + + fromRoutingConfig := getValueByPath(fromObject, []string{"routingConfig"}) + if fromRoutingConfig != nil { + setValueByPath(toObject, []string{"routingConfig"}, fromRoutingConfig) + } + + fromModelSelectionConfig := getValueByPath(fromObject, []string{"modelConfig"}) + if fromModelSelectionConfig != nil { + fromModelSelectionConfig, err = modelSelectionConfigFromVertex(ac, fromModelSelectionConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"modelSelectionConfig"}, fromModelSelectionConfig) + } + + fromSafetySettings := getValueByPath(fromObject, []string{"safetySettings"}) + if fromSafetySettings != nil { + fromSafetySettings, err = applyConverterToSlice(ac, fromSafetySettings.([]any), safetySettingFromVertex) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"safetySettings"}, fromSafetySettings) + } + + fromTools := getValueByPath(fromObject, []string{"tools"}) + if fromTools != nil { + fromTools, err = applyItemTransformerToSlice(ac, fromTools.([]any), tTool) + if err != nil { + return nil, err + } + + fromTools, err = tTools(ac, fromTools) + if err != nil { + return nil, err + } + + fromTools, err = applyConverterToSlice(ac, fromTools.([]any), toolFromVertex) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"tools"}, fromTools) + } + + fromToolConfig := getValueByPath(fromObject, []string{"toolConfig"}) + if fromToolConfig != nil { + fromToolConfig, err = toolConfigFromVertex(ac, fromToolConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"toolConfig"}, fromToolConfig) + } + + fromLabels := getValueByPath(fromObject, []string{"labels"}) + if fromLabels != nil { + setValueByPath(toObject, []string{"labels"}, fromLabels) + } + + fromCachedContent := getValueByPath(fromObject, []string{"cachedContent"}) + if fromCachedContent != nil { + fromCachedContent, err = tCachedContentName(ac, fromCachedContent) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"cachedContent"}, fromCachedContent) + } + + fromResponseModalities := getValueByPath(fromObject, []string{"responseModalities"}) + if fromResponseModalities != nil { + setValueByPath(toObject, []string{"responseModalities"}, fromResponseModalities) + } + + fromMediaResolution := getValueByPath(fromObject, []string{"mediaResolution"}) + if fromMediaResolution != nil { + setValueByPath(toObject, []string{"mediaResolution"}, fromMediaResolution) + } + + fromSpeechConfig := getValueByPath(fromObject, []string{"speechConfig"}) + if fromSpeechConfig != nil { + fromSpeechConfig, err = tSpeechConfig(ac, fromSpeechConfig) + if err != nil { + return nil, err + } + + fromSpeechConfig, err = speechConfigFromVertex(ac, fromSpeechConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"speechConfig"}, fromSpeechConfig) + } + + fromAudioTimestamp := getValueByPath(fromObject, []string{"audioTimestamp"}) + if fromAudioTimestamp != nil { + setValueByPath(toObject, []string{"audioTimestamp"}, fromAudioTimestamp) + } + + fromThinkingConfig := getValueByPath(fromObject, []string{"thinkingConfig"}) + if fromThinkingConfig != nil { + fromThinkingConfig, err = thinkingConfigFromVertex(ac, fromThinkingConfig.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"thinkingConfig"}, fromThinkingConfig) + } + + return toObject, nil +} + +func inlinedRequestFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func batchJobSourceFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromFormat := getValueByPath(fromObject, []string{"instancesFormat"}) + if fromFormat != nil { + setValueByPath(toObject, []string{"format"}, fromFormat) + } + + fromGcsUri := getValueByPath(fromObject, []string{"gcsSource", "uris"}) + if fromGcsUri != nil { + setValueByPath(toObject, []string{"gcsUri"}, fromGcsUri) + } + + fromBigqueryUri := getValueByPath(fromObject, []string{"bigquerySource", "inputUri"}) + if fromBigqueryUri != nil { + setValueByPath(toObject, []string{"bigqueryUri"}, fromBigqueryUri) + } + + return toObject, nil +} + +func inlinedResponseFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + return toObject, nil +} + +func batchJobDestinationFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromFormat := getValueByPath(fromObject, []string{"predictionsFormat"}) + if fromFormat != nil { + setValueByPath(toObject, []string{"format"}, fromFormat) + } + + fromGcsUri := getValueByPath(fromObject, []string{"gcsDestination", "outputUriPrefix"}) + if fromGcsUri != nil { + setValueByPath(toObject, []string{"gcsUri"}, fromGcsUri) + } + + fromBigqueryUri := getValueByPath(fromObject, []string{"bigqueryDestination", "outputUri"}) + if fromBigqueryUri != nil { + setValueByPath(toObject, []string{"bigqueryUri"}, fromBigqueryUri) + } + + return toObject, nil +} + +func batchJobFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromName := getValueByPath(fromObject, []string{"name"}) + if fromName != nil { + setValueByPath(toObject, []string{"name"}, fromName) + } + + fromDisplayName := getValueByPath(fromObject, []string{"displayName"}) + if fromDisplayName != nil { + setValueByPath(toObject, []string{"displayName"}, fromDisplayName) + } + + fromState := getValueByPath(fromObject, []string{"state"}) + if fromState != nil { + fromState, err = tJobState(ac, fromState) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"state"}, fromState) + } + + fromError := getValueByPath(fromObject, []string{"error"}) + if fromError != nil { + fromError, err = jobErrorFromVertex(ac, fromError.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"error"}, fromError) + } + + fromCreateTime := getValueByPath(fromObject, []string{"createTime"}) + if fromCreateTime != nil { + setValueByPath(toObject, []string{"createTime"}, fromCreateTime) + } + + fromStartTime := getValueByPath(fromObject, []string{"startTime"}) + if fromStartTime != nil { + setValueByPath(toObject, []string{"startTime"}, fromStartTime) + } + + fromEndTime := getValueByPath(fromObject, []string{"endTime"}) + if fromEndTime != nil { + setValueByPath(toObject, []string{"endTime"}, fromEndTime) + } + + fromUpdateTime := getValueByPath(fromObject, []string{"updateTime"}) + if fromUpdateTime != nil { + setValueByPath(toObject, []string{"updateTime"}, fromUpdateTime) + } + + fromModel := getValueByPath(fromObject, []string{"model"}) + if fromModel != nil { + setValueByPath(toObject, []string{"model"}, fromModel) + } + + fromSrc := getValueByPath(fromObject, []string{"inputConfig"}) + if fromSrc != nil { + fromSrc, err = batchJobSourceFromVertex(ac, fromSrc.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"src"}, fromSrc) + } + + fromDest := getValueByPath(fromObject, []string{"outputConfig"}) + if fromDest != nil { + fromDest, err = batchJobDestinationFromVertex(ac, fromDest.(map[string]any), toObject) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"dest"}, fromDest) + } + + return toObject, nil +} + +func listBatchJobsResponseFromVertex(ac *apiClient, fromObject map[string]any, parentObject map[string]any) (toObject map[string]any, err error) { + toObject = make(map[string]any) + + fromNextPageToken := getValueByPath(fromObject, []string{"nextPageToken"}) + if fromNextPageToken != nil { + setValueByPath(toObject, []string{"nextPageToken"}, fromNextPageToken) + } + + fromBatchJobs := getValueByPath(fromObject, []string{"batchPredictionJobs"}) + if fromBatchJobs != nil { + fromBatchJobs, err = applyConverterToSlice(ac, fromBatchJobs.([]any), batchJobFromVertex) + if err != nil { + return nil, err + } + + setValueByPath(toObject, []string{"batchJobs"}, fromBatchJobs) + } + + return toObject, nil +} + +type Batches struct { + apiClient *apiClient +} + +func (m Batches) create(ctx context.Context, model string, src *BatchJobSource, config *CreateBatchJobConfig) (*BatchJob, error) { + parameterMap := make(map[string]any) + + kwargs := map[string]any{"model": model, "src": src, "config": config} + deepMarshal(kwargs, ¶meterMap) + + var httpOptions *HTTPOptions + if config == nil { + httpOptions = mergeHTTPOptions(m.apiClient.clientConfig, nil) + } else { + httpOptions = mergeHTTPOptions(m.apiClient.clientConfig, config.HTTPOptions) + config.HTTPOptions = nil + } + var response = new(BatchJob) + var responseMap map[string]any + var fromConverter func(*apiClient, map[string]any, map[string]any) (map[string]any, error) + var toConverter func(*apiClient, map[string]any, map[string]any) (map[string]any, error) + if m.apiClient.clientConfig.Backend == BackendVertexAI { + toConverter = createBatchJobParametersToVertex + fromConverter = batchJobFromVertex + } else { + toConverter = createBatchJobParametersToMldev + fromConverter = batchJobFromMldev + } + + body, err := toConverter(m.apiClient, parameterMap, nil) + if err != nil { + return nil, err + } + var path string + var urlParams map[string]any + if _, ok := body["_url"]; ok { + urlParams = body["_url"].(map[string]any) + delete(body, "_url") + } + if m.apiClient.clientConfig.Backend == BackendVertexAI { + path, err = formatMap("batchPredictionJobs", urlParams) + } else { + path, err = formatMap("{model}:batchGenerateContent", urlParams) + } + if err != nil { + return nil, fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err) + } + if _, ok := body["_query"]; ok { + query, err := createURLQuery(body["_query"].(map[string]any)) + if err != nil { + return nil, err + } + path += "?" + query + delete(body, "_query") + } + + if _, ok := body["config"]; ok { + delete(body, "config") + } + responseMap, err = sendRequest(ctx, m.apiClient, path, http.MethodPost, body, httpOptions) + if err != nil { + return nil, err + } + responseMap, err = fromConverter(m.apiClient, responseMap, nil) + if err != nil { + return nil, err + } + err = mapToStruct(responseMap, response) + if err != nil { + return nil, err + } + return response, nil +} + +func (m Batches) Get(ctx context.Context, name string, config *GetBatchJobConfig) (*BatchJob, error) { + parameterMap := make(map[string]any) + + kwargs := map[string]any{"name": name, "config": config} + deepMarshal(kwargs, ¶meterMap) + + var httpOptions *HTTPOptions + if config == nil { + httpOptions = mergeHTTPOptions(m.apiClient.clientConfig, nil) + } else { + httpOptions = mergeHTTPOptions(m.apiClient.clientConfig, config.HTTPOptions) + config.HTTPOptions = nil + } + var response = new(BatchJob) + var responseMap map[string]any + var fromConverter func(*apiClient, map[string]any, map[string]any) (map[string]any, error) + var toConverter func(*apiClient, map[string]any, map[string]any) (map[string]any, error) + if m.apiClient.clientConfig.Backend == BackendVertexAI { + toConverter = getBatchJobParametersToVertex + fromConverter = batchJobFromVertex + } else { + toConverter = getBatchJobParametersToMldev + fromConverter = batchJobFromMldev + } + + body, err := toConverter(m.apiClient, parameterMap, nil) + if err != nil { + return nil, err + } + var path string + var urlParams map[string]any + if _, ok := body["_url"]; ok { + urlParams = body["_url"].(map[string]any) + delete(body, "_url") + } + if m.apiClient.clientConfig.Backend == BackendVertexAI { + path, err = formatMap("batchPredictionJobs/{name}", urlParams) + } else { + path, err = formatMap("batches/{name}", urlParams) + } + if err != nil { + return nil, fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err) + } + if _, ok := body["_query"]; ok { + query, err := createURLQuery(body["_query"].(map[string]any)) + if err != nil { + return nil, err + } + path += "?" + query + delete(body, "_query") + } + + if _, ok := body["config"]; ok { + delete(body, "config") + } + responseMap, err = sendRequest(ctx, m.apiClient, path, http.MethodGet, body, httpOptions) + if err != nil { + return nil, err + } + responseMap, err = fromConverter(m.apiClient, responseMap, nil) + if err != nil { + return nil, err + } + err = mapToStruct(responseMap, response) + if err != nil { + return nil, err + } + return response, nil +} + +func (m Batches) Cancel(ctx context.Context, name string, config *CancelBatchJobConfig) error { + parameterMap := make(map[string]any) + + kwargs := map[string]any{"name": name, "config": config} + deepMarshal(kwargs, ¶meterMap) + + var httpOptions *HTTPOptions + if config == nil { + httpOptions = mergeHTTPOptions(m.apiClient.clientConfig, nil) + } else { + httpOptions = mergeHTTPOptions(m.apiClient.clientConfig, config.HTTPOptions) + config.HTTPOptions = nil + } + var toConverter func(*apiClient, map[string]any, map[string]any) (map[string]any, error) + if m.apiClient.clientConfig.Backend == BackendVertexAI { + toConverter = cancelBatchJobParametersToVertex + + } else { + toConverter = cancelBatchJobParametersToMldev + + } + + body, err := toConverter(m.apiClient, parameterMap, nil) + if err != nil { + return err + } + var path string + var urlParams map[string]any + if _, ok := body["_url"]; ok { + urlParams = body["_url"].(map[string]any) + delete(body, "_url") + } + if m.apiClient.clientConfig.Backend == BackendVertexAI { + path, err = formatMap("batchPredictionJobs/{name}:cancel", urlParams) + } else { + path, err = formatMap("batches/{name}:cancel", urlParams) + } + if err != nil { + return fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err) + } + if _, ok := body["_query"]; ok { + query, err := createURLQuery(body["_query"].(map[string]any)) + if err != nil { + return err + } + path += "?" + query + delete(body, "_query") + } + + if _, ok := body["config"]; ok { + delete(body, "config") + } + _, err = sendRequest(ctx, m.apiClient, path, http.MethodPost, body, httpOptions) + if err != nil { + return err + } + return nil +} + +func (m Batches) list(ctx context.Context, config *ListBatchJobsConfig) (*ListBatchJobsResponse, error) { + parameterMap := make(map[string]any) + + kwargs := map[string]any{"config": config} + deepMarshal(kwargs, ¶meterMap) + + var httpOptions *HTTPOptions + if config == nil { + httpOptions = mergeHTTPOptions(m.apiClient.clientConfig, nil) + } else { + httpOptions = mergeHTTPOptions(m.apiClient.clientConfig, config.HTTPOptions) + config.HTTPOptions = nil + } + var response = new(ListBatchJobsResponse) + var responseMap map[string]any + var fromConverter func(*apiClient, map[string]any, map[string]any) (map[string]any, error) + var toConverter func(*apiClient, map[string]any, map[string]any) (map[string]any, error) + if m.apiClient.clientConfig.Backend == BackendVertexAI { + toConverter = listBatchJobsParametersToVertex + fromConverter = listBatchJobsResponseFromVertex + } else { + toConverter = listBatchJobsParametersToMldev + fromConverter = listBatchJobsResponseFromMldev + } + + body, err := toConverter(m.apiClient, parameterMap, nil) + if err != nil { + return nil, err + } + var path string + var urlParams map[string]any + if _, ok := body["_url"]; ok { + urlParams = body["_url"].(map[string]any) + delete(body, "_url") + } + if m.apiClient.clientConfig.Backend == BackendVertexAI { + path, err = formatMap("batchPredictionJobs", urlParams) + } else { + path, err = formatMap("batches", urlParams) + } + if err != nil { + return nil, fmt.Errorf("invalid url params: %#v.\n%w", urlParams, err) + } + if _, ok := body["_query"]; ok { + query, err := createURLQuery(body["_query"].(map[string]any)) + if err != nil { + return nil, err + } + path += "?" + query + delete(body, "_query") + } + + if _, ok := body["config"]; ok { + delete(body, "config") + } + responseMap, err = sendRequest(ctx, m.apiClient, path, http.MethodGet, body, httpOptions) + if err != nil { + return nil, err + } + responseMap, err = fromConverter(m.apiClient, responseMap, nil) + if err != nil { + return nil, err + } + err = mapToStruct(responseMap, response) + if err != nil { + return nil, err + } + return response, nil +} + +// Create a batch job. +func (b Batches) Create(ctx context.Context, model string, src *BatchJobSource, config *CreateBatchJobConfig) (*BatchJob, error) { + if b.apiClient.clientConfig.Backend == BackendVertexAI { + if len(src.InlinedRequests) > 0 { + return nil, fmt.Errorf("InlinedRequests is not supported for Vertex AI backend.") + } + if src.FileName != "" { + return nil, fmt.Errorf("FileName is not supported for Vertex AI backend.") + } + if len(src.GCSURI) != 0 && src.BigqueryURI != "" { + return nil, fmt.Errorf("Only one of GCSURI ([]string) and BigqueryURI (string) can be set.") + } + if len(src.GCSURI) == 0 && src.BigqueryURI == "" { + return nil, fmt.Errorf("One of GCSURI ([]string) and BigqueryURI (string) must be set.") + } + } else { + if src.FileName != "" && len(src.InlinedRequests) > 0 { + return nil, fmt.Errorf("Only one of FileName and InlinedRequests can be set.") + } + if src.FileName == "" && len(src.InlinedRequests) == 0 { + return nil, fmt.Errorf("One of FileName and InlinedRequests must be set.") + } + } + return b.create(ctx, model, src, config) +} + +// List retrieves a paginated list of batch jobs. +func (b Batches) List(ctx context.Context, config *ListBatchJobsConfig) (Page[BatchJob], error) { + listFunc := func(ctx context.Context, config map[string]any) ([]*BatchJob, string, error) { + var c ListBatchJobsConfig + if err := mapToStruct(config, &c); err != nil { + return nil, "", err + } + resp, err := b.list(ctx, &c) + if err != nil { + return nil, "", err + } + return resp.BatchJobs, resp.NextPageToken, nil + } + c := make(map[string]any) + deepMarshal(config, &c) + return newPage(ctx, "batchJobs", c, listFunc) +} + +// All retrieves all batch job resources. +// +// This method handles pagination internally, making multiple API calls as needed +// to fetch all entries. It returns an iterator that yields each cached +// content entry one by one. You do not need to manage pagination +// tokens or make multiple calls to retrieve all data. +func (b Batches) All(ctx context.Context) iter.Seq2[*BatchJob, error] { + listFunc := func(ctx context.Context, config map[string]any) ([]*BatchJob, string, error) { + var c ListBatchJobsConfig + if err := mapToStruct(config, &c); err != nil { + return nil, "", err + } + resp, err := b.list(ctx, &c) + if err != nil { + return nil, "", err + } + return resp.BatchJobs, resp.NextPageToken, nil + } + p, err := newPage(ctx, "BatchJobs", map[string]any{}, listFunc) + if err != nil { + return yieldErrorAndEndIterator[BatchJob](err) + } + return p.all(ctx) +} diff --git a/client.go b/client.go index c4d567f4..8d3b0a49 100644 --- a/client.go +++ b/client.go @@ -42,6 +42,8 @@ type Client struct { Files *Files // Operations provides access to long-running operations. Operations *Operations + // Batches provides access to the Batch service. + Batches *Batches } // Backend is the GenAI backend to use for the client. @@ -323,6 +325,7 @@ func NewClient(ctx context.Context, cc *ClientConfig) (*Client, error) { Chats: &Chats{apiClient: ac}, Operations: &Operations{apiClient: ac}, Files: &Files{apiClient: ac}, + Batches: &Batches{apiClient: ac}, } return c, nil } diff --git a/examples/batches/README.md b/examples/batches/README.md new file mode 100644 index 00000000..de986257 --- /dev/null +++ b/examples/batches/README.md @@ -0,0 +1,26 @@ +# Running the example: + +## Set up the environment variables: + +### For VertexAI Backend + +``` +export GOOGLE_GENAI_USE_VERTEXAI=true +export GOOGLE_CLOUD_PROJECT={YOUR_PROJECT_ID} +export GOOGLE_CLOUD_LOCATION={YOUR_LOCATION} +``` + +### For GeminiAPI Backend +``` +export GOOGLE_GENAI_USE_VERTEXAI=false +export GOOGLE_API_KEY={YOUR_API_KEY} +``` + +Once you setup the environment variables, you can download, build and run the +example using the following commands. + +``` +$ go get google.golang.org/genai +$ cd `go list -f '{{.Dir}}' google.golang.org/genai/examples/batches` +$ go run create_get_cancel.go +``` diff --git a/examples/batches/create_get_cancel.go b/examples/batches/create_get_cancel.go new file mode 100644 index 00000000..6e402832 --- /dev/null +++ b/examples/batches/create_get_cancel.go @@ -0,0 +1,138 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build ignore_vet + +package main + +import ( + "context" + "encoding/json" + "flag" + "fmt" + "log" + + "google.golang.org/genai" +) + +func print(r any) { + // Marshal the result to JSON. + response, err := json.MarshalIndent(r, "", " ") + if err != nil { + log.Fatal(err) + } + // Log the output. + fmt.Println(string(response)) +} + +func run(ctx context.Context) { + // Create a Gemini Developer API client. + client, err := genai.NewClient(ctx, nil) + if err != nil { + log.Fatal(err) + } + if client.ClientConfig().Backend == genai.BackendVertexAI { + fmt.Println("Calling VertexAI Backend...") + var model = flag.String("model", "gemini-1.5-flash-002", "the model name, e.g. gemini-1.5-pro-002") + // Create a batch job. + result, err := client.Batches.Create( + ctx, + *model, + &genai.BatchJobSource{ + GCSURI: []string{ + "gs://unified-genai-tests/batches/input/generate_content_requests.jsonl", + }, + Format: "jsonl", + }, + &genai.CreateBatchJobConfig{ + DisplayName: "test-batch-job", + Dest: &genai.BatchJobDestination{ + Format: "jsonl", + GCSURI: "gs://unified-genai-tests/batches/output", + }, + }, + ) + if err != nil { + log.Fatal(err) + } + fmt.Println("Created batch job:") + print(result) + // Get the batch job. + result, err = client.Batches.Get(ctx, result.Name, &genai.GetBatchJobConfig{}) + if err != nil { + log.Fatal(err) + } + fmt.Println("Retrieved batch job:") + print(result) + + // Cancel the batch job. + err = client.Batches.Cancel(ctx, result.Name, &genai.CancelBatchJobConfig{}) + if err != nil { + log.Fatal(err) + } + fmt.Println("Cancelled batch job:", result.Name) + } else { + fmt.Println("Calling GeminiAPI Backend...") + var model = flag.String("model", "gemini-2.0-flash", "the model name, e.g. gemini-1.5-pro-002") + // Create a batch job. + result, err := client.Batches.Create( + ctx, + *model, + &genai.BatchJobSource{ + InlinedRequests: []*genai.InlinedRequest{ + { + Contents: []*genai.Content{ + { + Role: "user", + Parts: []*genai.Part{ + { + Text: "Hello!", + }, + }, + }, + }, + }, + }, + }, + &genai.CreateBatchJobConfig{ + DisplayName: "test-batch-job", + }, + ) + if err != nil { + log.Fatal(err) + } + fmt.Println("Created batch job:") + print(result) + // Get the batch job. + result, err = client.Batches.Get(ctx, result.Name, &genai.GetBatchJobConfig{}) + if err != nil { + log.Fatal(err) + } + fmt.Println("Retrieved batch job:") + print(result) + + // Cancel the batch job. + err = client.Batches.Cancel(ctx, result.Name, &genai.CancelBatchJobConfig{}) + if err != nil { + log.Fatal(err) + } + fmt.Println("Cancelled batch job:", result.Name) + } +} + +func main() { + ctx := context.Background() + flag.Parse() + run(ctx) +} diff --git a/main_test.go b/main_test.go index 5b83d057..8d338581 100644 --- a/main_test.go +++ b/main_test.go @@ -57,6 +57,12 @@ var ( // TODO(b/424824119): generateVideos tests disabled due to backwards compatibility "/models/generate_videos", + // TODO(b/427475992) Empty response isn't supported in replay, added example. + "batches/cancel", + // Recorded request has Union types, Go only support one type. Added example. + "batches/create", + // filter=display_name%3A%22genai_%2A%22&pageSize=5 are reordered and mismatched + "batches/list/test_list_batch_jobs_with_config", }, unitMode: []string{ // We don't run table tests in unit mode. diff --git a/transformer.go b/transformer.go index 6c65a135..7e4668ac 100644 --- a/transformer.go +++ b/transformer.go @@ -18,6 +18,7 @@ import ( "fmt" "log" "regexp" + "strconv" "strings" ) @@ -273,3 +274,52 @@ func tAudioBlob(ac *apiClient, blob any) (any, error) { return nil, fmt.Errorf("tAudioBlob: blob is not a map") } } + +func tBatchJobSource(_ *apiClient, src any) (any, error) { + return src, nil +} + +func tBatchJobDestination(_ *apiClient, dest any) (any, error) { + return dest, nil +} + +func tBatchJobName(ac *apiClient, name any) (any, error) { + var ( + mldevBatchPattern = regexp.MustCompile("batches/[^/]+$") + vertexBatchPattern = regexp.MustCompile("^projects/[^/]+/locations/[^/]+/batchPredictionJobs/[^/]+$") + ) + // Convert any to string. + nameStr := name.(string) + if ac.clientConfig.Backend == BackendVertexAI { + if vertexBatchPattern.MatchString(nameStr) { + parts := strings.Split(nameStr, "/") + return parts[len(parts)-1], nil + } + if _, err := strconv.Atoi(nameStr); err == nil { + return nameStr, nil + } + return nil, fmt.Errorf("Invalid batch job name: %s. Expected format like 'projects/id/locations/id/batchPredictionJobs/id' or 'id'", nameStr) + } + if mldevBatchPattern.MatchString(nameStr) { + parts := strings.Split(nameStr, "/") + return parts[len(parts)-1], nil + } + return nil, fmt.Errorf("Invalid batch job name: %s. Expected format like 'batches/id'", nameStr) +} + +func tJobState(_ *apiClient, state any) (any, error) { + switch state { + case "BATCH_STATE_UNSPECIFIED": + return "JOB_STATE_UNSPECIFIED", nil + case "BATCH_STATE_PENDING": + return "JOB_STATE_PENDING", nil + case "BATCH_STATE_SUCCEEDED": + return "JOB_STATE_SUCCEEDED", nil + case "BATCH_STATE_FAILED": + return "JOB_STATE_FAILED", nil + case "BATCH_STATE_CANCELLED": + return "JOB_STATE_CANCELLED", nil + default: + return state, nil + } +} diff --git a/types.go b/types.go index fc619e19..5a16808b 100644 --- a/types.go +++ b/types.go @@ -449,6 +449,38 @@ const ( FileSourceGenerated FileSource = "GENERATED" ) +// Job state. +type JobState string + +const ( + // The job state is unspecified. + JobStateUnspecified JobState = "JOB_STATE_UNSPECIFIED" + // The job has been just created or resumed and processing has not yet begun. + JobStateQueued JobState = "JOB_STATE_QUEUED" + // The service is preparing to run the job. + JobStatePending JobState = "JOB_STATE_PENDING" + // The job is in progress. + JobStateRunning JobState = "JOB_STATE_RUNNING" + // The job completed successfully. + JobStateSucceeded JobState = "JOB_STATE_SUCCEEDED" + // The job failed. + JobStateFailed JobState = "JOB_STATE_FAILED" + // The job is being cancelled. From this state the job may only go to either `JOB_STATE_SUCCEEDED`, + // `JOB_STATE_FAILED` or `JOB_STATE_CANCELLED`. + JobStateCancelling JobState = "JOB_STATE_CANCELLING" + // The job has been cancelled. + JobStateCancelled JobState = "JOB_STATE_CANCELLED" + // The job has been stopped, and can be resumed. + JobStatePaused JobState = "JOB_STATE_PAUSED" + // The job has expired. + JobStateExpired JobState = "JOB_STATE_EXPIRED" + // The job is being updated. Only jobs in the `JOB_STATE_RUNNING` state can be updated. + // After updating, the job goes back to the `JOB_STATE_RUNNING` state. + JobStateUpdating JobState = "JOB_STATE_UPDATING" + // The job is partially succeeded, some results may be missing due to errors. + JobStatePartiallySucceeded JobState = "JOB_STATE_PARTIALLY_SUCCEEDED" +) + // Server content modalities. type MediaModality string @@ -3110,6 +3142,147 @@ type DeleteFileConfig struct { type DeleteFileResponse struct { } +// Config for inlined request. +type InlinedRequest struct { + // ID of the model to use. For a list of models, see `Google models + // `_. + Model string `json:"model,omitempty"` + // Content of the request. + Contents []*Content `json:"contents,omitempty"` + // Optional. Configuration that contains optional model parameters. + Config *GenerateContentConfig `json:"config,omitempty"` +} + +// Config for `src` parameter. +type BatchJobSource struct { + // Storage format of the input files. Must be one of: + // 'jsonl', 'bigquery'. + Format string `json:"format,omitempty"` + // Optional. The Google Cloud Storage URIs to input files. + GCSURI []string `json:"gcsUri,omitempty"` + // Optional. The BigQuery URI to input table. + BigqueryURI string `json:"bigqueryUri,omitempty"` + // Optional. The Gemini Developer API's file resource name of the input data + // (e.g. "files/12345"). + FileName string `json:"fileName,omitempty"` + // Optional. The Gemini Developer API's inlined input data to run batch job. + InlinedRequests []*InlinedRequest `json:"inlinedRequests,omitempty"` +} + +// Job error. +type JobError struct { + // A list of messages that carry the error details. There is a common set of message + // types for APIs to use. + Details []string `json:"details,omitempty"` + // The status code. + Code *int32 `json:"code,omitempty"` + // A developer-facing error message, which should be in English. Any user-facing error + // message should be localized and sent in the `details` field. + Message string `json:"message,omitempty"` +} + +// Config for `inlined_responses` parameter. +type InlinedResponse struct { + // The response to the request. + Response *GenerateContentResponse `json:"response,omitempty"` + // Optional. The error encountered while processing the request. + Error *JobError `json:"error,omitempty"` +} + +// Config for `des` parameter. +type BatchJobDestination struct { + // Storage format of the output files. Must be one of: + // 'jsonl', 'bigquery'. + Format string `json:"format,omitempty"` + // Optional. The Google Cloud Storage URI to the output file. + GCSURI string `json:"gcsUri,omitempty"` + // Optional. The BigQuery URI to the output table. + BigqueryURI string `json:"bigqueryUri,omitempty"` + // Optional. The Gemini Developer API's file resource name of the output data + // (e.g. "files/12345"). The file will be a JSONL file with a single response + // per line. The responses will be GenerateContentResponse messages formatted + // as JSON. The responses will be written in the same order as the input + // requests. + FileName string `json:"fileName,omitempty"` + // Optional. The responses to the requests in the batch. Returned when the batch was + // built using inlined requests. The responses will be in the same order as + // the input requests. + InlinedResponses []*InlinedResponse `json:"inlinedResponses,omitempty"` +} + +// Config for optional parameters. +type CreateBatchJobConfig struct { + // Optional. Used to override HTTP request options. + HTTPOptions *HTTPOptions `json:"httpOptions,omitempty"` + // Optional. The user-defined name of this BatchJob. + DisplayName string `json:"displayName,omitempty"` + // GCS or BigQuery URI prefix for the output predictions. Example: + // "gs://path/to/output/data" or "bq://projectId.bqDatasetId.bqTableId". + Dest *BatchJobDestination `json:"dest,omitempty"` +} + +// Config for batches.create return value. +type BatchJob struct { + // The resource name of the BatchJob. Output only.". + Name string `json:"name,omitempty"` + // The display name of the BatchJob. + DisplayName string `json:"displayName,omitempty"` + // The state of the BatchJob. + State JobState `json:"state,omitempty"` + // Output only. Only populated when the job's state is JOB_STATE_FAILED or JOB_STATE_CANCELLED. + Error *JobError `json:"error,omitempty"` + // The time when the BatchJob was created. + CreateTime time.Time `json:"createTime,omitempty"` + // Output only. Time when the Job for the first time entered the `JOB_STATE_RUNNING` + // state. + StartTime time.Time `json:"startTime,omitempty"` + // The time when the BatchJob was completed. + EndTime time.Time `json:"endTime,omitempty"` + // The time when the BatchJob was last updated. + UpdateTime time.Time `json:"updateTime,omitempty"` + // The name of the model that produces the predictions via the BatchJob. + Model string `json:"model,omitempty"` + // Configuration for the input data. + Src *BatchJobSource `json:"src,omitempty"` + // Configuration for the output data. + Dest *BatchJobDestination `json:"dest,omitempty"` +} + +// Optional parameters. +type GetBatchJobConfig struct { + // Optional. Used to override HTTP request options. + HTTPOptions *HTTPOptions `json:"httpOptions,omitempty"` +} + +// Optional parameters. +type CancelBatchJobConfig struct { + // Optional. Used to override HTTP request options. + HTTPOptions *HTTPOptions `json:"httpOptions,omitempty"` +} + +// Config for optional parameters. +type ListBatchJobsConfig struct { + // Optional. Used to override HTTP request options. + HTTPOptions *HTTPOptions `json:"httpOptions,omitempty"` + // Optional. PageSize specifies the maximum number of cached contents to return per + // API call. If zero, the server will use a default value. + PageSize int32 `json:"pageSize,omitempty"` + // Optional. PageToken represents a token used for pagination in API responses. It's + // an opaque string that should be passed to subsequent requests to retrieve the next + // page of results. An empty PageToken typically indicates that there are no further + // pages available. + PageToken string `json:"pageToken,omitempty"` + // Optional. + Filter string `json:"filter,omitempty"` +} + +// Config for batches.list return value. +type ListBatchJobsResponse struct { + NextPageToken string `json:"nextPageToken,omitempty"` + + BatchJobs []*BatchJob `json:"batchJobs,omitempty"` +} + type GetOperationConfig struct { // Optional. Used to override HTTP request options. HTTPOptions *HTTPOptions `json:"httpOptions,omitempty"` From a8a31a5680617e6ca9c078aadabdb248d06480ee Mon Sep 17 00:00:00 2001 From: Wanlin Du Date: Wed, 25 Jun 2025 13:25:41 -0700 Subject: [PATCH 6/8] chore: update all the generateContent replay files PiperOrigin-RevId: 775814881 --- table_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/table_test.go b/table_test.go index f1e68d70..f2a3717f 100644 --- a/table_test.go +++ b/table_test.go @@ -330,6 +330,8 @@ func TestTable(t *testing.T) { } } for _, v := range want { + // TODO(b/425393586): Remove this hack once golang support sdkHttpResponse. + delete(v, "sdkHttpResponse") _ = convertFloat64ToString(v) } for _, v := range got { From 84ad7461e89d227926c2dc20306fed921fcd09c2 Mon Sep 17 00:00:00 2001 From: Amy Wu Date: Wed, 25 Jun 2025 14:50:07 -0700 Subject: [PATCH 7/8] feat: Batches support in Java PiperOrigin-RevId: 775846485 --- batches.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/batches.go b/batches.go index 56b1bf72..a96a2ab9 100644 --- a/batches.go +++ b/batches.go @@ -2740,6 +2740,9 @@ func listBatchJobsResponseFromVertex(ac *apiClient, fromObject map[string]any, p return toObject, nil } +// Batches provides methods for managing the batch jobs. +// You don't need to initiate this struct. Create a client instance via NewClient, and +// then access Batches through client.Batches field. type Batches struct { apiClient *apiClient } @@ -2814,6 +2817,7 @@ func (m Batches) create(ctx context.Context, model string, src *BatchJobSource, return response, nil } +// Get gets a batch job resource. func (m Batches) Get(ctx context.Context, name string, config *GetBatchJobConfig) (*BatchJob, error) { parameterMap := make(map[string]any) @@ -2884,6 +2888,7 @@ func (m Batches) Get(ctx context.Context, name string, config *GetBatchJobConfig return response, nil } +// Cancel cancels a batch job resource. func (m Batches) Cancel(ctx context.Context, name string, config *CancelBatchJobConfig) error { parameterMap := make(map[string]any) From 4e2b106645be33f0971b35f46944bf18067395f2 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 25 Jun 2025 15:33:43 -0700 Subject: [PATCH 8/8] chore(main): release 1.13.0 (#383) * chore(main): release 1.13.0 * Update CHANGELOG.md --------- Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Annie Luc --- .release-please-manifest.json | 2 +- CHANGELOG.md | 10 ++++++++++ version.go | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index de0960ab..f94eeca2 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.12.0" + ".": "1.13.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 01cd76c1..192bc0b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [1.13.0](https://github.com/googleapis/go-genai/compare/v1.12.0...v1.13.0) (2025-06-25) + + +### Features + +* Add compressionQuality enum for generate_videos ([061e567](https://github.com/googleapis/go-genai/commit/061e5674e1744d3bdaade62d3fb8f94c65e77c4c)) +* Add enhance_input_image and image_preservation_factor fields for upscale_image ([6b9e07f](https://github.com/googleapis/go-genai/commit/6b9e07fee4864b54690e84ee9b67cf8a588d89d9)) +* Batches support in Go ([dcae33f](https://github.com/googleapis/go-genai/commit/dcae33f83abfbad8b3cd14930ca0514a61a217d8)) +* expose the responseJsonSchema in GenerateContentConfig ([611adde](https://github.com/googleapis/go-genai/commit/611adde2f1989e66b6e5d029f7d077e7630ada71)) + ## [1.12.0](https://github.com/googleapis/go-genai/compare/v1.11.1...v1.12.0) (2025-06-18) diff --git a/version.go b/version.go index d00ffe56..973f572f 100644 --- a/version.go +++ b/version.go @@ -16,5 +16,5 @@ package genai var ( // Version is the version of the SDK. - version = "1.12.0" // x-release-please-version + version = "1.13.0" // x-release-please-version )