From 919c22a79e357a4be03e98bd24b4d02282ca7a0d Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Thu, 1 May 2025 10:14:26 -0700 Subject: [PATCH 01/18] feat: Add `Tool.enterprise_web_search` field PiperOrigin-RevId: 753635643 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 12 ----- examples/pom.xml | 2 +- pom.xml | 2 +- .../java/com/google/genai/LiveConverters.java | 32 +++++++++++ src/main/java/com/google/genai/Models.java | 32 +++++++++++ .../genai/types/EnterpriseWebSearch.java | 54 +++++++++++++++++++ .../java/com/google/genai/types/Tool.java | 10 ++++ 8 files changed, 131 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/google/genai/types/EnterpriseWebSearch.java diff --git a/.release-please-manifest.json b/.release-please-manifest.json index ac0317144eb..4208b5cb79b 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.6.1" + ".": "0.6.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 48aa195d234..f37b76c209a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,5 @@ # Changelog -## [0.6.1](https://github.com/googleapis/java-genai/compare/v0.6.0...v0.6.1) (2025-05-01) - - -### Bug Fixes - -* generateContentStream failed to find converter method GenerateContentResponseFromXxx ([590cb98](https://github.com/googleapis/java-genai/commit/590cb987874e6a812b0b3e5dab3f75fe919adafa)) - - -### Miscellaneous Chores - -* release 0.6.1 ([19c6373](https://github.com/googleapis/java-genai/commit/19c6373ac4e8dbc703d84b2d6564468ba810f739)) - ## [0.6.0](https://github.com/googleapis/java-genai/compare/v0.5.0...v0.6.0) (2025-04-30) diff --git a/examples/pom.xml b/examples/pom.xml index 133e3f2de9f..24f6937cde8 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ com.google.genai.examples google-genai-examples - 0.6.1 + 0.7.0-SNAPSHOT google-genai-examples diff --git a/pom.xml b/pom.xml index c3a97977ef4..037977cbfbe 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.google.genai google-genai google-genai - 0.6.1 + 0.7.0-SNAPSHOT jar Java idiomatic SDK for the Gemini Developer APIs and Vertex AI APIs. diff --git a/src/main/java/com/google/genai/LiveConverters.java b/src/main/java/com/google/genai/LiveConverters.java index 852ed9f50c4..e21c28edd31 100644 --- a/src/main/java/com/google/genai/LiveConverters.java +++ b/src/main/java/com/google/genai/LiveConverters.java @@ -309,6 +309,22 @@ ObjectNode googleSearchRetrievalToVertex( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode enterpriseWebSearchToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode enterpriseWebSearchToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode toolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -338,6 +354,11 @@ ObjectNode toolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pare toObject)); } + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"enterpriseWebSearch"}))) { + throw new IllegalArgumentException( + "enterpriseWebSearch parameter is not supported in Gemini API."); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecution"}) != null) { Common.setValueByPath( toObject, @@ -387,6 +408,17 @@ ObjectNode toolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par toObject)); } + if (Common.getValueByPath(fromObject, new String[] {"enterpriseWebSearch"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"enterpriseWebSearch"}, + enterpriseWebSearchToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"enterpriseWebSearch"})), + toObject)); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecution"}) != null) { Common.setValueByPath( toObject, diff --git a/src/main/java/com/google/genai/Models.java b/src/main/java/com/google/genai/Models.java index 74fa50dfc70..80d6d74020a 100644 --- a/src/main/java/com/google/genai/Models.java +++ b/src/main/java/com/google/genai/Models.java @@ -239,6 +239,14 @@ ObjectNode googleSearchRetrievalToMldev( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode enterpriseWebSearchToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode toolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -268,6 +276,11 @@ ObjectNode toolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pare toObject)); } + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"enterpriseWebSearch"}))) { + throw new IllegalArgumentException( + "enterpriseWebSearch parameter is not supported in Gemini API."); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecution"}) != null) { Common.setValueByPath( toObject, @@ -1183,6 +1196,14 @@ ObjectNode googleSearchRetrievalToVertex( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode enterpriseWebSearchToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode toolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -1215,6 +1236,17 @@ ObjectNode toolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par toObject)); } + if (Common.getValueByPath(fromObject, new String[] {"enterpriseWebSearch"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"enterpriseWebSearch"}, + enterpriseWebSearchToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"enterpriseWebSearch"})), + toObject)); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecution"}) != null) { Common.setValueByPath( toObject, diff --git a/src/main/java/com/google/genai/types/EnterpriseWebSearch.java b/src/main/java/com/google/genai/types/EnterpriseWebSearch.java new file mode 100644 index 00000000000..29543cfc27f --- /dev/null +++ b/src/main/java/com/google/genai/types/EnterpriseWebSearch.java @@ -0,0 +1,54 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; + +/** Tool to search public web data, powered by Vertex AI Search and Sec4 compliance. */ +@AutoValue +@JsonDeserialize(builder = EnterpriseWebSearch.Builder.class) +public abstract class EnterpriseWebSearch extends JsonSerializable { + /** Instantiates a builder for EnterpriseWebSearch. */ + public static Builder builder() { + return new AutoValue_EnterpriseWebSearch.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for EnterpriseWebSearch. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `EnterpriseWebSearch.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_EnterpriseWebSearch.Builder(); + } + + public abstract EnterpriseWebSearch build(); + } + + /** Deserializes a JSON string to a EnterpriseWebSearch object. */ + public static EnterpriseWebSearch fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, EnterpriseWebSearch.class); + } +} diff --git a/src/main/java/com/google/genai/types/Tool.java b/src/main/java/com/google/genai/types/Tool.java index b135e4663b5..b17e25a9ae5 100644 --- a/src/main/java/com/google/genai/types/Tool.java +++ b/src/main/java/com/google/genai/types/Tool.java @@ -51,6 +51,13 @@ public abstract class Tool extends JsonSerializable { @JsonProperty("googleSearchRetrieval") public abstract Optional googleSearchRetrieval(); + /** + * Optional. Enterprise web search tool type. Specialized retrieval tool that is powered by Vertex + * AI Search and Sec4 compliance. + */ + @JsonProperty("enterpriseWebSearch") + public abstract Optional enterpriseWebSearch(); + /** * Optional. CodeExecution tool type. Enables the model to execute code as part of generation. * This field is only used by the Gemini Developer API services. @@ -94,6 +101,9 @@ private static Builder create() { @JsonProperty("googleSearchRetrieval") public abstract Builder googleSearchRetrieval(GoogleSearchRetrieval googleSearchRetrieval); + @JsonProperty("enterpriseWebSearch") + public abstract Builder enterpriseWebSearch(EnterpriseWebSearch enterpriseWebSearch); + @JsonProperty("codeExecution") public abstract Builder codeExecution(ToolCodeExecution codeExecution); From 2d66f4a1f9e0b1694c3fc05c49cd07e758a20c38 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 10:16:43 -0700 Subject: [PATCH 02/18] Copybara import of the project: -- 6c456a55fe9f4ce6729dd841a43409f65298da05 by release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>: chore(main): release 0.6.1 COPYBARA_INTEGRATE_REVIEW=https://github.com/googleapis/java-genai/pull/220 from googleapis:release-please--branches--main 6c456a55fe9f4ce6729dd841a43409f65298da05 PiperOrigin-RevId: 753636520 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 12 ++++++++++++ examples/pom.xml | 2 +- pom.xml | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 4208b5cb79b..ac0317144eb 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.6.0" + ".": "0.6.1" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f37b76c209a..48aa195d234 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [0.6.1](https://github.com/googleapis/java-genai/compare/v0.6.0...v0.6.1) (2025-05-01) + + +### Bug Fixes + +* generateContentStream failed to find converter method GenerateContentResponseFromXxx ([590cb98](https://github.com/googleapis/java-genai/commit/590cb987874e6a812b0b3e5dab3f75fe919adafa)) + + +### Miscellaneous Chores + +* release 0.6.1 ([19c6373](https://github.com/googleapis/java-genai/commit/19c6373ac4e8dbc703d84b2d6564468ba810f739)) + ## [0.6.0](https://github.com/googleapis/java-genai/compare/v0.5.0...v0.6.0) (2025-04-30) diff --git a/examples/pom.xml b/examples/pom.xml index 24f6937cde8..133e3f2de9f 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ com.google.genai.examples google-genai-examples - 0.7.0-SNAPSHOT + 0.6.1 google-genai-examples diff --git a/pom.xml b/pom.xml index 037977cbfbe..c3a97977ef4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.google.genai google-genai google-genai - 0.7.0-SNAPSHOT + 0.6.1 jar Java idiomatic SDK for the Gemini Developer APIs and Vertex AI APIs. From 0139ff1c9c30620b7f3aa051502b1f147fbe0434 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 1 May 2025 13:22:59 -0400 Subject: [PATCH 03/18] chore(main): release 0.7.0-SNAPSHOT (#222) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- examples/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/pom.xml b/examples/pom.xml index 133e3f2de9f..24f6937cde8 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ com.google.genai.examples google-genai-examples - 0.6.1 + 0.7.0-SNAPSHOT google-genai-examples diff --git a/pom.xml b/pom.xml index c3a97977ef4..037977cbfbe 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.google.genai google-genai google-genai - 0.6.1 + 0.7.0-SNAPSHOT jar Java idiomatic SDK for the Gemini Developer APIs and Vertex AI APIs. From 334382d7882aeaf7bc0218be8c849a554ebf7979 Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Thu, 1 May 2025 10:42:33 -0700 Subject: [PATCH 04/18] chore: update readme to 0.6.1 PiperOrigin-RevId: 753646357 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f1db787c8e..228b6559e24 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ If you're using Maven, add the following to your dependencies: com.google.genai google-genai - 0.6.0 + 0.6.1 ``` From 78c2a390ef7ad34dac5cf14ff10838ba9c0899c4 Mon Sep 17 00:00:00 2001 From: Jaycee Li Date: Thu, 1 May 2025 11:53:25 -0700 Subject: [PATCH 05/18] docs: Add javadoc to public classes/methods PiperOrigin-RevId: 753672840 --- src/main/java/com/google/genai/AsyncModels.java | 12 ++++++++++++ .../java/com/google/genai/AsyncOperations.java | 1 + src/main/java/com/google/genai/Models.java | 16 ++++++++++++++++ src/main/java/com/google/genai/Operations.java | 5 +++++ 4 files changed, 34 insertions(+) diff --git a/src/main/java/com/google/genai/AsyncModels.java b/src/main/java/com/google/genai/AsyncModels.java index 87acc460b3b..ac83d36b12a 100644 --- a/src/main/java/com/google/genai/AsyncModels.java +++ b/src/main/java/com/google/genai/AsyncModels.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; +/** Async module of {@link Models} */ public final class AsyncModels { Models models; @@ -43,6 +44,17 @@ public AsyncModels(ApiClient apiClient) { this.models = new Models(apiClient); } + /** + * Asynchronously generates videos given a GenAI model, and a prompt or an image. + * + * @param model the name of the GenAI model to use for generating videos + * @param prompt the text prompt for generating the videos. Optional for image to video use cases. + * @param image the input image for generating the videos. Optional if prompt is provided. + * @param config a {@link com.google.genai.types.GenerateVideosConfig} instance that specifies the + * optional configurations + * @return a {@link com.google.genai.types.GenerateVideosOperation} instance that contains the + * generated videos. + */ public CompletableFuture generateVideos( String model, String prompt, Image image, GenerateVideosConfig config) { return CompletableFuture.supplyAsync(() -> models.generateVideos(model, prompt, image, config)); diff --git a/src/main/java/com/google/genai/AsyncOperations.java b/src/main/java/com/google/genai/AsyncOperations.java index 39309dddbab..b93f7a611c0 100644 --- a/src/main/java/com/google/genai/AsyncOperations.java +++ b/src/main/java/com/google/genai/AsyncOperations.java @@ -22,6 +22,7 @@ import com.google.genai.types.GetOperationConfig; import java.util.concurrent.CompletableFuture; +/** Async module of {@link Operations} */ public final class AsyncOperations { Operations operations; diff --git a/src/main/java/com/google/genai/Models.java b/src/main/java/com/google/genai/Models.java index 80d6d74020a..a49216bee12 100644 --- a/src/main/java/com/google/genai/Models.java +++ b/src/main/java/com/google/genai/Models.java @@ -56,6 +56,11 @@ import org.apache.http.HttpEntity; import org.apache.http.util.EntityUtils; +/** + * Provides methods for interacting with the available GenAI models. Instantiating this class is not + * required. After instantiating a {@link Client}, access methods through + * `client.models.methodName(...)` directly. + */ public final class Models { private final ApiClient apiClient; @@ -3919,6 +3924,17 @@ private UpscaleImageResponse privateUpscaleImage( } } + /** + * Generates videos given a GenAI model, and a prompt or an image. + * + * @param model the name of the GenAI model to use for generating videos + * @param prompt the text prompt for generating the videos. Optional for image to video use cases. + * @param image the input image for generating the videos. Optional if prompt is provided. + * @param config a {@link com.google.genai.types.GenerateVideosConfig} instance that specifies the + * optional configurations + * @return a {@link com.google.genai.types.GenerateVideosOperation} instance that contains the + * generated videos. + */ public GenerateVideosOperation generateVideos( String model, String prompt, Image image, GenerateVideosConfig config) { diff --git a/src/main/java/com/google/genai/Operations.java b/src/main/java/com/google/genai/Operations.java index 32aacdab812..8a01fafce9f 100644 --- a/src/main/java/com/google/genai/Operations.java +++ b/src/main/java/com/google/genai/Operations.java @@ -32,6 +32,11 @@ import org.apache.http.HttpEntity; import org.apache.http.util.EntityUtils; +/** + * Provides methods for managing the long-running operations. Instantiating this class is not + * required. After instantiating a {@link Client}, access methods through + * `client.operations.methodName(...)` directly. + */ public final class Operations { private final ApiClient apiClient; From 98d2ea64ce3027f3f7e1654daca29dd768cf2f1e Mon Sep 17 00:00:00 2001 From: Jaycee Li Date: Thu, 1 May 2025 12:50:35 -0700 Subject: [PATCH 06/18] chore: add experimental documentation to Operations/Veo PiperOrigin-RevId: 753692640 --- src/main/java/com/google/genai/AsyncModels.java | 2 ++ src/main/java/com/google/genai/Models.java | 2 ++ src/main/java/com/google/genai/Operations.java | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/main/java/com/google/genai/AsyncModels.java b/src/main/java/com/google/genai/AsyncModels.java index ac83d36b12a..6e57cb63425 100644 --- a/src/main/java/com/google/genai/AsyncModels.java +++ b/src/main/java/com/google/genai/AsyncModels.java @@ -47,6 +47,8 @@ public AsyncModels(ApiClient apiClient) { /** * Asynchronously generates videos given a GenAI model, and a prompt or an image. * + *

This method is experimental. + * * @param model the name of the GenAI model to use for generating videos * @param prompt the text prompt for generating the videos. Optional for image to video use cases. * @param image the input image for generating the videos. Optional if prompt is provided. diff --git a/src/main/java/com/google/genai/Models.java b/src/main/java/com/google/genai/Models.java index a49216bee12..0559005ad28 100644 --- a/src/main/java/com/google/genai/Models.java +++ b/src/main/java/com/google/genai/Models.java @@ -3927,6 +3927,8 @@ private UpscaleImageResponse privateUpscaleImage( /** * Generates videos given a GenAI model, and a prompt or an image. * + *

This method is experimental. + * * @param model the name of the GenAI model to use for generating videos * @param prompt the text prompt for generating the videos. Optional for image to video use cases. * @param image the input image for generating the videos. Optional if prompt is provided. diff --git a/src/main/java/com/google/genai/Operations.java b/src/main/java/com/google/genai/Operations.java index 8a01fafce9f..894daf07155 100644 --- a/src/main/java/com/google/genai/Operations.java +++ b/src/main/java/com/google/genai/Operations.java @@ -36,6 +36,8 @@ * Provides methods for managing the long-running operations. Instantiating this class is not * required. After instantiating a {@link Client}, access methods through * `client.operations.methodName(...)` directly. + * + *

This module is experimental. */ public final class Operations { private final ApiClient apiClient; From 8b8fb4515d994b24bd1a3bb3b500f415c2dddeca Mon Sep 17 00:00:00 2001 From: Qiao Wang Date: Fri, 2 May 2025 10:01:00 -0700 Subject: [PATCH 07/18] feat: Add countTokens method support PiperOrigin-RevId: 754041344 --- .../google/genai/examples/CountTokens.java | 56 ++++ .../examples/CountTokensWithConfigs.java | 71 ++++++ .../java/com/google/genai/AsyncModels.java | 7 + src/main/java/com/google/genai/Models.java | 241 ++++++++++++++++++ .../google/genai/types/CountTokensConfig.java | 84 ++++++ .../genai/types/CountTokensParameters.java | 81 ++++++ .../genai/types/CountTokensResponse.java | 70 +++++ .../com/google/genai/types/TokensInfo.java | 78 ++++++ 8 files changed, 688 insertions(+) create mode 100644 examples/src/main/java/com/google/genai/examples/CountTokens.java create mode 100644 examples/src/main/java/com/google/genai/examples/CountTokensWithConfigs.java create mode 100644 src/main/java/com/google/genai/types/CountTokensConfig.java create mode 100644 src/main/java/com/google/genai/types/CountTokensParameters.java create mode 100644 src/main/java/com/google/genai/types/CountTokensResponse.java create mode 100644 src/main/java/com/google/genai/types/TokensInfo.java diff --git a/examples/src/main/java/com/google/genai/examples/CountTokens.java b/examples/src/main/java/com/google/genai/examples/CountTokens.java new file mode 100644 index 00000000000..dad964e9d3f --- /dev/null +++ b/examples/src/main/java/com/google/genai/examples/CountTokens.java @@ -0,0 +1,56 @@ +/* + * 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 + * + * https://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. + */ + +/** + * Usage: + * + *

1a. If you are using Vertex AI, setup ADC to get credentials: + * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp + * + *

Then set Project, Location, and USE_VERTEXAI flag as environment variables: + * + *

export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT + * + *

export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION + * + *

1b. If you are using Gemini Developer AI, set an API key environment variable. You can find a + * list of available API keys here: https://aistudio.google.com/app/apikey + * + *

export GOOGLE_API_KEY=YOUR_API_KEY + * + *

2. Compile the java package and run the sample code. + * + *

mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.CountTokens" + */ +package com.google.genai.examples; + +import com.google.genai.Client; +import com.google.genai.types.CountTokensResponse; + +/** An example of using the Unified Gen AI Java SDK to count tokens for simple text input. */ +public class CountTokens { + public static void main(String[] args) { + // Instantiate the client. The client by default uses the Gemini Developer API. It gets the API + // key from the environment variable `GOOGLE_API_KEY`. + Client client = new Client(); + + CountTokensResponse response = + client.models.countTokens("gemini-2.0-flash-001", "What is your name?", null); + + // Gets the text string from the response by the quick accessor method `text()`. + System.out.println("Unary response: " + response); + } +} diff --git a/examples/src/main/java/com/google/genai/examples/CountTokensWithConfigs.java b/examples/src/main/java/com/google/genai/examples/CountTokensWithConfigs.java new file mode 100644 index 00000000000..2c898e51820 --- /dev/null +++ b/examples/src/main/java/com/google/genai/examples/CountTokensWithConfigs.java @@ -0,0 +1,71 @@ +/* + * 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 + * + * https://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. + */ + +/** + * Usage: + * + *

1a. If you are using Vertex AI, setup ADC to get credentials: + * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp + * + *

Then set Project, Location, and USE_VERTEXAI flag as environment variables: + * + *

export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT + * + *

export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION + * + *

1b. If you are using Gemini Developer AI, set an API key environment variable. You can find a + * list of available API keys here: https://aistudio.google.com/app/apikey + * + *

export GOOGLE_API_KEY=YOUR_API_KEY + * + *

2. Compile the java package and run the sample code. + * + *

mvn clean compile + * + *

mvn exec:java -Dexec.mainClass="com.google.genai.examples.CountTokensWithConfigs" + */ +package com.google.genai.examples; + +import com.google.common.collect.ImmutableList; +import com.google.genai.Client; +import com.google.genai.types.Content; +import com.google.genai.types.CountTokensConfig; +import com.google.genai.types.CountTokensResponse; +import com.google.genai.types.GoogleSearch; +import com.google.genai.types.Part; +import com.google.genai.types.SafetySetting; +import com.google.genai.types.Tool; + +/** An example of using the Unified Gen AI Java SDK to generate content with extra configs. */ +public class CountTokensWithConfigs { + public static void main(String[] args) { + // Instantiate the client using Vertex AI. + Client client = Client.builder().vertexAI(true).build(); + + // Sets the system instruction in the config. + Content systemInstruction = Content.fromParts(Part.fromText("You are a history teacher.")); + + CountTokensConfig config = + CountTokensConfig.builder() + .systemInstruction(systemInstruction) + .build(); + + CountTokensResponse response = + client.models.countTokens("gemini-2.0-flash-001", "Tell me the history of LLM", config); + + System.out.println("Response: " + response); + } +} diff --git a/src/main/java/com/google/genai/AsyncModels.java b/src/main/java/com/google/genai/AsyncModels.java index 6e57cb63425..2ea255c433c 100644 --- a/src/main/java/com/google/genai/AsyncModels.java +++ b/src/main/java/com/google/genai/AsyncModels.java @@ -19,6 +19,8 @@ package com.google.genai; import com.google.genai.types.Content; +import com.google.genai.types.CountTokensConfig; +import com.google.genai.types.CountTokensResponse; import com.google.genai.types.EditImageConfig; import com.google.genai.types.EditImageResponse; import com.google.genai.types.EmbedContentConfig; @@ -44,6 +46,11 @@ public AsyncModels(ApiClient apiClient) { this.models = new Models(apiClient); } + public CompletableFuture countTokens( + String model, List contents, CountTokensConfig config) { + return CompletableFuture.supplyAsync(() -> models.countTokens(model, contents, config)); + } + /** * Asynchronously generates videos given a GenAI model, and a prompt or an image. * diff --git a/src/main/java/com/google/genai/Models.java b/src/main/java/com/google/genai/Models.java index 0559005ad28..d3b36c5c4c3 100644 --- a/src/main/java/com/google/genai/Models.java +++ b/src/main/java/com/google/genai/Models.java @@ -25,6 +25,9 @@ import com.google.common.collect.ImmutableList; import com.google.genai.errors.GenAiIOException; import com.google.genai.types.Content; +import com.google.genai.types.CountTokensConfig; +import com.google.genai.types.CountTokensParameters; +import com.google.genai.types.CountTokensResponse; import com.google.genai.types.EditImageConfig; import com.google.genai.types.EditImageParameters; import com.google.genai.types.EditImageResponse; @@ -882,6 +885,66 @@ ObjectNode generateImagesParametersToMldev( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode countTokensConfigToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"systemInstruction"}))) { + throw new IllegalArgumentException( + "systemInstruction parameter is not supported in Gemini API."); + } + + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"tools"}))) { + throw new IllegalArgumentException("tools parameter is not supported in Gemini API."); + } + + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"generationConfig"}))) { + throw new IllegalArgumentException( + "generationConfig parameter is not supported in Gemini API."); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode countTokensParametersToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"_url", "model"}, + Transformers.tModel( + this.apiClient, Common.getValueByPath(fromObject, new String[] {"model"}))); + } + + if (Common.getValueByPath(fromObject, new String[] {"contents"}) != null) { + ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"contents"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add(contentToMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"contents"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"config"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"config"}, + countTokensConfigToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"config"})), + toObject)); + } + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode imageToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -2313,6 +2376,84 @@ ObjectNode upscaleImageAPIParametersToVertex( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode countTokensConfigToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + if (Common.getValueByPath(fromObject, new String[] {"systemInstruction"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"systemInstruction"}, + contentToVertex( + apiClient, + JsonSerializable.toJsonNode( + Transformers.tContent( + this.apiClient, + Common.getValueByPath(fromObject, new String[] {"systemInstruction"}))), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"tools"}) != null) { + ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"tools"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add(toolToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(parentObject, new String[] {"tools"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"generationConfig"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"generationConfig"}, + Common.getValueByPath(fromObject, new String[] {"generationConfig"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode countTokensParametersToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"_url", "model"}, + Transformers.tModel( + this.apiClient, Common.getValueByPath(fromObject, new String[] {"model"}))); + } + + if (Common.getValueByPath(fromObject, new String[] {"contents"}) != null) { + ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"contents"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add(contentToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"contents"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"config"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"config"}, + countTokensConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"config"})), + toObject)); + } + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode generateVideosConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { @@ -2846,6 +2987,27 @@ ObjectNode generateImagesResponseFromMldev( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode countTokensResponseFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"totalTokens"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"totalTokens"}, + Common.getValueByPath(fromObject, new String[] {"totalTokens"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"cachedContentTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"cachedContentTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"cachedContentTokenCount"})); + } + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode videoFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -3487,6 +3649,20 @@ ObjectNode upscaleImageResponseFromVertex( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode countTokensResponseFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"totalTokens"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"totalTokens"}, + Common.getValueByPath(fromObject, new String[] {"totalTokens"})); + } + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode videoFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -3924,6 +4100,57 @@ private UpscaleImageResponse privateUpscaleImage( } } + public CountTokensResponse countTokens( + String model, List contents, CountTokensConfig config) { + + CountTokensParameters.Builder parameterBuilder = CountTokensParameters.builder(); + + if (!Common.isZero(model)) { + parameterBuilder.model(model); + } + if (!Common.isZero(contents)) { + parameterBuilder.contents(contents); + } + if (!Common.isZero(config)) { + parameterBuilder.config(config); + } + JsonNode parameterNode = JsonSerializable.toJsonNode(parameterBuilder.build()); + + ObjectNode body; + String path; + if (this.apiClient.vertexAI()) { + body = countTokensParametersToVertex(this.apiClient, parameterNode, null); + path = Common.formatMap("{model}:countTokens", body.get("_url")); + } else { + body = countTokensParametersToMldev(this.apiClient, parameterNode, null); + path = Common.formatMap("{model}:countTokens", body.get("_url")); + } + body.remove("_url"); + + // TODO: Handle "_query" in the body (for list support). + + // TODO: Remove the hack that removes config. + body.remove("config"); + + try (ApiResponse response = + this.apiClient.request("post", path, JsonSerializable.toJsonString(body))) { + HttpEntity entity = response.getEntity(); + String responseString; + try { + responseString = EntityUtils.toString(entity); + } catch (IOException e) { + throw new GenAiIOException("Failed to read HTTP response.", e); + } + JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString); + if (this.apiClient.vertexAI()) { + responseNode = countTokensResponseFromVertex(this.apiClient, responseNode, null); + } else { + responseNode = countTokensResponseFromMldev(this.apiClient, responseNode, null); + } + return JsonSerializable.fromJsonNode(responseNode, CountTokensResponse.class); + } + } + /** * Generates videos given a GenAI model, and a prompt or an image. * @@ -4085,6 +4312,20 @@ public ResponseStream generateContentStream( model, Transformers.tContents(this.apiClient, (Object) text), config); } + /** + * Counts tokens given a GenAI model and a text string. + * + * @param model the name of the GenAI model to use. + * @param text the text string to send to count tokens for. + * @param config a {@link com.google.genai.types.CountTokensConfig} instance that specifies the + * optional configurations + * @return a {@link com.google.genai.types.CountTokensResponse} instance that contains tokens + * count. + */ + public CountTokensResponse countTokens(String model, String text, CountTokensConfig config) { + return countTokens(model, Transformers.tContents(this.apiClient, (Object) text), config); + } + /** * Generates images given a GenAI model and a prompt. * diff --git a/src/main/java/com/google/genai/types/CountTokensConfig.java b/src/main/java/com/google/genai/types/CountTokensConfig.java new file mode 100644 index 00000000000..671780f25d2 --- /dev/null +++ b/src/main/java/com/google/genai/types/CountTokensConfig.java @@ -0,0 +1,84 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.List; +import java.util.Optional; + +/** Config for the count_tokens method. */ +@AutoValue +@JsonDeserialize(builder = CountTokensConfig.Builder.class) +public abstract class CountTokensConfig extends JsonSerializable { + /** Instructions for the model to steer it toward better performance. */ + @JsonProperty("systemInstruction") + public abstract Optional systemInstruction(); + + /** + * Code that enables the system to interact with external systems to perform an action outside of + * the knowledge and scope of the model. + */ + @JsonProperty("tools") + public abstract Optional> tools(); + + /** + * Configuration that the model uses to generate the response. Not supported by the Gemini + * Developer API. + */ + @JsonProperty("generationConfig") + public abstract Optional generationConfig(); + + /** Instantiates a builder for CountTokensConfig. */ + public static Builder builder() { + return new AutoValue_CountTokensConfig.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for CountTokensConfig. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `CountTokensConfig.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_CountTokensConfig.Builder(); + } + + @JsonProperty("systemInstruction") + public abstract Builder systemInstruction(Content systemInstruction); + + @JsonProperty("tools") + public abstract Builder tools(List tools); + + @JsonProperty("generationConfig") + public abstract Builder generationConfig(GenerationConfig generationConfig); + + public abstract CountTokensConfig build(); + } + + /** Deserializes a JSON string to a CountTokensConfig object. */ + public static CountTokensConfig fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, CountTokensConfig.class); + } +} diff --git a/src/main/java/com/google/genai/types/CountTokensParameters.java b/src/main/java/com/google/genai/types/CountTokensParameters.java new file mode 100644 index 00000000000..f964fd3bd1e --- /dev/null +++ b/src/main/java/com/google/genai/types/CountTokensParameters.java @@ -0,0 +1,81 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.List; +import java.util.Optional; + +/** Parameters for counting tokens. */ +@AutoValue +@JsonDeserialize(builder = CountTokensParameters.Builder.class) +public abstract class CountTokensParameters extends JsonSerializable { + /** + * ID of the model to use. For a list of models, see `Google models + * `_. + */ + @JsonProperty("model") + public abstract Optional model(); + + /** Input content. */ + @JsonProperty("contents") + public abstract Optional> contents(); + + /** Configuration for counting tokens. */ + @JsonProperty("config") + public abstract Optional config(); + + /** Instantiates a builder for CountTokensParameters. */ + public static Builder builder() { + return new AutoValue_CountTokensParameters.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for CountTokensParameters. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `CountTokensParameters.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_CountTokensParameters.Builder(); + } + + @JsonProperty("model") + public abstract Builder model(String model); + + @JsonProperty("contents") + public abstract Builder contents(List contents); + + @JsonProperty("config") + public abstract Builder config(CountTokensConfig config); + + public abstract CountTokensParameters build(); + } + + /** Deserializes a JSON string to a CountTokensParameters object. */ + public static CountTokensParameters fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, CountTokensParameters.class); + } +} diff --git a/src/main/java/com/google/genai/types/CountTokensResponse.java b/src/main/java/com/google/genai/types/CountTokensResponse.java new file mode 100644 index 00000000000..7d965a37b87 --- /dev/null +++ b/src/main/java/com/google/genai/types/CountTokensResponse.java @@ -0,0 +1,70 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.Optional; + +/** Response for counting tokens. */ +@AutoValue +@JsonDeserialize(builder = CountTokensResponse.Builder.class) +public abstract class CountTokensResponse extends JsonSerializable { + /** Total number of tokens. */ + @JsonProperty("totalTokens") + public abstract Optional totalTokens(); + + /** Number of tokens in the cached part of the prompt (the cached content). */ + @JsonProperty("cachedContentTokenCount") + public abstract Optional cachedContentTokenCount(); + + /** Instantiates a builder for CountTokensResponse. */ + public static Builder builder() { + return new AutoValue_CountTokensResponse.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for CountTokensResponse. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `CountTokensResponse.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_CountTokensResponse.Builder(); + } + + @JsonProperty("totalTokens") + public abstract Builder totalTokens(Integer totalTokens); + + @JsonProperty("cachedContentTokenCount") + public abstract Builder cachedContentTokenCount(Integer cachedContentTokenCount); + + public abstract CountTokensResponse build(); + } + + /** Deserializes a JSON string to a CountTokensResponse object. */ + public static CountTokensResponse fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, CountTokensResponse.class); + } +} diff --git a/src/main/java/com/google/genai/types/TokensInfo.java b/src/main/java/com/google/genai/types/TokensInfo.java new file mode 100644 index 00000000000..645611f4e9f --- /dev/null +++ b/src/main/java/com/google/genai/types/TokensInfo.java @@ -0,0 +1,78 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.List; +import java.util.Optional; + +/** Tokens info with a list of tokens and the corresponding list of token ids. */ +@AutoValue +@JsonDeserialize(builder = TokensInfo.Builder.class) +public abstract class TokensInfo extends JsonSerializable { + /** Optional. Optional fields for the role from the corresponding Content. */ + @JsonProperty("role") + public abstract Optional role(); + + /** A list of token ids from the input. */ + @JsonProperty("tokenIds") + public abstract Optional> tokenIds(); + + /** A list of tokens from the input. */ + @JsonProperty("tokens") + public abstract Optional> tokens(); + + /** Instantiates a builder for TokensInfo. */ + public static Builder builder() { + return new AutoValue_TokensInfo.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for TokensInfo. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `TokensInfo.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_TokensInfo.Builder(); + } + + @JsonProperty("role") + public abstract Builder role(String role); + + @JsonProperty("tokenIds") + public abstract Builder tokenIds(List tokenIds); + + @JsonProperty("tokens") + public abstract Builder tokens(List tokens); + + public abstract TokensInfo build(); + } + + /** Deserializes a JSON string to a TokensInfo object. */ + public static TokensInfo fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, TokensInfo.class); + } +} From afed3d0c00e8d5b473f06b596a4a00732a29ab56 Mon Sep 17 00:00:00 2001 From: Jaycee Li Date: Fri, 2 May 2025 12:59:30 -0700 Subject: [PATCH 08/18] chore: Update the return type of `HttpApiClient.request` PiperOrigin-RevId: 754104976 --- src/main/java/com/google/genai/HttpApiClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/genai/HttpApiClient.java b/src/main/java/com/google/genai/HttpApiClient.java index 3adc03cfeba..1e6f3dccc7e 100644 --- a/src/main/java/com/google/genai/HttpApiClient.java +++ b/src/main/java/com/google/genai/HttpApiClient.java @@ -49,7 +49,7 @@ final class HttpApiClient extends ApiClient { /** Sends a Http request given the http method, path, and request json string. */ @Override - public ApiResponse request(String httpMethod, String path, String requestJson) { + public HttpApiResponse request(String httpMethod, String path, String requestJson) { boolean queryBaseModel = httpMethod.equalsIgnoreCase("GET") && path.startsWith("publishers/google/models/"); if (this.vertexAI() && !path.startsWith("projects/") && !queryBaseModel) { @@ -119,7 +119,7 @@ private void setHeaders(HttpRequestBase request) { } /** Executes the given HTTP request. */ - private ApiResponse executeRequest(HttpRequestBase request) { + private HttpApiResponse executeRequest(HttpRequestBase request) { try { return new HttpApiResponse(httpClient.execute(request)); } catch (IOException e) { From 85c751e5e8e715ef26cf5524cb57a7d77953a734 Mon Sep 17 00:00:00 2001 From: Qiao Wang Date: Fri, 2 May 2025 13:29:19 -0700 Subject: [PATCH 09/18] feat: Add computeTokens support PiperOrigin-RevId: 754114912 --- .../google/genai/examples/ComputeTokens.java | 55 ++++++++ .../java/com/google/genai/AsyncModels.java | 7 ++ src/main/java/com/google/genai/Models.java | 118 ++++++++++++++++++ .../genai/types/ComputeTokensConfig.java | 54 ++++++++ .../genai/types/ComputeTokensParameters.java | 81 ++++++++++++ .../genai/types/ComputeTokensResponse.java | 68 ++++++++++ 6 files changed, 383 insertions(+) create mode 100644 examples/src/main/java/com/google/genai/examples/ComputeTokens.java create mode 100644 src/main/java/com/google/genai/types/ComputeTokensConfig.java create mode 100644 src/main/java/com/google/genai/types/ComputeTokensParameters.java create mode 100644 src/main/java/com/google/genai/types/ComputeTokensResponse.java diff --git a/examples/src/main/java/com/google/genai/examples/ComputeTokens.java b/examples/src/main/java/com/google/genai/examples/ComputeTokens.java new file mode 100644 index 00000000000..a5dc01ca984 --- /dev/null +++ b/examples/src/main/java/com/google/genai/examples/ComputeTokens.java @@ -0,0 +1,55 @@ +/* + * 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 + * + * https://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. + */ + +/** + * Usage: + * + *

1a. If you are using Vertex AI, setup ADC to get credentials: + * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp + * + *

Then set Project, Location, and USE_VERTEXAI flag as environment variables: + * + *

export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT + * + *

export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION + * + *

1b. If you are using Gemini Developer AI, set an API key environment variable. You can find a + * list of available API keys here: https://aistudio.google.com/app/apikey + * + *

export GOOGLE_API_KEY=YOUR_API_KEY + * + *

2. Compile the java package and run the sample code. + * + *

mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.CountTokens" + */ +package com.google.genai.examples; + +import com.google.genai.Client; +import com.google.genai.types.ComputeTokensResponse; + +/** An example of using the Unified Gen AI Java SDK to compute tokens for simple text input. */ +public class ComputeTokens { + public static void main(String[] args) { + // Instantiate the client using Vertex AI. + Client client = Client.builder().vertexAI(true).build(); + + ComputeTokensResponse response = + client.models.computeTokens("gemini-2.0-flash-001", "What is your name?", null); + + // Gets the text string from the response by the quick accessor method `text()`. + System.out.println("Unary response: " + response); + } +} diff --git a/src/main/java/com/google/genai/AsyncModels.java b/src/main/java/com/google/genai/AsyncModels.java index 2ea255c433c..682d85a293d 100644 --- a/src/main/java/com/google/genai/AsyncModels.java +++ b/src/main/java/com/google/genai/AsyncModels.java @@ -18,6 +18,8 @@ package com.google.genai; +import com.google.genai.types.ComputeTokensConfig; +import com.google.genai.types.ComputeTokensResponse; import com.google.genai.types.Content; import com.google.genai.types.CountTokensConfig; import com.google.genai.types.CountTokensResponse; @@ -51,6 +53,11 @@ public CompletableFuture countTokens( return CompletableFuture.supplyAsync(() -> models.countTokens(model, contents, config)); } + public CompletableFuture computeTokens( + String model, List contents, ComputeTokensConfig config) { + return CompletableFuture.supplyAsync(() -> models.computeTokens(model, contents, config)); + } + /** * Asynchronously generates videos given a GenAI model, and a prompt or an image. * diff --git a/src/main/java/com/google/genai/Models.java b/src/main/java/com/google/genai/Models.java index d3b36c5c4c3..5ff4125c0c2 100644 --- a/src/main/java/com/google/genai/Models.java +++ b/src/main/java/com/google/genai/Models.java @@ -24,6 +24,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.ImmutableList; import com.google.genai.errors.GenAiIOException; +import com.google.genai.types.ComputeTokensConfig; +import com.google.genai.types.ComputeTokensParameters; +import com.google.genai.types.ComputeTokensResponse; import com.google.genai.types.Content; import com.google.genai.types.CountTokensConfig; import com.google.genai.types.CountTokensParameters; @@ -2454,6 +2457,40 @@ ObjectNode countTokensParametersToVertex( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode computeTokensParametersToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"_url", "model"}, + Transformers.tModel( + this.apiClient, Common.getValueByPath(fromObject, new String[] {"model"}))); + } + + if (Common.getValueByPath(fromObject, new String[] {"contents"}) != null) { + ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"contents"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add(contentToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"contents"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"config"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"config"}, + Common.getValueByPath(fromObject, new String[] {"config"})); + } + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode generateVideosConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { @@ -3663,6 +3700,20 @@ ObjectNode countTokensResponseFromVertex( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode computeTokensResponseFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"tokensInfo"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"tokensInfo"}, + Common.getValueByPath(fromObject, new String[] {"tokensInfo"})); + } + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode videoFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -4151,6 +4202,58 @@ public CountTokensResponse countTokens( } } + public ComputeTokensResponse computeTokens( + String model, List contents, ComputeTokensConfig config) { + + ComputeTokensParameters.Builder parameterBuilder = ComputeTokensParameters.builder(); + + if (!Common.isZero(model)) { + parameterBuilder.model(model); + } + if (!Common.isZero(contents)) { + parameterBuilder.contents(contents); + } + if (!Common.isZero(config)) { + parameterBuilder.config(config); + } + JsonNode parameterNode = JsonSerializable.toJsonNode(parameterBuilder.build()); + + ObjectNode body; + String path; + if (this.apiClient.vertexAI()) { + body = computeTokensParametersToVertex(this.apiClient, parameterNode, null); + path = Common.formatMap("{model}:computeTokens", body.get("_url")); + } else { + throw new UnsupportedOperationException( + "This method is not supported by the Gemini Developer API."); + } + body.remove("_url"); + + // TODO: Handle "_query" in the body (for list support). + + // TODO: Remove the hack that removes config. + body.remove("config"); + + try (ApiResponse response = + this.apiClient.request("post", path, JsonSerializable.toJsonString(body))) { + HttpEntity entity = response.getEntity(); + String responseString; + try { + responseString = EntityUtils.toString(entity); + } catch (IOException e) { + throw new GenAiIOException("Failed to read HTTP response.", e); + } + JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString); + if (this.apiClient.vertexAI()) { + responseNode = computeTokensResponseFromVertex(this.apiClient, responseNode, null); + } else { + throw new UnsupportedOperationException( + "This method is not supported by the Gemini Developer API."); + } + return JsonSerializable.fromJsonNode(responseNode, ComputeTokensResponse.class); + } + } + /** * Generates videos given a GenAI model, and a prompt or an image. * @@ -4326,6 +4429,21 @@ public CountTokensResponse countTokens(String model, String text, CountTokensCon return countTokens(model, Transformers.tContents(this.apiClient, (Object) text), config); } + /** + * Computes tokens given a GenAI model and a text string. + * + * @param model the name of the GenAI model to use. + * @param text the text string to send to compute tokens for. + * @param config a {@link com.google.genai.types.ComputeTokensConfig} instance that specifies the + * optional configurations + * @return a {@link com.google.genai.types.ComputeTokensResponse} instance that contains tokens + * results. + */ + public ComputeTokensResponse computeTokens( + String model, String text, ComputeTokensConfig config) { + return computeTokens(model, Transformers.tContents(this.apiClient, (Object) text), config); + } + /** * Generates images given a GenAI model and a prompt. * diff --git a/src/main/java/com/google/genai/types/ComputeTokensConfig.java b/src/main/java/com/google/genai/types/ComputeTokensConfig.java new file mode 100644 index 00000000000..8f9aebf57f6 --- /dev/null +++ b/src/main/java/com/google/genai/types/ComputeTokensConfig.java @@ -0,0 +1,54 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; + +/** Optional parameters for computing tokens. */ +@AutoValue +@JsonDeserialize(builder = ComputeTokensConfig.Builder.class) +public abstract class ComputeTokensConfig extends JsonSerializable { + /** Instantiates a builder for ComputeTokensConfig. */ + public static Builder builder() { + return new AutoValue_ComputeTokensConfig.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for ComputeTokensConfig. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `ComputeTokensConfig.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_ComputeTokensConfig.Builder(); + } + + public abstract ComputeTokensConfig build(); + } + + /** Deserializes a JSON string to a ComputeTokensConfig object. */ + public static ComputeTokensConfig fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, ComputeTokensConfig.class); + } +} diff --git a/src/main/java/com/google/genai/types/ComputeTokensParameters.java b/src/main/java/com/google/genai/types/ComputeTokensParameters.java new file mode 100644 index 00000000000..515b484237b --- /dev/null +++ b/src/main/java/com/google/genai/types/ComputeTokensParameters.java @@ -0,0 +1,81 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.List; +import java.util.Optional; + +/** Parameters for computing tokens. */ +@AutoValue +@JsonDeserialize(builder = ComputeTokensParameters.Builder.class) +public abstract class ComputeTokensParameters extends JsonSerializable { + /** + * ID of the model to use. For a list of models, see `Google models + * `_. + */ + @JsonProperty("model") + public abstract Optional model(); + + /** Input content. */ + @JsonProperty("contents") + public abstract Optional> contents(); + + /** Optional parameters for the request. */ + @JsonProperty("config") + public abstract Optional config(); + + /** Instantiates a builder for ComputeTokensParameters. */ + public static Builder builder() { + return new AutoValue_ComputeTokensParameters.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for ComputeTokensParameters. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `ComputeTokensParameters.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_ComputeTokensParameters.Builder(); + } + + @JsonProperty("model") + public abstract Builder model(String model); + + @JsonProperty("contents") + public abstract Builder contents(List contents); + + @JsonProperty("config") + public abstract Builder config(ComputeTokensConfig config); + + public abstract ComputeTokensParameters build(); + } + + /** Deserializes a JSON string to a ComputeTokensParameters object. */ + public static ComputeTokensParameters fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, ComputeTokensParameters.class); + } +} diff --git a/src/main/java/com/google/genai/types/ComputeTokensResponse.java b/src/main/java/com/google/genai/types/ComputeTokensResponse.java new file mode 100644 index 00000000000..a30887a013b --- /dev/null +++ b/src/main/java/com/google/genai/types/ComputeTokensResponse.java @@ -0,0 +1,68 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.List; +import java.util.Optional; + +/** Response for computing tokens. */ +@AutoValue +@JsonDeserialize(builder = ComputeTokensResponse.Builder.class) +public abstract class ComputeTokensResponse extends JsonSerializable { + /** + * Lists of tokens info from the input. A ComputeTokensRequest could have multiple instances with + * a prompt in each instance. We also need to return lists of tokens info for the request with + * multiple instances. + */ + @JsonProperty("tokensInfo") + public abstract Optional> tokensInfo(); + + /** Instantiates a builder for ComputeTokensResponse. */ + public static Builder builder() { + return new AutoValue_ComputeTokensResponse.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for ComputeTokensResponse. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `ComputeTokensResponse.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_ComputeTokensResponse.Builder(); + } + + @JsonProperty("tokensInfo") + public abstract Builder tokensInfo(List tokensInfo); + + public abstract ComputeTokensResponse build(); + } + + /** Deserializes a JSON string to a ComputeTokensResponse object. */ + public static ComputeTokensResponse fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, ComputeTokensResponse.class); + } +} From 906597026e36c09cded0d8cb50ffe14a96c5faff Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Fri, 2 May 2025 17:31:37 -0700 Subject: [PATCH 10/18] feat: enable input transcription for Gemini API. PiperOrigin-RevId: 754188580 --- .../java/com/google/genai/LiveConverters.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/google/genai/LiveConverters.java b/src/main/java/com/google/genai/LiveConverters.java index e21c28edd31..eafc545ddcd 100644 --- a/src/main/java/com/google/genai/LiveConverters.java +++ b/src/main/java/com/google/genai/LiveConverters.java @@ -807,10 +807,15 @@ ObjectNode liveConnectConfigToMldev( Common.setValueByPath(parentObject, new String[] {"setup", "tools"}, result); } - if (!Common.isZero( - Common.getValueByPath(fromObject, new String[] {"inputAudioTranscription"}))) { - throw new IllegalArgumentException( - "inputAudioTranscription parameter is not supported in Gemini API."); + if (Common.getValueByPath(fromObject, new String[] {"inputAudioTranscription"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "inputAudioTranscription"}, + audioTranscriptionConfigToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"inputAudioTranscription"})), + toObject)); } if (Common.getValueByPath(fromObject, new String[] {"outputAudioTranscription"}) != null) { @@ -1212,10 +1217,15 @@ ObjectNode liveClientSetupToMldev( toObject)); } - if (!Common.isZero( - Common.getValueByPath(fromObject, new String[] {"inputAudioTranscription"}))) { - throw new IllegalArgumentException( - "inputAudioTranscription parameter is not supported in Gemini API."); + if (Common.getValueByPath(fromObject, new String[] {"inputAudioTranscription"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"inputAudioTranscription"}, + audioTranscriptionConfigToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"inputAudioTranscription"})), + toObject)); } if (Common.getValueByPath(fromObject, new String[] {"outputAudioTranscription"}) != null) { From 6a3e35ca4d5f27eaa5bf82017e85b7ad0ee82558 Mon Sep 17 00:00:00 2001 From: Annie Luc Date: Sun, 4 May 2025 16:07:20 -0700 Subject: [PATCH 11/18] No public description PiperOrigin-RevId: 754711049 --- .../java/com/google/genai/LiveConverters.java | 28 +++++++++++++++++++ src/main/java/com/google/genai/Models.java | 28 +++++++++++++++++++ .../java/com/google/genai/types/Part.java | 7 +++++ 3 files changed, 63 insertions(+) diff --git a/src/main/java/com/google/genai/LiveConverters.java b/src/main/java/com/google/genai/LiveConverters.java index eafc545ddcd..09742e5e971 100644 --- a/src/main/java/com/google/genai/LiveConverters.java +++ b/src/main/java/com/google/genai/LiveConverters.java @@ -44,6 +44,13 @@ ObjectNode partToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pare Common.getValueByPath(fromObject, new String[] {"thought"})); } + if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thoughtSignature"}, + Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -113,6 +120,13 @@ ObjectNode partToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par Common.getValueByPath(fromObject, new String[] {"thought"})); } + if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thoughtSignature"}, + Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -1682,6 +1696,13 @@ ObjectNode partFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pa Common.getValueByPath(fromObject, new String[] {"thought"})); } + if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thoughtSignature"}, + Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -1751,6 +1772,13 @@ ObjectNode partFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode p Common.getValueByPath(fromObject, new String[] {"thought"})); } + if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thoughtSignature"}, + Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, diff --git a/src/main/java/com/google/genai/Models.java b/src/main/java/com/google/genai/Models.java index 5ff4125c0c2..79a13b79dde 100644 --- a/src/main/java/com/google/genai/Models.java +++ b/src/main/java/com/google/genai/Models.java @@ -88,6 +88,13 @@ ObjectNode partToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pare Common.getValueByPath(fromObject, new String[] {"thought"})); } + if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thoughtSignature"}, + Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -1101,6 +1108,13 @@ ObjectNode partToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par Common.getValueByPath(fromObject, new String[] {"thought"})); } + if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thoughtSignature"}, + Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -2631,6 +2645,13 @@ ObjectNode partFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pa Common.getValueByPath(fromObject, new String[] {"thought"})); } + if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thoughtSignature"}, + Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -3192,6 +3213,13 @@ ObjectNode partFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode p Common.getValueByPath(fromObject, new String[] {"thought"})); } + if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thoughtSignature"}, + Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, diff --git a/src/main/java/com/google/genai/types/Part.java b/src/main/java/com/google/genai/types/Part.java index 7316236980a..aa5cd2e823e 100644 --- a/src/main/java/com/google/genai/types/Part.java +++ b/src/main/java/com/google/genai/types/Part.java @@ -43,6 +43,10 @@ public abstract class Part extends JsonSerializable { @JsonProperty("thought") public abstract Optional thought(); + /** An opaque signature for the thought so it can be reused in subsequent requests. */ + @JsonProperty("thoughtSignature") + public abstract Optional thoughtSignature(); + /** Optional. Result of executing the [ExecutableCode]. */ @JsonProperty("codeExecutionResult") public abstract Optional codeExecutionResult(); @@ -101,6 +105,9 @@ private static Builder create() { @JsonProperty("thought") public abstract Builder thought(boolean thought); + @JsonProperty("thoughtSignature") + public abstract Builder thoughtSignature(byte[] thoughtSignature); + @JsonProperty("codeExecutionResult") public abstract Builder codeExecutionResult(CodeExecutionResult codeExecutionResult); From 04971fce22baf0c926dca8ec90646ef81c28130a Mon Sep 17 00:00:00 2001 From: Sara Robinson Date: Mon, 5 May 2025 09:56:55 -0700 Subject: [PATCH 12/18] feat!: add enum support PiperOrigin-RevId: 754974940 --- README.md | 13 +- .../google/genai/examples/EditImageAsync.java | 6 +- .../examples/EditImageControlReference.java | 3 +- .../examples/EditImageMaskReference.java | 6 +- .../examples/EditImageSubjectReference.java | 3 +- .../examples/GenerateContentWithConfigs.java | 10 +- .../GenerateContentWithFunctionCall.java | 7 +- .../GenerateContentWithResponseSchema.java | 22 +- ...AudioConfigurableSpeechDetectionAsync.java | 3 +- .../examples/LiveAudioConversationAsync.java | 3 +- ...LiveTextContextWindowCompressionAsync.java | 3 +- .../examples/LiveTextConversationAsync.java | 3 +- .../LiveTextToAudioTranscriptionAsync.java | 3 +- .../LiveTextToTextGenerationAsync.java | 5 +- src/main/java/com/google/genai/ChatBase.java | 10 +- .../google/genai/types/ActivityHandling.java | 65 ++++++ .../types/AutomaticActivityDetection.java | 24 ++- .../com/google/genai/types/BlockedReason.java | 67 ++++++ .../com/google/genai/types/Candidate.java | 12 +- .../genai/types/CodeExecutionResult.java | 12 +- .../genai/types/ControlReferenceConfig.java | 12 +- .../genai/types/ControlReferenceType.java | 67 ++++++ .../genai/types/DynamicRetrievalConfig.java | 12 +- .../types/DynamicRetrievalConfigMode.java | 65 ++++++ .../google/genai/types/EditImageConfig.java | 48 ++++- .../java/com/google/genai/types/EditMode.java | 71 +++++++ .../google/genai/types/EndSensitivity.java | 65 ++++++ .../google/genai/types/ExecutableCode.java | 12 +- .../types/FeatureSelectionPreference.java | 66 ++++++ .../com/google/genai/types/FinishReason.java | 78 +++++++ .../genai/types/FunctionCallingConfig.java | 12 +- .../types/FunctionCallingConfigMode.java | 67 ++++++ .../genai/types/FunctionDeclaration.java | 9 +- .../genai/types/GenerateContentConfig.java | 12 +- .../genai/types/GenerateContentResponse.java | 19 +- ...GenerateContentResponsePromptFeedback.java | 12 +- .../GenerateContentResponseUsageMetadata.java | 12 +- .../genai/types/GenerateImagesConfig.java | 36 +++- .../google/genai/types/GenerationConfig.java | 12 +- ...ionConfigRoutingConfigAutoRoutingMode.java | 12 +- .../google/genai/types/HarmBlockMethod.java | 68 ++++++ .../genai/types/HarmBlockThreshold.java | 68 ++++++ .../com/google/genai/types/HarmCategory.java | 68 ++++++ .../google/genai/types/HarmProbability.java | 67 ++++++ .../com/google/genai/types/HarmSeverity.java | 67 ++++++ .../genai/types/ImagePromptLanguage.java | 68 ++++++ .../java/com/google/genai/types/Language.java | 64 ++++++ .../google/genai/types/LiveConnectConfig.java | 29 ++- .../genai/types/MaskReferenceConfig.java | 12 +- .../google/genai/types/MaskReferenceMode.java | 68 ++++++ .../com/google/genai/types/MediaModality.java | 69 ++++++ .../google/genai/types/MediaResolution.java | 66 ++++++ .../java/com/google/genai/types/Modality.java | 66 ++++++ .../genai/types/ModalityTokenCount.java | 12 +- .../java/com/google/genai/types/Mode.java | 64 ++++++ .../genai/types/ModelRoutingPreference.java | 67 ++++++ .../genai/types/ModelSelectionConfig.java | 13 +- .../java/com/google/genai/types/Outcome.java | 66 ++++++ .../google/genai/types/PersonGeneration.java | 66 ++++++ .../genai/types/RealtimeInputConfig.java | 24 ++- .../google/genai/types/SafetyFilterLevel.java | 67 ++++++ .../com/google/genai/types/SafetyRating.java | 36 +++- .../com/google/genai/types/SafetySetting.java | 36 +++- .../java/com/google/genai/types/Schema.java | 12 +- .../google/genai/types/StartSensitivity.java | 65 ++++++ .../genai/types/SubjectReferenceConfig.java | 12 +- .../genai/types/SubjectReferenceType.java | 67 ++++++ .../com/google/genai/types/TrafficType.java | 68 ++++++ .../com/google/genai/types/TurnCoverage.java | 65 ++++++ .../java/com/google/genai/types/Type.java | 69 ++++++ .../com/google/genai/types/UsageMetadata.java | 12 +- src/test/java/com/google/genai/ChatTest.java | 3 +- .../genai/ForwardCompatibilityTest.java | 198 +++++++++++++++++- .../com/google/genai/TransformerTest.java | 38 ++-- .../genai/types/FunctionDeclarationTest.java | 18 +- .../types/GenerateContentResponseTest.java | 52 +++-- 76 files changed, 2724 insertions(+), 165 deletions(-) create mode 100644 src/main/java/com/google/genai/types/ActivityHandling.java create mode 100644 src/main/java/com/google/genai/types/BlockedReason.java create mode 100644 src/main/java/com/google/genai/types/ControlReferenceType.java create mode 100644 src/main/java/com/google/genai/types/DynamicRetrievalConfigMode.java create mode 100644 src/main/java/com/google/genai/types/EditMode.java create mode 100644 src/main/java/com/google/genai/types/EndSensitivity.java create mode 100644 src/main/java/com/google/genai/types/FeatureSelectionPreference.java create mode 100644 src/main/java/com/google/genai/types/FinishReason.java create mode 100644 src/main/java/com/google/genai/types/FunctionCallingConfigMode.java create mode 100644 src/main/java/com/google/genai/types/HarmBlockMethod.java create mode 100644 src/main/java/com/google/genai/types/HarmBlockThreshold.java create mode 100644 src/main/java/com/google/genai/types/HarmCategory.java create mode 100644 src/main/java/com/google/genai/types/HarmProbability.java create mode 100644 src/main/java/com/google/genai/types/HarmSeverity.java create mode 100644 src/main/java/com/google/genai/types/ImagePromptLanguage.java create mode 100644 src/main/java/com/google/genai/types/Language.java create mode 100644 src/main/java/com/google/genai/types/MaskReferenceMode.java create mode 100644 src/main/java/com/google/genai/types/MediaModality.java create mode 100644 src/main/java/com/google/genai/types/MediaResolution.java create mode 100644 src/main/java/com/google/genai/types/Modality.java create mode 100644 src/main/java/com/google/genai/types/Mode.java create mode 100644 src/main/java/com/google/genai/types/ModelRoutingPreference.java create mode 100644 src/main/java/com/google/genai/types/Outcome.java create mode 100644 src/main/java/com/google/genai/types/PersonGeneration.java create mode 100644 src/main/java/com/google/genai/types/SafetyFilterLevel.java create mode 100644 src/main/java/com/google/genai/types/StartSensitivity.java create mode 100644 src/main/java/com/google/genai/types/SubjectReferenceType.java create mode 100644 src/main/java/com/google/genai/types/TrafficType.java create mode 100644 src/main/java/com/google/genai/types/TurnCoverage.java create mode 100644 src/main/java/com/google/genai/types/Type.java diff --git a/README.md b/README.md index 228b6559e24..08490970d9b 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,8 @@ import com.google.genai.types.Content; import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.GoogleSearch; +import com.google.genai.types.HarmBlockThreshold; +import com.google.genai.types.HarmCategory; import com.google.genai.types.Part; import com.google.genai.types.SafetySetting; import com.google.genai.types.Tool; @@ -227,12 +229,12 @@ public class GenerateContentWithConfigs { ImmutableList safetySettings = ImmutableList.of( SafetySetting.builder() - .category("HARM_CATEGORY_HATE_SPEECH") - .threshold("BLOCK_ONLY_HIGH") + .category(HarmCategory.Known.HARM_CATEGORY_HATE_SPEECH) + .threshold(HarmBlockThreshold.Known.BLOCK_ONLY_HIGH) .build(), SafetySetting.builder() - .category("HARM_CATEGORY_DANGEROUS_CONTENT") - .threshold("BLOCK_LOW_AND_ABOVE") + .category(HarmCategory.Known.HARM_CATEGORY_DANGEROUS_CONTENT) + .threshold(HarmBlockThreshold.Known.BLOCK_LOW_AND_ABOVE) .build()); // Sets the system instruction in the config. @@ -270,6 +272,7 @@ import com.google.genai.Client; import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.Schema; +import com.google.genai.types.Type; public class GenerateContentWithSchema { public static void main(String[] args) { @@ -280,7 +283,7 @@ public class GenerateContentWithSchema { .type("object") .properties( ImmutableMap.of( - "name", Schema.builder().type("string").description("Your Name").build())) + "name", Schema.builder().type(Type.Known.STRING).description("Your Name").build())) .build(); GenerateContentConfig config = GenerateContentConfig.builder() diff --git a/examples/src/main/java/com/google/genai/examples/EditImageAsync.java b/examples/src/main/java/com/google/genai/examples/EditImageAsync.java index 8659936caa1..ae2780ad5f0 100644 --- a/examples/src/main/java/com/google/genai/examples/EditImageAsync.java +++ b/examples/src/main/java/com/google/genai/examples/EditImageAsync.java @@ -40,11 +40,13 @@ import com.google.genai.Client; import com.google.genai.types.EditImageConfig; import com.google.genai.types.EditImageResponse; +import com.google.genai.types.EditMode; import com.google.genai.types.GenerateImagesConfig; import com.google.genai.types.GenerateImagesResponse; import com.google.genai.types.Image; import com.google.genai.types.MaskReferenceConfig; import com.google.genai.types.MaskReferenceImage; +import com.google.genai.types.MaskReferenceMode; import com.google.genai.types.RawReferenceImage; import com.google.genai.types.ReferenceImage; import java.io.IOException; @@ -81,7 +83,7 @@ public static void main(String[] args) throws IOException, HttpException { // Edit image with a mask. EditImageConfig editImageConfig = EditImageConfig.builder() - .editMode("EDIT_MODE_INPAINT_INSERTION") + .editMode(EditMode.Known.EDIT_MODE_INPAINT_INSERTION) .numberOfImages(1) .outputMimeType("image/jpeg") .build(); @@ -96,7 +98,7 @@ public static void main(String[] args) throws IOException, HttpException { .referenceId(2) .config( MaskReferenceConfig.builder() - .maskMode("MASK_MODE_BACKGROUND") + .maskMode(MaskReferenceMode.Known.MASK_MODE_BACKGROUND) .maskDilation(0.0f) .build()) .build(); diff --git a/examples/src/main/java/com/google/genai/examples/EditImageControlReference.java b/examples/src/main/java/com/google/genai/examples/EditImageControlReference.java index 3a5339e8a3a..459943a3a17 100644 --- a/examples/src/main/java/com/google/genai/examples/EditImageControlReference.java +++ b/examples/src/main/java/com/google/genai/examples/EditImageControlReference.java @@ -41,6 +41,7 @@ import com.google.genai.Client; import com.google.genai.types.ControlReferenceConfig; import com.google.genai.types.ControlReferenceImage; +import com.google.genai.types.ControlReferenceType; import com.google.genai.types.EditImageConfig; import com.google.genai.types.EditImageResponse; import com.google.genai.types.GenerateImagesConfig; @@ -83,7 +84,7 @@ public static void main(String[] args) { .referenceImage(generatedImage) .config( ControlReferenceConfig.builder() - .controlType("CONTROL_TYPE_SCRIBBLE") + .controlType(ControlReferenceType.Known.CONTROL_TYPE_SCRIBBLE) .enableControlImageComputation(true) .build()) .build(); diff --git a/examples/src/main/java/com/google/genai/examples/EditImageMaskReference.java b/examples/src/main/java/com/google/genai/examples/EditImageMaskReference.java index bc8cf524c69..7c59c308947 100644 --- a/examples/src/main/java/com/google/genai/examples/EditImageMaskReference.java +++ b/examples/src/main/java/com/google/genai/examples/EditImageMaskReference.java @@ -40,11 +40,13 @@ import com.google.genai.Client; import com.google.genai.types.EditImageConfig; import com.google.genai.types.EditImageResponse; +import com.google.genai.types.EditMode; import com.google.genai.types.GenerateImagesConfig; import com.google.genai.types.GenerateImagesResponse; import com.google.genai.types.Image; import com.google.genai.types.MaskReferenceConfig; import com.google.genai.types.MaskReferenceImage; +import com.google.genai.types.MaskReferenceMode; import com.google.genai.types.RawReferenceImage; import com.google.genai.types.ReferenceImage; import java.util.ArrayList; @@ -74,7 +76,7 @@ public static void main(String[] args) { // Edit image with a mask. EditImageConfig editImageConfig = EditImageConfig.builder() - .editMode("EDIT_MODE_INPAINT_INSERTION") + .editMode(EditMode.Known.EDIT_MODE_INPAINT_INSERTION) .numberOfImages(1) .outputMimeType("image/jpeg") .build(); @@ -89,7 +91,7 @@ public static void main(String[] args) { .referenceId(2) .config( MaskReferenceConfig.builder() - .maskMode("MASK_MODE_BACKGROUND") + .maskMode(MaskReferenceMode.Known.MASK_MODE_BACKGROUND) .maskDilation(0.0f) .build()) .build(); diff --git a/examples/src/main/java/com/google/genai/examples/EditImageSubjectReference.java b/examples/src/main/java/com/google/genai/examples/EditImageSubjectReference.java index 8a6e17c636a..2959356dd98 100644 --- a/examples/src/main/java/com/google/genai/examples/EditImageSubjectReference.java +++ b/examples/src/main/java/com/google/genai/examples/EditImageSubjectReference.java @@ -47,6 +47,7 @@ import com.google.genai.types.ReferenceImage; import com.google.genai.types.SubjectReferenceConfig; import com.google.genai.types.SubjectReferenceImage; +import com.google.genai.types.SubjectReferenceType; import java.util.ArrayList; /** An example of using the Unified Gen AI Java SDK to edit an image (Subject reference). */ @@ -82,7 +83,7 @@ public static void main(String[] args) { .referenceId(1) .config( SubjectReferenceConfig.builder() - .subjectType("SUBJECT_TYPE_PRODUCT") + .subjectType(SubjectReferenceType.Known.SUBJECT_TYPE_PRODUCT) .subjectDescription("Product logo") .build()) .build(); diff --git a/examples/src/main/java/com/google/genai/examples/GenerateContentWithConfigs.java b/examples/src/main/java/com/google/genai/examples/GenerateContentWithConfigs.java index 7df4200daf8..9ef496967e9 100644 --- a/examples/src/main/java/com/google/genai/examples/GenerateContentWithConfigs.java +++ b/examples/src/main/java/com/google/genai/examples/GenerateContentWithConfigs.java @@ -45,6 +45,8 @@ import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.GoogleSearch; +import com.google.genai.types.HarmBlockThreshold; +import com.google.genai.types.HarmCategory; import com.google.genai.types.Part; import com.google.genai.types.SafetySetting; import com.google.genai.types.Tool; @@ -59,12 +61,12 @@ public static void main(String[] args) { ImmutableList safetySettings = ImmutableList.of( SafetySetting.builder() - .category("HARM_CATEGORY_HATE_SPEECH") - .threshold("BLOCK_ONLY_HIGH") + .category(HarmCategory.Known.HARM_CATEGORY_HATE_SPEECH) + .threshold(HarmBlockThreshold.Known.BLOCK_ONLY_HIGH) .build(), SafetySetting.builder() - .category("HARM_CATEGORY_DANGEROUS_CONTENT") - .threshold("BLOCK_LOW_AND_ABOVE") + .category(HarmCategory.Known.HARM_CATEGORY_DANGEROUS_CONTENT) + .threshold(HarmBlockThreshold.Known.BLOCK_LOW_AND_ABOVE) .build()); // Sets the system instruction in the config. diff --git a/examples/src/main/java/com/google/genai/examples/GenerateContentWithFunctionCall.java b/examples/src/main/java/com/google/genai/examples/GenerateContentWithFunctionCall.java index 4a40153ab62..5f4fbc76c82 100644 --- a/examples/src/main/java/com/google/genai/examples/GenerateContentWithFunctionCall.java +++ b/examples/src/main/java/com/google/genai/examples/GenerateContentWithFunctionCall.java @@ -46,6 +46,7 @@ import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.Schema; +import com.google.genai.types.Type; /** An example of using the Unified Gen AI Java SDK to generate content with function calling. */ public class GenerateContentWithFunctionCall { @@ -58,17 +59,17 @@ public static void main(String[] args) { .name("get_current_weather") .parameters( Schema.builder() - .type("object") + .type(Type.Known.OBJECT) .properties( ImmutableMap.of( "location", Schema.builder() - .type("string") + .type(Type.Known.STRING) .description("The location to get the weather for.") .build(), "unit", Schema.builder() - .type("string") + .type(Type.Known.STRING) .description("The unit to return the weather in, e.g. 'celsius'.") .build())) .required(ImmutableList.of("location", "unit")) diff --git a/examples/src/main/java/com/google/genai/examples/GenerateContentWithResponseSchema.java b/examples/src/main/java/com/google/genai/examples/GenerateContentWithResponseSchema.java index 0f655a9af73..799b11240af 100644 --- a/examples/src/main/java/com/google/genai/examples/GenerateContentWithResponseSchema.java +++ b/examples/src/main/java/com/google/genai/examples/GenerateContentWithResponseSchema.java @@ -39,12 +39,13 @@ */ package com.google.genai.examples; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.genai.Client; import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.Schema; +import com.google.genai.types.Type; /** * GenerateContentWithResponseSchema generates a content and returns a json object by passing a @@ -54,21 +55,21 @@ public class GenerateContentWithResponseSchema { public static void main(String[] args) { Client client = new Client(); - Schema schema = Schema.builder() - .type("ARRAY") + Schema schema = + Schema.builder() + .type(Type.Known.ARRAY) .items( Schema.builder() - .type("OBJECT") + .type(Type.Known.OBJECT) .properties( ImmutableMap.of( "recipe_name", - Schema.builder().type("STRING").build(), + Schema.builder().type(Type.Known.STRING).build(), "ingredients", Schema.builder() - .type("ARRAY") - .items(Schema.builder().type("STRING").build()) - .build() - )) + .type(Type.Known.ARRAY) + .items(Schema.builder().type(Type.Known.STRING).build()) + .build())) .required(ImmutableList.of("recipe_name", "ingredients")) .build()) .build(); @@ -80,7 +81,8 @@ public static void main(String[] args) { .build(); GenerateContentResponse response = - client.models.generateContent("gemini-2.0-flash-001", "List a few popular cookie recipes.", config); + client.models.generateContent( + "gemini-2.0-flash-001", "List a few popular cookie recipes.", config); System.out.println("Response: " + response.text()); } diff --git a/examples/src/main/java/com/google/genai/examples/LiveAudioConfigurableSpeechDetectionAsync.java b/examples/src/main/java/com/google/genai/examples/LiveAudioConfigurableSpeechDetectionAsync.java index c5b43b122b1..02dac8b935f 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveAudioConfigurableSpeechDetectionAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveAudioConfigurableSpeechDetectionAsync.java @@ -65,6 +65,7 @@ import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.TargetDataLine; +import com.google.genai.types.Modality; /** * Example of using the live module for a streaming audio conversation with configurable speech @@ -149,7 +150,7 @@ public static void main(String[] args) throws LineUnavailableException { // --- Live API Config for Audio --- LiveConnectConfig config = LiveConnectConfig.builder() - .responseModalities(ImmutableList.of("AUDIO")) + .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.AUDIO)) .realtimeInputConfig( RealtimeInputConfig.builder() .activityHandling("NO_INTERRUPTION") diff --git a/examples/src/main/java/com/google/genai/examples/LiveAudioConversationAsync.java b/examples/src/main/java/com/google/genai/examples/LiveAudioConversationAsync.java index 9f456afd66c..bfc7038e41f 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveAudioConversationAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveAudioConversationAsync.java @@ -51,6 +51,7 @@ import com.google.genai.types.LiveConnectConfig; import com.google.genai.types.LiveSendRealtimeInputParameters; import com.google.genai.types.LiveServerMessage; +import com.google.genai.types.Modality; import com.google.genai.types.PrebuiltVoiceConfig; import com.google.genai.types.SpeechConfig; import com.google.genai.types.VoiceConfig; @@ -146,7 +147,7 @@ public static void main(String[] args) throws LineUnavailableException { String voiceName = "Aoede"; LiveConnectConfig config = LiveConnectConfig.builder() - .responseModalities(ImmutableList.of("AUDIO")) + .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.AUDIO)) .speechConfig( SpeechConfig.builder() .voiceConfig( diff --git a/examples/src/main/java/com/google/genai/examples/LiveTextContextWindowCompressionAsync.java b/examples/src/main/java/com/google/genai/examples/LiveTextContextWindowCompressionAsync.java index 0b91703eb5e..fd0ed31a6c2 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveTextContextWindowCompressionAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveTextContextWindowCompressionAsync.java @@ -51,6 +51,7 @@ import java.util.concurrent.CompletableFuture; import com.google.genai.types.GroundingChunk; import com.google.genai.types.GroundingChunkWeb; +import com.google.genai.types.Modality; import java.util.List; import java.util.Optional; @@ -68,7 +69,7 @@ public static void main(String[] args) { LiveConnectConfig config = LiveConnectConfig.builder() - .responseModalities(ImmutableList.of("TEXT")) + .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.TEXT)) .contextWindowCompression( ContextWindowCompressionConfig.builder() .triggerTokens(1000L) diff --git a/examples/src/main/java/com/google/genai/examples/LiveTextConversationAsync.java b/examples/src/main/java/com/google/genai/examples/LiveTextConversationAsync.java index 14ef21728dc..ba351745f8c 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveTextConversationAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveTextConversationAsync.java @@ -47,6 +47,7 @@ import com.google.genai.types.LiveSendClientContentParameters; import com.google.genai.types.LiveServerContent; import com.google.genai.types.LiveServerMessage; +import com.google.genai.types.Modality; import com.google.genai.types.Part; import java.io.Console; import java.util.concurrent.CompletableFuture; @@ -62,7 +63,7 @@ public static void main(String[] args) { LiveConnectConfig config = LiveConnectConfig.builder() - .responseModalities(ImmutableList.of("TEXT")) + .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.TEXT)) .topP(0.8f) .maxOutputTokens(30) .seed(1234) diff --git a/examples/src/main/java/com/google/genai/examples/LiveTextToAudioTranscriptionAsync.java b/examples/src/main/java/com/google/genai/examples/LiveTextToAudioTranscriptionAsync.java index f3b9431adec..e1b04f45fb1 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveTextToAudioTranscriptionAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveTextToAudioTranscriptionAsync.java @@ -57,6 +57,7 @@ import com.google.genai.types.GroundingChunkWeb; import java.util.List; import java.util.Optional; +import com.google.genai.types.Modality; /** Example of using the live module to send and receive messages asynchronously. */ public class LiveTextToAudioTranscriptionAsync { @@ -77,7 +78,7 @@ public static void main(String[] args) { LiveConnectConfig config = LiveConnectConfig.builder() - .responseModalities(ImmutableList.of("AUDIO")) + .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.AUDIO)) .outputAudioTranscription(AudioTranscriptionConfig.builder().build()) .systemInstruction(systemInstruction) .speechConfig(SpeechConfig.builder().languageCode("ja-JP").build()) diff --git a/examples/src/main/java/com/google/genai/examples/LiveTextToTextGenerationAsync.java b/examples/src/main/java/com/google/genai/examples/LiveTextToTextGenerationAsync.java index 7346159ea0d..33ddce11765 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveTextToTextGenerationAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveTextToTextGenerationAsync.java @@ -46,6 +46,7 @@ import com.google.genai.types.LiveSendClientContentParameters; import com.google.genai.types.LiveServerContent; import com.google.genai.types.LiveServerMessage; +import com.google.genai.types.Modality; import com.google.genai.types.Part; import java.util.concurrent.CompletableFuture; @@ -58,7 +59,9 @@ public static void main(String[] args) { Client.builder().httpOptions(HttpOptions.builder().apiVersion("v1beta").build()).build(); LiveConnectConfig config = - LiveConnectConfig.builder().responseModalities(ImmutableList.of("TEXT")).build(); + LiveConnectConfig.builder() + .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.TEXT)) + .build(); CompletableFuture allDone = new CompletableFuture<>(); diff --git a/src/main/java/com/google/genai/ChatBase.java b/src/main/java/com/google/genai/ChatBase.java index 4afa17b09be..ba22b59130c 100644 --- a/src/main/java/com/google/genai/ChatBase.java +++ b/src/main/java/com/google/genai/ChatBase.java @@ -59,12 +59,10 @@ protected void recordHistory(List currentHistory, GenerateContentRespon response.checkFinishReason(); this.curatedHistory.addAll(validatedHistory); } catch (IllegalArgumentException e) { - if (!response.finishReason().isEmpty()) { - logger.warning( - "Response finished unexpectedly with reason: " - + response.finishReason() - + ". Adding the response to comprehenisive history, but not to curated history."); - } + logger.warning( + "Response finished unexpectedly with reason: " + + response.finishReason().toString() + + ". Adding the response to comprehenisive history, but not to curated history."); } } diff --git a/src/main/java/com/google/genai/types/ActivityHandling.java b/src/main/java/com/google/genai/types/ActivityHandling.java new file mode 100644 index 00000000000..584e673a3d8 --- /dev/null +++ b/src/main/java/com/google/genai/types/ActivityHandling.java @@ -0,0 +1,65 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** The different ways of handling user activity. */ +public class ActivityHandling { + + /** Enum representing the known values for ActivityHandling. */ + public enum Known { + ACTIVITY_HANDLING_UNSPECIFIED, + START_OF_ACTIVITY_INTERRUPTS, + NO_INTERRUPTION + } + + private Known activityHandlingEnum; + private final String value; + + @JsonCreator + public ActivityHandling(String value) { + this.value = value; + for (Known activityHandlingEnum : Known.values()) { + if (activityHandlingEnum.toString().equalsIgnoreCase(value)) { + this.activityHandlingEnum = activityHandlingEnum; + break; + } + } + if (this.activityHandlingEnum == null) { + this.activityHandlingEnum = Known.ACTIVITY_HANDLING_UNSPECIFIED; + } + } + + public ActivityHandling(Known knownValue) { + this.activityHandlingEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.activityHandlingEnum; + } +} diff --git a/src/main/java/com/google/genai/types/AutomaticActivityDetection.java b/src/main/java/com/google/genai/types/AutomaticActivityDetection.java index 0569e388370..8e094903573 100644 --- a/src/main/java/com/google/genai/types/AutomaticActivityDetection.java +++ b/src/main/java/com/google/genai/types/AutomaticActivityDetection.java @@ -38,11 +38,11 @@ public abstract class AutomaticActivityDetection extends JsonSerializable { /** Determines how likely speech is to be detected. */ @JsonProperty("startOfSpeechSensitivity") - public abstract Optional startOfSpeechSensitivity(); + public abstract Optional startOfSpeechSensitivity(); /** Determines how likely detected speech is ended. */ @JsonProperty("endOfSpeechSensitivity") - public abstract Optional endOfSpeechSensitivity(); + public abstract Optional endOfSpeechSensitivity(); /** * The required duration of detected speech before start-of-speech is committed. The lower this @@ -81,10 +81,26 @@ private static Builder create() { public abstract Builder disabled(boolean disabled); @JsonProperty("startOfSpeechSensitivity") - public abstract Builder startOfSpeechSensitivity(String startOfSpeechSensitivity); + public abstract Builder startOfSpeechSensitivity(StartSensitivity startOfSpeechSensitivity); + + public Builder startOfSpeechSensitivity(StartSensitivity.Known knownType) { + return startOfSpeechSensitivity(new StartSensitivity(knownType)); + } + + public Builder startOfSpeechSensitivity(String startOfSpeechSensitivity) { + return startOfSpeechSensitivity(new StartSensitivity(startOfSpeechSensitivity)); + } @JsonProperty("endOfSpeechSensitivity") - public abstract Builder endOfSpeechSensitivity(String endOfSpeechSensitivity); + public abstract Builder endOfSpeechSensitivity(EndSensitivity endOfSpeechSensitivity); + + public Builder endOfSpeechSensitivity(EndSensitivity.Known knownType) { + return endOfSpeechSensitivity(new EndSensitivity(knownType)); + } + + public Builder endOfSpeechSensitivity(String endOfSpeechSensitivity) { + return endOfSpeechSensitivity(new EndSensitivity(endOfSpeechSensitivity)); + } @JsonProperty("prefixPaddingMs") public abstract Builder prefixPaddingMs(Integer prefixPaddingMs); diff --git a/src/main/java/com/google/genai/types/BlockedReason.java b/src/main/java/com/google/genai/types/BlockedReason.java new file mode 100644 index 00000000000..4fe10b675d1 --- /dev/null +++ b/src/main/java/com/google/genai/types/BlockedReason.java @@ -0,0 +1,67 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Output only. Blocked reason. */ +public class BlockedReason { + + /** Enum representing the known values for BlockedReason. */ + public enum Known { + BLOCKED_REASON_UNSPECIFIED, + SAFETY, + OTHER, + BLOCKLIST, + PROHIBITED_CONTENT + } + + private Known blockedReasonEnum; + private final String value; + + @JsonCreator + public BlockedReason(String value) { + this.value = value; + for (Known blockedReasonEnum : Known.values()) { + if (blockedReasonEnum.toString().equalsIgnoreCase(value)) { + this.blockedReasonEnum = blockedReasonEnum; + break; + } + } + if (this.blockedReasonEnum == null) { + this.blockedReasonEnum = Known.BLOCKED_REASON_UNSPECIFIED; + } + } + + public BlockedReason(Known knownValue) { + this.blockedReasonEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.blockedReasonEnum; + } +} diff --git a/src/main/java/com/google/genai/types/Candidate.java b/src/main/java/com/google/genai/types/Candidate.java index 302df3a55e1..0bb855bf03b 100644 --- a/src/main/java/com/google/genai/types/Candidate.java +++ b/src/main/java/com/google/genai/types/Candidate.java @@ -51,7 +51,7 @@ public abstract class Candidate extends JsonSerializable { * generating the tokens. */ @JsonProperty("finishReason") - public abstract Optional finishReason(); + public abstract Optional finishReason(); /** Output only. Average log probability score of the candidate. */ @JsonProperty("avgLogprobs") @@ -106,7 +106,15 @@ private static Builder create() { public abstract Builder tokenCount(Integer tokenCount); @JsonProperty("finishReason") - public abstract Builder finishReason(String finishReason); + public abstract Builder finishReason(FinishReason finishReason); + + public Builder finishReason(FinishReason.Known knownType) { + return finishReason(new FinishReason(knownType)); + } + + public Builder finishReason(String finishReason) { + return finishReason(new FinishReason(finishReason)); + } @JsonProperty("avgLogprobs") public abstract Builder avgLogprobs(Double avgLogprobs); diff --git a/src/main/java/com/google/genai/types/CodeExecutionResult.java b/src/main/java/com/google/genai/types/CodeExecutionResult.java index d6453f2b6af..db6beceba06 100644 --- a/src/main/java/com/google/genai/types/CodeExecutionResult.java +++ b/src/main/java/com/google/genai/types/CodeExecutionResult.java @@ -34,7 +34,7 @@ public abstract class CodeExecutionResult extends JsonSerializable { /** Required. Outcome of the code execution. */ @JsonProperty("outcome") - public abstract Optional outcome(); + public abstract Optional outcome(); /** * Optional. Contains stdout when code execution is successful, stderr or other description @@ -61,7 +61,15 @@ private static Builder create() { } @JsonProperty("outcome") - public abstract Builder outcome(String outcome); + public abstract Builder outcome(Outcome outcome); + + public Builder outcome(Outcome.Known knownType) { + return outcome(new Outcome(knownType)); + } + + public Builder outcome(String outcome) { + return outcome(new Outcome(outcome)); + } @JsonProperty("output") public abstract Builder output(String output); diff --git a/src/main/java/com/google/genai/types/ControlReferenceConfig.java b/src/main/java/com/google/genai/types/ControlReferenceConfig.java index 0e3cf63ba20..ae01af9607f 100644 --- a/src/main/java/com/google/genai/types/ControlReferenceConfig.java +++ b/src/main/java/com/google/genai/types/ControlReferenceConfig.java @@ -31,7 +31,7 @@ public abstract class ControlReferenceConfig extends JsonSerializable { /** The type of control reference image to use. */ @JsonProperty("controlType") - public abstract Optional controlType(); + public abstract Optional controlType(); /** * Defaults to False. When set to True, the control image will be computed by the model based on @@ -58,7 +58,15 @@ private static Builder create() { } @JsonProperty("controlType") - public abstract Builder controlType(String controlType); + public abstract Builder controlType(ControlReferenceType controlType); + + public Builder controlType(ControlReferenceType.Known knownType) { + return controlType(new ControlReferenceType(knownType)); + } + + public Builder controlType(String controlType) { + return controlType(new ControlReferenceType(controlType)); + } @JsonProperty("enableControlImageComputation") public abstract Builder enableControlImageComputation(boolean enableControlImageComputation); diff --git a/src/main/java/com/google/genai/types/ControlReferenceType.java b/src/main/java/com/google/genai/types/ControlReferenceType.java new file mode 100644 index 00000000000..ca3c67afa7d --- /dev/null +++ b/src/main/java/com/google/genai/types/ControlReferenceType.java @@ -0,0 +1,67 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Enum representing the control type of a control reference image. */ +public class ControlReferenceType { + + /** Enum representing the known values for ControlReferenceType. */ + public enum Known { + CONTROL_TYPE_DEFAULT, + CONTROL_TYPE_CANNY, + CONTROL_TYPE_SCRIBBLE, + CONTROL_TYPE_FACE_MESH, + CONTROL_REFERENCE_TYPE_UNSPECIFIED + } + + private Known controlReferenceTypeEnum; + private final String value; + + @JsonCreator + public ControlReferenceType(String value) { + this.value = value; + for (Known controlReferenceTypeEnum : Known.values()) { + if (controlReferenceTypeEnum.toString().equalsIgnoreCase(value)) { + this.controlReferenceTypeEnum = controlReferenceTypeEnum; + break; + } + } + if (this.controlReferenceTypeEnum == null) { + this.controlReferenceTypeEnum = Known.CONTROL_REFERENCE_TYPE_UNSPECIFIED; + } + } + + public ControlReferenceType(Known knownValue) { + this.controlReferenceTypeEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.controlReferenceTypeEnum; + } +} diff --git a/src/main/java/com/google/genai/types/DynamicRetrievalConfig.java b/src/main/java/com/google/genai/types/DynamicRetrievalConfig.java index 81d6fdd7aef..0b459a6d6fc 100644 --- a/src/main/java/com/google/genai/types/DynamicRetrievalConfig.java +++ b/src/main/java/com/google/genai/types/DynamicRetrievalConfig.java @@ -31,7 +31,7 @@ public abstract class DynamicRetrievalConfig extends JsonSerializable { /** The mode of the predictor to be used in dynamic retrieval. */ @JsonProperty("mode") - public abstract Optional mode(); + public abstract Optional mode(); /** * Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is @@ -58,7 +58,15 @@ private static Builder create() { } @JsonProperty("mode") - public abstract Builder mode(String mode); + public abstract Builder mode(DynamicRetrievalConfigMode mode); + + public Builder mode(DynamicRetrievalConfigMode.Known knownType) { + return mode(new DynamicRetrievalConfigMode(knownType)); + } + + public Builder mode(String mode) { + return mode(new DynamicRetrievalConfigMode(mode)); + } @JsonProperty("dynamicThreshold") public abstract Builder dynamicThreshold(Float dynamicThreshold); diff --git a/src/main/java/com/google/genai/types/DynamicRetrievalConfigMode.java b/src/main/java/com/google/genai/types/DynamicRetrievalConfigMode.java new file mode 100644 index 00000000000..4cc65d39510 --- /dev/null +++ b/src/main/java/com/google/genai/types/DynamicRetrievalConfigMode.java @@ -0,0 +1,65 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Config for the dynamic retrieval config mode. */ +public class DynamicRetrievalConfigMode { + + /** Enum representing the known values for DynamicRetrievalConfigMode. */ + public enum Known { + MODE_UNSPECIFIED, + MODE_DYNAMIC, + DYNAMIC_RETRIEVAL_CONFIG_MODE_UNSPECIFIED + } + + private Known dynamicRetrievalConfigModeEnum; + private final String value; + + @JsonCreator + public DynamicRetrievalConfigMode(String value) { + this.value = value; + for (Known dynamicRetrievalConfigModeEnum : Known.values()) { + if (dynamicRetrievalConfigModeEnum.toString().equalsIgnoreCase(value)) { + this.dynamicRetrievalConfigModeEnum = dynamicRetrievalConfigModeEnum; + break; + } + } + if (this.dynamicRetrievalConfigModeEnum == null) { + this.dynamicRetrievalConfigModeEnum = Known.DYNAMIC_RETRIEVAL_CONFIG_MODE_UNSPECIFIED; + } + } + + public DynamicRetrievalConfigMode(Known knownValue) { + this.dynamicRetrievalConfigModeEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.dynamicRetrievalConfigModeEnum; + } +} diff --git a/src/main/java/com/google/genai/types/EditImageConfig.java b/src/main/java/com/google/genai/types/EditImageConfig.java index c817183d1cf..5ce44c7e732 100644 --- a/src/main/java/com/google/genai/types/EditImageConfig.java +++ b/src/main/java/com/google/genai/types/EditImageConfig.java @@ -60,11 +60,11 @@ public abstract class EditImageConfig extends JsonSerializable { /** Filter level for safety filtering. */ @JsonProperty("safetyFilterLevel") - public abstract Optional safetyFilterLevel(); + public abstract Optional safetyFilterLevel(); /** Allows generation of people by the model. */ @JsonProperty("personGeneration") - public abstract Optional personGeneration(); + public abstract Optional personGeneration(); /** * Whether to report the safety scores of each generated image and the positive prompt in the @@ -82,7 +82,7 @@ public abstract class EditImageConfig extends JsonSerializable { /** Language of the text in the prompt. */ @JsonProperty("language") - public abstract Optional language(); + public abstract Optional language(); /** MIME type of the generated image. */ @JsonProperty("outputMimeType") @@ -94,7 +94,7 @@ public abstract class EditImageConfig extends JsonSerializable { /** Describes the editing mode for the request. */ @JsonProperty("editMode") - public abstract Optional editMode(); + public abstract Optional editMode(); /** * The number of sampling steps. A higher value has better image quality, while a lower value has @@ -139,10 +139,26 @@ private static Builder create() { public abstract Builder seed(Integer seed); @JsonProperty("safetyFilterLevel") - public abstract Builder safetyFilterLevel(String safetyFilterLevel); + public abstract Builder safetyFilterLevel(SafetyFilterLevel safetyFilterLevel); + + public Builder safetyFilterLevel(SafetyFilterLevel.Known knownType) { + return safetyFilterLevel(new SafetyFilterLevel(knownType)); + } + + public Builder safetyFilterLevel(String safetyFilterLevel) { + return safetyFilterLevel(new SafetyFilterLevel(safetyFilterLevel)); + } @JsonProperty("personGeneration") - public abstract Builder personGeneration(String personGeneration); + public abstract Builder personGeneration(PersonGeneration personGeneration); + + public Builder personGeneration(PersonGeneration.Known knownType) { + return personGeneration(new PersonGeneration(knownType)); + } + + public Builder personGeneration(String personGeneration) { + return personGeneration(new PersonGeneration(personGeneration)); + } @JsonProperty("includeSafetyAttributes") public abstract Builder includeSafetyAttributes(boolean includeSafetyAttributes); @@ -151,7 +167,15 @@ private static Builder create() { public abstract Builder includeRaiReason(boolean includeRaiReason); @JsonProperty("language") - public abstract Builder language(String language); + public abstract Builder language(ImagePromptLanguage language); + + public Builder language(ImagePromptLanguage.Known knownType) { + return language(new ImagePromptLanguage(knownType)); + } + + public Builder language(String language) { + return language(new ImagePromptLanguage(language)); + } @JsonProperty("outputMimeType") public abstract Builder outputMimeType(String outputMimeType); @@ -160,7 +184,15 @@ private static Builder create() { public abstract Builder outputCompressionQuality(Integer outputCompressionQuality); @JsonProperty("editMode") - public abstract Builder editMode(String editMode); + public abstract Builder editMode(EditMode editMode); + + public Builder editMode(EditMode.Known knownType) { + return editMode(new EditMode(knownType)); + } + + public Builder editMode(String editMode) { + return editMode(new EditMode(editMode)); + } @JsonProperty("baseSteps") public abstract Builder baseSteps(Integer baseSteps); diff --git a/src/main/java/com/google/genai/types/EditMode.java b/src/main/java/com/google/genai/types/EditMode.java new file mode 100644 index 00000000000..47cd76a2fd8 --- /dev/null +++ b/src/main/java/com/google/genai/types/EditMode.java @@ -0,0 +1,71 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Enum representing the Imagen 3 Edit mode. */ +public class EditMode { + + /** Enum representing the known values for EditMode. */ + public enum Known { + EDIT_MODE_DEFAULT, + EDIT_MODE_INPAINT_REMOVAL, + EDIT_MODE_INPAINT_INSERTION, + EDIT_MODE_OUTPAINT, + EDIT_MODE_CONTROLLED_EDITING, + EDIT_MODE_STYLE, + EDIT_MODE_BGSWAP, + EDIT_MODE_PRODUCT_IMAGE, + EDIT_MODE_UNSPECIFIED + } + + private Known editModeEnum; + private final String value; + + @JsonCreator + public EditMode(String value) { + this.value = value; + for (Known editModeEnum : Known.values()) { + if (editModeEnum.toString().equalsIgnoreCase(value)) { + this.editModeEnum = editModeEnum; + break; + } + } + if (this.editModeEnum == null) { + this.editModeEnum = Known.EDIT_MODE_UNSPECIFIED; + } + } + + public EditMode(Known knownValue) { + this.editModeEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.editModeEnum; + } +} diff --git a/src/main/java/com/google/genai/types/EndSensitivity.java b/src/main/java/com/google/genai/types/EndSensitivity.java new file mode 100644 index 00000000000..6a206e8d516 --- /dev/null +++ b/src/main/java/com/google/genai/types/EndSensitivity.java @@ -0,0 +1,65 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** End of speech sensitivity. */ +public class EndSensitivity { + + /** Enum representing the known values for EndSensitivity. */ + public enum Known { + END_SENSITIVITY_UNSPECIFIED, + END_SENSITIVITY_HIGH, + END_SENSITIVITY_LOW + } + + private Known endSensitivityEnum; + private final String value; + + @JsonCreator + public EndSensitivity(String value) { + this.value = value; + for (Known endSensitivityEnum : Known.values()) { + if (endSensitivityEnum.toString().equalsIgnoreCase(value)) { + this.endSensitivityEnum = endSensitivityEnum; + break; + } + } + if (this.endSensitivityEnum == null) { + this.endSensitivityEnum = Known.END_SENSITIVITY_UNSPECIFIED; + } + } + + public EndSensitivity(Known knownValue) { + this.endSensitivityEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.endSensitivityEnum; + } +} diff --git a/src/main/java/com/google/genai/types/ExecutableCode.java b/src/main/java/com/google/genai/types/ExecutableCode.java index 8113d5817f4..02aa06c4f34 100644 --- a/src/main/java/com/google/genai/types/ExecutableCode.java +++ b/src/main/java/com/google/genai/types/ExecutableCode.java @@ -39,7 +39,7 @@ public abstract class ExecutableCode extends JsonSerializable { /** Required. Programming language of the `code`. */ @JsonProperty("language") - public abstract Optional language(); + public abstract Optional language(); /** Instantiates a builder for ExecutableCode. */ public static Builder builder() { @@ -62,7 +62,15 @@ private static Builder create() { public abstract Builder code(String code); @JsonProperty("language") - public abstract Builder language(String language); + public abstract Builder language(Language language); + + public Builder language(Language.Known knownType) { + return language(new Language(knownType)); + } + + public Builder language(String language) { + return language(new Language(language)); + } public abstract ExecutableCode build(); } diff --git a/src/main/java/com/google/genai/types/FeatureSelectionPreference.java b/src/main/java/com/google/genai/types/FeatureSelectionPreference.java new file mode 100644 index 00000000000..b3b746ca612 --- /dev/null +++ b/src/main/java/com/google/genai/types/FeatureSelectionPreference.java @@ -0,0 +1,66 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Options for feature selection preference. */ +public class FeatureSelectionPreference { + + /** Enum representing the known values for FeatureSelectionPreference. */ + public enum Known { + FEATURE_SELECTION_PREFERENCE_UNSPECIFIED, + PRIORITIZE_QUALITY, + BALANCED, + PRIORITIZE_COST + } + + private Known featureSelectionPreferenceEnum; + private final String value; + + @JsonCreator + public FeatureSelectionPreference(String value) { + this.value = value; + for (Known featureSelectionPreferenceEnum : Known.values()) { + if (featureSelectionPreferenceEnum.toString().equalsIgnoreCase(value)) { + this.featureSelectionPreferenceEnum = featureSelectionPreferenceEnum; + break; + } + } + if (this.featureSelectionPreferenceEnum == null) { + this.featureSelectionPreferenceEnum = Known.FEATURE_SELECTION_PREFERENCE_UNSPECIFIED; + } + } + + public FeatureSelectionPreference(Known knownValue) { + this.featureSelectionPreferenceEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.featureSelectionPreferenceEnum; + } +} diff --git a/src/main/java/com/google/genai/types/FinishReason.java b/src/main/java/com/google/genai/types/FinishReason.java new file mode 100644 index 00000000000..24ddaae8045 --- /dev/null +++ b/src/main/java/com/google/genai/types/FinishReason.java @@ -0,0 +1,78 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Output only. The reason why the model stopped generating tokens. + * + *

If empty, the model has not stopped generating the tokens. + */ +public class FinishReason { + + /** Enum representing the known values for FinishReason. */ + public enum Known { + FINISH_REASON_UNSPECIFIED, + STOP, + MAX_TOKENS, + SAFETY, + RECITATION, + LANGUAGE, + OTHER, + BLOCKLIST, + PROHIBITED_CONTENT, + SPII, + MALFORMED_FUNCTION_CALL, + IMAGE_SAFETY + } + + private Known finishReasonEnum; + private final String value; + + @JsonCreator + public FinishReason(String value) { + this.value = value; + for (Known finishReasonEnum : Known.values()) { + if (finishReasonEnum.toString().equalsIgnoreCase(value)) { + this.finishReasonEnum = finishReasonEnum; + break; + } + } + if (this.finishReasonEnum == null) { + this.finishReasonEnum = Known.FINISH_REASON_UNSPECIFIED; + } + } + + public FinishReason(Known knownValue) { + this.finishReasonEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.finishReasonEnum; + } +} diff --git a/src/main/java/com/google/genai/types/FunctionCallingConfig.java b/src/main/java/com/google/genai/types/FunctionCallingConfig.java index cb30626ce94..08105de9b3b 100644 --- a/src/main/java/com/google/genai/types/FunctionCallingConfig.java +++ b/src/main/java/com/google/genai/types/FunctionCallingConfig.java @@ -32,7 +32,7 @@ public abstract class FunctionCallingConfig extends JsonSerializable { /** Optional. Function calling mode. */ @JsonProperty("mode") - public abstract Optional mode(); + public abstract Optional mode(); /** * Optional. Function names to call. Only set when the Mode is ANY. Function names should match @@ -60,7 +60,15 @@ private static Builder create() { } @JsonProperty("mode") - public abstract Builder mode(String mode); + public abstract Builder mode(FunctionCallingConfigMode mode); + + public Builder mode(FunctionCallingConfigMode.Known knownType) { + return mode(new FunctionCallingConfigMode(knownType)); + } + + public Builder mode(String mode) { + return mode(new FunctionCallingConfigMode(mode)); + } @JsonProperty("allowedFunctionNames") public abstract Builder allowedFunctionNames(List allowedFunctionNames); diff --git a/src/main/java/com/google/genai/types/FunctionCallingConfigMode.java b/src/main/java/com/google/genai/types/FunctionCallingConfigMode.java new file mode 100644 index 00000000000..c84f7c294c0 --- /dev/null +++ b/src/main/java/com/google/genai/types/FunctionCallingConfigMode.java @@ -0,0 +1,67 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Config for the function calling config mode. */ +public class FunctionCallingConfigMode { + + /** Enum representing the known values for FunctionCallingConfigMode. */ + public enum Known { + MODE_UNSPECIFIED, + AUTO, + ANY, + NONE, + FUNCTION_CALLING_CONFIG_MODE_UNSPECIFIED + } + + private Known functionCallingConfigModeEnum; + private final String value; + + @JsonCreator + public FunctionCallingConfigMode(String value) { + this.value = value; + for (Known functionCallingConfigModeEnum : Known.values()) { + if (functionCallingConfigModeEnum.toString().equalsIgnoreCase(value)) { + this.functionCallingConfigModeEnum = functionCallingConfigModeEnum; + break; + } + } + if (this.functionCallingConfigModeEnum == null) { + this.functionCallingConfigModeEnum = Known.FUNCTION_CALLING_CONFIG_MODE_UNSPECIFIED; + } + } + + public FunctionCallingConfigMode(Known knownValue) { + this.functionCallingConfigModeEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.functionCallingConfigModeEnum; + } +} diff --git a/src/main/java/com/google/genai/types/FunctionDeclaration.java b/src/main/java/com/google/genai/types/FunctionDeclaration.java index 1e4306eabdb..ac481de487f 100644 --- a/src/main/java/com/google/genai/types/FunctionDeclaration.java +++ b/src/main/java/com/google/genai/types/FunctionDeclaration.java @@ -189,19 +189,20 @@ public static FunctionDeclaration fromMethod( */ private static Schema buildTypeSchema(String parameterName, Class parameterType) { Schema.Builder parameterSchemaBuilder = Schema.builder().title(parameterName); + switch (parameterType.getName()) { case "java.lang.String": - parameterSchemaBuilder.type("STRING"); + parameterSchemaBuilder = parameterSchemaBuilder.type("STRING"); break; case "boolean": - parameterSchemaBuilder.type("BOOLEAN"); + parameterSchemaBuilder = parameterSchemaBuilder.type("BOOLEAN"); break; case "int": - parameterSchemaBuilder.type("INTEGER"); + parameterSchemaBuilder = parameterSchemaBuilder.type("INTEGER"); break; case "double": case "float": - parameterSchemaBuilder.type("NUMBER"); + parameterSchemaBuilder = parameterSchemaBuilder.type("NUMBER"); break; default: throw new IllegalArgumentException( diff --git a/src/main/java/com/google/genai/types/GenerateContentConfig.java b/src/main/java/com/google/genai/types/GenerateContentConfig.java index 0ca1f8962d2..fa8978e095b 100644 --- a/src/main/java/com/google/genai/types/GenerateContentConfig.java +++ b/src/main/java/com/google/genai/types/GenerateContentConfig.java @@ -163,7 +163,7 @@ public abstract class GenerateContentConfig extends JsonSerializable { /** If specified, the media resolution specified will be used. */ @JsonProperty("mediaResolution") - public abstract Optional mediaResolution(); + public abstract Optional mediaResolution(); /** The speech generation configuration. */ @JsonProperty("speechConfig") @@ -261,7 +261,15 @@ private static Builder create() { public abstract Builder responseModalities(List responseModalities); @JsonProperty("mediaResolution") - public abstract Builder mediaResolution(String mediaResolution); + public abstract Builder mediaResolution(MediaResolution mediaResolution); + + public Builder mediaResolution(MediaResolution.Known knownType) { + return mediaResolution(new MediaResolution(knownType)); + } + + public Builder mediaResolution(String mediaResolution) { + return mediaResolution(new MediaResolution(mediaResolution)); + } @JsonProperty("speechConfig") public abstract Builder speechConfig(SpeechConfig speechConfig); diff --git a/src/main/java/com/google/genai/types/GenerateContentResponse.java b/src/main/java/com/google/genai/types/GenerateContentResponse.java index 1bca0cdc61f..9aed1e7f4da 100644 --- a/src/main/java/com/google/genai/types/GenerateContentResponse.java +++ b/src/main/java/com/google/genai/types/GenerateContentResponse.java @@ -109,8 +109,11 @@ public static GenerateContentResponse fromJson(String jsonString) { private static final Logger logger = Logger.getLogger(GenerateContentResponse.class.getName()); - private static final ImmutableList EXPECTED_FINISH_REASONS = - ImmutableList.of("FINISH_REASON_UNSPECIFIED", "STOP", "MAX_TOKENS", ""); + private static final ImmutableList EXPECTED_FINISH_REASONS = + ImmutableList.of( + FinishReason.Known.FINISH_REASON_UNSPECIFIED, + FinishReason.Known.STOP, + FinishReason.Known.MAX_TOKENS); /** * Returns the list of parts in the first candidate of the response. @@ -248,7 +251,7 @@ public static GenerateContentResponse fromJson(String jsonString) { } /** Gets the finish reason in a GenerateContentResponse. */ - public String finishReason() { + public FinishReason finishReason() { List candidates = candidates().orElse(Arrays.asList(Candidate.builder().build())); if (candidates.size() > 1) { logger.warning( @@ -256,14 +259,18 @@ public String finishReason() { "This response has %d candidates, will only use the first candidate", candidates.size())); } - return candidates.get(0).finishReason().orElse(""); + Optional finishReason = candidates.get(0).finishReason(); + if (!finishReason.isPresent()) { + return new FinishReason(FinishReason.Known.FINISH_REASON_UNSPECIFIED); + } + return finishReason.get(); } /** Throws an exception if the response finishes unexpectedly. */ @InternalApi public void checkFinishReason() { - String finishReason = this.finishReason(); - if (!EXPECTED_FINISH_REASONS.contains(finishReason)) { + FinishReason finishReason = this.finishReason(); + if (!EXPECTED_FINISH_REASONS.contains(finishReason.knownEnum())) { throw new IllegalArgumentException( String.format("The response finished unexpectedly with reason %s.", finishReason)); } diff --git a/src/main/java/com/google/genai/types/GenerateContentResponsePromptFeedback.java b/src/main/java/com/google/genai/types/GenerateContentResponsePromptFeedback.java index 2b71d41d450..1da134a3d44 100644 --- a/src/main/java/com/google/genai/types/GenerateContentResponsePromptFeedback.java +++ b/src/main/java/com/google/genai/types/GenerateContentResponsePromptFeedback.java @@ -32,7 +32,7 @@ public abstract class GenerateContentResponsePromptFeedback extends JsonSerializable { /** Output only. Blocked reason. */ @JsonProperty("blockReason") - public abstract Optional blockReason(); + public abstract Optional blockReason(); /** Output only. A readable block reason message. */ @JsonProperty("blockReasonMessage") @@ -63,7 +63,15 @@ private static Builder create() { } @JsonProperty("blockReason") - public abstract Builder blockReason(String blockReason); + public abstract Builder blockReason(BlockedReason blockReason); + + public Builder blockReason(BlockedReason.Known knownType) { + return blockReason(new BlockedReason(knownType)); + } + + public Builder blockReason(String blockReason) { + return blockReason(new BlockedReason(blockReason)); + } @JsonProperty("blockReasonMessage") public abstract Builder blockReasonMessage(String blockReasonMessage); diff --git a/src/main/java/com/google/genai/types/GenerateContentResponseUsageMetadata.java b/src/main/java/com/google/genai/types/GenerateContentResponseUsageMetadata.java index e2529fe4297..3bca80f067e 100644 --- a/src/main/java/com/google/genai/types/GenerateContentResponseUsageMetadata.java +++ b/src/main/java/com/google/genai/types/GenerateContentResponseUsageMetadata.java @@ -78,7 +78,7 @@ public abstract class GenerateContentResponseUsageMetadata extends JsonSerializa * Throughput quota. */ @JsonProperty("trafficType") - public abstract Optional trafficType(); + public abstract Optional trafficType(); /** Instantiates a builder for GenerateContentResponseUsageMetadata. */ public static Builder builder() { @@ -133,7 +133,15 @@ public abstract Builder toolUsePromptTokensDetails( public abstract Builder totalTokenCount(Integer totalTokenCount); @JsonProperty("trafficType") - public abstract Builder trafficType(String trafficType); + public abstract Builder trafficType(TrafficType trafficType); + + public Builder trafficType(TrafficType.Known knownType) { + return trafficType(new TrafficType(knownType)); + } + + public Builder trafficType(String trafficType) { + return trafficType(new TrafficType(trafficType)); + } public abstract GenerateContentResponseUsageMetadata build(); } diff --git a/src/main/java/com/google/genai/types/GenerateImagesConfig.java b/src/main/java/com/google/genai/types/GenerateImagesConfig.java index 99dba897cb3..eda299da2e9 100644 --- a/src/main/java/com/google/genai/types/GenerateImagesConfig.java +++ b/src/main/java/com/google/genai/types/GenerateImagesConfig.java @@ -60,11 +60,11 @@ public abstract class GenerateImagesConfig extends JsonSerializable { /** Filter level for safety filtering. */ @JsonProperty("safetyFilterLevel") - public abstract Optional safetyFilterLevel(); + public abstract Optional safetyFilterLevel(); /** Allows generation of people by the model. */ @JsonProperty("personGeneration") - public abstract Optional personGeneration(); + public abstract Optional personGeneration(); /** * Whether to report the safety scores of each generated image and the positive prompt in the @@ -82,7 +82,7 @@ public abstract class GenerateImagesConfig extends JsonSerializable { /** Language of the text in the prompt. */ @JsonProperty("language") - public abstract Optional language(); + public abstract Optional language(); /** MIME type of the generated image. */ @JsonProperty("outputMimeType") @@ -136,10 +136,26 @@ private static Builder create() { public abstract Builder seed(Integer seed); @JsonProperty("safetyFilterLevel") - public abstract Builder safetyFilterLevel(String safetyFilterLevel); + public abstract Builder safetyFilterLevel(SafetyFilterLevel safetyFilterLevel); + + public Builder safetyFilterLevel(SafetyFilterLevel.Known knownType) { + return safetyFilterLevel(new SafetyFilterLevel(knownType)); + } + + public Builder safetyFilterLevel(String safetyFilterLevel) { + return safetyFilterLevel(new SafetyFilterLevel(safetyFilterLevel)); + } @JsonProperty("personGeneration") - public abstract Builder personGeneration(String personGeneration); + public abstract Builder personGeneration(PersonGeneration personGeneration); + + public Builder personGeneration(PersonGeneration.Known knownType) { + return personGeneration(new PersonGeneration(knownType)); + } + + public Builder personGeneration(String personGeneration) { + return personGeneration(new PersonGeneration(personGeneration)); + } @JsonProperty("includeSafetyAttributes") public abstract Builder includeSafetyAttributes(boolean includeSafetyAttributes); @@ -148,7 +164,15 @@ private static Builder create() { public abstract Builder includeRaiReason(boolean includeRaiReason); @JsonProperty("language") - public abstract Builder language(String language); + public abstract Builder language(ImagePromptLanguage language); + + public Builder language(ImagePromptLanguage.Known knownType) { + return language(new ImagePromptLanguage(knownType)); + } + + public Builder language(String language) { + return language(new ImagePromptLanguage(language)); + } @JsonProperty("outputMimeType") public abstract Builder outputMimeType(String outputMimeType); diff --git a/src/main/java/com/google/genai/types/GenerationConfig.java b/src/main/java/com/google/genai/types/GenerationConfig.java index feec1afd0c9..eaf6c8d1c98 100644 --- a/src/main/java/com/google/genai/types/GenerationConfig.java +++ b/src/main/java/com/google/genai/types/GenerationConfig.java @@ -52,7 +52,7 @@ public abstract class GenerationConfig extends JsonSerializable { /** Optional. If specified, the media resolution specified will be used. */ @JsonProperty("mediaResolution") - public abstract Optional mediaResolution(); + public abstract Optional mediaResolution(); /** Optional. Positive penalties. */ @JsonProperty("presencePenalty") @@ -138,7 +138,15 @@ private static Builder create() { public abstract Builder maxOutputTokens(Integer maxOutputTokens); @JsonProperty("mediaResolution") - public abstract Builder mediaResolution(String mediaResolution); + public abstract Builder mediaResolution(MediaResolution mediaResolution); + + public Builder mediaResolution(MediaResolution.Known knownType) { + return mediaResolution(new MediaResolution(knownType)); + } + + public Builder mediaResolution(String mediaResolution) { + return mediaResolution(new MediaResolution(mediaResolution)); + } @JsonProperty("presencePenalty") public abstract Builder presencePenalty(Float presencePenalty); diff --git a/src/main/java/com/google/genai/types/GenerationConfigRoutingConfigAutoRoutingMode.java b/src/main/java/com/google/genai/types/GenerationConfigRoutingConfigAutoRoutingMode.java index c35de4f6033..0a196921b5f 100644 --- a/src/main/java/com/google/genai/types/GenerationConfigRoutingConfigAutoRoutingMode.java +++ b/src/main/java/com/google/genai/types/GenerationConfigRoutingConfigAutoRoutingMode.java @@ -34,7 +34,7 @@ public abstract class GenerationConfigRoutingConfigAutoRoutingMode extends JsonSerializable { /** The model routing preference. */ @JsonProperty("modelRoutingPreference") - public abstract Optional modelRoutingPreference(); + public abstract Optional modelRoutingPreference(); /** Instantiates a builder for GenerationConfigRoutingConfigAutoRoutingMode. */ public static Builder builder() { @@ -57,7 +57,15 @@ private static Builder create() { } @JsonProperty("modelRoutingPreference") - public abstract Builder modelRoutingPreference(String modelRoutingPreference); + public abstract Builder modelRoutingPreference(ModelRoutingPreference modelRoutingPreference); + + public Builder modelRoutingPreference(ModelRoutingPreference.Known knownType) { + return modelRoutingPreference(new ModelRoutingPreference(knownType)); + } + + public Builder modelRoutingPreference(String modelRoutingPreference) { + return modelRoutingPreference(new ModelRoutingPreference(modelRoutingPreference)); + } public abstract GenerationConfigRoutingConfigAutoRoutingMode build(); } diff --git a/src/main/java/com/google/genai/types/HarmBlockMethod.java b/src/main/java/com/google/genai/types/HarmBlockMethod.java new file mode 100644 index 00000000000..5f12aff1b63 --- /dev/null +++ b/src/main/java/com/google/genai/types/HarmBlockMethod.java @@ -0,0 +1,68 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Optional. Specify if the threshold is used for probability or severity score. If not specified, + * the threshold is used for probability score. + */ +public class HarmBlockMethod { + + /** Enum representing the known values for HarmBlockMethod. */ + public enum Known { + HARM_BLOCK_METHOD_UNSPECIFIED, + SEVERITY, + PROBABILITY + } + + private Known harmBlockMethodEnum; + private final String value; + + @JsonCreator + public HarmBlockMethod(String value) { + this.value = value; + for (Known harmBlockMethodEnum : Known.values()) { + if (harmBlockMethodEnum.toString().equalsIgnoreCase(value)) { + this.harmBlockMethodEnum = harmBlockMethodEnum; + break; + } + } + if (this.harmBlockMethodEnum == null) { + this.harmBlockMethodEnum = Known.HARM_BLOCK_METHOD_UNSPECIFIED; + } + } + + public HarmBlockMethod(Known knownValue) { + this.harmBlockMethodEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.harmBlockMethodEnum; + } +} diff --git a/src/main/java/com/google/genai/types/HarmBlockThreshold.java b/src/main/java/com/google/genai/types/HarmBlockThreshold.java new file mode 100644 index 00000000000..d20913a50b1 --- /dev/null +++ b/src/main/java/com/google/genai/types/HarmBlockThreshold.java @@ -0,0 +1,68 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Required. The harm block threshold. */ +public class HarmBlockThreshold { + + /** Enum representing the known values for HarmBlockThreshold. */ + public enum Known { + HARM_BLOCK_THRESHOLD_UNSPECIFIED, + BLOCK_LOW_AND_ABOVE, + BLOCK_MEDIUM_AND_ABOVE, + BLOCK_ONLY_HIGH, + BLOCK_NONE, + OFF + } + + private Known harmBlockThresholdEnum; + private final String value; + + @JsonCreator + public HarmBlockThreshold(String value) { + this.value = value; + for (Known harmBlockThresholdEnum : Known.values()) { + if (harmBlockThresholdEnum.toString().equalsIgnoreCase(value)) { + this.harmBlockThresholdEnum = harmBlockThresholdEnum; + break; + } + } + if (this.harmBlockThresholdEnum == null) { + this.harmBlockThresholdEnum = Known.HARM_BLOCK_THRESHOLD_UNSPECIFIED; + } + } + + public HarmBlockThreshold(Known knownValue) { + this.harmBlockThresholdEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.harmBlockThresholdEnum; + } +} diff --git a/src/main/java/com/google/genai/types/HarmCategory.java b/src/main/java/com/google/genai/types/HarmCategory.java new file mode 100644 index 00000000000..907752d01df --- /dev/null +++ b/src/main/java/com/google/genai/types/HarmCategory.java @@ -0,0 +1,68 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Required. Harm category. */ +public class HarmCategory { + + /** Enum representing the known values for HarmCategory. */ + public enum Known { + HARM_CATEGORY_UNSPECIFIED, + HARM_CATEGORY_HATE_SPEECH, + HARM_CATEGORY_DANGEROUS_CONTENT, + HARM_CATEGORY_HARASSMENT, + HARM_CATEGORY_SEXUALLY_EXPLICIT, + HARM_CATEGORY_CIVIC_INTEGRITY + } + + private Known harmCategoryEnum; + private final String value; + + @JsonCreator + public HarmCategory(String value) { + this.value = value; + for (Known harmCategoryEnum : Known.values()) { + if (harmCategoryEnum.toString().equalsIgnoreCase(value)) { + this.harmCategoryEnum = harmCategoryEnum; + break; + } + } + if (this.harmCategoryEnum == null) { + this.harmCategoryEnum = Known.HARM_CATEGORY_UNSPECIFIED; + } + } + + public HarmCategory(Known knownValue) { + this.harmCategoryEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.harmCategoryEnum; + } +} diff --git a/src/main/java/com/google/genai/types/HarmProbability.java b/src/main/java/com/google/genai/types/HarmProbability.java new file mode 100644 index 00000000000..323bd303cff --- /dev/null +++ b/src/main/java/com/google/genai/types/HarmProbability.java @@ -0,0 +1,67 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Output only. Harm probability levels in the content. */ +public class HarmProbability { + + /** Enum representing the known values for HarmProbability. */ + public enum Known { + HARM_PROBABILITY_UNSPECIFIED, + NEGLIGIBLE, + LOW, + MEDIUM, + HIGH + } + + private Known harmProbabilityEnum; + private final String value; + + @JsonCreator + public HarmProbability(String value) { + this.value = value; + for (Known harmProbabilityEnum : Known.values()) { + if (harmProbabilityEnum.toString().equalsIgnoreCase(value)) { + this.harmProbabilityEnum = harmProbabilityEnum; + break; + } + } + if (this.harmProbabilityEnum == null) { + this.harmProbabilityEnum = Known.HARM_PROBABILITY_UNSPECIFIED; + } + } + + public HarmProbability(Known knownValue) { + this.harmProbabilityEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.harmProbabilityEnum; + } +} diff --git a/src/main/java/com/google/genai/types/HarmSeverity.java b/src/main/java/com/google/genai/types/HarmSeverity.java new file mode 100644 index 00000000000..e053dc5e310 --- /dev/null +++ b/src/main/java/com/google/genai/types/HarmSeverity.java @@ -0,0 +1,67 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Output only. Harm severity levels in the content. */ +public class HarmSeverity { + + /** Enum representing the known values for HarmSeverity. */ + public enum Known { + HARM_SEVERITY_UNSPECIFIED, + HARM_SEVERITY_NEGLIGIBLE, + HARM_SEVERITY_LOW, + HARM_SEVERITY_MEDIUM, + HARM_SEVERITY_HIGH + } + + private Known harmSeverityEnum; + private final String value; + + @JsonCreator + public HarmSeverity(String value) { + this.value = value; + for (Known harmSeverityEnum : Known.values()) { + if (harmSeverityEnum.toString().equalsIgnoreCase(value)) { + this.harmSeverityEnum = harmSeverityEnum; + break; + } + } + if (this.harmSeverityEnum == null) { + this.harmSeverityEnum = Known.HARM_SEVERITY_UNSPECIFIED; + } + } + + public HarmSeverity(Known knownValue) { + this.harmSeverityEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.harmSeverityEnum; + } +} diff --git a/src/main/java/com/google/genai/types/ImagePromptLanguage.java b/src/main/java/com/google/genai/types/ImagePromptLanguage.java new file mode 100644 index 00000000000..08110a34b65 --- /dev/null +++ b/src/main/java/com/google/genai/types/ImagePromptLanguage.java @@ -0,0 +1,68 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Enum that specifies the language of the text in the prompt. */ +public class ImagePromptLanguage { + + /** Enum representing the known values for ImagePromptLanguage. */ + public enum Known { + AUTO, + EN, + JA, + KO, + HI, + IMAGE_PROMPT_LANGUAGE_UNSPECIFIED + } + + private Known imagePromptLanguageEnum; + private final String value; + + @JsonCreator + public ImagePromptLanguage(String value) { + this.value = value; + for (Known imagePromptLanguageEnum : Known.values()) { + if (imagePromptLanguageEnum.toString().equalsIgnoreCase(value)) { + this.imagePromptLanguageEnum = imagePromptLanguageEnum; + break; + } + } + if (this.imagePromptLanguageEnum == null) { + this.imagePromptLanguageEnum = Known.IMAGE_PROMPT_LANGUAGE_UNSPECIFIED; + } + } + + public ImagePromptLanguage(Known knownValue) { + this.imagePromptLanguageEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.imagePromptLanguageEnum; + } +} diff --git a/src/main/java/com/google/genai/types/Language.java b/src/main/java/com/google/genai/types/Language.java new file mode 100644 index 00000000000..94da1260369 --- /dev/null +++ b/src/main/java/com/google/genai/types/Language.java @@ -0,0 +1,64 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Required. Programming language of the `code`. */ +public class Language { + + /** Enum representing the known values for Language. */ + public enum Known { + LANGUAGE_UNSPECIFIED, + PYTHON + } + + private Known languageEnum; + private final String value; + + @JsonCreator + public Language(String value) { + this.value = value; + for (Known languageEnum : Known.values()) { + if (languageEnum.toString().equalsIgnoreCase(value)) { + this.languageEnum = languageEnum; + break; + } + } + if (this.languageEnum == null) { + this.languageEnum = Known.LANGUAGE_UNSPECIFIED; + } + } + + public Language(Known knownValue) { + this.languageEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.languageEnum; + } +} diff --git a/src/main/java/com/google/genai/types/LiveConnectConfig.java b/src/main/java/com/google/genai/types/LiveConnectConfig.java index f7eeed7a7d7..69fe0750554 100644 --- a/src/main/java/com/google/genai/types/LiveConnectConfig.java +++ b/src/main/java/com/google/genai/types/LiveConnectConfig.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableList; import com.google.genai.JsonSerializable; import java.util.List; import java.util.Optional; @@ -35,7 +36,7 @@ public abstract class LiveConnectConfig extends JsonSerializable { * return. Defaults to AUDIO if not specified. */ @JsonProperty("responseModalities") - public abstract Optional> responseModalities(); + public abstract Optional> responseModalities(); /** * Value that controls the degree of randomness in token selection. Lower temperatures are good @@ -68,7 +69,7 @@ public abstract class LiveConnectConfig extends JsonSerializable { /** If specified, the media resolution specified will be used. */ @JsonProperty("mediaResolution") - public abstract Optional mediaResolution(); + public abstract Optional mediaResolution(); /** * When ``seed`` is fixed to a specific number, the model makes a best effort to provide the same @@ -137,7 +138,19 @@ private static Builder create() { } @JsonProperty("responseModalities") - public abstract Builder responseModalities(List responseModalities); + public abstract Builder responseModalities(List responseModalities); + + public Builder responseModalitiesFromKnown(List knownTypes) { + List listItems = + knownTypes.stream().map(Modality::new).collect(ImmutableList.toImmutableList()); + return responseModalities(listItems); + } + + public Builder responseModalitiesFromString(List responseModalities) { + List listItems = + responseModalities.stream().map(Modality::new).collect(ImmutableList.toImmutableList()); + return responseModalities(listItems); + } @JsonProperty("temperature") public abstract Builder temperature(Float temperature); @@ -152,7 +165,15 @@ private static Builder create() { public abstract Builder maxOutputTokens(Integer maxOutputTokens); @JsonProperty("mediaResolution") - public abstract Builder mediaResolution(String mediaResolution); + public abstract Builder mediaResolution(MediaResolution mediaResolution); + + public Builder mediaResolution(MediaResolution.Known knownType) { + return mediaResolution(new MediaResolution(knownType)); + } + + public Builder mediaResolution(String mediaResolution) { + return mediaResolution(new MediaResolution(mediaResolution)); + } @JsonProperty("seed") public abstract Builder seed(Integer seed); diff --git a/src/main/java/com/google/genai/types/MaskReferenceConfig.java b/src/main/java/com/google/genai/types/MaskReferenceConfig.java index 20702c6ac89..45d9bdb6315 100644 --- a/src/main/java/com/google/genai/types/MaskReferenceConfig.java +++ b/src/main/java/com/google/genai/types/MaskReferenceConfig.java @@ -35,7 +35,7 @@ public abstract class MaskReferenceConfig extends JsonSerializable { * MASK_MODE_USER_PROVIDED is used). */ @JsonProperty("maskMode") - public abstract Optional maskMode(); + public abstract Optional maskMode(); /** * A list of up to 5 class ids to use for semantic segmentation. Automatically creates an image @@ -66,7 +66,15 @@ private static Builder create() { } @JsonProperty("maskMode") - public abstract Builder maskMode(String maskMode); + public abstract Builder maskMode(MaskReferenceMode maskMode); + + public Builder maskMode(MaskReferenceMode.Known knownType) { + return maskMode(new MaskReferenceMode(knownType)); + } + + public Builder maskMode(String maskMode) { + return maskMode(new MaskReferenceMode(maskMode)); + } @JsonProperty("segmentationClasses") public abstract Builder segmentationClasses(List segmentationClasses); diff --git a/src/main/java/com/google/genai/types/MaskReferenceMode.java b/src/main/java/com/google/genai/types/MaskReferenceMode.java new file mode 100644 index 00000000000..9f8cd391a7b --- /dev/null +++ b/src/main/java/com/google/genai/types/MaskReferenceMode.java @@ -0,0 +1,68 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Enum representing the mask mode of a mask reference image. */ +public class MaskReferenceMode { + + /** Enum representing the known values for MaskReferenceMode. */ + public enum Known { + MASK_MODE_DEFAULT, + MASK_MODE_USER_PROVIDED, + MASK_MODE_BACKGROUND, + MASK_MODE_FOREGROUND, + MASK_MODE_SEMANTIC, + MASK_REFERENCE_MODE_UNSPECIFIED + } + + private Known maskReferenceModeEnum; + private final String value; + + @JsonCreator + public MaskReferenceMode(String value) { + this.value = value; + for (Known maskReferenceModeEnum : Known.values()) { + if (maskReferenceModeEnum.toString().equalsIgnoreCase(value)) { + this.maskReferenceModeEnum = maskReferenceModeEnum; + break; + } + } + if (this.maskReferenceModeEnum == null) { + this.maskReferenceModeEnum = Known.MASK_REFERENCE_MODE_UNSPECIFIED; + } + } + + public MaskReferenceMode(Known knownValue) { + this.maskReferenceModeEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.maskReferenceModeEnum; + } +} diff --git a/src/main/java/com/google/genai/types/MediaModality.java b/src/main/java/com/google/genai/types/MediaModality.java new file mode 100644 index 00000000000..1f7becdcd97 --- /dev/null +++ b/src/main/java/com/google/genai/types/MediaModality.java @@ -0,0 +1,69 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Server content modalities. */ +public class MediaModality { + + /** Enum representing the known values for MediaModality. */ + public enum Known { + MODALITY_UNSPECIFIED, + TEXT, + IMAGE, + VIDEO, + AUDIO, + DOCUMENT, + MEDIA_MODALITY_UNSPECIFIED + } + + private Known mediaModalityEnum; + private final String value; + + @JsonCreator + public MediaModality(String value) { + this.value = value; + for (Known mediaModalityEnum : Known.values()) { + if (mediaModalityEnum.toString().equalsIgnoreCase(value)) { + this.mediaModalityEnum = mediaModalityEnum; + break; + } + } + if (this.mediaModalityEnum == null) { + this.mediaModalityEnum = Known.MEDIA_MODALITY_UNSPECIFIED; + } + } + + public MediaModality(Known knownValue) { + this.mediaModalityEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.mediaModalityEnum; + } +} diff --git a/src/main/java/com/google/genai/types/MediaResolution.java b/src/main/java/com/google/genai/types/MediaResolution.java new file mode 100644 index 00000000000..75276a27177 --- /dev/null +++ b/src/main/java/com/google/genai/types/MediaResolution.java @@ -0,0 +1,66 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** The media resolution to use. */ +public class MediaResolution { + + /** Enum representing the known values for MediaResolution. */ + public enum Known { + MEDIA_RESOLUTION_UNSPECIFIED, + MEDIA_RESOLUTION_LOW, + MEDIA_RESOLUTION_MEDIUM, + MEDIA_RESOLUTION_HIGH + } + + private Known mediaResolutionEnum; + private final String value; + + @JsonCreator + public MediaResolution(String value) { + this.value = value; + for (Known mediaResolutionEnum : Known.values()) { + if (mediaResolutionEnum.toString().equalsIgnoreCase(value)) { + this.mediaResolutionEnum = mediaResolutionEnum; + break; + } + } + if (this.mediaResolutionEnum == null) { + this.mediaResolutionEnum = Known.MEDIA_RESOLUTION_UNSPECIFIED; + } + } + + public MediaResolution(Known knownValue) { + this.mediaResolutionEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.mediaResolutionEnum; + } +} diff --git a/src/main/java/com/google/genai/types/Modality.java b/src/main/java/com/google/genai/types/Modality.java new file mode 100644 index 00000000000..41cf1ac04a1 --- /dev/null +++ b/src/main/java/com/google/genai/types/Modality.java @@ -0,0 +1,66 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Server content modalities. */ +public class Modality { + + /** Enum representing the known values for Modality. */ + public enum Known { + MODALITY_UNSPECIFIED, + TEXT, + IMAGE, + AUDIO + } + + private Known modalityEnum; + private final String value; + + @JsonCreator + public Modality(String value) { + this.value = value; + for (Known modalityEnum : Known.values()) { + if (modalityEnum.toString().equalsIgnoreCase(value)) { + this.modalityEnum = modalityEnum; + break; + } + } + if (this.modalityEnum == null) { + this.modalityEnum = Known.MODALITY_UNSPECIFIED; + } + } + + public Modality(Known knownValue) { + this.modalityEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.modalityEnum; + } +} diff --git a/src/main/java/com/google/genai/types/ModalityTokenCount.java b/src/main/java/com/google/genai/types/ModalityTokenCount.java index 2e5b501c0d7..d4ca57ccafd 100644 --- a/src/main/java/com/google/genai/types/ModalityTokenCount.java +++ b/src/main/java/com/google/genai/types/ModalityTokenCount.java @@ -31,7 +31,7 @@ public abstract class ModalityTokenCount extends JsonSerializable { /** The modality associated with this token count. */ @JsonProperty("modality") - public abstract Optional modality(); + public abstract Optional modality(); /** Number of tokens. */ @JsonProperty("tokenCount") @@ -55,7 +55,15 @@ private static Builder create() { } @JsonProperty("modality") - public abstract Builder modality(String modality); + public abstract Builder modality(MediaModality modality); + + public Builder modality(MediaModality.Known knownType) { + return modality(new MediaModality(knownType)); + } + + public Builder modality(String modality) { + return modality(new MediaModality(modality)); + } @JsonProperty("tokenCount") public abstract Builder tokenCount(Integer tokenCount); diff --git a/src/main/java/com/google/genai/types/Mode.java b/src/main/java/com/google/genai/types/Mode.java new file mode 100644 index 00000000000..e0ccf1dfddd --- /dev/null +++ b/src/main/java/com/google/genai/types/Mode.java @@ -0,0 +1,64 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** The mode of the predictor to be used in dynamic retrieval. */ +public class Mode { + + /** Enum representing the known values for Mode. */ + public enum Known { + MODE_UNSPECIFIED, + MODE_DYNAMIC + } + + private Known modeEnum; + private final String value; + + @JsonCreator + public Mode(String value) { + this.value = value; + for (Known modeEnum : Known.values()) { + if (modeEnum.toString().equalsIgnoreCase(value)) { + this.modeEnum = modeEnum; + break; + } + } + if (this.modeEnum == null) { + this.modeEnum = Known.MODE_UNSPECIFIED; + } + } + + public Mode(Known knownValue) { + this.modeEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.modeEnum; + } +} diff --git a/src/main/java/com/google/genai/types/ModelRoutingPreference.java b/src/main/java/com/google/genai/types/ModelRoutingPreference.java new file mode 100644 index 00000000000..4b6da9c9cc5 --- /dev/null +++ b/src/main/java/com/google/genai/types/ModelRoutingPreference.java @@ -0,0 +1,67 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** The model routing preference. */ +public class ModelRoutingPreference { + + /** Enum representing the known values for ModelRoutingPreference. */ + public enum Known { + UNKNOWN, + PRIORITIZE_QUALITY, + BALANCED, + PRIORITIZE_COST, + MODEL_ROUTING_PREFERENCE_UNSPECIFIED + } + + private Known modelRoutingPreferenceEnum; + private final String value; + + @JsonCreator + public ModelRoutingPreference(String value) { + this.value = value; + for (Known modelRoutingPreferenceEnum : Known.values()) { + if (modelRoutingPreferenceEnum.toString().equalsIgnoreCase(value)) { + this.modelRoutingPreferenceEnum = modelRoutingPreferenceEnum; + break; + } + } + if (this.modelRoutingPreferenceEnum == null) { + this.modelRoutingPreferenceEnum = Known.MODEL_ROUTING_PREFERENCE_UNSPECIFIED; + } + } + + public ModelRoutingPreference(Known knownValue) { + this.modelRoutingPreferenceEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.modelRoutingPreferenceEnum; + } +} diff --git a/src/main/java/com/google/genai/types/ModelSelectionConfig.java b/src/main/java/com/google/genai/types/ModelSelectionConfig.java index 6ea122a3b58..ec5fe1c15ac 100644 --- a/src/main/java/com/google/genai/types/ModelSelectionConfig.java +++ b/src/main/java/com/google/genai/types/ModelSelectionConfig.java @@ -31,7 +31,7 @@ public abstract class ModelSelectionConfig extends JsonSerializable { /** Options for feature selection preference. */ @JsonProperty("featureSelectionPreference") - public abstract Optional featureSelectionPreference(); + public abstract Optional featureSelectionPreference(); /** Instantiates a builder for ModelSelectionConfig. */ public static Builder builder() { @@ -51,7 +51,16 @@ private static Builder create() { } @JsonProperty("featureSelectionPreference") - public abstract Builder featureSelectionPreference(String featureSelectionPreference); + public abstract Builder featureSelectionPreference( + FeatureSelectionPreference featureSelectionPreference); + + public Builder featureSelectionPreference(FeatureSelectionPreference.Known knownType) { + return featureSelectionPreference(new FeatureSelectionPreference(knownType)); + } + + public Builder featureSelectionPreference(String featureSelectionPreference) { + return featureSelectionPreference(new FeatureSelectionPreference(featureSelectionPreference)); + } public abstract ModelSelectionConfig build(); } diff --git a/src/main/java/com/google/genai/types/Outcome.java b/src/main/java/com/google/genai/types/Outcome.java new file mode 100644 index 00000000000..adedf92fed0 --- /dev/null +++ b/src/main/java/com/google/genai/types/Outcome.java @@ -0,0 +1,66 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Required. Outcome of the code execution. */ +public class Outcome { + + /** Enum representing the known values for Outcome. */ + public enum Known { + OUTCOME_UNSPECIFIED, + OUTCOME_OK, + OUTCOME_FAILED, + OUTCOME_DEADLINE_EXCEEDED + } + + private Known outcomeEnum; + private final String value; + + @JsonCreator + public Outcome(String value) { + this.value = value; + for (Known outcomeEnum : Known.values()) { + if (outcomeEnum.toString().equalsIgnoreCase(value)) { + this.outcomeEnum = outcomeEnum; + break; + } + } + if (this.outcomeEnum == null) { + this.outcomeEnum = Known.OUTCOME_UNSPECIFIED; + } + } + + public Outcome(Known knownValue) { + this.outcomeEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.outcomeEnum; + } +} diff --git a/src/main/java/com/google/genai/types/PersonGeneration.java b/src/main/java/com/google/genai/types/PersonGeneration.java new file mode 100644 index 00000000000..3d9cedb249e --- /dev/null +++ b/src/main/java/com/google/genai/types/PersonGeneration.java @@ -0,0 +1,66 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Enum that controls the generation of people. */ +public class PersonGeneration { + + /** Enum representing the known values for PersonGeneration. */ + public enum Known { + DONT_ALLOW, + ALLOW_ADULT, + ALLOW_ALL, + PERSON_GENERATION_UNSPECIFIED + } + + private Known personGenerationEnum; + private final String value; + + @JsonCreator + public PersonGeneration(String value) { + this.value = value; + for (Known personGenerationEnum : Known.values()) { + if (personGenerationEnum.toString().equalsIgnoreCase(value)) { + this.personGenerationEnum = personGenerationEnum; + break; + } + } + if (this.personGenerationEnum == null) { + this.personGenerationEnum = Known.PERSON_GENERATION_UNSPECIFIED; + } + } + + public PersonGeneration(Known knownValue) { + this.personGenerationEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.personGenerationEnum; + } +} diff --git a/src/main/java/com/google/genai/types/RealtimeInputConfig.java b/src/main/java/com/google/genai/types/RealtimeInputConfig.java index 07dc5793271..02c868f3ff9 100644 --- a/src/main/java/com/google/genai/types/RealtimeInputConfig.java +++ b/src/main/java/com/google/genai/types/RealtimeInputConfig.java @@ -42,11 +42,11 @@ public abstract class RealtimeInputConfig extends JsonSerializable { /** Defines what effect activity has. */ @JsonProperty("activityHandling") - public abstract Optional activityHandling(); + public abstract Optional activityHandling(); /** Defines which input is included in the user's turn. */ @JsonProperty("turnCoverage") - public abstract Optional turnCoverage(); + public abstract Optional turnCoverage(); /** Instantiates a builder for RealtimeInputConfig. */ public static Builder builder() { @@ -70,10 +70,26 @@ public abstract Builder automaticActivityDetection( AutomaticActivityDetection automaticActivityDetection); @JsonProperty("activityHandling") - public abstract Builder activityHandling(String activityHandling); + public abstract Builder activityHandling(ActivityHandling activityHandling); + + public Builder activityHandling(ActivityHandling.Known knownType) { + return activityHandling(new ActivityHandling(knownType)); + } + + public Builder activityHandling(String activityHandling) { + return activityHandling(new ActivityHandling(activityHandling)); + } @JsonProperty("turnCoverage") - public abstract Builder turnCoverage(String turnCoverage); + public abstract Builder turnCoverage(TurnCoverage turnCoverage); + + public Builder turnCoverage(TurnCoverage.Known knownType) { + return turnCoverage(new TurnCoverage(knownType)); + } + + public Builder turnCoverage(String turnCoverage) { + return turnCoverage(new TurnCoverage(turnCoverage)); + } public abstract RealtimeInputConfig build(); } diff --git a/src/main/java/com/google/genai/types/SafetyFilterLevel.java b/src/main/java/com/google/genai/types/SafetyFilterLevel.java new file mode 100644 index 00000000000..c504d5f590c --- /dev/null +++ b/src/main/java/com/google/genai/types/SafetyFilterLevel.java @@ -0,0 +1,67 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Enum that controls the safety filter level for objectionable content. */ +public class SafetyFilterLevel { + + /** Enum representing the known values for SafetyFilterLevel. */ + public enum Known { + BLOCK_LOW_AND_ABOVE, + BLOCK_MEDIUM_AND_ABOVE, + BLOCK_ONLY_HIGH, + BLOCK_NONE, + SAFETY_FILTER_LEVEL_UNSPECIFIED + } + + private Known safetyFilterLevelEnum; + private final String value; + + @JsonCreator + public SafetyFilterLevel(String value) { + this.value = value; + for (Known safetyFilterLevelEnum : Known.values()) { + if (safetyFilterLevelEnum.toString().equalsIgnoreCase(value)) { + this.safetyFilterLevelEnum = safetyFilterLevelEnum; + break; + } + } + if (this.safetyFilterLevelEnum == null) { + this.safetyFilterLevelEnum = Known.SAFETY_FILTER_LEVEL_UNSPECIFIED; + } + } + + public SafetyFilterLevel(Known knownValue) { + this.safetyFilterLevelEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.safetyFilterLevelEnum; + } +} diff --git a/src/main/java/com/google/genai/types/SafetyRating.java b/src/main/java/com/google/genai/types/SafetyRating.java index f0d4102edcd..d8a0bb1743b 100644 --- a/src/main/java/com/google/genai/types/SafetyRating.java +++ b/src/main/java/com/google/genai/types/SafetyRating.java @@ -35,11 +35,11 @@ public abstract class SafetyRating extends JsonSerializable { /** Output only. Harm category. */ @JsonProperty("category") - public abstract Optional category(); + public abstract Optional category(); /** Output only. Harm probability levels in the content. */ @JsonProperty("probability") - public abstract Optional probability(); + public abstract Optional probability(); /** Output only. Harm probability score. */ @JsonProperty("probabilityScore") @@ -47,7 +47,7 @@ public abstract class SafetyRating extends JsonSerializable { /** Output only. Harm severity levels in the content. */ @JsonProperty("severity") - public abstract Optional severity(); + public abstract Optional severity(); /** Output only. Harm severity score. */ @JsonProperty("severityScore") @@ -74,16 +74,40 @@ private static Builder create() { public abstract Builder blocked(boolean blocked); @JsonProperty("category") - public abstract Builder category(String category); + public abstract Builder category(HarmCategory category); + + public Builder category(HarmCategory.Known knownType) { + return category(new HarmCategory(knownType)); + } + + public Builder category(String category) { + return category(new HarmCategory(category)); + } @JsonProperty("probability") - public abstract Builder probability(String probability); + public abstract Builder probability(HarmProbability probability); + + public Builder probability(HarmProbability.Known knownType) { + return probability(new HarmProbability(knownType)); + } + + public Builder probability(String probability) { + return probability(new HarmProbability(probability)); + } @JsonProperty("probabilityScore") public abstract Builder probabilityScore(Float probabilityScore); @JsonProperty("severity") - public abstract Builder severity(String severity); + public abstract Builder severity(HarmSeverity severity); + + public Builder severity(HarmSeverity.Known knownType) { + return severity(new HarmSeverity(knownType)); + } + + public Builder severity(String severity) { + return severity(new HarmSeverity(severity)); + } @JsonProperty("severityScore") public abstract Builder severityScore(Float severityScore); diff --git a/src/main/java/com/google/genai/types/SafetySetting.java b/src/main/java/com/google/genai/types/SafetySetting.java index 4a15084fb9a..fd77a779214 100644 --- a/src/main/java/com/google/genai/types/SafetySetting.java +++ b/src/main/java/com/google/genai/types/SafetySetting.java @@ -31,15 +31,15 @@ public abstract class SafetySetting extends JsonSerializable { /** Determines if the harm block method uses probability or probability and severity scores. */ @JsonProperty("method") - public abstract Optional method(); + public abstract Optional method(); /** Required. Harm category. */ @JsonProperty("category") - public abstract Optional category(); + public abstract Optional category(); /** Required. The harm block threshold. */ @JsonProperty("threshold") - public abstract Optional threshold(); + public abstract Optional threshold(); /** Instantiates a builder for SafetySetting. */ public static Builder builder() { @@ -59,13 +59,37 @@ private static Builder create() { } @JsonProperty("method") - public abstract Builder method(String method); + public abstract Builder method(HarmBlockMethod method); + + public Builder method(HarmBlockMethod.Known knownType) { + return method(new HarmBlockMethod(knownType)); + } + + public Builder method(String method) { + return method(new HarmBlockMethod(method)); + } @JsonProperty("category") - public abstract Builder category(String category); + public abstract Builder category(HarmCategory category); + + public Builder category(HarmCategory.Known knownType) { + return category(new HarmCategory(knownType)); + } + + public Builder category(String category) { + return category(new HarmCategory(category)); + } @JsonProperty("threshold") - public abstract Builder threshold(String threshold); + public abstract Builder threshold(HarmBlockThreshold threshold); + + public Builder threshold(HarmBlockThreshold.Known knownType) { + return threshold(new HarmBlockThreshold(knownType)); + } + + public Builder threshold(String threshold) { + return threshold(new HarmBlockThreshold(threshold)); + } public abstract SafetySetting build(); } diff --git a/src/main/java/com/google/genai/types/Schema.java b/src/main/java/com/google/genai/types/Schema.java index b067fbcdfe8..4f5d676a66e 100644 --- a/src/main/java/com/google/genai/types/Schema.java +++ b/src/main/java/com/google/genai/types/Schema.java @@ -137,7 +137,7 @@ public abstract class Schema extends JsonSerializable { /** Optional. The type of the data. */ @JsonProperty("type") - public abstract Optional type(); + public abstract Optional type(); /** Instantiates a builder for Schema. */ public static Builder builder() { @@ -220,7 +220,15 @@ private static Builder create() { public abstract Builder title(String title); @JsonProperty("type") - public abstract Builder type(String type); + public abstract Builder type(Type type); + + public Builder type(Type.Known knownType) { + return type(new Type(knownType)); + } + + public Builder type(String type) { + return type(new Type(type)); + } public abstract Schema build(); } diff --git a/src/main/java/com/google/genai/types/StartSensitivity.java b/src/main/java/com/google/genai/types/StartSensitivity.java new file mode 100644 index 00000000000..22befcea470 --- /dev/null +++ b/src/main/java/com/google/genai/types/StartSensitivity.java @@ -0,0 +1,65 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Start of speech sensitivity. */ +public class StartSensitivity { + + /** Enum representing the known values for StartSensitivity. */ + public enum Known { + START_SENSITIVITY_UNSPECIFIED, + START_SENSITIVITY_HIGH, + START_SENSITIVITY_LOW + } + + private Known startSensitivityEnum; + private final String value; + + @JsonCreator + public StartSensitivity(String value) { + this.value = value; + for (Known startSensitivityEnum : Known.values()) { + if (startSensitivityEnum.toString().equalsIgnoreCase(value)) { + this.startSensitivityEnum = startSensitivityEnum; + break; + } + } + if (this.startSensitivityEnum == null) { + this.startSensitivityEnum = Known.START_SENSITIVITY_UNSPECIFIED; + } + } + + public StartSensitivity(Known knownValue) { + this.startSensitivityEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.startSensitivityEnum; + } +} diff --git a/src/main/java/com/google/genai/types/SubjectReferenceConfig.java b/src/main/java/com/google/genai/types/SubjectReferenceConfig.java index 98330013031..067a40a6346 100644 --- a/src/main/java/com/google/genai/types/SubjectReferenceConfig.java +++ b/src/main/java/com/google/genai/types/SubjectReferenceConfig.java @@ -31,7 +31,7 @@ public abstract class SubjectReferenceConfig extends JsonSerializable { /** The subject type of a subject reference image. */ @JsonProperty("subjectType") - public abstract Optional subjectType(); + public abstract Optional subjectType(); /** Subject description for the image. */ @JsonProperty("subjectDescription") @@ -55,7 +55,15 @@ private static Builder create() { } @JsonProperty("subjectType") - public abstract Builder subjectType(String subjectType); + public abstract Builder subjectType(SubjectReferenceType subjectType); + + public Builder subjectType(SubjectReferenceType.Known knownType) { + return subjectType(new SubjectReferenceType(knownType)); + } + + public Builder subjectType(String subjectType) { + return subjectType(new SubjectReferenceType(subjectType)); + } @JsonProperty("subjectDescription") public abstract Builder subjectDescription(String subjectDescription); diff --git a/src/main/java/com/google/genai/types/SubjectReferenceType.java b/src/main/java/com/google/genai/types/SubjectReferenceType.java new file mode 100644 index 00000000000..5c11cc6bd9e --- /dev/null +++ b/src/main/java/com/google/genai/types/SubjectReferenceType.java @@ -0,0 +1,67 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Enum representing the subject type of a subject reference image. */ +public class SubjectReferenceType { + + /** Enum representing the known values for SubjectReferenceType. */ + public enum Known { + SUBJECT_TYPE_DEFAULT, + SUBJECT_TYPE_PERSON, + SUBJECT_TYPE_ANIMAL, + SUBJECT_TYPE_PRODUCT, + SUBJECT_REFERENCE_TYPE_UNSPECIFIED + } + + private Known subjectReferenceTypeEnum; + private final String value; + + @JsonCreator + public SubjectReferenceType(String value) { + this.value = value; + for (Known subjectReferenceTypeEnum : Known.values()) { + if (subjectReferenceTypeEnum.toString().equalsIgnoreCase(value)) { + this.subjectReferenceTypeEnum = subjectReferenceTypeEnum; + break; + } + } + if (this.subjectReferenceTypeEnum == null) { + this.subjectReferenceTypeEnum = Known.SUBJECT_REFERENCE_TYPE_UNSPECIFIED; + } + } + + public SubjectReferenceType(Known knownValue) { + this.subjectReferenceTypeEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.subjectReferenceTypeEnum; + } +} diff --git a/src/main/java/com/google/genai/types/TrafficType.java b/src/main/java/com/google/genai/types/TrafficType.java new file mode 100644 index 00000000000..46219a6e4cf --- /dev/null +++ b/src/main/java/com/google/genai/types/TrafficType.java @@ -0,0 +1,68 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Output only. Traffic type. This shows whether a request consumes Pay-As-You-Go or Provisioned + * Throughput quota. + */ +public class TrafficType { + + /** Enum representing the known values for TrafficType. */ + public enum Known { + TRAFFIC_TYPE_UNSPECIFIED, + ON_DEMAND, + PROVISIONED_THROUGHPUT + } + + private Known trafficTypeEnum; + private final String value; + + @JsonCreator + public TrafficType(String value) { + this.value = value; + for (Known trafficTypeEnum : Known.values()) { + if (trafficTypeEnum.toString().equalsIgnoreCase(value)) { + this.trafficTypeEnum = trafficTypeEnum; + break; + } + } + if (this.trafficTypeEnum == null) { + this.trafficTypeEnum = Known.TRAFFIC_TYPE_UNSPECIFIED; + } + } + + public TrafficType(Known knownValue) { + this.trafficTypeEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.trafficTypeEnum; + } +} diff --git a/src/main/java/com/google/genai/types/TurnCoverage.java b/src/main/java/com/google/genai/types/TurnCoverage.java new file mode 100644 index 00000000000..2aa0a7d1781 --- /dev/null +++ b/src/main/java/com/google/genai/types/TurnCoverage.java @@ -0,0 +1,65 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Options about which input is included in the user's turn. */ +public class TurnCoverage { + + /** Enum representing the known values for TurnCoverage. */ + public enum Known { + TURN_COVERAGE_UNSPECIFIED, + TURN_INCLUDES_ONLY_ACTIVITY, + TURN_INCLUDES_ALL_INPUT + } + + private Known turnCoverageEnum; + private final String value; + + @JsonCreator + public TurnCoverage(String value) { + this.value = value; + for (Known turnCoverageEnum : Known.values()) { + if (turnCoverageEnum.toString().equalsIgnoreCase(value)) { + this.turnCoverageEnum = turnCoverageEnum; + break; + } + } + if (this.turnCoverageEnum == null) { + this.turnCoverageEnum = Known.TURN_COVERAGE_UNSPECIFIED; + } + } + + public TurnCoverage(Known knownValue) { + this.turnCoverageEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.turnCoverageEnum; + } +} diff --git a/src/main/java/com/google/genai/types/Type.java b/src/main/java/com/google/genai/types/Type.java new file mode 100644 index 00000000000..aac6f88893f --- /dev/null +++ b/src/main/java/com/google/genai/types/Type.java @@ -0,0 +1,69 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Optional. The type of the data. */ +public class Type { + + /** Enum representing the known values for Type. */ + public enum Known { + TYPE_UNSPECIFIED, + STRING, + NUMBER, + INTEGER, + BOOLEAN, + ARRAY, + OBJECT + } + + private Known typeEnum; + private final String value; + + @JsonCreator + public Type(String value) { + this.value = value; + for (Known typeEnum : Known.values()) { + if (typeEnum.toString().equalsIgnoreCase(value)) { + this.typeEnum = typeEnum; + break; + } + } + if (this.typeEnum == null) { + this.typeEnum = Known.TYPE_UNSPECIFIED; + } + } + + public Type(Known knownValue) { + this.typeEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.typeEnum; + } +} diff --git a/src/main/java/com/google/genai/types/UsageMetadata.java b/src/main/java/com/google/genai/types/UsageMetadata.java index f9f705d838a..95c733c5103 100644 --- a/src/main/java/com/google/genai/types/UsageMetadata.java +++ b/src/main/java/com/google/genai/types/UsageMetadata.java @@ -78,7 +78,7 @@ public abstract class UsageMetadata extends JsonSerializable { * quota. */ @JsonProperty("trafficType") - public abstract Optional trafficType(); + public abstract Optional trafficType(); /** Instantiates a builder for UsageMetadata. */ public static Builder builder() { @@ -129,7 +129,15 @@ public abstract Builder toolUsePromptTokensDetails( List toolUsePromptTokensDetails); @JsonProperty("trafficType") - public abstract Builder trafficType(String trafficType); + public abstract Builder trafficType(TrafficType trafficType); + + public Builder trafficType(TrafficType.Known knownType) { + return trafficType(new TrafficType(knownType)); + } + + public Builder trafficType(String trafficType) { + return trafficType(new TrafficType(trafficType)); + } public abstract UsageMetadata build(); } diff --git a/src/test/java/com/google/genai/ChatTest.java b/src/test/java/com/google/genai/ChatTest.java index a22313150d8..c995b2f5511 100644 --- a/src/test/java/com/google/genai/ChatTest.java +++ b/src/test/java/com/google/genai/ChatTest.java @@ -23,6 +23,7 @@ import com.google.genai.types.Candidate; import com.google.genai.types.Content; +import com.google.genai.types.FinishReason; import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.GenerateContentResponseUsageMetadata; @@ -103,7 +104,7 @@ public class ChatTest { Part.builder().text(STREAMING_RESPONSE_CHUNK_3).build())) .role("model") .build()) - .finishReason("STOP") + .finishReason(FinishReason.Known.STOP) .build())) .usageMetadata( GenerateContentResponseUsageMetadata.builder() diff --git a/src/test/java/com/google/genai/ForwardCompatibilityTest.java b/src/test/java/com/google/genai/ForwardCompatibilityTest.java index f5db1607b2a..95887f57fb0 100644 --- a/src/test/java/com/google/genai/ForwardCompatibilityTest.java +++ b/src/test/java/com/google/genai/ForwardCompatibilityTest.java @@ -16,21 +16,56 @@ package com.google.genai; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.collect.ImmutableList; +import com.google.genai.types.FeatureSelectionPreference; +import com.google.genai.types.FinishReason; +import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; +import com.google.genai.types.HarmBlockThreshold; +import com.google.genai.types.HarmCategory; +import com.google.genai.types.ModelSelectionConfig; +import com.google.genai.types.SafetySetting; import java.lang.reflect.Field; +import java.util.Optional; import org.apache.http.HttpEntity; import org.apache.http.entity.StringEntity; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; import org.mockito.Mockito; public class ForwardCompatibilityTest { + + ApiClient mockedClient; + ApiResponse mockedResponse; + HttpEntity mockedEntity; + Client client; + GenerateContentResponse returnResponse; + ObjectMapper objectMapper; + + @BeforeEach + void setUp() { + mockedClient = Mockito.mock(ApiClient.class); + mockedResponse = Mockito.mock(ApiResponse.class); + when(mockedClient.request(anyString(), anyString(), anyString())).thenReturn(mockedResponse); + mockedEntity = Mockito.mock(HttpEntity.class); + returnResponse = GenerateContentResponse.builder().build(); + + objectMapper = new ObjectMapper(); + + client = Client.builder().build(); + } + @Test public void testForwardCompatibility() throws Exception { // Mocks and test setup. @@ -57,8 +92,169 @@ public void testForwardCompatibility() throws Exception { apiClientField.set(client.models, mockedClient); GenerateContentResponse response = - client.models.generateContent("gemini-2.0-flash", "What is your name?", null); + client.models.generateContent("gemini-2.0-flash-exp", "What is your name?", null); assertNotNull(response); } + + @Test + public void testEnumForwardCompatibilityFinishReason() throws Exception { + /** Tests a response with two different unrecognized enum values for FinishReason. */ + JsonNode rootNode = objectMapper.readTree(returnResponse.toJson()); + ObjectNode rootObjectNode = (ObjectNode) rootNode; + + ArrayNode candidatesArray = objectMapper.createArrayNode(); + ObjectNode candidateObject = objectMapper.createObjectNode(); + candidateObject.put("finishReason", "NEW_UNKNOWN_VALUE"); + + ObjectNode candidateObject2 = objectMapper.createObjectNode(); + candidateObject2.put("finishReason", "ANOTHER_VALUE"); + + candidatesArray.add(candidateObject); + candidatesArray.add(candidateObject2); + rootObjectNode.putArray("candidates").addAll(candidatesArray); + + String jsonString = objectMapper.writeValueAsString(rootNode); + StringEntity content = new StringEntity(jsonString); + when(mockedResponse.getEntity()).thenReturn(content); + + Client client = Client.builder().build(); + // Make the apiClient field public so that it can be spied on in the tests. This is a + // workaround for the fact that the ApiClient is a final class and cannot be spied on directly. + Field apiClientField = Models.class.getDeclaredField("apiClient"); + apiClientField.setAccessible(true); + apiClientField.set(client.models, mockedClient); + + GenerateContentResponse response = + client.models.generateContent("gemini-2.0-flash-exp", "What is your name?", null); + Optional finishReason1 = response.candidates().get().get(0).finishReason(); + Optional finishReason2 = response.candidates().get().get(1).finishReason(); + + if (finishReason1.isPresent()) { + FinishReason finishReason = finishReason1.get(); + assert finishReason.toString().equals("NEW_UNKNOWN_VALUE"); + assert (finishReason.knownEnum().equals(FinishReason.Known.FINISH_REASON_UNSPECIFIED)); + } + if (finishReason2.isPresent()) { + FinishReason finishReason = finishReason2.get(); + assert finishReason.toString().equals("ANOTHER_VALUE"); + assert (finishReason.knownEnum().equals(FinishReason.Known.FINISH_REASON_UNSPECIFIED)); + } + } + + @Test + public void testFinishReasonEnumReturnsEnum() throws Exception { + /** Tests knownEnum method returns the correct enum value. */ + JsonNode rootNode = objectMapper.readTree(returnResponse.toJson()); + ObjectNode rootObjectNode = (ObjectNode) rootNode; + + ArrayNode candidatesArray = objectMapper.createArrayNode(); + ObjectNode candidateObject = objectMapper.createObjectNode(); + candidateObject.put("finishReason", "MAX_TOKENS"); + candidatesArray.add(candidateObject); + rootObjectNode.putArray("candidates").addAll(candidatesArray); + + String jsonString = objectMapper.writeValueAsString(rootNode); + StringEntity content = new StringEntity(jsonString); + when(mockedResponse.getEntity()).thenReturn(content); + + Client client = Client.builder().build(); + // Make the apiClient field public so that it can be spied on in the tests. This is a + // workaround for the fact that the ApiClient is a final class and cannot be spied on directly. + Field apiClientField = Models.class.getDeclaredField("apiClient"); + apiClientField.setAccessible(true); + apiClientField.set(client.models, mockedClient); + + GenerateContentResponse response = + client.models.generateContent("gemini-2.0-flash-exp", "What is your name?", null); + + Optional finishReasonResponse = response.candidates().get().get(0).finishReason(); + + if (finishReasonResponse.isPresent()) { + FinishReason finishReason = finishReasonResponse.get(); + assert (finishReason.knownEnum().equals(FinishReason.Known.MAX_TOKENS)); + } + } + + @Test + public void testEnumForwardCompatibilitySafetyFilterLevel() throws Exception { + /** Tests setting an unrecognized enum value for SafetyFilterLevel. */ + JsonNode rootNode = objectMapper.readTree(returnResponse.toJson()); + ObjectNode rootObjectNode = (ObjectNode) rootNode; + + ArrayNode candidatesArray = objectMapper.createArrayNode(); + ObjectNode candidateObject = objectMapper.createObjectNode(); + ArrayNode safetyRatingsArray = objectMapper.createArrayNode(); + ObjectNode safetyRatingsObjectNode = objectMapper.createObjectNode(); + + safetyRatingsObjectNode.put("category", "UNKNOWN_SAFETY_RATING_VALUE"); + safetyRatingsArray.add(safetyRatingsObjectNode); + candidateObject.put("safetyRatings", safetyRatingsArray); + candidatesArray.add(candidateObject); + rootObjectNode.putArray("candidates").addAll(candidatesArray); + + String jsonString = objectMapper.writeValueAsString(rootNode); + StringEntity content = new StringEntity(jsonString); + when(mockedResponse.getEntity()).thenReturn(content); + + Client client = Client.builder().build(); + // Make the apiClient field public so that it can be spied on in the tests. This is a + // workaround for the fact that the ApiClient is a final class and cannot be spied on + Field apiClientField = Models.class.getDeclaredField("apiClient"); + apiClientField.setAccessible(true); + apiClientField.set(client.models, mockedClient); + + GenerateContentResponse response = + client.models.generateContent("gemini-2.0-flash-exp", "What is your name?", null); + + Optional harmCategory = + response.candidates().get().get(0).safetyRatings().get().get(0).category(); + + if (harmCategory.isPresent()) { + assert (harmCategory.get().knownEnum()).equals(HarmCategory.Known.HARM_CATEGORY_UNSPECIFIED); + assert (harmCategory.get().toString().equals("UNKNOWN_SAFETY_RATING_VALUE")); + } + } + + @Test + public void testInlineEnum() throws Exception { + /** Tests instantiating an inline enum (ModelRoutingPreference) in the request. */ + GenerateContentConfig config = + GenerateContentConfig.builder() + .modelSelectionConfig( + ModelSelectionConfig.builder() + .featureSelectionPreference(FeatureSelectionPreference.Known.PRIORITIZE_QUALITY) + .build()) + .build(); + } + + public void testEnumSendingUnknownSafetysettings() throws Exception { + /** Tests sending an enum value that is not in the enum definition. */ + GenerateContentConfig config = + GenerateContentConfig.builder() + .safetySettings( + ImmutableList.of( + SafetySetting.builder() + .threshold(new HarmBlockThreshold("NEW_UNKNOWN_VALUE")) + .build())) + .build(); + + Client client = Client.builder().build(); + // Make the apiClient field public so that it can be spied on in the tests. This is a + // workaround for the fact that the ApiClient is a final class and cannot be spied on + Field apiClientField = Models.class.getDeclaredField("apiClient"); + apiClientField.setAccessible(true); + apiClientField.set(client.models, mockedClient); + when(mockedResponse.getEntity()).thenReturn(new StringEntity("{}")); + + GenerateContentResponse response = + client.models.generateContent("gemini-2.0-flash-exp", "What is your name?", config); + + ArgumentCaptor stringCaptor = ArgumentCaptor.forClass(String.class); + verify(mockedClient).request(anyString(), anyString(), stringCaptor.capture()); + assertEquals( + "{\"contents\":[{\"parts\":[{\"text\":\"What is your name?\"}],\"role\":\"user\"}]," + + "\"safetySettings\":[{\"threshold\":\"NEW_UNKNOWN_VALUE\"}],\"generationConfig\":{}}", + stringCaptor.getValue()); + } } diff --git a/src/test/java/com/google/genai/TransformerTest.java b/src/test/java/com/google/genai/TransformerTest.java index a733a01a1b7..dd964d2f9ba 100644 --- a/src/test/java/com/google/genai/TransformerTest.java +++ b/src/test/java/com/google/genai/TransformerTest.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.genai.types.HttpOptions; +import com.google.genai.types.Type; import com.google.genai.types.Schema; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -67,45 +68,48 @@ public void testTSchema_GeminiAPI_title_success() { public void testTSchema_AnyOf_success() { Schema schema = Schema.builder() - .type("OBJECT") + .type(Type.Known.OBJECT) .anyOf( ImmutableList.of( - Schema.builder().type("STRING").build(), - Schema.builder().type("NUMBER").build())) + Schema.builder().type(Type.Known.STRING).build(), + Schema.builder().type(Type.Known.NUMBER).build())) .build(); Schema transformedSchema = Transformers.tSchema(VERTEX_AI_CLIENT, schema); assertEquals(2, transformedSchema.anyOf().get().size()); - assertEquals("STRING", transformedSchema.anyOf().get().get(0).type().get()); - assertEquals("NUMBER", transformedSchema.anyOf().get().get(1).type().get()); - assertEquals("OBJECT", transformedSchema.type().get()); + assertEquals("STRING", transformedSchema.anyOf().get().get(0).type().get().toString()); + assertEquals("NUMBER", transformedSchema.anyOf().get().get(1).type().get().toString()); + assertEquals("OBJECT", transformedSchema.type().get().toString()); } @Test public void testTSchema_Items_success() { Schema schema = - Schema.builder().type("ARRAY").items(Schema.builder().type("STRING").build()).build(); + Schema.builder() + .type(new Type("ARRAY")) + .items(Schema.builder().type(Type.Known.STRING).build()) + .build(); Schema transformedSchema = Transformers.tSchema(GEMINI_API_CLIENT, schema); - assertEquals("STRING", transformedSchema.items().get().type().get()); - assertEquals("ARRAY", transformedSchema.type().get()); + assertEquals("STRING", transformedSchema.items().get().type().get().toString()); + assertEquals("ARRAY", transformedSchema.type().get().toString()); } @Test public void testTSchema_Required_sucess() { - Schema schema = Schema.builder() - .type("ARRAY") + Schema schema = + Schema.builder() + .type(Type.Known.ARRAY) .items( Schema.builder() - .type("OBJECT") + .type(Type.Known.OBJECT) .properties( ImmutableMap.of( "recipe_name", - Schema.builder().type("STRING").build(), + Schema.builder().type(Type.Known.STRING).build(), "ingredients", Schema.builder() - .type("ARRAY") - .items(Schema.builder().type("STRING").build()) - .build() - )) + .type(Type.Known.ARRAY) + .items(Schema.builder().type(Type.Known.STRING).build()) + .build())) .required(ImmutableList.of("recipe_name", "ingredients")) .build()) .build(); diff --git a/src/test/java/com/google/genai/types/FunctionDeclarationTest.java b/src/test/java/com/google/genai/types/FunctionDeclarationTest.java index 5c741b21846..a18b761dcfd 100644 --- a/src/test/java/com/google/genai/types/FunctionDeclarationTest.java +++ b/src/test/java/com/google/genai/types/FunctionDeclarationTest.java @@ -47,7 +47,7 @@ public class FunctionDeclarationTest { .description(FUNCTION_DESCRIPTION) .parameters( Schema.builder() - .type("OBJECT") + .type(Type.Known.OBJECT) .properties(buildPropertiesMap()) .required(REQUIRED_PARAM_NAMES) .build()) @@ -57,15 +57,19 @@ public class FunctionDeclarationTest { private static Map buildPropertiesMap() { Map properties = new HashMap<>(); properties.put( - STRING_PARAM_NAME, Schema.builder().type("STRING").title(STRING_PARAM_NAME).build()); + STRING_PARAM_NAME, + Schema.builder().type(Type.Known.STRING).title(STRING_PARAM_NAME).build()); properties.put( - INTEGER_PARAM_NAME, Schema.builder().type("INTEGER").title(INTEGER_PARAM_NAME).build()); + INTEGER_PARAM_NAME, + Schema.builder().type(Type.Known.INTEGER).title(INTEGER_PARAM_NAME).build()); properties.put( - DOUBLE_PARAM_NAME, Schema.builder().type("NUMBER").title(DOUBLE_PARAM_NAME).build()); + DOUBLE_PARAM_NAME, + Schema.builder().type(Type.Known.NUMBER).title(DOUBLE_PARAM_NAME).build()); properties.put( - FLOAT_PARAM_NAME, Schema.builder().type("NUMBER").title(FLOAT_PARAM_NAME).build()); + FLOAT_PARAM_NAME, Schema.builder().type(Type.Known.NUMBER).title(FLOAT_PARAM_NAME).build()); properties.put( - BOOLEAN_PARAM_NAME, Schema.builder().type("BOOLEAN").title(BOOLEAN_PARAM_NAME).build()); + BOOLEAN_PARAM_NAME, + Schema.builder().type(Type.Known.BOOLEAN).title(BOOLEAN_PARAM_NAME).build()); return properties; } @@ -123,7 +127,7 @@ public void fromMethodWithParameterNames_returnsFunctionDeclaration() FLOAT_PARAM_NAME, BOOLEAN_PARAM_NAME); - assertEquals(EXPECTED_FUNCTION_DECLARATION, functionDeclaration); + assertEquals(EXPECTED_FUNCTION_DECLARATION.toString(), functionDeclaration.toString()); } @Test diff --git a/src/test/java/com/google/genai/types/GenerateContentResponseTest.java b/src/test/java/com/google/genai/types/GenerateContentResponseTest.java index 05163bca70b..10f8089c3c9 100644 --- a/src/test/java/com/google/genai/types/GenerateContentResponseTest.java +++ b/src/test/java/com/google/genai/types/GenerateContentResponseTest.java @@ -56,14 +56,17 @@ public class GenerateContentResponseTest { private static final Part PART_WITH_EXECUTABLE_CODE = Part.builder() .executableCode( - ExecutableCode.builder().code("executableCode").language("python").build()) + ExecutableCode.builder() + .code("executableCode") + .language(Language.Known.PYTHON) + .build()) .build(); private static final Part PART_WITH_CODE_EXECUTION_RESULT = Part.builder() .codeExecutionResult( CodeExecutionResult.builder() .output("codeExecutionResult") - .outcome("success") + .outcome(Outcome.Known.OUTCOME_OK) .build()) .build(); @@ -91,21 +94,36 @@ public class GenerateContentResponseTest { Content.builder().parts(ImmutableList.of(PART_WITH_CODE_EXECUTION_RESULT, PART_1)).build(); private static final Candidate CANDIDATE_1 = - Candidate.builder().content(CONTENT_1).finishReason("STOP").build(); + Candidate.builder().content(CONTENT_1).finishReason(FinishReason.Known.STOP).build(); private static final Candidate CANDIDATE_2 = - Candidate.builder().content(CONTENT_2).finishReason("STOP").build(); + Candidate.builder().content(CONTENT_2).finishReason(FinishReason.Known.STOP).build(); private static final Candidate CANDIDATE_WITH_EMPTY_PARTS = - Candidate.builder().content(CONTENT_WITH_EMPTY_PARTS).finishReason("STOP").build(); + Candidate.builder() + .content(CONTENT_WITH_EMPTY_PARTS) + .finishReason(FinishReason.Known.STOP) + .build(); private static final Candidate CANDIDATE_WITH_THOUGHT = - Candidate.builder().content(CONTENT_WITH_THOUGHT).finishReason("STOP").build(); + Candidate.builder() + .content(CONTENT_WITH_THOUGHT) + .finishReason(FinishReason.Known.STOP) + .build(); private static final Candidate CANDIDATE_WITH_MULTIPLE_PARTS = - Candidate.builder().content(CONTENT_WITH_MULTIPLE_PARTS).finishReason("STOP").build(); + Candidate.builder() + .content(CONTENT_WITH_MULTIPLE_PARTS) + .finishReason(FinishReason.Known.STOP) + .build(); private static final Candidate CANDIDATE_WITH_FUNCTION_CALLS = - Candidate.builder().content(CONTENT_WITH_FUNCTION_CALLS).finishReason("STOP").build(); + Candidate.builder() + .content(CONTENT_WITH_FUNCTION_CALLS) + .finishReason(FinishReason.Known.STOP) + .build(); private static final Candidate CANDIDATE_WITH_MIXED_PARTS = - Candidate.builder().content(CONTENT_WITH_MIXED_PARTS).finishReason("STOP").build(); + Candidate.builder() + .content(CONTENT_WITH_MIXED_PARTS) + .finishReason(FinishReason.Known.STOP) + .build(); private static final Candidate CANDIDATE_WITH_UNEXPECTED_FINISH_REASON = - Candidate.builder().content(CONTENT_1).finishReason("SAFETY").build(); + Candidate.builder().content(CONTENT_1).finishReason(FinishReason.Known.SAFETY).build(); @Test public void testParts_EmptyCandidates() { @@ -330,9 +348,9 @@ public void testExecutableCode_MultipleCandidates() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_EXECUTABLE_CODE) - .finishReason("STOP") + .finishReason(FinishReason.Known.STOP) .build(), - CANDIDATE_1)) + CANDIDATE_1)) .build(); String result = response.executableCode(); @@ -348,7 +366,7 @@ public void testExecutableCode_PartWithExecutableCode() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_EXECUTABLE_CODE) - .finishReason("STOP") + .finishReason(FinishReason.Known.STOP) .build())) .build(); @@ -376,7 +394,7 @@ public void testExecutableCode_MultipleParts() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_EXECUTABLE_CODE_AND_TEXT) - .finishReason("STOP") + .finishReason(FinishReason.Known.STOP) .build())) .build(); @@ -426,7 +444,7 @@ public void testCodeExecutionResult_MultipleCandidates() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_CODE_EXECUTION_RESULT) - .finishReason("STOP") + .finishReason(FinishReason.Known.STOP) .build(), CANDIDATE_1)) .build(); @@ -444,7 +462,7 @@ public void testCodeExecutionResult_PartWithCodeExecutionResult() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_CODE_EXECUTION_RESULT) - .finishReason("STOP") + .finishReason(FinishReason.Known.STOP) .build())) .build(); @@ -471,7 +489,7 @@ public void testCodeExecutionResult_MultipleParts() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_CODE_EXECUTION_RESULT_AND_TEXT) - .finishReason("STOP") + .finishReason(FinishReason.Known.STOP) .build())) .build(); From 6cb7d7a3cfd0bef4a4ad13ea1c2ed95148320707 Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Mon, 5 May 2025 10:51:11 -0700 Subject: [PATCH 13/18] feat!: add enum support PiperOrigin-RevId: 754997060 --- README.md | 13 +- .../google/genai/examples/EditImageAsync.java | 6 +- .../examples/EditImageControlReference.java | 3 +- .../examples/EditImageMaskReference.java | 6 +- .../examples/EditImageSubjectReference.java | 3 +- .../examples/GenerateContentWithConfigs.java | 10 +- .../GenerateContentWithFunctionCall.java | 7 +- .../GenerateContentWithResponseSchema.java | 22 +- ...AudioConfigurableSpeechDetectionAsync.java | 3 +- .../examples/LiveAudioConversationAsync.java | 3 +- ...LiveTextContextWindowCompressionAsync.java | 3 +- .../examples/LiveTextConversationAsync.java | 3 +- .../LiveTextToAudioTranscriptionAsync.java | 3 +- .../LiveTextToTextGenerationAsync.java | 5 +- src/main/java/com/google/genai/ChatBase.java | 10 +- .../google/genai/types/ActivityHandling.java | 65 ------ .../types/AutomaticActivityDetection.java | 24 +-- .../com/google/genai/types/BlockedReason.java | 67 ------ .../com/google/genai/types/Candidate.java | 12 +- .../genai/types/CodeExecutionResult.java | 12 +- .../genai/types/ControlReferenceConfig.java | 12 +- .../genai/types/ControlReferenceType.java | 67 ------ .../genai/types/DynamicRetrievalConfig.java | 12 +- .../types/DynamicRetrievalConfigMode.java | 65 ------ .../google/genai/types/EditImageConfig.java | 48 +---- .../java/com/google/genai/types/EditMode.java | 71 ------- .../google/genai/types/EndSensitivity.java | 65 ------ .../google/genai/types/ExecutableCode.java | 12 +- .../types/FeatureSelectionPreference.java | 66 ------ .../com/google/genai/types/FinishReason.java | 78 ------- .../genai/types/FunctionCallingConfig.java | 12 +- .../types/FunctionCallingConfigMode.java | 67 ------ .../genai/types/FunctionDeclaration.java | 9 +- .../genai/types/GenerateContentConfig.java | 12 +- .../genai/types/GenerateContentResponse.java | 19 +- ...GenerateContentResponsePromptFeedback.java | 12 +- .../GenerateContentResponseUsageMetadata.java | 12 +- .../genai/types/GenerateImagesConfig.java | 36 +--- .../google/genai/types/GenerationConfig.java | 12 +- ...ionConfigRoutingConfigAutoRoutingMode.java | 12 +- .../google/genai/types/HarmBlockMethod.java | 68 ------ .../genai/types/HarmBlockThreshold.java | 68 ------ .../com/google/genai/types/HarmCategory.java | 68 ------ .../google/genai/types/HarmProbability.java | 67 ------ .../com/google/genai/types/HarmSeverity.java | 67 ------ .../genai/types/ImagePromptLanguage.java | 68 ------ .../java/com/google/genai/types/Language.java | 64 ------ .../google/genai/types/LiveConnectConfig.java | 29 +-- .../genai/types/MaskReferenceConfig.java | 12 +- .../google/genai/types/MaskReferenceMode.java | 68 ------ .../com/google/genai/types/MediaModality.java | 69 ------ .../google/genai/types/MediaResolution.java | 66 ------ .../java/com/google/genai/types/Modality.java | 66 ------ .../genai/types/ModalityTokenCount.java | 12 +- .../java/com/google/genai/types/Mode.java | 64 ------ .../genai/types/ModelRoutingPreference.java | 67 ------ .../genai/types/ModelSelectionConfig.java | 13 +- .../java/com/google/genai/types/Outcome.java | 66 ------ .../google/genai/types/PersonGeneration.java | 66 ------ .../genai/types/RealtimeInputConfig.java | 24 +-- .../google/genai/types/SafetyFilterLevel.java | 67 ------ .../com/google/genai/types/SafetyRating.java | 36 +--- .../com/google/genai/types/SafetySetting.java | 36 +--- .../java/com/google/genai/types/Schema.java | 12 +- .../google/genai/types/StartSensitivity.java | 65 ------ .../genai/types/SubjectReferenceConfig.java | 12 +- .../genai/types/SubjectReferenceType.java | 67 ------ .../com/google/genai/types/TrafficType.java | 68 ------ .../com/google/genai/types/TurnCoverage.java | 65 ------ .../java/com/google/genai/types/Type.java | 69 ------ .../com/google/genai/types/UsageMetadata.java | 12 +- src/test/java/com/google/genai/ChatTest.java | 3 +- .../genai/ForwardCompatibilityTest.java | 198 +----------------- .../com/google/genai/TransformerTest.java | 38 ++-- .../genai/types/FunctionDeclarationTest.java | 18 +- .../types/GenerateContentResponseTest.java | 52 ++--- 76 files changed, 165 insertions(+), 2724 deletions(-) delete mode 100644 src/main/java/com/google/genai/types/ActivityHandling.java delete mode 100644 src/main/java/com/google/genai/types/BlockedReason.java delete mode 100644 src/main/java/com/google/genai/types/ControlReferenceType.java delete mode 100644 src/main/java/com/google/genai/types/DynamicRetrievalConfigMode.java delete mode 100644 src/main/java/com/google/genai/types/EditMode.java delete mode 100644 src/main/java/com/google/genai/types/EndSensitivity.java delete mode 100644 src/main/java/com/google/genai/types/FeatureSelectionPreference.java delete mode 100644 src/main/java/com/google/genai/types/FinishReason.java delete mode 100644 src/main/java/com/google/genai/types/FunctionCallingConfigMode.java delete mode 100644 src/main/java/com/google/genai/types/HarmBlockMethod.java delete mode 100644 src/main/java/com/google/genai/types/HarmBlockThreshold.java delete mode 100644 src/main/java/com/google/genai/types/HarmCategory.java delete mode 100644 src/main/java/com/google/genai/types/HarmProbability.java delete mode 100644 src/main/java/com/google/genai/types/HarmSeverity.java delete mode 100644 src/main/java/com/google/genai/types/ImagePromptLanguage.java delete mode 100644 src/main/java/com/google/genai/types/Language.java delete mode 100644 src/main/java/com/google/genai/types/MaskReferenceMode.java delete mode 100644 src/main/java/com/google/genai/types/MediaModality.java delete mode 100644 src/main/java/com/google/genai/types/MediaResolution.java delete mode 100644 src/main/java/com/google/genai/types/Modality.java delete mode 100644 src/main/java/com/google/genai/types/Mode.java delete mode 100644 src/main/java/com/google/genai/types/ModelRoutingPreference.java delete mode 100644 src/main/java/com/google/genai/types/Outcome.java delete mode 100644 src/main/java/com/google/genai/types/PersonGeneration.java delete mode 100644 src/main/java/com/google/genai/types/SafetyFilterLevel.java delete mode 100644 src/main/java/com/google/genai/types/StartSensitivity.java delete mode 100644 src/main/java/com/google/genai/types/SubjectReferenceType.java delete mode 100644 src/main/java/com/google/genai/types/TrafficType.java delete mode 100644 src/main/java/com/google/genai/types/TurnCoverage.java delete mode 100644 src/main/java/com/google/genai/types/Type.java diff --git a/README.md b/README.md index 08490970d9b..228b6559e24 100644 --- a/README.md +++ b/README.md @@ -215,8 +215,6 @@ import com.google.genai.types.Content; import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.GoogleSearch; -import com.google.genai.types.HarmBlockThreshold; -import com.google.genai.types.HarmCategory; import com.google.genai.types.Part; import com.google.genai.types.SafetySetting; import com.google.genai.types.Tool; @@ -229,12 +227,12 @@ public class GenerateContentWithConfigs { ImmutableList safetySettings = ImmutableList.of( SafetySetting.builder() - .category(HarmCategory.Known.HARM_CATEGORY_HATE_SPEECH) - .threshold(HarmBlockThreshold.Known.BLOCK_ONLY_HIGH) + .category("HARM_CATEGORY_HATE_SPEECH") + .threshold("BLOCK_ONLY_HIGH") .build(), SafetySetting.builder() - .category(HarmCategory.Known.HARM_CATEGORY_DANGEROUS_CONTENT) - .threshold(HarmBlockThreshold.Known.BLOCK_LOW_AND_ABOVE) + .category("HARM_CATEGORY_DANGEROUS_CONTENT") + .threshold("BLOCK_LOW_AND_ABOVE") .build()); // Sets the system instruction in the config. @@ -272,7 +270,6 @@ import com.google.genai.Client; import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.Schema; -import com.google.genai.types.Type; public class GenerateContentWithSchema { public static void main(String[] args) { @@ -283,7 +280,7 @@ public class GenerateContentWithSchema { .type("object") .properties( ImmutableMap.of( - "name", Schema.builder().type(Type.Known.STRING).description("Your Name").build())) + "name", Schema.builder().type("string").description("Your Name").build())) .build(); GenerateContentConfig config = GenerateContentConfig.builder() diff --git a/examples/src/main/java/com/google/genai/examples/EditImageAsync.java b/examples/src/main/java/com/google/genai/examples/EditImageAsync.java index ae2780ad5f0..8659936caa1 100644 --- a/examples/src/main/java/com/google/genai/examples/EditImageAsync.java +++ b/examples/src/main/java/com/google/genai/examples/EditImageAsync.java @@ -40,13 +40,11 @@ import com.google.genai.Client; import com.google.genai.types.EditImageConfig; import com.google.genai.types.EditImageResponse; -import com.google.genai.types.EditMode; import com.google.genai.types.GenerateImagesConfig; import com.google.genai.types.GenerateImagesResponse; import com.google.genai.types.Image; import com.google.genai.types.MaskReferenceConfig; import com.google.genai.types.MaskReferenceImage; -import com.google.genai.types.MaskReferenceMode; import com.google.genai.types.RawReferenceImage; import com.google.genai.types.ReferenceImage; import java.io.IOException; @@ -83,7 +81,7 @@ public static void main(String[] args) throws IOException, HttpException { // Edit image with a mask. EditImageConfig editImageConfig = EditImageConfig.builder() - .editMode(EditMode.Known.EDIT_MODE_INPAINT_INSERTION) + .editMode("EDIT_MODE_INPAINT_INSERTION") .numberOfImages(1) .outputMimeType("image/jpeg") .build(); @@ -98,7 +96,7 @@ public static void main(String[] args) throws IOException, HttpException { .referenceId(2) .config( MaskReferenceConfig.builder() - .maskMode(MaskReferenceMode.Known.MASK_MODE_BACKGROUND) + .maskMode("MASK_MODE_BACKGROUND") .maskDilation(0.0f) .build()) .build(); diff --git a/examples/src/main/java/com/google/genai/examples/EditImageControlReference.java b/examples/src/main/java/com/google/genai/examples/EditImageControlReference.java index 459943a3a17..3a5339e8a3a 100644 --- a/examples/src/main/java/com/google/genai/examples/EditImageControlReference.java +++ b/examples/src/main/java/com/google/genai/examples/EditImageControlReference.java @@ -41,7 +41,6 @@ import com.google.genai.Client; import com.google.genai.types.ControlReferenceConfig; import com.google.genai.types.ControlReferenceImage; -import com.google.genai.types.ControlReferenceType; import com.google.genai.types.EditImageConfig; import com.google.genai.types.EditImageResponse; import com.google.genai.types.GenerateImagesConfig; @@ -84,7 +83,7 @@ public static void main(String[] args) { .referenceImage(generatedImage) .config( ControlReferenceConfig.builder() - .controlType(ControlReferenceType.Known.CONTROL_TYPE_SCRIBBLE) + .controlType("CONTROL_TYPE_SCRIBBLE") .enableControlImageComputation(true) .build()) .build(); diff --git a/examples/src/main/java/com/google/genai/examples/EditImageMaskReference.java b/examples/src/main/java/com/google/genai/examples/EditImageMaskReference.java index 7c59c308947..bc8cf524c69 100644 --- a/examples/src/main/java/com/google/genai/examples/EditImageMaskReference.java +++ b/examples/src/main/java/com/google/genai/examples/EditImageMaskReference.java @@ -40,13 +40,11 @@ import com.google.genai.Client; import com.google.genai.types.EditImageConfig; import com.google.genai.types.EditImageResponse; -import com.google.genai.types.EditMode; import com.google.genai.types.GenerateImagesConfig; import com.google.genai.types.GenerateImagesResponse; import com.google.genai.types.Image; import com.google.genai.types.MaskReferenceConfig; import com.google.genai.types.MaskReferenceImage; -import com.google.genai.types.MaskReferenceMode; import com.google.genai.types.RawReferenceImage; import com.google.genai.types.ReferenceImage; import java.util.ArrayList; @@ -76,7 +74,7 @@ public static void main(String[] args) { // Edit image with a mask. EditImageConfig editImageConfig = EditImageConfig.builder() - .editMode(EditMode.Known.EDIT_MODE_INPAINT_INSERTION) + .editMode("EDIT_MODE_INPAINT_INSERTION") .numberOfImages(1) .outputMimeType("image/jpeg") .build(); @@ -91,7 +89,7 @@ public static void main(String[] args) { .referenceId(2) .config( MaskReferenceConfig.builder() - .maskMode(MaskReferenceMode.Known.MASK_MODE_BACKGROUND) + .maskMode("MASK_MODE_BACKGROUND") .maskDilation(0.0f) .build()) .build(); diff --git a/examples/src/main/java/com/google/genai/examples/EditImageSubjectReference.java b/examples/src/main/java/com/google/genai/examples/EditImageSubjectReference.java index 2959356dd98..8a6e17c636a 100644 --- a/examples/src/main/java/com/google/genai/examples/EditImageSubjectReference.java +++ b/examples/src/main/java/com/google/genai/examples/EditImageSubjectReference.java @@ -47,7 +47,6 @@ import com.google.genai.types.ReferenceImage; import com.google.genai.types.SubjectReferenceConfig; import com.google.genai.types.SubjectReferenceImage; -import com.google.genai.types.SubjectReferenceType; import java.util.ArrayList; /** An example of using the Unified Gen AI Java SDK to edit an image (Subject reference). */ @@ -83,7 +82,7 @@ public static void main(String[] args) { .referenceId(1) .config( SubjectReferenceConfig.builder() - .subjectType(SubjectReferenceType.Known.SUBJECT_TYPE_PRODUCT) + .subjectType("SUBJECT_TYPE_PRODUCT") .subjectDescription("Product logo") .build()) .build(); diff --git a/examples/src/main/java/com/google/genai/examples/GenerateContentWithConfigs.java b/examples/src/main/java/com/google/genai/examples/GenerateContentWithConfigs.java index 9ef496967e9..7df4200daf8 100644 --- a/examples/src/main/java/com/google/genai/examples/GenerateContentWithConfigs.java +++ b/examples/src/main/java/com/google/genai/examples/GenerateContentWithConfigs.java @@ -45,8 +45,6 @@ import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.GoogleSearch; -import com.google.genai.types.HarmBlockThreshold; -import com.google.genai.types.HarmCategory; import com.google.genai.types.Part; import com.google.genai.types.SafetySetting; import com.google.genai.types.Tool; @@ -61,12 +59,12 @@ public static void main(String[] args) { ImmutableList safetySettings = ImmutableList.of( SafetySetting.builder() - .category(HarmCategory.Known.HARM_CATEGORY_HATE_SPEECH) - .threshold(HarmBlockThreshold.Known.BLOCK_ONLY_HIGH) + .category("HARM_CATEGORY_HATE_SPEECH") + .threshold("BLOCK_ONLY_HIGH") .build(), SafetySetting.builder() - .category(HarmCategory.Known.HARM_CATEGORY_DANGEROUS_CONTENT) - .threshold(HarmBlockThreshold.Known.BLOCK_LOW_AND_ABOVE) + .category("HARM_CATEGORY_DANGEROUS_CONTENT") + .threshold("BLOCK_LOW_AND_ABOVE") .build()); // Sets the system instruction in the config. diff --git a/examples/src/main/java/com/google/genai/examples/GenerateContentWithFunctionCall.java b/examples/src/main/java/com/google/genai/examples/GenerateContentWithFunctionCall.java index 5f4fbc76c82..4a40153ab62 100644 --- a/examples/src/main/java/com/google/genai/examples/GenerateContentWithFunctionCall.java +++ b/examples/src/main/java/com/google/genai/examples/GenerateContentWithFunctionCall.java @@ -46,7 +46,6 @@ import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.Schema; -import com.google.genai.types.Type; /** An example of using the Unified Gen AI Java SDK to generate content with function calling. */ public class GenerateContentWithFunctionCall { @@ -59,17 +58,17 @@ public static void main(String[] args) { .name("get_current_weather") .parameters( Schema.builder() - .type(Type.Known.OBJECT) + .type("object") .properties( ImmutableMap.of( "location", Schema.builder() - .type(Type.Known.STRING) + .type("string") .description("The location to get the weather for.") .build(), "unit", Schema.builder() - .type(Type.Known.STRING) + .type("string") .description("The unit to return the weather in, e.g. 'celsius'.") .build())) .required(ImmutableList.of("location", "unit")) diff --git a/examples/src/main/java/com/google/genai/examples/GenerateContentWithResponseSchema.java b/examples/src/main/java/com/google/genai/examples/GenerateContentWithResponseSchema.java index 799b11240af..0f655a9af73 100644 --- a/examples/src/main/java/com/google/genai/examples/GenerateContentWithResponseSchema.java +++ b/examples/src/main/java/com/google/genai/examples/GenerateContentWithResponseSchema.java @@ -39,13 +39,12 @@ */ package com.google.genai.examples; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableList; import com.google.genai.Client; import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.Schema; -import com.google.genai.types.Type; /** * GenerateContentWithResponseSchema generates a content and returns a json object by passing a @@ -55,21 +54,21 @@ public class GenerateContentWithResponseSchema { public static void main(String[] args) { Client client = new Client(); - Schema schema = - Schema.builder() - .type(Type.Known.ARRAY) + Schema schema = Schema.builder() + .type("ARRAY") .items( Schema.builder() - .type(Type.Known.OBJECT) + .type("OBJECT") .properties( ImmutableMap.of( "recipe_name", - Schema.builder().type(Type.Known.STRING).build(), + Schema.builder().type("STRING").build(), "ingredients", Schema.builder() - .type(Type.Known.ARRAY) - .items(Schema.builder().type(Type.Known.STRING).build()) - .build())) + .type("ARRAY") + .items(Schema.builder().type("STRING").build()) + .build() + )) .required(ImmutableList.of("recipe_name", "ingredients")) .build()) .build(); @@ -81,8 +80,7 @@ public static void main(String[] args) { .build(); GenerateContentResponse response = - client.models.generateContent( - "gemini-2.0-flash-001", "List a few popular cookie recipes.", config); + client.models.generateContent("gemini-2.0-flash-001", "List a few popular cookie recipes.", config); System.out.println("Response: " + response.text()); } diff --git a/examples/src/main/java/com/google/genai/examples/LiveAudioConfigurableSpeechDetectionAsync.java b/examples/src/main/java/com/google/genai/examples/LiveAudioConfigurableSpeechDetectionAsync.java index 02dac8b935f..c5b43b122b1 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveAudioConfigurableSpeechDetectionAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveAudioConfigurableSpeechDetectionAsync.java @@ -65,7 +65,6 @@ import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.TargetDataLine; -import com.google.genai.types.Modality; /** * Example of using the live module for a streaming audio conversation with configurable speech @@ -150,7 +149,7 @@ public static void main(String[] args) throws LineUnavailableException { // --- Live API Config for Audio --- LiveConnectConfig config = LiveConnectConfig.builder() - .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.AUDIO)) + .responseModalities(ImmutableList.of("AUDIO")) .realtimeInputConfig( RealtimeInputConfig.builder() .activityHandling("NO_INTERRUPTION") diff --git a/examples/src/main/java/com/google/genai/examples/LiveAudioConversationAsync.java b/examples/src/main/java/com/google/genai/examples/LiveAudioConversationAsync.java index bfc7038e41f..9f456afd66c 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveAudioConversationAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveAudioConversationAsync.java @@ -51,7 +51,6 @@ import com.google.genai.types.LiveConnectConfig; import com.google.genai.types.LiveSendRealtimeInputParameters; import com.google.genai.types.LiveServerMessage; -import com.google.genai.types.Modality; import com.google.genai.types.PrebuiltVoiceConfig; import com.google.genai.types.SpeechConfig; import com.google.genai.types.VoiceConfig; @@ -147,7 +146,7 @@ public static void main(String[] args) throws LineUnavailableException { String voiceName = "Aoede"; LiveConnectConfig config = LiveConnectConfig.builder() - .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.AUDIO)) + .responseModalities(ImmutableList.of("AUDIO")) .speechConfig( SpeechConfig.builder() .voiceConfig( diff --git a/examples/src/main/java/com/google/genai/examples/LiveTextContextWindowCompressionAsync.java b/examples/src/main/java/com/google/genai/examples/LiveTextContextWindowCompressionAsync.java index fd0ed31a6c2..0b91703eb5e 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveTextContextWindowCompressionAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveTextContextWindowCompressionAsync.java @@ -51,7 +51,6 @@ import java.util.concurrent.CompletableFuture; import com.google.genai.types.GroundingChunk; import com.google.genai.types.GroundingChunkWeb; -import com.google.genai.types.Modality; import java.util.List; import java.util.Optional; @@ -69,7 +68,7 @@ public static void main(String[] args) { LiveConnectConfig config = LiveConnectConfig.builder() - .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.TEXT)) + .responseModalities(ImmutableList.of("TEXT")) .contextWindowCompression( ContextWindowCompressionConfig.builder() .triggerTokens(1000L) diff --git a/examples/src/main/java/com/google/genai/examples/LiveTextConversationAsync.java b/examples/src/main/java/com/google/genai/examples/LiveTextConversationAsync.java index ba351745f8c..14ef21728dc 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveTextConversationAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveTextConversationAsync.java @@ -47,7 +47,6 @@ import com.google.genai.types.LiveSendClientContentParameters; import com.google.genai.types.LiveServerContent; import com.google.genai.types.LiveServerMessage; -import com.google.genai.types.Modality; import com.google.genai.types.Part; import java.io.Console; import java.util.concurrent.CompletableFuture; @@ -63,7 +62,7 @@ public static void main(String[] args) { LiveConnectConfig config = LiveConnectConfig.builder() - .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.TEXT)) + .responseModalities(ImmutableList.of("TEXT")) .topP(0.8f) .maxOutputTokens(30) .seed(1234) diff --git a/examples/src/main/java/com/google/genai/examples/LiveTextToAudioTranscriptionAsync.java b/examples/src/main/java/com/google/genai/examples/LiveTextToAudioTranscriptionAsync.java index e1b04f45fb1..f3b9431adec 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveTextToAudioTranscriptionAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveTextToAudioTranscriptionAsync.java @@ -57,7 +57,6 @@ import com.google.genai.types.GroundingChunkWeb; import java.util.List; import java.util.Optional; -import com.google.genai.types.Modality; /** Example of using the live module to send and receive messages asynchronously. */ public class LiveTextToAudioTranscriptionAsync { @@ -78,7 +77,7 @@ public static void main(String[] args) { LiveConnectConfig config = LiveConnectConfig.builder() - .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.AUDIO)) + .responseModalities(ImmutableList.of("AUDIO")) .outputAudioTranscription(AudioTranscriptionConfig.builder().build()) .systemInstruction(systemInstruction) .speechConfig(SpeechConfig.builder().languageCode("ja-JP").build()) diff --git a/examples/src/main/java/com/google/genai/examples/LiveTextToTextGenerationAsync.java b/examples/src/main/java/com/google/genai/examples/LiveTextToTextGenerationAsync.java index 33ddce11765..7346159ea0d 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveTextToTextGenerationAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveTextToTextGenerationAsync.java @@ -46,7 +46,6 @@ import com.google.genai.types.LiveSendClientContentParameters; import com.google.genai.types.LiveServerContent; import com.google.genai.types.LiveServerMessage; -import com.google.genai.types.Modality; import com.google.genai.types.Part; import java.util.concurrent.CompletableFuture; @@ -59,9 +58,7 @@ public static void main(String[] args) { Client.builder().httpOptions(HttpOptions.builder().apiVersion("v1beta").build()).build(); LiveConnectConfig config = - LiveConnectConfig.builder() - .responseModalitiesFromKnown(ImmutableList.of(Modality.Known.TEXT)) - .build(); + LiveConnectConfig.builder().responseModalities(ImmutableList.of("TEXT")).build(); CompletableFuture allDone = new CompletableFuture<>(); diff --git a/src/main/java/com/google/genai/ChatBase.java b/src/main/java/com/google/genai/ChatBase.java index ba22b59130c..4afa17b09be 100644 --- a/src/main/java/com/google/genai/ChatBase.java +++ b/src/main/java/com/google/genai/ChatBase.java @@ -59,10 +59,12 @@ protected void recordHistory(List currentHistory, GenerateContentRespon response.checkFinishReason(); this.curatedHistory.addAll(validatedHistory); } catch (IllegalArgumentException e) { - logger.warning( - "Response finished unexpectedly with reason: " - + response.finishReason().toString() - + ". Adding the response to comprehenisive history, but not to curated history."); + if (!response.finishReason().isEmpty()) { + logger.warning( + "Response finished unexpectedly with reason: " + + response.finishReason() + + ". Adding the response to comprehenisive history, but not to curated history."); + } } } diff --git a/src/main/java/com/google/genai/types/ActivityHandling.java b/src/main/java/com/google/genai/types/ActivityHandling.java deleted file mode 100644 index 584e673a3d8..00000000000 --- a/src/main/java/com/google/genai/types/ActivityHandling.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** The different ways of handling user activity. */ -public class ActivityHandling { - - /** Enum representing the known values for ActivityHandling. */ - public enum Known { - ACTIVITY_HANDLING_UNSPECIFIED, - START_OF_ACTIVITY_INTERRUPTS, - NO_INTERRUPTION - } - - private Known activityHandlingEnum; - private final String value; - - @JsonCreator - public ActivityHandling(String value) { - this.value = value; - for (Known activityHandlingEnum : Known.values()) { - if (activityHandlingEnum.toString().equalsIgnoreCase(value)) { - this.activityHandlingEnum = activityHandlingEnum; - break; - } - } - if (this.activityHandlingEnum == null) { - this.activityHandlingEnum = Known.ACTIVITY_HANDLING_UNSPECIFIED; - } - } - - public ActivityHandling(Known knownValue) { - this.activityHandlingEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.activityHandlingEnum; - } -} diff --git a/src/main/java/com/google/genai/types/AutomaticActivityDetection.java b/src/main/java/com/google/genai/types/AutomaticActivityDetection.java index 8e094903573..0569e388370 100644 --- a/src/main/java/com/google/genai/types/AutomaticActivityDetection.java +++ b/src/main/java/com/google/genai/types/AutomaticActivityDetection.java @@ -38,11 +38,11 @@ public abstract class AutomaticActivityDetection extends JsonSerializable { /** Determines how likely speech is to be detected. */ @JsonProperty("startOfSpeechSensitivity") - public abstract Optional startOfSpeechSensitivity(); + public abstract Optional startOfSpeechSensitivity(); /** Determines how likely detected speech is ended. */ @JsonProperty("endOfSpeechSensitivity") - public abstract Optional endOfSpeechSensitivity(); + public abstract Optional endOfSpeechSensitivity(); /** * The required duration of detected speech before start-of-speech is committed. The lower this @@ -81,26 +81,10 @@ private static Builder create() { public abstract Builder disabled(boolean disabled); @JsonProperty("startOfSpeechSensitivity") - public abstract Builder startOfSpeechSensitivity(StartSensitivity startOfSpeechSensitivity); - - public Builder startOfSpeechSensitivity(StartSensitivity.Known knownType) { - return startOfSpeechSensitivity(new StartSensitivity(knownType)); - } - - public Builder startOfSpeechSensitivity(String startOfSpeechSensitivity) { - return startOfSpeechSensitivity(new StartSensitivity(startOfSpeechSensitivity)); - } + public abstract Builder startOfSpeechSensitivity(String startOfSpeechSensitivity); @JsonProperty("endOfSpeechSensitivity") - public abstract Builder endOfSpeechSensitivity(EndSensitivity endOfSpeechSensitivity); - - public Builder endOfSpeechSensitivity(EndSensitivity.Known knownType) { - return endOfSpeechSensitivity(new EndSensitivity(knownType)); - } - - public Builder endOfSpeechSensitivity(String endOfSpeechSensitivity) { - return endOfSpeechSensitivity(new EndSensitivity(endOfSpeechSensitivity)); - } + public abstract Builder endOfSpeechSensitivity(String endOfSpeechSensitivity); @JsonProperty("prefixPaddingMs") public abstract Builder prefixPaddingMs(Integer prefixPaddingMs); diff --git a/src/main/java/com/google/genai/types/BlockedReason.java b/src/main/java/com/google/genai/types/BlockedReason.java deleted file mode 100644 index 4fe10b675d1..00000000000 --- a/src/main/java/com/google/genai/types/BlockedReason.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Output only. Blocked reason. */ -public class BlockedReason { - - /** Enum representing the known values for BlockedReason. */ - public enum Known { - BLOCKED_REASON_UNSPECIFIED, - SAFETY, - OTHER, - BLOCKLIST, - PROHIBITED_CONTENT - } - - private Known blockedReasonEnum; - private final String value; - - @JsonCreator - public BlockedReason(String value) { - this.value = value; - for (Known blockedReasonEnum : Known.values()) { - if (blockedReasonEnum.toString().equalsIgnoreCase(value)) { - this.blockedReasonEnum = blockedReasonEnum; - break; - } - } - if (this.blockedReasonEnum == null) { - this.blockedReasonEnum = Known.BLOCKED_REASON_UNSPECIFIED; - } - } - - public BlockedReason(Known knownValue) { - this.blockedReasonEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.blockedReasonEnum; - } -} diff --git a/src/main/java/com/google/genai/types/Candidate.java b/src/main/java/com/google/genai/types/Candidate.java index 0bb855bf03b..302df3a55e1 100644 --- a/src/main/java/com/google/genai/types/Candidate.java +++ b/src/main/java/com/google/genai/types/Candidate.java @@ -51,7 +51,7 @@ public abstract class Candidate extends JsonSerializable { * generating the tokens. */ @JsonProperty("finishReason") - public abstract Optional finishReason(); + public abstract Optional finishReason(); /** Output only. Average log probability score of the candidate. */ @JsonProperty("avgLogprobs") @@ -106,15 +106,7 @@ private static Builder create() { public abstract Builder tokenCount(Integer tokenCount); @JsonProperty("finishReason") - public abstract Builder finishReason(FinishReason finishReason); - - public Builder finishReason(FinishReason.Known knownType) { - return finishReason(new FinishReason(knownType)); - } - - public Builder finishReason(String finishReason) { - return finishReason(new FinishReason(finishReason)); - } + public abstract Builder finishReason(String finishReason); @JsonProperty("avgLogprobs") public abstract Builder avgLogprobs(Double avgLogprobs); diff --git a/src/main/java/com/google/genai/types/CodeExecutionResult.java b/src/main/java/com/google/genai/types/CodeExecutionResult.java index db6beceba06..d6453f2b6af 100644 --- a/src/main/java/com/google/genai/types/CodeExecutionResult.java +++ b/src/main/java/com/google/genai/types/CodeExecutionResult.java @@ -34,7 +34,7 @@ public abstract class CodeExecutionResult extends JsonSerializable { /** Required. Outcome of the code execution. */ @JsonProperty("outcome") - public abstract Optional outcome(); + public abstract Optional outcome(); /** * Optional. Contains stdout when code execution is successful, stderr or other description @@ -61,15 +61,7 @@ private static Builder create() { } @JsonProperty("outcome") - public abstract Builder outcome(Outcome outcome); - - public Builder outcome(Outcome.Known knownType) { - return outcome(new Outcome(knownType)); - } - - public Builder outcome(String outcome) { - return outcome(new Outcome(outcome)); - } + public abstract Builder outcome(String outcome); @JsonProperty("output") public abstract Builder output(String output); diff --git a/src/main/java/com/google/genai/types/ControlReferenceConfig.java b/src/main/java/com/google/genai/types/ControlReferenceConfig.java index ae01af9607f..0e3cf63ba20 100644 --- a/src/main/java/com/google/genai/types/ControlReferenceConfig.java +++ b/src/main/java/com/google/genai/types/ControlReferenceConfig.java @@ -31,7 +31,7 @@ public abstract class ControlReferenceConfig extends JsonSerializable { /** The type of control reference image to use. */ @JsonProperty("controlType") - public abstract Optional controlType(); + public abstract Optional controlType(); /** * Defaults to False. When set to True, the control image will be computed by the model based on @@ -58,15 +58,7 @@ private static Builder create() { } @JsonProperty("controlType") - public abstract Builder controlType(ControlReferenceType controlType); - - public Builder controlType(ControlReferenceType.Known knownType) { - return controlType(new ControlReferenceType(knownType)); - } - - public Builder controlType(String controlType) { - return controlType(new ControlReferenceType(controlType)); - } + public abstract Builder controlType(String controlType); @JsonProperty("enableControlImageComputation") public abstract Builder enableControlImageComputation(boolean enableControlImageComputation); diff --git a/src/main/java/com/google/genai/types/ControlReferenceType.java b/src/main/java/com/google/genai/types/ControlReferenceType.java deleted file mode 100644 index ca3c67afa7d..00000000000 --- a/src/main/java/com/google/genai/types/ControlReferenceType.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Enum representing the control type of a control reference image. */ -public class ControlReferenceType { - - /** Enum representing the known values for ControlReferenceType. */ - public enum Known { - CONTROL_TYPE_DEFAULT, - CONTROL_TYPE_CANNY, - CONTROL_TYPE_SCRIBBLE, - CONTROL_TYPE_FACE_MESH, - CONTROL_REFERENCE_TYPE_UNSPECIFIED - } - - private Known controlReferenceTypeEnum; - private final String value; - - @JsonCreator - public ControlReferenceType(String value) { - this.value = value; - for (Known controlReferenceTypeEnum : Known.values()) { - if (controlReferenceTypeEnum.toString().equalsIgnoreCase(value)) { - this.controlReferenceTypeEnum = controlReferenceTypeEnum; - break; - } - } - if (this.controlReferenceTypeEnum == null) { - this.controlReferenceTypeEnum = Known.CONTROL_REFERENCE_TYPE_UNSPECIFIED; - } - } - - public ControlReferenceType(Known knownValue) { - this.controlReferenceTypeEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.controlReferenceTypeEnum; - } -} diff --git a/src/main/java/com/google/genai/types/DynamicRetrievalConfig.java b/src/main/java/com/google/genai/types/DynamicRetrievalConfig.java index 0b459a6d6fc..81d6fdd7aef 100644 --- a/src/main/java/com/google/genai/types/DynamicRetrievalConfig.java +++ b/src/main/java/com/google/genai/types/DynamicRetrievalConfig.java @@ -31,7 +31,7 @@ public abstract class DynamicRetrievalConfig extends JsonSerializable { /** The mode of the predictor to be used in dynamic retrieval. */ @JsonProperty("mode") - public abstract Optional mode(); + public abstract Optional mode(); /** * Optional. The threshold to be used in dynamic retrieval. If not set, a system default value is @@ -58,15 +58,7 @@ private static Builder create() { } @JsonProperty("mode") - public abstract Builder mode(DynamicRetrievalConfigMode mode); - - public Builder mode(DynamicRetrievalConfigMode.Known knownType) { - return mode(new DynamicRetrievalConfigMode(knownType)); - } - - public Builder mode(String mode) { - return mode(new DynamicRetrievalConfigMode(mode)); - } + public abstract Builder mode(String mode); @JsonProperty("dynamicThreshold") public abstract Builder dynamicThreshold(Float dynamicThreshold); diff --git a/src/main/java/com/google/genai/types/DynamicRetrievalConfigMode.java b/src/main/java/com/google/genai/types/DynamicRetrievalConfigMode.java deleted file mode 100644 index 4cc65d39510..00000000000 --- a/src/main/java/com/google/genai/types/DynamicRetrievalConfigMode.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Config for the dynamic retrieval config mode. */ -public class DynamicRetrievalConfigMode { - - /** Enum representing the known values for DynamicRetrievalConfigMode. */ - public enum Known { - MODE_UNSPECIFIED, - MODE_DYNAMIC, - DYNAMIC_RETRIEVAL_CONFIG_MODE_UNSPECIFIED - } - - private Known dynamicRetrievalConfigModeEnum; - private final String value; - - @JsonCreator - public DynamicRetrievalConfigMode(String value) { - this.value = value; - for (Known dynamicRetrievalConfigModeEnum : Known.values()) { - if (dynamicRetrievalConfigModeEnum.toString().equalsIgnoreCase(value)) { - this.dynamicRetrievalConfigModeEnum = dynamicRetrievalConfigModeEnum; - break; - } - } - if (this.dynamicRetrievalConfigModeEnum == null) { - this.dynamicRetrievalConfigModeEnum = Known.DYNAMIC_RETRIEVAL_CONFIG_MODE_UNSPECIFIED; - } - } - - public DynamicRetrievalConfigMode(Known knownValue) { - this.dynamicRetrievalConfigModeEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.dynamicRetrievalConfigModeEnum; - } -} diff --git a/src/main/java/com/google/genai/types/EditImageConfig.java b/src/main/java/com/google/genai/types/EditImageConfig.java index 5ce44c7e732..c817183d1cf 100644 --- a/src/main/java/com/google/genai/types/EditImageConfig.java +++ b/src/main/java/com/google/genai/types/EditImageConfig.java @@ -60,11 +60,11 @@ public abstract class EditImageConfig extends JsonSerializable { /** Filter level for safety filtering. */ @JsonProperty("safetyFilterLevel") - public abstract Optional safetyFilterLevel(); + public abstract Optional safetyFilterLevel(); /** Allows generation of people by the model. */ @JsonProperty("personGeneration") - public abstract Optional personGeneration(); + public abstract Optional personGeneration(); /** * Whether to report the safety scores of each generated image and the positive prompt in the @@ -82,7 +82,7 @@ public abstract class EditImageConfig extends JsonSerializable { /** Language of the text in the prompt. */ @JsonProperty("language") - public abstract Optional language(); + public abstract Optional language(); /** MIME type of the generated image. */ @JsonProperty("outputMimeType") @@ -94,7 +94,7 @@ public abstract class EditImageConfig extends JsonSerializable { /** Describes the editing mode for the request. */ @JsonProperty("editMode") - public abstract Optional editMode(); + public abstract Optional editMode(); /** * The number of sampling steps. A higher value has better image quality, while a lower value has @@ -139,26 +139,10 @@ private static Builder create() { public abstract Builder seed(Integer seed); @JsonProperty("safetyFilterLevel") - public abstract Builder safetyFilterLevel(SafetyFilterLevel safetyFilterLevel); - - public Builder safetyFilterLevel(SafetyFilterLevel.Known knownType) { - return safetyFilterLevel(new SafetyFilterLevel(knownType)); - } - - public Builder safetyFilterLevel(String safetyFilterLevel) { - return safetyFilterLevel(new SafetyFilterLevel(safetyFilterLevel)); - } + public abstract Builder safetyFilterLevel(String safetyFilterLevel); @JsonProperty("personGeneration") - public abstract Builder personGeneration(PersonGeneration personGeneration); - - public Builder personGeneration(PersonGeneration.Known knownType) { - return personGeneration(new PersonGeneration(knownType)); - } - - public Builder personGeneration(String personGeneration) { - return personGeneration(new PersonGeneration(personGeneration)); - } + public abstract Builder personGeneration(String personGeneration); @JsonProperty("includeSafetyAttributes") public abstract Builder includeSafetyAttributes(boolean includeSafetyAttributes); @@ -167,15 +151,7 @@ public Builder personGeneration(String personGeneration) { public abstract Builder includeRaiReason(boolean includeRaiReason); @JsonProperty("language") - public abstract Builder language(ImagePromptLanguage language); - - public Builder language(ImagePromptLanguage.Known knownType) { - return language(new ImagePromptLanguage(knownType)); - } - - public Builder language(String language) { - return language(new ImagePromptLanguage(language)); - } + public abstract Builder language(String language); @JsonProperty("outputMimeType") public abstract Builder outputMimeType(String outputMimeType); @@ -184,15 +160,7 @@ public Builder language(String language) { public abstract Builder outputCompressionQuality(Integer outputCompressionQuality); @JsonProperty("editMode") - public abstract Builder editMode(EditMode editMode); - - public Builder editMode(EditMode.Known knownType) { - return editMode(new EditMode(knownType)); - } - - public Builder editMode(String editMode) { - return editMode(new EditMode(editMode)); - } + public abstract Builder editMode(String editMode); @JsonProperty("baseSteps") public abstract Builder baseSteps(Integer baseSteps); diff --git a/src/main/java/com/google/genai/types/EditMode.java b/src/main/java/com/google/genai/types/EditMode.java deleted file mode 100644 index 47cd76a2fd8..00000000000 --- a/src/main/java/com/google/genai/types/EditMode.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Enum representing the Imagen 3 Edit mode. */ -public class EditMode { - - /** Enum representing the known values for EditMode. */ - public enum Known { - EDIT_MODE_DEFAULT, - EDIT_MODE_INPAINT_REMOVAL, - EDIT_MODE_INPAINT_INSERTION, - EDIT_MODE_OUTPAINT, - EDIT_MODE_CONTROLLED_EDITING, - EDIT_MODE_STYLE, - EDIT_MODE_BGSWAP, - EDIT_MODE_PRODUCT_IMAGE, - EDIT_MODE_UNSPECIFIED - } - - private Known editModeEnum; - private final String value; - - @JsonCreator - public EditMode(String value) { - this.value = value; - for (Known editModeEnum : Known.values()) { - if (editModeEnum.toString().equalsIgnoreCase(value)) { - this.editModeEnum = editModeEnum; - break; - } - } - if (this.editModeEnum == null) { - this.editModeEnum = Known.EDIT_MODE_UNSPECIFIED; - } - } - - public EditMode(Known knownValue) { - this.editModeEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.editModeEnum; - } -} diff --git a/src/main/java/com/google/genai/types/EndSensitivity.java b/src/main/java/com/google/genai/types/EndSensitivity.java deleted file mode 100644 index 6a206e8d516..00000000000 --- a/src/main/java/com/google/genai/types/EndSensitivity.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** End of speech sensitivity. */ -public class EndSensitivity { - - /** Enum representing the known values for EndSensitivity. */ - public enum Known { - END_SENSITIVITY_UNSPECIFIED, - END_SENSITIVITY_HIGH, - END_SENSITIVITY_LOW - } - - private Known endSensitivityEnum; - private final String value; - - @JsonCreator - public EndSensitivity(String value) { - this.value = value; - for (Known endSensitivityEnum : Known.values()) { - if (endSensitivityEnum.toString().equalsIgnoreCase(value)) { - this.endSensitivityEnum = endSensitivityEnum; - break; - } - } - if (this.endSensitivityEnum == null) { - this.endSensitivityEnum = Known.END_SENSITIVITY_UNSPECIFIED; - } - } - - public EndSensitivity(Known knownValue) { - this.endSensitivityEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.endSensitivityEnum; - } -} diff --git a/src/main/java/com/google/genai/types/ExecutableCode.java b/src/main/java/com/google/genai/types/ExecutableCode.java index 02aa06c4f34..8113d5817f4 100644 --- a/src/main/java/com/google/genai/types/ExecutableCode.java +++ b/src/main/java/com/google/genai/types/ExecutableCode.java @@ -39,7 +39,7 @@ public abstract class ExecutableCode extends JsonSerializable { /** Required. Programming language of the `code`. */ @JsonProperty("language") - public abstract Optional language(); + public abstract Optional language(); /** Instantiates a builder for ExecutableCode. */ public static Builder builder() { @@ -62,15 +62,7 @@ private static Builder create() { public abstract Builder code(String code); @JsonProperty("language") - public abstract Builder language(Language language); - - public Builder language(Language.Known knownType) { - return language(new Language(knownType)); - } - - public Builder language(String language) { - return language(new Language(language)); - } + public abstract Builder language(String language); public abstract ExecutableCode build(); } diff --git a/src/main/java/com/google/genai/types/FeatureSelectionPreference.java b/src/main/java/com/google/genai/types/FeatureSelectionPreference.java deleted file mode 100644 index b3b746ca612..00000000000 --- a/src/main/java/com/google/genai/types/FeatureSelectionPreference.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Options for feature selection preference. */ -public class FeatureSelectionPreference { - - /** Enum representing the known values for FeatureSelectionPreference. */ - public enum Known { - FEATURE_SELECTION_PREFERENCE_UNSPECIFIED, - PRIORITIZE_QUALITY, - BALANCED, - PRIORITIZE_COST - } - - private Known featureSelectionPreferenceEnum; - private final String value; - - @JsonCreator - public FeatureSelectionPreference(String value) { - this.value = value; - for (Known featureSelectionPreferenceEnum : Known.values()) { - if (featureSelectionPreferenceEnum.toString().equalsIgnoreCase(value)) { - this.featureSelectionPreferenceEnum = featureSelectionPreferenceEnum; - break; - } - } - if (this.featureSelectionPreferenceEnum == null) { - this.featureSelectionPreferenceEnum = Known.FEATURE_SELECTION_PREFERENCE_UNSPECIFIED; - } - } - - public FeatureSelectionPreference(Known knownValue) { - this.featureSelectionPreferenceEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.featureSelectionPreferenceEnum; - } -} diff --git a/src/main/java/com/google/genai/types/FinishReason.java b/src/main/java/com/google/genai/types/FinishReason.java deleted file mode 100644 index 24ddaae8045..00000000000 --- a/src/main/java/com/google/genai/types/FinishReason.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** - * Output only. The reason why the model stopped generating tokens. - * - *

If empty, the model has not stopped generating the tokens. - */ -public class FinishReason { - - /** Enum representing the known values for FinishReason. */ - public enum Known { - FINISH_REASON_UNSPECIFIED, - STOP, - MAX_TOKENS, - SAFETY, - RECITATION, - LANGUAGE, - OTHER, - BLOCKLIST, - PROHIBITED_CONTENT, - SPII, - MALFORMED_FUNCTION_CALL, - IMAGE_SAFETY - } - - private Known finishReasonEnum; - private final String value; - - @JsonCreator - public FinishReason(String value) { - this.value = value; - for (Known finishReasonEnum : Known.values()) { - if (finishReasonEnum.toString().equalsIgnoreCase(value)) { - this.finishReasonEnum = finishReasonEnum; - break; - } - } - if (this.finishReasonEnum == null) { - this.finishReasonEnum = Known.FINISH_REASON_UNSPECIFIED; - } - } - - public FinishReason(Known knownValue) { - this.finishReasonEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.finishReasonEnum; - } -} diff --git a/src/main/java/com/google/genai/types/FunctionCallingConfig.java b/src/main/java/com/google/genai/types/FunctionCallingConfig.java index 08105de9b3b..cb30626ce94 100644 --- a/src/main/java/com/google/genai/types/FunctionCallingConfig.java +++ b/src/main/java/com/google/genai/types/FunctionCallingConfig.java @@ -32,7 +32,7 @@ public abstract class FunctionCallingConfig extends JsonSerializable { /** Optional. Function calling mode. */ @JsonProperty("mode") - public abstract Optional mode(); + public abstract Optional mode(); /** * Optional. Function names to call. Only set when the Mode is ANY. Function names should match @@ -60,15 +60,7 @@ private static Builder create() { } @JsonProperty("mode") - public abstract Builder mode(FunctionCallingConfigMode mode); - - public Builder mode(FunctionCallingConfigMode.Known knownType) { - return mode(new FunctionCallingConfigMode(knownType)); - } - - public Builder mode(String mode) { - return mode(new FunctionCallingConfigMode(mode)); - } + public abstract Builder mode(String mode); @JsonProperty("allowedFunctionNames") public abstract Builder allowedFunctionNames(List allowedFunctionNames); diff --git a/src/main/java/com/google/genai/types/FunctionCallingConfigMode.java b/src/main/java/com/google/genai/types/FunctionCallingConfigMode.java deleted file mode 100644 index c84f7c294c0..00000000000 --- a/src/main/java/com/google/genai/types/FunctionCallingConfigMode.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Config for the function calling config mode. */ -public class FunctionCallingConfigMode { - - /** Enum representing the known values for FunctionCallingConfigMode. */ - public enum Known { - MODE_UNSPECIFIED, - AUTO, - ANY, - NONE, - FUNCTION_CALLING_CONFIG_MODE_UNSPECIFIED - } - - private Known functionCallingConfigModeEnum; - private final String value; - - @JsonCreator - public FunctionCallingConfigMode(String value) { - this.value = value; - for (Known functionCallingConfigModeEnum : Known.values()) { - if (functionCallingConfigModeEnum.toString().equalsIgnoreCase(value)) { - this.functionCallingConfigModeEnum = functionCallingConfigModeEnum; - break; - } - } - if (this.functionCallingConfigModeEnum == null) { - this.functionCallingConfigModeEnum = Known.FUNCTION_CALLING_CONFIG_MODE_UNSPECIFIED; - } - } - - public FunctionCallingConfigMode(Known knownValue) { - this.functionCallingConfigModeEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.functionCallingConfigModeEnum; - } -} diff --git a/src/main/java/com/google/genai/types/FunctionDeclaration.java b/src/main/java/com/google/genai/types/FunctionDeclaration.java index ac481de487f..1e4306eabdb 100644 --- a/src/main/java/com/google/genai/types/FunctionDeclaration.java +++ b/src/main/java/com/google/genai/types/FunctionDeclaration.java @@ -189,20 +189,19 @@ public static FunctionDeclaration fromMethod( */ private static Schema buildTypeSchema(String parameterName, Class parameterType) { Schema.Builder parameterSchemaBuilder = Schema.builder().title(parameterName); - switch (parameterType.getName()) { case "java.lang.String": - parameterSchemaBuilder = parameterSchemaBuilder.type("STRING"); + parameterSchemaBuilder.type("STRING"); break; case "boolean": - parameterSchemaBuilder = parameterSchemaBuilder.type("BOOLEAN"); + parameterSchemaBuilder.type("BOOLEAN"); break; case "int": - parameterSchemaBuilder = parameterSchemaBuilder.type("INTEGER"); + parameterSchemaBuilder.type("INTEGER"); break; case "double": case "float": - parameterSchemaBuilder = parameterSchemaBuilder.type("NUMBER"); + parameterSchemaBuilder.type("NUMBER"); break; default: throw new IllegalArgumentException( diff --git a/src/main/java/com/google/genai/types/GenerateContentConfig.java b/src/main/java/com/google/genai/types/GenerateContentConfig.java index fa8978e095b..0ca1f8962d2 100644 --- a/src/main/java/com/google/genai/types/GenerateContentConfig.java +++ b/src/main/java/com/google/genai/types/GenerateContentConfig.java @@ -163,7 +163,7 @@ public abstract class GenerateContentConfig extends JsonSerializable { /** If specified, the media resolution specified will be used. */ @JsonProperty("mediaResolution") - public abstract Optional mediaResolution(); + public abstract Optional mediaResolution(); /** The speech generation configuration. */ @JsonProperty("speechConfig") @@ -261,15 +261,7 @@ private static Builder create() { public abstract Builder responseModalities(List responseModalities); @JsonProperty("mediaResolution") - public abstract Builder mediaResolution(MediaResolution mediaResolution); - - public Builder mediaResolution(MediaResolution.Known knownType) { - return mediaResolution(new MediaResolution(knownType)); - } - - public Builder mediaResolution(String mediaResolution) { - return mediaResolution(new MediaResolution(mediaResolution)); - } + public abstract Builder mediaResolution(String mediaResolution); @JsonProperty("speechConfig") public abstract Builder speechConfig(SpeechConfig speechConfig); diff --git a/src/main/java/com/google/genai/types/GenerateContentResponse.java b/src/main/java/com/google/genai/types/GenerateContentResponse.java index 9aed1e7f4da..1bca0cdc61f 100644 --- a/src/main/java/com/google/genai/types/GenerateContentResponse.java +++ b/src/main/java/com/google/genai/types/GenerateContentResponse.java @@ -109,11 +109,8 @@ public static GenerateContentResponse fromJson(String jsonString) { private static final Logger logger = Logger.getLogger(GenerateContentResponse.class.getName()); - private static final ImmutableList EXPECTED_FINISH_REASONS = - ImmutableList.of( - FinishReason.Known.FINISH_REASON_UNSPECIFIED, - FinishReason.Known.STOP, - FinishReason.Known.MAX_TOKENS); + private static final ImmutableList EXPECTED_FINISH_REASONS = + ImmutableList.of("FINISH_REASON_UNSPECIFIED", "STOP", "MAX_TOKENS", ""); /** * Returns the list of parts in the first candidate of the response. @@ -251,7 +248,7 @@ public static GenerateContentResponse fromJson(String jsonString) { } /** Gets the finish reason in a GenerateContentResponse. */ - public FinishReason finishReason() { + public String finishReason() { List candidates = candidates().orElse(Arrays.asList(Candidate.builder().build())); if (candidates.size() > 1) { logger.warning( @@ -259,18 +256,14 @@ public FinishReason finishReason() { "This response has %d candidates, will only use the first candidate", candidates.size())); } - Optional finishReason = candidates.get(0).finishReason(); - if (!finishReason.isPresent()) { - return new FinishReason(FinishReason.Known.FINISH_REASON_UNSPECIFIED); - } - return finishReason.get(); + return candidates.get(0).finishReason().orElse(""); } /** Throws an exception if the response finishes unexpectedly. */ @InternalApi public void checkFinishReason() { - FinishReason finishReason = this.finishReason(); - if (!EXPECTED_FINISH_REASONS.contains(finishReason.knownEnum())) { + String finishReason = this.finishReason(); + if (!EXPECTED_FINISH_REASONS.contains(finishReason)) { throw new IllegalArgumentException( String.format("The response finished unexpectedly with reason %s.", finishReason)); } diff --git a/src/main/java/com/google/genai/types/GenerateContentResponsePromptFeedback.java b/src/main/java/com/google/genai/types/GenerateContentResponsePromptFeedback.java index 1da134a3d44..2b71d41d450 100644 --- a/src/main/java/com/google/genai/types/GenerateContentResponsePromptFeedback.java +++ b/src/main/java/com/google/genai/types/GenerateContentResponsePromptFeedback.java @@ -32,7 +32,7 @@ public abstract class GenerateContentResponsePromptFeedback extends JsonSerializable { /** Output only. Blocked reason. */ @JsonProperty("blockReason") - public abstract Optional blockReason(); + public abstract Optional blockReason(); /** Output only. A readable block reason message. */ @JsonProperty("blockReasonMessage") @@ -63,15 +63,7 @@ private static Builder create() { } @JsonProperty("blockReason") - public abstract Builder blockReason(BlockedReason blockReason); - - public Builder blockReason(BlockedReason.Known knownType) { - return blockReason(new BlockedReason(knownType)); - } - - public Builder blockReason(String blockReason) { - return blockReason(new BlockedReason(blockReason)); - } + public abstract Builder blockReason(String blockReason); @JsonProperty("blockReasonMessage") public abstract Builder blockReasonMessage(String blockReasonMessage); diff --git a/src/main/java/com/google/genai/types/GenerateContentResponseUsageMetadata.java b/src/main/java/com/google/genai/types/GenerateContentResponseUsageMetadata.java index 3bca80f067e..e2529fe4297 100644 --- a/src/main/java/com/google/genai/types/GenerateContentResponseUsageMetadata.java +++ b/src/main/java/com/google/genai/types/GenerateContentResponseUsageMetadata.java @@ -78,7 +78,7 @@ public abstract class GenerateContentResponseUsageMetadata extends JsonSerializa * Throughput quota. */ @JsonProperty("trafficType") - public abstract Optional trafficType(); + public abstract Optional trafficType(); /** Instantiates a builder for GenerateContentResponseUsageMetadata. */ public static Builder builder() { @@ -133,15 +133,7 @@ public abstract Builder toolUsePromptTokensDetails( public abstract Builder totalTokenCount(Integer totalTokenCount); @JsonProperty("trafficType") - public abstract Builder trafficType(TrafficType trafficType); - - public Builder trafficType(TrafficType.Known knownType) { - return trafficType(new TrafficType(knownType)); - } - - public Builder trafficType(String trafficType) { - return trafficType(new TrafficType(trafficType)); - } + public abstract Builder trafficType(String trafficType); public abstract GenerateContentResponseUsageMetadata build(); } diff --git a/src/main/java/com/google/genai/types/GenerateImagesConfig.java b/src/main/java/com/google/genai/types/GenerateImagesConfig.java index eda299da2e9..99dba897cb3 100644 --- a/src/main/java/com/google/genai/types/GenerateImagesConfig.java +++ b/src/main/java/com/google/genai/types/GenerateImagesConfig.java @@ -60,11 +60,11 @@ public abstract class GenerateImagesConfig extends JsonSerializable { /** Filter level for safety filtering. */ @JsonProperty("safetyFilterLevel") - public abstract Optional safetyFilterLevel(); + public abstract Optional safetyFilterLevel(); /** Allows generation of people by the model. */ @JsonProperty("personGeneration") - public abstract Optional personGeneration(); + public abstract Optional personGeneration(); /** * Whether to report the safety scores of each generated image and the positive prompt in the @@ -82,7 +82,7 @@ public abstract class GenerateImagesConfig extends JsonSerializable { /** Language of the text in the prompt. */ @JsonProperty("language") - public abstract Optional language(); + public abstract Optional language(); /** MIME type of the generated image. */ @JsonProperty("outputMimeType") @@ -136,26 +136,10 @@ private static Builder create() { public abstract Builder seed(Integer seed); @JsonProperty("safetyFilterLevel") - public abstract Builder safetyFilterLevel(SafetyFilterLevel safetyFilterLevel); - - public Builder safetyFilterLevel(SafetyFilterLevel.Known knownType) { - return safetyFilterLevel(new SafetyFilterLevel(knownType)); - } - - public Builder safetyFilterLevel(String safetyFilterLevel) { - return safetyFilterLevel(new SafetyFilterLevel(safetyFilterLevel)); - } + public abstract Builder safetyFilterLevel(String safetyFilterLevel); @JsonProperty("personGeneration") - public abstract Builder personGeneration(PersonGeneration personGeneration); - - public Builder personGeneration(PersonGeneration.Known knownType) { - return personGeneration(new PersonGeneration(knownType)); - } - - public Builder personGeneration(String personGeneration) { - return personGeneration(new PersonGeneration(personGeneration)); - } + public abstract Builder personGeneration(String personGeneration); @JsonProperty("includeSafetyAttributes") public abstract Builder includeSafetyAttributes(boolean includeSafetyAttributes); @@ -164,15 +148,7 @@ public Builder personGeneration(String personGeneration) { public abstract Builder includeRaiReason(boolean includeRaiReason); @JsonProperty("language") - public abstract Builder language(ImagePromptLanguage language); - - public Builder language(ImagePromptLanguage.Known knownType) { - return language(new ImagePromptLanguage(knownType)); - } - - public Builder language(String language) { - return language(new ImagePromptLanguage(language)); - } + public abstract Builder language(String language); @JsonProperty("outputMimeType") public abstract Builder outputMimeType(String outputMimeType); diff --git a/src/main/java/com/google/genai/types/GenerationConfig.java b/src/main/java/com/google/genai/types/GenerationConfig.java index eaf6c8d1c98..feec1afd0c9 100644 --- a/src/main/java/com/google/genai/types/GenerationConfig.java +++ b/src/main/java/com/google/genai/types/GenerationConfig.java @@ -52,7 +52,7 @@ public abstract class GenerationConfig extends JsonSerializable { /** Optional. If specified, the media resolution specified will be used. */ @JsonProperty("mediaResolution") - public abstract Optional mediaResolution(); + public abstract Optional mediaResolution(); /** Optional. Positive penalties. */ @JsonProperty("presencePenalty") @@ -138,15 +138,7 @@ private static Builder create() { public abstract Builder maxOutputTokens(Integer maxOutputTokens); @JsonProperty("mediaResolution") - public abstract Builder mediaResolution(MediaResolution mediaResolution); - - public Builder mediaResolution(MediaResolution.Known knownType) { - return mediaResolution(new MediaResolution(knownType)); - } - - public Builder mediaResolution(String mediaResolution) { - return mediaResolution(new MediaResolution(mediaResolution)); - } + public abstract Builder mediaResolution(String mediaResolution); @JsonProperty("presencePenalty") public abstract Builder presencePenalty(Float presencePenalty); diff --git a/src/main/java/com/google/genai/types/GenerationConfigRoutingConfigAutoRoutingMode.java b/src/main/java/com/google/genai/types/GenerationConfigRoutingConfigAutoRoutingMode.java index 0a196921b5f..c35de4f6033 100644 --- a/src/main/java/com/google/genai/types/GenerationConfigRoutingConfigAutoRoutingMode.java +++ b/src/main/java/com/google/genai/types/GenerationConfigRoutingConfigAutoRoutingMode.java @@ -34,7 +34,7 @@ public abstract class GenerationConfigRoutingConfigAutoRoutingMode extends JsonSerializable { /** The model routing preference. */ @JsonProperty("modelRoutingPreference") - public abstract Optional modelRoutingPreference(); + public abstract Optional modelRoutingPreference(); /** Instantiates a builder for GenerationConfigRoutingConfigAutoRoutingMode. */ public static Builder builder() { @@ -57,15 +57,7 @@ private static Builder create() { } @JsonProperty("modelRoutingPreference") - public abstract Builder modelRoutingPreference(ModelRoutingPreference modelRoutingPreference); - - public Builder modelRoutingPreference(ModelRoutingPreference.Known knownType) { - return modelRoutingPreference(new ModelRoutingPreference(knownType)); - } - - public Builder modelRoutingPreference(String modelRoutingPreference) { - return modelRoutingPreference(new ModelRoutingPreference(modelRoutingPreference)); - } + public abstract Builder modelRoutingPreference(String modelRoutingPreference); public abstract GenerationConfigRoutingConfigAutoRoutingMode build(); } diff --git a/src/main/java/com/google/genai/types/HarmBlockMethod.java b/src/main/java/com/google/genai/types/HarmBlockMethod.java deleted file mode 100644 index 5f12aff1b63..00000000000 --- a/src/main/java/com/google/genai/types/HarmBlockMethod.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** - * Optional. Specify if the threshold is used for probability or severity score. If not specified, - * the threshold is used for probability score. - */ -public class HarmBlockMethod { - - /** Enum representing the known values for HarmBlockMethod. */ - public enum Known { - HARM_BLOCK_METHOD_UNSPECIFIED, - SEVERITY, - PROBABILITY - } - - private Known harmBlockMethodEnum; - private final String value; - - @JsonCreator - public HarmBlockMethod(String value) { - this.value = value; - for (Known harmBlockMethodEnum : Known.values()) { - if (harmBlockMethodEnum.toString().equalsIgnoreCase(value)) { - this.harmBlockMethodEnum = harmBlockMethodEnum; - break; - } - } - if (this.harmBlockMethodEnum == null) { - this.harmBlockMethodEnum = Known.HARM_BLOCK_METHOD_UNSPECIFIED; - } - } - - public HarmBlockMethod(Known knownValue) { - this.harmBlockMethodEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.harmBlockMethodEnum; - } -} diff --git a/src/main/java/com/google/genai/types/HarmBlockThreshold.java b/src/main/java/com/google/genai/types/HarmBlockThreshold.java deleted file mode 100644 index d20913a50b1..00000000000 --- a/src/main/java/com/google/genai/types/HarmBlockThreshold.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Required. The harm block threshold. */ -public class HarmBlockThreshold { - - /** Enum representing the known values for HarmBlockThreshold. */ - public enum Known { - HARM_BLOCK_THRESHOLD_UNSPECIFIED, - BLOCK_LOW_AND_ABOVE, - BLOCK_MEDIUM_AND_ABOVE, - BLOCK_ONLY_HIGH, - BLOCK_NONE, - OFF - } - - private Known harmBlockThresholdEnum; - private final String value; - - @JsonCreator - public HarmBlockThreshold(String value) { - this.value = value; - for (Known harmBlockThresholdEnum : Known.values()) { - if (harmBlockThresholdEnum.toString().equalsIgnoreCase(value)) { - this.harmBlockThresholdEnum = harmBlockThresholdEnum; - break; - } - } - if (this.harmBlockThresholdEnum == null) { - this.harmBlockThresholdEnum = Known.HARM_BLOCK_THRESHOLD_UNSPECIFIED; - } - } - - public HarmBlockThreshold(Known knownValue) { - this.harmBlockThresholdEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.harmBlockThresholdEnum; - } -} diff --git a/src/main/java/com/google/genai/types/HarmCategory.java b/src/main/java/com/google/genai/types/HarmCategory.java deleted file mode 100644 index 907752d01df..00000000000 --- a/src/main/java/com/google/genai/types/HarmCategory.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Required. Harm category. */ -public class HarmCategory { - - /** Enum representing the known values for HarmCategory. */ - public enum Known { - HARM_CATEGORY_UNSPECIFIED, - HARM_CATEGORY_HATE_SPEECH, - HARM_CATEGORY_DANGEROUS_CONTENT, - HARM_CATEGORY_HARASSMENT, - HARM_CATEGORY_SEXUALLY_EXPLICIT, - HARM_CATEGORY_CIVIC_INTEGRITY - } - - private Known harmCategoryEnum; - private final String value; - - @JsonCreator - public HarmCategory(String value) { - this.value = value; - for (Known harmCategoryEnum : Known.values()) { - if (harmCategoryEnum.toString().equalsIgnoreCase(value)) { - this.harmCategoryEnum = harmCategoryEnum; - break; - } - } - if (this.harmCategoryEnum == null) { - this.harmCategoryEnum = Known.HARM_CATEGORY_UNSPECIFIED; - } - } - - public HarmCategory(Known knownValue) { - this.harmCategoryEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.harmCategoryEnum; - } -} diff --git a/src/main/java/com/google/genai/types/HarmProbability.java b/src/main/java/com/google/genai/types/HarmProbability.java deleted file mode 100644 index 323bd303cff..00000000000 --- a/src/main/java/com/google/genai/types/HarmProbability.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Output only. Harm probability levels in the content. */ -public class HarmProbability { - - /** Enum representing the known values for HarmProbability. */ - public enum Known { - HARM_PROBABILITY_UNSPECIFIED, - NEGLIGIBLE, - LOW, - MEDIUM, - HIGH - } - - private Known harmProbabilityEnum; - private final String value; - - @JsonCreator - public HarmProbability(String value) { - this.value = value; - for (Known harmProbabilityEnum : Known.values()) { - if (harmProbabilityEnum.toString().equalsIgnoreCase(value)) { - this.harmProbabilityEnum = harmProbabilityEnum; - break; - } - } - if (this.harmProbabilityEnum == null) { - this.harmProbabilityEnum = Known.HARM_PROBABILITY_UNSPECIFIED; - } - } - - public HarmProbability(Known knownValue) { - this.harmProbabilityEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.harmProbabilityEnum; - } -} diff --git a/src/main/java/com/google/genai/types/HarmSeverity.java b/src/main/java/com/google/genai/types/HarmSeverity.java deleted file mode 100644 index e053dc5e310..00000000000 --- a/src/main/java/com/google/genai/types/HarmSeverity.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Output only. Harm severity levels in the content. */ -public class HarmSeverity { - - /** Enum representing the known values for HarmSeverity. */ - public enum Known { - HARM_SEVERITY_UNSPECIFIED, - HARM_SEVERITY_NEGLIGIBLE, - HARM_SEVERITY_LOW, - HARM_SEVERITY_MEDIUM, - HARM_SEVERITY_HIGH - } - - private Known harmSeverityEnum; - private final String value; - - @JsonCreator - public HarmSeverity(String value) { - this.value = value; - for (Known harmSeverityEnum : Known.values()) { - if (harmSeverityEnum.toString().equalsIgnoreCase(value)) { - this.harmSeverityEnum = harmSeverityEnum; - break; - } - } - if (this.harmSeverityEnum == null) { - this.harmSeverityEnum = Known.HARM_SEVERITY_UNSPECIFIED; - } - } - - public HarmSeverity(Known knownValue) { - this.harmSeverityEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.harmSeverityEnum; - } -} diff --git a/src/main/java/com/google/genai/types/ImagePromptLanguage.java b/src/main/java/com/google/genai/types/ImagePromptLanguage.java deleted file mode 100644 index 08110a34b65..00000000000 --- a/src/main/java/com/google/genai/types/ImagePromptLanguage.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Enum that specifies the language of the text in the prompt. */ -public class ImagePromptLanguage { - - /** Enum representing the known values for ImagePromptLanguage. */ - public enum Known { - AUTO, - EN, - JA, - KO, - HI, - IMAGE_PROMPT_LANGUAGE_UNSPECIFIED - } - - private Known imagePromptLanguageEnum; - private final String value; - - @JsonCreator - public ImagePromptLanguage(String value) { - this.value = value; - for (Known imagePromptLanguageEnum : Known.values()) { - if (imagePromptLanguageEnum.toString().equalsIgnoreCase(value)) { - this.imagePromptLanguageEnum = imagePromptLanguageEnum; - break; - } - } - if (this.imagePromptLanguageEnum == null) { - this.imagePromptLanguageEnum = Known.IMAGE_PROMPT_LANGUAGE_UNSPECIFIED; - } - } - - public ImagePromptLanguage(Known knownValue) { - this.imagePromptLanguageEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.imagePromptLanguageEnum; - } -} diff --git a/src/main/java/com/google/genai/types/Language.java b/src/main/java/com/google/genai/types/Language.java deleted file mode 100644 index 94da1260369..00000000000 --- a/src/main/java/com/google/genai/types/Language.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Required. Programming language of the `code`. */ -public class Language { - - /** Enum representing the known values for Language. */ - public enum Known { - LANGUAGE_UNSPECIFIED, - PYTHON - } - - private Known languageEnum; - private final String value; - - @JsonCreator - public Language(String value) { - this.value = value; - for (Known languageEnum : Known.values()) { - if (languageEnum.toString().equalsIgnoreCase(value)) { - this.languageEnum = languageEnum; - break; - } - } - if (this.languageEnum == null) { - this.languageEnum = Known.LANGUAGE_UNSPECIFIED; - } - } - - public Language(Known knownValue) { - this.languageEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.languageEnum; - } -} diff --git a/src/main/java/com/google/genai/types/LiveConnectConfig.java b/src/main/java/com/google/genai/types/LiveConnectConfig.java index 69fe0750554..f7eeed7a7d7 100644 --- a/src/main/java/com/google/genai/types/LiveConnectConfig.java +++ b/src/main/java/com/google/genai/types/LiveConnectConfig.java @@ -22,7 +22,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.auto.value.AutoValue; -import com.google.common.collect.ImmutableList; import com.google.genai.JsonSerializable; import java.util.List; import java.util.Optional; @@ -36,7 +35,7 @@ public abstract class LiveConnectConfig extends JsonSerializable { * return. Defaults to AUDIO if not specified. */ @JsonProperty("responseModalities") - public abstract Optional> responseModalities(); + public abstract Optional> responseModalities(); /** * Value that controls the degree of randomness in token selection. Lower temperatures are good @@ -69,7 +68,7 @@ public abstract class LiveConnectConfig extends JsonSerializable { /** If specified, the media resolution specified will be used. */ @JsonProperty("mediaResolution") - public abstract Optional mediaResolution(); + public abstract Optional mediaResolution(); /** * When ``seed`` is fixed to a specific number, the model makes a best effort to provide the same @@ -138,19 +137,7 @@ private static Builder create() { } @JsonProperty("responseModalities") - public abstract Builder responseModalities(List responseModalities); - - public Builder responseModalitiesFromKnown(List knownTypes) { - List listItems = - knownTypes.stream().map(Modality::new).collect(ImmutableList.toImmutableList()); - return responseModalities(listItems); - } - - public Builder responseModalitiesFromString(List responseModalities) { - List listItems = - responseModalities.stream().map(Modality::new).collect(ImmutableList.toImmutableList()); - return responseModalities(listItems); - } + public abstract Builder responseModalities(List responseModalities); @JsonProperty("temperature") public abstract Builder temperature(Float temperature); @@ -165,15 +152,7 @@ public Builder responseModalitiesFromString(List responseModalities) { public abstract Builder maxOutputTokens(Integer maxOutputTokens); @JsonProperty("mediaResolution") - public abstract Builder mediaResolution(MediaResolution mediaResolution); - - public Builder mediaResolution(MediaResolution.Known knownType) { - return mediaResolution(new MediaResolution(knownType)); - } - - public Builder mediaResolution(String mediaResolution) { - return mediaResolution(new MediaResolution(mediaResolution)); - } + public abstract Builder mediaResolution(String mediaResolution); @JsonProperty("seed") public abstract Builder seed(Integer seed); diff --git a/src/main/java/com/google/genai/types/MaskReferenceConfig.java b/src/main/java/com/google/genai/types/MaskReferenceConfig.java index 45d9bdb6315..20702c6ac89 100644 --- a/src/main/java/com/google/genai/types/MaskReferenceConfig.java +++ b/src/main/java/com/google/genai/types/MaskReferenceConfig.java @@ -35,7 +35,7 @@ public abstract class MaskReferenceConfig extends JsonSerializable { * MASK_MODE_USER_PROVIDED is used). */ @JsonProperty("maskMode") - public abstract Optional maskMode(); + public abstract Optional maskMode(); /** * A list of up to 5 class ids to use for semantic segmentation. Automatically creates an image @@ -66,15 +66,7 @@ private static Builder create() { } @JsonProperty("maskMode") - public abstract Builder maskMode(MaskReferenceMode maskMode); - - public Builder maskMode(MaskReferenceMode.Known knownType) { - return maskMode(new MaskReferenceMode(knownType)); - } - - public Builder maskMode(String maskMode) { - return maskMode(new MaskReferenceMode(maskMode)); - } + public abstract Builder maskMode(String maskMode); @JsonProperty("segmentationClasses") public abstract Builder segmentationClasses(List segmentationClasses); diff --git a/src/main/java/com/google/genai/types/MaskReferenceMode.java b/src/main/java/com/google/genai/types/MaskReferenceMode.java deleted file mode 100644 index 9f8cd391a7b..00000000000 --- a/src/main/java/com/google/genai/types/MaskReferenceMode.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Enum representing the mask mode of a mask reference image. */ -public class MaskReferenceMode { - - /** Enum representing the known values for MaskReferenceMode. */ - public enum Known { - MASK_MODE_DEFAULT, - MASK_MODE_USER_PROVIDED, - MASK_MODE_BACKGROUND, - MASK_MODE_FOREGROUND, - MASK_MODE_SEMANTIC, - MASK_REFERENCE_MODE_UNSPECIFIED - } - - private Known maskReferenceModeEnum; - private final String value; - - @JsonCreator - public MaskReferenceMode(String value) { - this.value = value; - for (Known maskReferenceModeEnum : Known.values()) { - if (maskReferenceModeEnum.toString().equalsIgnoreCase(value)) { - this.maskReferenceModeEnum = maskReferenceModeEnum; - break; - } - } - if (this.maskReferenceModeEnum == null) { - this.maskReferenceModeEnum = Known.MASK_REFERENCE_MODE_UNSPECIFIED; - } - } - - public MaskReferenceMode(Known knownValue) { - this.maskReferenceModeEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.maskReferenceModeEnum; - } -} diff --git a/src/main/java/com/google/genai/types/MediaModality.java b/src/main/java/com/google/genai/types/MediaModality.java deleted file mode 100644 index 1f7becdcd97..00000000000 --- a/src/main/java/com/google/genai/types/MediaModality.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Server content modalities. */ -public class MediaModality { - - /** Enum representing the known values for MediaModality. */ - public enum Known { - MODALITY_UNSPECIFIED, - TEXT, - IMAGE, - VIDEO, - AUDIO, - DOCUMENT, - MEDIA_MODALITY_UNSPECIFIED - } - - private Known mediaModalityEnum; - private final String value; - - @JsonCreator - public MediaModality(String value) { - this.value = value; - for (Known mediaModalityEnum : Known.values()) { - if (mediaModalityEnum.toString().equalsIgnoreCase(value)) { - this.mediaModalityEnum = mediaModalityEnum; - break; - } - } - if (this.mediaModalityEnum == null) { - this.mediaModalityEnum = Known.MEDIA_MODALITY_UNSPECIFIED; - } - } - - public MediaModality(Known knownValue) { - this.mediaModalityEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.mediaModalityEnum; - } -} diff --git a/src/main/java/com/google/genai/types/MediaResolution.java b/src/main/java/com/google/genai/types/MediaResolution.java deleted file mode 100644 index 75276a27177..00000000000 --- a/src/main/java/com/google/genai/types/MediaResolution.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** The media resolution to use. */ -public class MediaResolution { - - /** Enum representing the known values for MediaResolution. */ - public enum Known { - MEDIA_RESOLUTION_UNSPECIFIED, - MEDIA_RESOLUTION_LOW, - MEDIA_RESOLUTION_MEDIUM, - MEDIA_RESOLUTION_HIGH - } - - private Known mediaResolutionEnum; - private final String value; - - @JsonCreator - public MediaResolution(String value) { - this.value = value; - for (Known mediaResolutionEnum : Known.values()) { - if (mediaResolutionEnum.toString().equalsIgnoreCase(value)) { - this.mediaResolutionEnum = mediaResolutionEnum; - break; - } - } - if (this.mediaResolutionEnum == null) { - this.mediaResolutionEnum = Known.MEDIA_RESOLUTION_UNSPECIFIED; - } - } - - public MediaResolution(Known knownValue) { - this.mediaResolutionEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.mediaResolutionEnum; - } -} diff --git a/src/main/java/com/google/genai/types/Modality.java b/src/main/java/com/google/genai/types/Modality.java deleted file mode 100644 index 41cf1ac04a1..00000000000 --- a/src/main/java/com/google/genai/types/Modality.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Server content modalities. */ -public class Modality { - - /** Enum representing the known values for Modality. */ - public enum Known { - MODALITY_UNSPECIFIED, - TEXT, - IMAGE, - AUDIO - } - - private Known modalityEnum; - private final String value; - - @JsonCreator - public Modality(String value) { - this.value = value; - for (Known modalityEnum : Known.values()) { - if (modalityEnum.toString().equalsIgnoreCase(value)) { - this.modalityEnum = modalityEnum; - break; - } - } - if (this.modalityEnum == null) { - this.modalityEnum = Known.MODALITY_UNSPECIFIED; - } - } - - public Modality(Known knownValue) { - this.modalityEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.modalityEnum; - } -} diff --git a/src/main/java/com/google/genai/types/ModalityTokenCount.java b/src/main/java/com/google/genai/types/ModalityTokenCount.java index d4ca57ccafd..2e5b501c0d7 100644 --- a/src/main/java/com/google/genai/types/ModalityTokenCount.java +++ b/src/main/java/com/google/genai/types/ModalityTokenCount.java @@ -31,7 +31,7 @@ public abstract class ModalityTokenCount extends JsonSerializable { /** The modality associated with this token count. */ @JsonProperty("modality") - public abstract Optional modality(); + public abstract Optional modality(); /** Number of tokens. */ @JsonProperty("tokenCount") @@ -55,15 +55,7 @@ private static Builder create() { } @JsonProperty("modality") - public abstract Builder modality(MediaModality modality); - - public Builder modality(MediaModality.Known knownType) { - return modality(new MediaModality(knownType)); - } - - public Builder modality(String modality) { - return modality(new MediaModality(modality)); - } + public abstract Builder modality(String modality); @JsonProperty("tokenCount") public abstract Builder tokenCount(Integer tokenCount); diff --git a/src/main/java/com/google/genai/types/Mode.java b/src/main/java/com/google/genai/types/Mode.java deleted file mode 100644 index e0ccf1dfddd..00000000000 --- a/src/main/java/com/google/genai/types/Mode.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** The mode of the predictor to be used in dynamic retrieval. */ -public class Mode { - - /** Enum representing the known values for Mode. */ - public enum Known { - MODE_UNSPECIFIED, - MODE_DYNAMIC - } - - private Known modeEnum; - private final String value; - - @JsonCreator - public Mode(String value) { - this.value = value; - for (Known modeEnum : Known.values()) { - if (modeEnum.toString().equalsIgnoreCase(value)) { - this.modeEnum = modeEnum; - break; - } - } - if (this.modeEnum == null) { - this.modeEnum = Known.MODE_UNSPECIFIED; - } - } - - public Mode(Known knownValue) { - this.modeEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.modeEnum; - } -} diff --git a/src/main/java/com/google/genai/types/ModelRoutingPreference.java b/src/main/java/com/google/genai/types/ModelRoutingPreference.java deleted file mode 100644 index 4b6da9c9cc5..00000000000 --- a/src/main/java/com/google/genai/types/ModelRoutingPreference.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** The model routing preference. */ -public class ModelRoutingPreference { - - /** Enum representing the known values for ModelRoutingPreference. */ - public enum Known { - UNKNOWN, - PRIORITIZE_QUALITY, - BALANCED, - PRIORITIZE_COST, - MODEL_ROUTING_PREFERENCE_UNSPECIFIED - } - - private Known modelRoutingPreferenceEnum; - private final String value; - - @JsonCreator - public ModelRoutingPreference(String value) { - this.value = value; - for (Known modelRoutingPreferenceEnum : Known.values()) { - if (modelRoutingPreferenceEnum.toString().equalsIgnoreCase(value)) { - this.modelRoutingPreferenceEnum = modelRoutingPreferenceEnum; - break; - } - } - if (this.modelRoutingPreferenceEnum == null) { - this.modelRoutingPreferenceEnum = Known.MODEL_ROUTING_PREFERENCE_UNSPECIFIED; - } - } - - public ModelRoutingPreference(Known knownValue) { - this.modelRoutingPreferenceEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.modelRoutingPreferenceEnum; - } -} diff --git a/src/main/java/com/google/genai/types/ModelSelectionConfig.java b/src/main/java/com/google/genai/types/ModelSelectionConfig.java index ec5fe1c15ac..6ea122a3b58 100644 --- a/src/main/java/com/google/genai/types/ModelSelectionConfig.java +++ b/src/main/java/com/google/genai/types/ModelSelectionConfig.java @@ -31,7 +31,7 @@ public abstract class ModelSelectionConfig extends JsonSerializable { /** Options for feature selection preference. */ @JsonProperty("featureSelectionPreference") - public abstract Optional featureSelectionPreference(); + public abstract Optional featureSelectionPreference(); /** Instantiates a builder for ModelSelectionConfig. */ public static Builder builder() { @@ -51,16 +51,7 @@ private static Builder create() { } @JsonProperty("featureSelectionPreference") - public abstract Builder featureSelectionPreference( - FeatureSelectionPreference featureSelectionPreference); - - public Builder featureSelectionPreference(FeatureSelectionPreference.Known knownType) { - return featureSelectionPreference(new FeatureSelectionPreference(knownType)); - } - - public Builder featureSelectionPreference(String featureSelectionPreference) { - return featureSelectionPreference(new FeatureSelectionPreference(featureSelectionPreference)); - } + public abstract Builder featureSelectionPreference(String featureSelectionPreference); public abstract ModelSelectionConfig build(); } diff --git a/src/main/java/com/google/genai/types/Outcome.java b/src/main/java/com/google/genai/types/Outcome.java deleted file mode 100644 index adedf92fed0..00000000000 --- a/src/main/java/com/google/genai/types/Outcome.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Required. Outcome of the code execution. */ -public class Outcome { - - /** Enum representing the known values for Outcome. */ - public enum Known { - OUTCOME_UNSPECIFIED, - OUTCOME_OK, - OUTCOME_FAILED, - OUTCOME_DEADLINE_EXCEEDED - } - - private Known outcomeEnum; - private final String value; - - @JsonCreator - public Outcome(String value) { - this.value = value; - for (Known outcomeEnum : Known.values()) { - if (outcomeEnum.toString().equalsIgnoreCase(value)) { - this.outcomeEnum = outcomeEnum; - break; - } - } - if (this.outcomeEnum == null) { - this.outcomeEnum = Known.OUTCOME_UNSPECIFIED; - } - } - - public Outcome(Known knownValue) { - this.outcomeEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.outcomeEnum; - } -} diff --git a/src/main/java/com/google/genai/types/PersonGeneration.java b/src/main/java/com/google/genai/types/PersonGeneration.java deleted file mode 100644 index 3d9cedb249e..00000000000 --- a/src/main/java/com/google/genai/types/PersonGeneration.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Enum that controls the generation of people. */ -public class PersonGeneration { - - /** Enum representing the known values for PersonGeneration. */ - public enum Known { - DONT_ALLOW, - ALLOW_ADULT, - ALLOW_ALL, - PERSON_GENERATION_UNSPECIFIED - } - - private Known personGenerationEnum; - private final String value; - - @JsonCreator - public PersonGeneration(String value) { - this.value = value; - for (Known personGenerationEnum : Known.values()) { - if (personGenerationEnum.toString().equalsIgnoreCase(value)) { - this.personGenerationEnum = personGenerationEnum; - break; - } - } - if (this.personGenerationEnum == null) { - this.personGenerationEnum = Known.PERSON_GENERATION_UNSPECIFIED; - } - } - - public PersonGeneration(Known knownValue) { - this.personGenerationEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.personGenerationEnum; - } -} diff --git a/src/main/java/com/google/genai/types/RealtimeInputConfig.java b/src/main/java/com/google/genai/types/RealtimeInputConfig.java index 02c868f3ff9..07dc5793271 100644 --- a/src/main/java/com/google/genai/types/RealtimeInputConfig.java +++ b/src/main/java/com/google/genai/types/RealtimeInputConfig.java @@ -42,11 +42,11 @@ public abstract class RealtimeInputConfig extends JsonSerializable { /** Defines what effect activity has. */ @JsonProperty("activityHandling") - public abstract Optional activityHandling(); + public abstract Optional activityHandling(); /** Defines which input is included in the user's turn. */ @JsonProperty("turnCoverage") - public abstract Optional turnCoverage(); + public abstract Optional turnCoverage(); /** Instantiates a builder for RealtimeInputConfig. */ public static Builder builder() { @@ -70,26 +70,10 @@ public abstract Builder automaticActivityDetection( AutomaticActivityDetection automaticActivityDetection); @JsonProperty("activityHandling") - public abstract Builder activityHandling(ActivityHandling activityHandling); - - public Builder activityHandling(ActivityHandling.Known knownType) { - return activityHandling(new ActivityHandling(knownType)); - } - - public Builder activityHandling(String activityHandling) { - return activityHandling(new ActivityHandling(activityHandling)); - } + public abstract Builder activityHandling(String activityHandling); @JsonProperty("turnCoverage") - public abstract Builder turnCoverage(TurnCoverage turnCoverage); - - public Builder turnCoverage(TurnCoverage.Known knownType) { - return turnCoverage(new TurnCoverage(knownType)); - } - - public Builder turnCoverage(String turnCoverage) { - return turnCoverage(new TurnCoverage(turnCoverage)); - } + public abstract Builder turnCoverage(String turnCoverage); public abstract RealtimeInputConfig build(); } diff --git a/src/main/java/com/google/genai/types/SafetyFilterLevel.java b/src/main/java/com/google/genai/types/SafetyFilterLevel.java deleted file mode 100644 index c504d5f590c..00000000000 --- a/src/main/java/com/google/genai/types/SafetyFilterLevel.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Enum that controls the safety filter level for objectionable content. */ -public class SafetyFilterLevel { - - /** Enum representing the known values for SafetyFilterLevel. */ - public enum Known { - BLOCK_LOW_AND_ABOVE, - BLOCK_MEDIUM_AND_ABOVE, - BLOCK_ONLY_HIGH, - BLOCK_NONE, - SAFETY_FILTER_LEVEL_UNSPECIFIED - } - - private Known safetyFilterLevelEnum; - private final String value; - - @JsonCreator - public SafetyFilterLevel(String value) { - this.value = value; - for (Known safetyFilterLevelEnum : Known.values()) { - if (safetyFilterLevelEnum.toString().equalsIgnoreCase(value)) { - this.safetyFilterLevelEnum = safetyFilterLevelEnum; - break; - } - } - if (this.safetyFilterLevelEnum == null) { - this.safetyFilterLevelEnum = Known.SAFETY_FILTER_LEVEL_UNSPECIFIED; - } - } - - public SafetyFilterLevel(Known knownValue) { - this.safetyFilterLevelEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.safetyFilterLevelEnum; - } -} diff --git a/src/main/java/com/google/genai/types/SafetyRating.java b/src/main/java/com/google/genai/types/SafetyRating.java index d8a0bb1743b..f0d4102edcd 100644 --- a/src/main/java/com/google/genai/types/SafetyRating.java +++ b/src/main/java/com/google/genai/types/SafetyRating.java @@ -35,11 +35,11 @@ public abstract class SafetyRating extends JsonSerializable { /** Output only. Harm category. */ @JsonProperty("category") - public abstract Optional category(); + public abstract Optional category(); /** Output only. Harm probability levels in the content. */ @JsonProperty("probability") - public abstract Optional probability(); + public abstract Optional probability(); /** Output only. Harm probability score. */ @JsonProperty("probabilityScore") @@ -47,7 +47,7 @@ public abstract class SafetyRating extends JsonSerializable { /** Output only. Harm severity levels in the content. */ @JsonProperty("severity") - public abstract Optional severity(); + public abstract Optional severity(); /** Output only. Harm severity score. */ @JsonProperty("severityScore") @@ -74,40 +74,16 @@ private static Builder create() { public abstract Builder blocked(boolean blocked); @JsonProperty("category") - public abstract Builder category(HarmCategory category); - - public Builder category(HarmCategory.Known knownType) { - return category(new HarmCategory(knownType)); - } - - public Builder category(String category) { - return category(new HarmCategory(category)); - } + public abstract Builder category(String category); @JsonProperty("probability") - public abstract Builder probability(HarmProbability probability); - - public Builder probability(HarmProbability.Known knownType) { - return probability(new HarmProbability(knownType)); - } - - public Builder probability(String probability) { - return probability(new HarmProbability(probability)); - } + public abstract Builder probability(String probability); @JsonProperty("probabilityScore") public abstract Builder probabilityScore(Float probabilityScore); @JsonProperty("severity") - public abstract Builder severity(HarmSeverity severity); - - public Builder severity(HarmSeverity.Known knownType) { - return severity(new HarmSeverity(knownType)); - } - - public Builder severity(String severity) { - return severity(new HarmSeverity(severity)); - } + public abstract Builder severity(String severity); @JsonProperty("severityScore") public abstract Builder severityScore(Float severityScore); diff --git a/src/main/java/com/google/genai/types/SafetySetting.java b/src/main/java/com/google/genai/types/SafetySetting.java index fd77a779214..4a15084fb9a 100644 --- a/src/main/java/com/google/genai/types/SafetySetting.java +++ b/src/main/java/com/google/genai/types/SafetySetting.java @@ -31,15 +31,15 @@ public abstract class SafetySetting extends JsonSerializable { /** Determines if the harm block method uses probability or probability and severity scores. */ @JsonProperty("method") - public abstract Optional method(); + public abstract Optional method(); /** Required. Harm category. */ @JsonProperty("category") - public abstract Optional category(); + public abstract Optional category(); /** Required. The harm block threshold. */ @JsonProperty("threshold") - public abstract Optional threshold(); + public abstract Optional threshold(); /** Instantiates a builder for SafetySetting. */ public static Builder builder() { @@ -59,37 +59,13 @@ private static Builder create() { } @JsonProperty("method") - public abstract Builder method(HarmBlockMethod method); - - public Builder method(HarmBlockMethod.Known knownType) { - return method(new HarmBlockMethod(knownType)); - } - - public Builder method(String method) { - return method(new HarmBlockMethod(method)); - } + public abstract Builder method(String method); @JsonProperty("category") - public abstract Builder category(HarmCategory category); - - public Builder category(HarmCategory.Known knownType) { - return category(new HarmCategory(knownType)); - } - - public Builder category(String category) { - return category(new HarmCategory(category)); - } + public abstract Builder category(String category); @JsonProperty("threshold") - public abstract Builder threshold(HarmBlockThreshold threshold); - - public Builder threshold(HarmBlockThreshold.Known knownType) { - return threshold(new HarmBlockThreshold(knownType)); - } - - public Builder threshold(String threshold) { - return threshold(new HarmBlockThreshold(threshold)); - } + public abstract Builder threshold(String threshold); public abstract SafetySetting build(); } diff --git a/src/main/java/com/google/genai/types/Schema.java b/src/main/java/com/google/genai/types/Schema.java index 4f5d676a66e..b067fbcdfe8 100644 --- a/src/main/java/com/google/genai/types/Schema.java +++ b/src/main/java/com/google/genai/types/Schema.java @@ -137,7 +137,7 @@ public abstract class Schema extends JsonSerializable { /** Optional. The type of the data. */ @JsonProperty("type") - public abstract Optional type(); + public abstract Optional type(); /** Instantiates a builder for Schema. */ public static Builder builder() { @@ -220,15 +220,7 @@ private static Builder create() { public abstract Builder title(String title); @JsonProperty("type") - public abstract Builder type(Type type); - - public Builder type(Type.Known knownType) { - return type(new Type(knownType)); - } - - public Builder type(String type) { - return type(new Type(type)); - } + public abstract Builder type(String type); public abstract Schema build(); } diff --git a/src/main/java/com/google/genai/types/StartSensitivity.java b/src/main/java/com/google/genai/types/StartSensitivity.java deleted file mode 100644 index 22befcea470..00000000000 --- a/src/main/java/com/google/genai/types/StartSensitivity.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Start of speech sensitivity. */ -public class StartSensitivity { - - /** Enum representing the known values for StartSensitivity. */ - public enum Known { - START_SENSITIVITY_UNSPECIFIED, - START_SENSITIVITY_HIGH, - START_SENSITIVITY_LOW - } - - private Known startSensitivityEnum; - private final String value; - - @JsonCreator - public StartSensitivity(String value) { - this.value = value; - for (Known startSensitivityEnum : Known.values()) { - if (startSensitivityEnum.toString().equalsIgnoreCase(value)) { - this.startSensitivityEnum = startSensitivityEnum; - break; - } - } - if (this.startSensitivityEnum == null) { - this.startSensitivityEnum = Known.START_SENSITIVITY_UNSPECIFIED; - } - } - - public StartSensitivity(Known knownValue) { - this.startSensitivityEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.startSensitivityEnum; - } -} diff --git a/src/main/java/com/google/genai/types/SubjectReferenceConfig.java b/src/main/java/com/google/genai/types/SubjectReferenceConfig.java index 067a40a6346..98330013031 100644 --- a/src/main/java/com/google/genai/types/SubjectReferenceConfig.java +++ b/src/main/java/com/google/genai/types/SubjectReferenceConfig.java @@ -31,7 +31,7 @@ public abstract class SubjectReferenceConfig extends JsonSerializable { /** The subject type of a subject reference image. */ @JsonProperty("subjectType") - public abstract Optional subjectType(); + public abstract Optional subjectType(); /** Subject description for the image. */ @JsonProperty("subjectDescription") @@ -55,15 +55,7 @@ private static Builder create() { } @JsonProperty("subjectType") - public abstract Builder subjectType(SubjectReferenceType subjectType); - - public Builder subjectType(SubjectReferenceType.Known knownType) { - return subjectType(new SubjectReferenceType(knownType)); - } - - public Builder subjectType(String subjectType) { - return subjectType(new SubjectReferenceType(subjectType)); - } + public abstract Builder subjectType(String subjectType); @JsonProperty("subjectDescription") public abstract Builder subjectDescription(String subjectDescription); diff --git a/src/main/java/com/google/genai/types/SubjectReferenceType.java b/src/main/java/com/google/genai/types/SubjectReferenceType.java deleted file mode 100644 index 5c11cc6bd9e..00000000000 --- a/src/main/java/com/google/genai/types/SubjectReferenceType.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Enum representing the subject type of a subject reference image. */ -public class SubjectReferenceType { - - /** Enum representing the known values for SubjectReferenceType. */ - public enum Known { - SUBJECT_TYPE_DEFAULT, - SUBJECT_TYPE_PERSON, - SUBJECT_TYPE_ANIMAL, - SUBJECT_TYPE_PRODUCT, - SUBJECT_REFERENCE_TYPE_UNSPECIFIED - } - - private Known subjectReferenceTypeEnum; - private final String value; - - @JsonCreator - public SubjectReferenceType(String value) { - this.value = value; - for (Known subjectReferenceTypeEnum : Known.values()) { - if (subjectReferenceTypeEnum.toString().equalsIgnoreCase(value)) { - this.subjectReferenceTypeEnum = subjectReferenceTypeEnum; - break; - } - } - if (this.subjectReferenceTypeEnum == null) { - this.subjectReferenceTypeEnum = Known.SUBJECT_REFERENCE_TYPE_UNSPECIFIED; - } - } - - public SubjectReferenceType(Known knownValue) { - this.subjectReferenceTypeEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.subjectReferenceTypeEnum; - } -} diff --git a/src/main/java/com/google/genai/types/TrafficType.java b/src/main/java/com/google/genai/types/TrafficType.java deleted file mode 100644 index 46219a6e4cf..00000000000 --- a/src/main/java/com/google/genai/types/TrafficType.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** - * Output only. Traffic type. This shows whether a request consumes Pay-As-You-Go or Provisioned - * Throughput quota. - */ -public class TrafficType { - - /** Enum representing the known values for TrafficType. */ - public enum Known { - TRAFFIC_TYPE_UNSPECIFIED, - ON_DEMAND, - PROVISIONED_THROUGHPUT - } - - private Known trafficTypeEnum; - private final String value; - - @JsonCreator - public TrafficType(String value) { - this.value = value; - for (Known trafficTypeEnum : Known.values()) { - if (trafficTypeEnum.toString().equalsIgnoreCase(value)) { - this.trafficTypeEnum = trafficTypeEnum; - break; - } - } - if (this.trafficTypeEnum == null) { - this.trafficTypeEnum = Known.TRAFFIC_TYPE_UNSPECIFIED; - } - } - - public TrafficType(Known knownValue) { - this.trafficTypeEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.trafficTypeEnum; - } -} diff --git a/src/main/java/com/google/genai/types/TurnCoverage.java b/src/main/java/com/google/genai/types/TurnCoverage.java deleted file mode 100644 index 2aa0a7d1781..00000000000 --- a/src/main/java/com/google/genai/types/TurnCoverage.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Options about which input is included in the user's turn. */ -public class TurnCoverage { - - /** Enum representing the known values for TurnCoverage. */ - public enum Known { - TURN_COVERAGE_UNSPECIFIED, - TURN_INCLUDES_ONLY_ACTIVITY, - TURN_INCLUDES_ALL_INPUT - } - - private Known turnCoverageEnum; - private final String value; - - @JsonCreator - public TurnCoverage(String value) { - this.value = value; - for (Known turnCoverageEnum : Known.values()) { - if (turnCoverageEnum.toString().equalsIgnoreCase(value)) { - this.turnCoverageEnum = turnCoverageEnum; - break; - } - } - if (this.turnCoverageEnum == null) { - this.turnCoverageEnum = Known.TURN_COVERAGE_UNSPECIFIED; - } - } - - public TurnCoverage(Known knownValue) { - this.turnCoverageEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.turnCoverageEnum; - } -} diff --git a/src/main/java/com/google/genai/types/Type.java b/src/main/java/com/google/genai/types/Type.java deleted file mode 100644 index aac6f88893f..00000000000 --- a/src/main/java/com/google/genai/types/Type.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 - * - * https://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. - */ - -// Auto-generated code. Do not edit. - -package com.google.genai.types; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** Optional. The type of the data. */ -public class Type { - - /** Enum representing the known values for Type. */ - public enum Known { - TYPE_UNSPECIFIED, - STRING, - NUMBER, - INTEGER, - BOOLEAN, - ARRAY, - OBJECT - } - - private Known typeEnum; - private final String value; - - @JsonCreator - public Type(String value) { - this.value = value; - for (Known typeEnum : Known.values()) { - if (typeEnum.toString().equalsIgnoreCase(value)) { - this.typeEnum = typeEnum; - break; - } - } - if (this.typeEnum == null) { - this.typeEnum = Known.TYPE_UNSPECIFIED; - } - } - - public Type(Known knownValue) { - this.typeEnum = knownValue; - this.value = knownValue.toString(); - } - - @Override - @JsonValue - public String toString() { - return this.value; - } - - public Known knownEnum() { - return this.typeEnum; - } -} diff --git a/src/main/java/com/google/genai/types/UsageMetadata.java b/src/main/java/com/google/genai/types/UsageMetadata.java index 95c733c5103..f9f705d838a 100644 --- a/src/main/java/com/google/genai/types/UsageMetadata.java +++ b/src/main/java/com/google/genai/types/UsageMetadata.java @@ -78,7 +78,7 @@ public abstract class UsageMetadata extends JsonSerializable { * quota. */ @JsonProperty("trafficType") - public abstract Optional trafficType(); + public abstract Optional trafficType(); /** Instantiates a builder for UsageMetadata. */ public static Builder builder() { @@ -129,15 +129,7 @@ public abstract Builder toolUsePromptTokensDetails( List toolUsePromptTokensDetails); @JsonProperty("trafficType") - public abstract Builder trafficType(TrafficType trafficType); - - public Builder trafficType(TrafficType.Known knownType) { - return trafficType(new TrafficType(knownType)); - } - - public Builder trafficType(String trafficType) { - return trafficType(new TrafficType(trafficType)); - } + public abstract Builder trafficType(String trafficType); public abstract UsageMetadata build(); } diff --git a/src/test/java/com/google/genai/ChatTest.java b/src/test/java/com/google/genai/ChatTest.java index c995b2f5511..a22313150d8 100644 --- a/src/test/java/com/google/genai/ChatTest.java +++ b/src/test/java/com/google/genai/ChatTest.java @@ -23,7 +23,6 @@ import com.google.genai.types.Candidate; import com.google.genai.types.Content; -import com.google.genai.types.FinishReason; import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.GenerateContentResponseUsageMetadata; @@ -104,7 +103,7 @@ public class ChatTest { Part.builder().text(STREAMING_RESPONSE_CHUNK_3).build())) .role("model") .build()) - .finishReason(FinishReason.Known.STOP) + .finishReason("STOP") .build())) .usageMetadata( GenerateContentResponseUsageMetadata.builder() diff --git a/src/test/java/com/google/genai/ForwardCompatibilityTest.java b/src/test/java/com/google/genai/ForwardCompatibilityTest.java index 95887f57fb0..f5db1607b2a 100644 --- a/src/test/java/com/google/genai/ForwardCompatibilityTest.java +++ b/src/test/java/com/google/genai/ForwardCompatibilityTest.java @@ -16,56 +16,21 @@ package com.google.genai; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.common.collect.ImmutableList; -import com.google.genai.types.FeatureSelectionPreference; -import com.google.genai.types.FinishReason; -import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; -import com.google.genai.types.HarmBlockThreshold; -import com.google.genai.types.HarmCategory; -import com.google.genai.types.ModelSelectionConfig; -import com.google.genai.types.SafetySetting; import java.lang.reflect.Field; -import java.util.Optional; import org.apache.http.HttpEntity; import org.apache.http.entity.StringEntity; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; import org.mockito.Mockito; public class ForwardCompatibilityTest { - - ApiClient mockedClient; - ApiResponse mockedResponse; - HttpEntity mockedEntity; - Client client; - GenerateContentResponse returnResponse; - ObjectMapper objectMapper; - - @BeforeEach - void setUp() { - mockedClient = Mockito.mock(ApiClient.class); - mockedResponse = Mockito.mock(ApiResponse.class); - when(mockedClient.request(anyString(), anyString(), anyString())).thenReturn(mockedResponse); - mockedEntity = Mockito.mock(HttpEntity.class); - returnResponse = GenerateContentResponse.builder().build(); - - objectMapper = new ObjectMapper(); - - client = Client.builder().build(); - } - @Test public void testForwardCompatibility() throws Exception { // Mocks and test setup. @@ -92,169 +57,8 @@ public void testForwardCompatibility() throws Exception { apiClientField.set(client.models, mockedClient); GenerateContentResponse response = - client.models.generateContent("gemini-2.0-flash-exp", "What is your name?", null); + client.models.generateContent("gemini-2.0-flash", "What is your name?", null); assertNotNull(response); } - - @Test - public void testEnumForwardCompatibilityFinishReason() throws Exception { - /** Tests a response with two different unrecognized enum values for FinishReason. */ - JsonNode rootNode = objectMapper.readTree(returnResponse.toJson()); - ObjectNode rootObjectNode = (ObjectNode) rootNode; - - ArrayNode candidatesArray = objectMapper.createArrayNode(); - ObjectNode candidateObject = objectMapper.createObjectNode(); - candidateObject.put("finishReason", "NEW_UNKNOWN_VALUE"); - - ObjectNode candidateObject2 = objectMapper.createObjectNode(); - candidateObject2.put("finishReason", "ANOTHER_VALUE"); - - candidatesArray.add(candidateObject); - candidatesArray.add(candidateObject2); - rootObjectNode.putArray("candidates").addAll(candidatesArray); - - String jsonString = objectMapper.writeValueAsString(rootNode); - StringEntity content = new StringEntity(jsonString); - when(mockedResponse.getEntity()).thenReturn(content); - - Client client = Client.builder().build(); - // Make the apiClient field public so that it can be spied on in the tests. This is a - // workaround for the fact that the ApiClient is a final class and cannot be spied on directly. - Field apiClientField = Models.class.getDeclaredField("apiClient"); - apiClientField.setAccessible(true); - apiClientField.set(client.models, mockedClient); - - GenerateContentResponse response = - client.models.generateContent("gemini-2.0-flash-exp", "What is your name?", null); - Optional finishReason1 = response.candidates().get().get(0).finishReason(); - Optional finishReason2 = response.candidates().get().get(1).finishReason(); - - if (finishReason1.isPresent()) { - FinishReason finishReason = finishReason1.get(); - assert finishReason.toString().equals("NEW_UNKNOWN_VALUE"); - assert (finishReason.knownEnum().equals(FinishReason.Known.FINISH_REASON_UNSPECIFIED)); - } - if (finishReason2.isPresent()) { - FinishReason finishReason = finishReason2.get(); - assert finishReason.toString().equals("ANOTHER_VALUE"); - assert (finishReason.knownEnum().equals(FinishReason.Known.FINISH_REASON_UNSPECIFIED)); - } - } - - @Test - public void testFinishReasonEnumReturnsEnum() throws Exception { - /** Tests knownEnum method returns the correct enum value. */ - JsonNode rootNode = objectMapper.readTree(returnResponse.toJson()); - ObjectNode rootObjectNode = (ObjectNode) rootNode; - - ArrayNode candidatesArray = objectMapper.createArrayNode(); - ObjectNode candidateObject = objectMapper.createObjectNode(); - candidateObject.put("finishReason", "MAX_TOKENS"); - candidatesArray.add(candidateObject); - rootObjectNode.putArray("candidates").addAll(candidatesArray); - - String jsonString = objectMapper.writeValueAsString(rootNode); - StringEntity content = new StringEntity(jsonString); - when(mockedResponse.getEntity()).thenReturn(content); - - Client client = Client.builder().build(); - // Make the apiClient field public so that it can be spied on in the tests. This is a - // workaround for the fact that the ApiClient is a final class and cannot be spied on directly. - Field apiClientField = Models.class.getDeclaredField("apiClient"); - apiClientField.setAccessible(true); - apiClientField.set(client.models, mockedClient); - - GenerateContentResponse response = - client.models.generateContent("gemini-2.0-flash-exp", "What is your name?", null); - - Optional finishReasonResponse = response.candidates().get().get(0).finishReason(); - - if (finishReasonResponse.isPresent()) { - FinishReason finishReason = finishReasonResponse.get(); - assert (finishReason.knownEnum().equals(FinishReason.Known.MAX_TOKENS)); - } - } - - @Test - public void testEnumForwardCompatibilitySafetyFilterLevel() throws Exception { - /** Tests setting an unrecognized enum value for SafetyFilterLevel. */ - JsonNode rootNode = objectMapper.readTree(returnResponse.toJson()); - ObjectNode rootObjectNode = (ObjectNode) rootNode; - - ArrayNode candidatesArray = objectMapper.createArrayNode(); - ObjectNode candidateObject = objectMapper.createObjectNode(); - ArrayNode safetyRatingsArray = objectMapper.createArrayNode(); - ObjectNode safetyRatingsObjectNode = objectMapper.createObjectNode(); - - safetyRatingsObjectNode.put("category", "UNKNOWN_SAFETY_RATING_VALUE"); - safetyRatingsArray.add(safetyRatingsObjectNode); - candidateObject.put("safetyRatings", safetyRatingsArray); - candidatesArray.add(candidateObject); - rootObjectNode.putArray("candidates").addAll(candidatesArray); - - String jsonString = objectMapper.writeValueAsString(rootNode); - StringEntity content = new StringEntity(jsonString); - when(mockedResponse.getEntity()).thenReturn(content); - - Client client = Client.builder().build(); - // Make the apiClient field public so that it can be spied on in the tests. This is a - // workaround for the fact that the ApiClient is a final class and cannot be spied on - Field apiClientField = Models.class.getDeclaredField("apiClient"); - apiClientField.setAccessible(true); - apiClientField.set(client.models, mockedClient); - - GenerateContentResponse response = - client.models.generateContent("gemini-2.0-flash-exp", "What is your name?", null); - - Optional harmCategory = - response.candidates().get().get(0).safetyRatings().get().get(0).category(); - - if (harmCategory.isPresent()) { - assert (harmCategory.get().knownEnum()).equals(HarmCategory.Known.HARM_CATEGORY_UNSPECIFIED); - assert (harmCategory.get().toString().equals("UNKNOWN_SAFETY_RATING_VALUE")); - } - } - - @Test - public void testInlineEnum() throws Exception { - /** Tests instantiating an inline enum (ModelRoutingPreference) in the request. */ - GenerateContentConfig config = - GenerateContentConfig.builder() - .modelSelectionConfig( - ModelSelectionConfig.builder() - .featureSelectionPreference(FeatureSelectionPreference.Known.PRIORITIZE_QUALITY) - .build()) - .build(); - } - - public void testEnumSendingUnknownSafetysettings() throws Exception { - /** Tests sending an enum value that is not in the enum definition. */ - GenerateContentConfig config = - GenerateContentConfig.builder() - .safetySettings( - ImmutableList.of( - SafetySetting.builder() - .threshold(new HarmBlockThreshold("NEW_UNKNOWN_VALUE")) - .build())) - .build(); - - Client client = Client.builder().build(); - // Make the apiClient field public so that it can be spied on in the tests. This is a - // workaround for the fact that the ApiClient is a final class and cannot be spied on - Field apiClientField = Models.class.getDeclaredField("apiClient"); - apiClientField.setAccessible(true); - apiClientField.set(client.models, mockedClient); - when(mockedResponse.getEntity()).thenReturn(new StringEntity("{}")); - - GenerateContentResponse response = - client.models.generateContent("gemini-2.0-flash-exp", "What is your name?", config); - - ArgumentCaptor stringCaptor = ArgumentCaptor.forClass(String.class); - verify(mockedClient).request(anyString(), anyString(), stringCaptor.capture()); - assertEquals( - "{\"contents\":[{\"parts\":[{\"text\":\"What is your name?\"}],\"role\":\"user\"}]," - + "\"safetySettings\":[{\"threshold\":\"NEW_UNKNOWN_VALUE\"}],\"generationConfig\":{}}", - stringCaptor.getValue()); - } } diff --git a/src/test/java/com/google/genai/TransformerTest.java b/src/test/java/com/google/genai/TransformerTest.java index dd964d2f9ba..a733a01a1b7 100644 --- a/src/test/java/com/google/genai/TransformerTest.java +++ b/src/test/java/com/google/genai/TransformerTest.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.genai.types.HttpOptions; -import com.google.genai.types.Type; import com.google.genai.types.Schema; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -68,48 +67,45 @@ public void testTSchema_GeminiAPI_title_success() { public void testTSchema_AnyOf_success() { Schema schema = Schema.builder() - .type(Type.Known.OBJECT) + .type("OBJECT") .anyOf( ImmutableList.of( - Schema.builder().type(Type.Known.STRING).build(), - Schema.builder().type(Type.Known.NUMBER).build())) + Schema.builder().type("STRING").build(), + Schema.builder().type("NUMBER").build())) .build(); Schema transformedSchema = Transformers.tSchema(VERTEX_AI_CLIENT, schema); assertEquals(2, transformedSchema.anyOf().get().size()); - assertEquals("STRING", transformedSchema.anyOf().get().get(0).type().get().toString()); - assertEquals("NUMBER", transformedSchema.anyOf().get().get(1).type().get().toString()); - assertEquals("OBJECT", transformedSchema.type().get().toString()); + assertEquals("STRING", transformedSchema.anyOf().get().get(0).type().get()); + assertEquals("NUMBER", transformedSchema.anyOf().get().get(1).type().get()); + assertEquals("OBJECT", transformedSchema.type().get()); } @Test public void testTSchema_Items_success() { Schema schema = - Schema.builder() - .type(new Type("ARRAY")) - .items(Schema.builder().type(Type.Known.STRING).build()) - .build(); + Schema.builder().type("ARRAY").items(Schema.builder().type("STRING").build()).build(); Schema transformedSchema = Transformers.tSchema(GEMINI_API_CLIENT, schema); - assertEquals("STRING", transformedSchema.items().get().type().get().toString()); - assertEquals("ARRAY", transformedSchema.type().get().toString()); + assertEquals("STRING", transformedSchema.items().get().type().get()); + assertEquals("ARRAY", transformedSchema.type().get()); } @Test public void testTSchema_Required_sucess() { - Schema schema = - Schema.builder() - .type(Type.Known.ARRAY) + Schema schema = Schema.builder() + .type("ARRAY") .items( Schema.builder() - .type(Type.Known.OBJECT) + .type("OBJECT") .properties( ImmutableMap.of( "recipe_name", - Schema.builder().type(Type.Known.STRING).build(), + Schema.builder().type("STRING").build(), "ingredients", Schema.builder() - .type(Type.Known.ARRAY) - .items(Schema.builder().type(Type.Known.STRING).build()) - .build())) + .type("ARRAY") + .items(Schema.builder().type("STRING").build()) + .build() + )) .required(ImmutableList.of("recipe_name", "ingredients")) .build()) .build(); diff --git a/src/test/java/com/google/genai/types/FunctionDeclarationTest.java b/src/test/java/com/google/genai/types/FunctionDeclarationTest.java index a18b761dcfd..5c741b21846 100644 --- a/src/test/java/com/google/genai/types/FunctionDeclarationTest.java +++ b/src/test/java/com/google/genai/types/FunctionDeclarationTest.java @@ -47,7 +47,7 @@ public class FunctionDeclarationTest { .description(FUNCTION_DESCRIPTION) .parameters( Schema.builder() - .type(Type.Known.OBJECT) + .type("OBJECT") .properties(buildPropertiesMap()) .required(REQUIRED_PARAM_NAMES) .build()) @@ -57,19 +57,15 @@ public class FunctionDeclarationTest { private static Map buildPropertiesMap() { Map properties = new HashMap<>(); properties.put( - STRING_PARAM_NAME, - Schema.builder().type(Type.Known.STRING).title(STRING_PARAM_NAME).build()); + STRING_PARAM_NAME, Schema.builder().type("STRING").title(STRING_PARAM_NAME).build()); properties.put( - INTEGER_PARAM_NAME, - Schema.builder().type(Type.Known.INTEGER).title(INTEGER_PARAM_NAME).build()); + INTEGER_PARAM_NAME, Schema.builder().type("INTEGER").title(INTEGER_PARAM_NAME).build()); properties.put( - DOUBLE_PARAM_NAME, - Schema.builder().type(Type.Known.NUMBER).title(DOUBLE_PARAM_NAME).build()); + DOUBLE_PARAM_NAME, Schema.builder().type("NUMBER").title(DOUBLE_PARAM_NAME).build()); properties.put( - FLOAT_PARAM_NAME, Schema.builder().type(Type.Known.NUMBER).title(FLOAT_PARAM_NAME).build()); + FLOAT_PARAM_NAME, Schema.builder().type("NUMBER").title(FLOAT_PARAM_NAME).build()); properties.put( - BOOLEAN_PARAM_NAME, - Schema.builder().type(Type.Known.BOOLEAN).title(BOOLEAN_PARAM_NAME).build()); + BOOLEAN_PARAM_NAME, Schema.builder().type("BOOLEAN").title(BOOLEAN_PARAM_NAME).build()); return properties; } @@ -127,7 +123,7 @@ public void fromMethodWithParameterNames_returnsFunctionDeclaration() FLOAT_PARAM_NAME, BOOLEAN_PARAM_NAME); - assertEquals(EXPECTED_FUNCTION_DECLARATION.toString(), functionDeclaration.toString()); + assertEquals(EXPECTED_FUNCTION_DECLARATION, functionDeclaration); } @Test diff --git a/src/test/java/com/google/genai/types/GenerateContentResponseTest.java b/src/test/java/com/google/genai/types/GenerateContentResponseTest.java index 10f8089c3c9..05163bca70b 100644 --- a/src/test/java/com/google/genai/types/GenerateContentResponseTest.java +++ b/src/test/java/com/google/genai/types/GenerateContentResponseTest.java @@ -56,17 +56,14 @@ public class GenerateContentResponseTest { private static final Part PART_WITH_EXECUTABLE_CODE = Part.builder() .executableCode( - ExecutableCode.builder() - .code("executableCode") - .language(Language.Known.PYTHON) - .build()) + ExecutableCode.builder().code("executableCode").language("python").build()) .build(); private static final Part PART_WITH_CODE_EXECUTION_RESULT = Part.builder() .codeExecutionResult( CodeExecutionResult.builder() .output("codeExecutionResult") - .outcome(Outcome.Known.OUTCOME_OK) + .outcome("success") .build()) .build(); @@ -94,36 +91,21 @@ public class GenerateContentResponseTest { Content.builder().parts(ImmutableList.of(PART_WITH_CODE_EXECUTION_RESULT, PART_1)).build(); private static final Candidate CANDIDATE_1 = - Candidate.builder().content(CONTENT_1).finishReason(FinishReason.Known.STOP).build(); + Candidate.builder().content(CONTENT_1).finishReason("STOP").build(); private static final Candidate CANDIDATE_2 = - Candidate.builder().content(CONTENT_2).finishReason(FinishReason.Known.STOP).build(); + Candidate.builder().content(CONTENT_2).finishReason("STOP").build(); private static final Candidate CANDIDATE_WITH_EMPTY_PARTS = - Candidate.builder() - .content(CONTENT_WITH_EMPTY_PARTS) - .finishReason(FinishReason.Known.STOP) - .build(); + Candidate.builder().content(CONTENT_WITH_EMPTY_PARTS).finishReason("STOP").build(); private static final Candidate CANDIDATE_WITH_THOUGHT = - Candidate.builder() - .content(CONTENT_WITH_THOUGHT) - .finishReason(FinishReason.Known.STOP) - .build(); + Candidate.builder().content(CONTENT_WITH_THOUGHT).finishReason("STOP").build(); private static final Candidate CANDIDATE_WITH_MULTIPLE_PARTS = - Candidate.builder() - .content(CONTENT_WITH_MULTIPLE_PARTS) - .finishReason(FinishReason.Known.STOP) - .build(); + Candidate.builder().content(CONTENT_WITH_MULTIPLE_PARTS).finishReason("STOP").build(); private static final Candidate CANDIDATE_WITH_FUNCTION_CALLS = - Candidate.builder() - .content(CONTENT_WITH_FUNCTION_CALLS) - .finishReason(FinishReason.Known.STOP) - .build(); + Candidate.builder().content(CONTENT_WITH_FUNCTION_CALLS).finishReason("STOP").build(); private static final Candidate CANDIDATE_WITH_MIXED_PARTS = - Candidate.builder() - .content(CONTENT_WITH_MIXED_PARTS) - .finishReason(FinishReason.Known.STOP) - .build(); + Candidate.builder().content(CONTENT_WITH_MIXED_PARTS).finishReason("STOP").build(); private static final Candidate CANDIDATE_WITH_UNEXPECTED_FINISH_REASON = - Candidate.builder().content(CONTENT_1).finishReason(FinishReason.Known.SAFETY).build(); + Candidate.builder().content(CONTENT_1).finishReason("SAFETY").build(); @Test public void testParts_EmptyCandidates() { @@ -348,9 +330,9 @@ public void testExecutableCode_MultipleCandidates() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_EXECUTABLE_CODE) - .finishReason(FinishReason.Known.STOP) + .finishReason("STOP") .build(), - CANDIDATE_1)) + CANDIDATE_1)) .build(); String result = response.executableCode(); @@ -366,7 +348,7 @@ public void testExecutableCode_PartWithExecutableCode() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_EXECUTABLE_CODE) - .finishReason(FinishReason.Known.STOP) + .finishReason("STOP") .build())) .build(); @@ -394,7 +376,7 @@ public void testExecutableCode_MultipleParts() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_EXECUTABLE_CODE_AND_TEXT) - .finishReason(FinishReason.Known.STOP) + .finishReason("STOP") .build())) .build(); @@ -444,7 +426,7 @@ public void testCodeExecutionResult_MultipleCandidates() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_CODE_EXECUTION_RESULT) - .finishReason(FinishReason.Known.STOP) + .finishReason("STOP") .build(), CANDIDATE_1)) .build(); @@ -462,7 +444,7 @@ public void testCodeExecutionResult_PartWithCodeExecutionResult() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_CODE_EXECUTION_RESULT) - .finishReason(FinishReason.Known.STOP) + .finishReason("STOP") .build())) .build(); @@ -489,7 +471,7 @@ public void testCodeExecutionResult_MultipleParts() { ImmutableList.of( Candidate.builder() .content(CONTENT_WITH_CODE_EXECUTION_RESULT_AND_TEXT) - .finishReason(FinishReason.Known.STOP) + .finishReason("STOP") .build())) .build(); From 24b112756b21e1b9650e434ba6f53557c8bf6531 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Mon, 5 May 2025 13:35:32 -0700 Subject: [PATCH 14/18] feat: Add support for Grounding with Google Maps PiperOrigin-RevId: 755055455 --- .../java/com/google/genai/LiveConverters.java | 164 ++++++++++++ src/main/java/com/google/genai/Models.java | 243 ++++++++++++++++++ .../com/google/genai/types/ApiKeyConfig.java | 63 +++++ .../com/google/genai/types/AuthConfig.java | 99 +++++++ .../AuthConfigGoogleServiceAccountConfig.java | 73 ++++++ .../types/AuthConfigHttpBasicAuthConfig.java | 71 +++++ .../genai/types/AuthConfigOauthConfig.java | 79 ++++++ .../genai/types/AuthConfigOidcConfig.java | 81 ++++++ .../java/com/google/genai/types/AuthType.java | 69 +++++ .../com/google/genai/types/GoogleMaps.java | 63 +++++ .../java/com/google/genai/types/LatLng.java | 77 ++++++ .../google/genai/types/RetrievalConfig.java | 63 +++++ .../java/com/google/genai/types/Tool.java | 7 + .../com/google/genai/types/ToolConfig.java | 7 + 14 files changed, 1159 insertions(+) create mode 100644 src/main/java/com/google/genai/types/ApiKeyConfig.java create mode 100644 src/main/java/com/google/genai/types/AuthConfig.java create mode 100644 src/main/java/com/google/genai/types/AuthConfigGoogleServiceAccountConfig.java create mode 100644 src/main/java/com/google/genai/types/AuthConfigHttpBasicAuthConfig.java create mode 100644 src/main/java/com/google/genai/types/AuthConfigOauthConfig.java create mode 100644 src/main/java/com/google/genai/types/AuthConfigOidcConfig.java create mode 100644 src/main/java/com/google/genai/types/AuthType.java create mode 100644 src/main/java/com/google/genai/types/GoogleMaps.java create mode 100644 src/main/java/com/google/genai/types/LatLng.java create mode 100644 src/main/java/com/google/genai/types/RetrievalConfig.java diff --git a/src/main/java/com/google/genai/LiveConverters.java b/src/main/java/com/google/genai/LiveConverters.java index 09742e5e971..403f287df97 100644 --- a/src/main/java/com/google/genai/LiveConverters.java +++ b/src/main/java/com/google/genai/LiveConverters.java @@ -339,6 +339,155 @@ ObjectNode enterpriseWebSearchToVertex( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode apiKeyConfigToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"apiKeyString"}))) { + throw new IllegalArgumentException("apiKeyString parameter is not supported in Gemini API."); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode apiKeyConfigToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"apiKeyString"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"apiKeyString"}, + Common.getValueByPath(fromObject, new String[] {"apiKeyString"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode authConfigToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"apiKeyConfig"}))) { + throw new IllegalArgumentException("apiKeyConfig parameter is not supported in Gemini API."); + } + + if (Common.getValueByPath(fromObject, new String[] {"authType"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"authType"}, + Common.getValueByPath(fromObject, new String[] {"authType"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"googleServiceAccountConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"googleServiceAccountConfig"}, + Common.getValueByPath(fromObject, new String[] {"googleServiceAccountConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"httpBasicAuthConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"httpBasicAuthConfig"}, + Common.getValueByPath(fromObject, new String[] {"httpBasicAuthConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"oauthConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"oauthConfig"}, + Common.getValueByPath(fromObject, new String[] {"oauthConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"oidcConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"oidcConfig"}, + Common.getValueByPath(fromObject, new String[] {"oidcConfig"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode authConfigToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"apiKeyConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"apiKeyConfig"}, + apiKeyConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"apiKeyConfig"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"authType"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"authType"}, + Common.getValueByPath(fromObject, new String[] {"authType"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"googleServiceAccountConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"googleServiceAccountConfig"}, + Common.getValueByPath(fromObject, new String[] {"googleServiceAccountConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"httpBasicAuthConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"httpBasicAuthConfig"}, + Common.getValueByPath(fromObject, new String[] {"httpBasicAuthConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"oauthConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"oauthConfig"}, + Common.getValueByPath(fromObject, new String[] {"oauthConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"oidcConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"oidcConfig"}, + Common.getValueByPath(fromObject, new String[] {"oidcConfig"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode googleMapsToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"authConfig"}))) { + throw new IllegalArgumentException("authConfig parameter is not supported in Gemini API."); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode googleMapsToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"authConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"authConfig"}, + authConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"authConfig"})), + toObject)); + } + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode toolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -373,6 +522,10 @@ ObjectNode toolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pare "enterpriseWebSearch parameter is not supported in Gemini API."); } + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"googleMaps"}))) { + throw new IllegalArgumentException("googleMaps parameter is not supported in Gemini API."); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecution"}) != null) { Common.setValueByPath( toObject, @@ -433,6 +586,17 @@ ObjectNode toolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par toObject)); } + if (Common.getValueByPath(fromObject, new String[] {"googleMaps"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"googleMaps"}, + googleMapsToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"googleMaps"})), + toObject)); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecution"}) != null) { Common.setValueByPath( toObject, diff --git a/src/main/java/com/google/genai/Models.java b/src/main/java/com/google/genai/Models.java index 79a13b79dde..5837df575cf 100644 --- a/src/main/java/com/google/genai/Models.java +++ b/src/main/java/com/google/genai/Models.java @@ -265,6 +265,72 @@ ObjectNode enterpriseWebSearchToMldev( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode apiKeyConfigToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"apiKeyString"}))) { + throw new IllegalArgumentException("apiKeyString parameter is not supported in Gemini API."); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode authConfigToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"apiKeyConfig"}))) { + throw new IllegalArgumentException("apiKeyConfig parameter is not supported in Gemini API."); + } + + if (Common.getValueByPath(fromObject, new String[] {"authType"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"authType"}, + Common.getValueByPath(fromObject, new String[] {"authType"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"googleServiceAccountConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"googleServiceAccountConfig"}, + Common.getValueByPath(fromObject, new String[] {"googleServiceAccountConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"httpBasicAuthConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"httpBasicAuthConfig"}, + Common.getValueByPath(fromObject, new String[] {"httpBasicAuthConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"oauthConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"oauthConfig"}, + Common.getValueByPath(fromObject, new String[] {"oauthConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"oidcConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"oidcConfig"}, + Common.getValueByPath(fromObject, new String[] {"oidcConfig"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode googleMapsToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"authConfig"}))) { + throw new IllegalArgumentException("authConfig parameter is not supported in Gemini API."); + } + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode toolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -299,6 +365,10 @@ ObjectNode toolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pare "enterpriseWebSearch parameter is not supported in Gemini API."); } + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"googleMaps"}))) { + throw new IllegalArgumentException("googleMaps parameter is not supported in Gemini API."); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecution"}) != null) { Common.setValueByPath( toObject, @@ -337,6 +407,31 @@ ObjectNode functionCallingConfigToMldev( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode latLngToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"latitude"}))) { + throw new IllegalArgumentException("latitude parameter is not supported in Gemini API."); + } + + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"longitude"}))) { + throw new IllegalArgumentException("longitude parameter is not supported in Gemini API."); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode retrievalConfigToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"latLng"}))) { + throw new IllegalArgumentException("latLng parameter is not supported in Gemini API."); + } + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode toolConfigToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -351,6 +446,11 @@ ObjectNode toolConfigToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNod toObject)); } + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"retrievalConfig"}))) { + throw new IllegalArgumentException( + "retrievalConfig parameter is not supported in Gemini API."); + } + return toObject; } @@ -1289,6 +1389,89 @@ ObjectNode enterpriseWebSearchToVertex( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode apiKeyConfigToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"apiKeyString"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"apiKeyString"}, + Common.getValueByPath(fromObject, new String[] {"apiKeyString"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode authConfigToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"apiKeyConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"apiKeyConfig"}, + apiKeyConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"apiKeyConfig"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"authType"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"authType"}, + Common.getValueByPath(fromObject, new String[] {"authType"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"googleServiceAccountConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"googleServiceAccountConfig"}, + Common.getValueByPath(fromObject, new String[] {"googleServiceAccountConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"httpBasicAuthConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"httpBasicAuthConfig"}, + Common.getValueByPath(fromObject, new String[] {"httpBasicAuthConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"oauthConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"oauthConfig"}, + Common.getValueByPath(fromObject, new String[] {"oauthConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"oidcConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"oidcConfig"}, + Common.getValueByPath(fromObject, new String[] {"oidcConfig"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode googleMapsToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"authConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"authConfig"}, + authConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"authConfig"})), + toObject)); + } + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode toolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -1332,6 +1515,17 @@ ObjectNode toolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par toObject)); } + if (Common.getValueByPath(fromObject, new String[] {"googleMaps"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"googleMaps"}, + googleMapsToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"googleMaps"})), + toObject)); + } + if (Common.getValueByPath(fromObject, new String[] {"codeExecution"}) != null) { Common.setValueByPath( toObject, @@ -1370,6 +1564,44 @@ ObjectNode functionCallingConfigToVertex( return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode latLngToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"latitude"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"latitude"}, + Common.getValueByPath(fromObject, new String[] {"latitude"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"longitude"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"longitude"}, + Common.getValueByPath(fromObject, new String[] {"longitude"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode retrievalConfigToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"latLng"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"latLng"}, + latLngToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"latLng"})), + toObject)); + } + + return toObject; + } + @ExcludeFromGeneratedCoverageReport ObjectNode toolConfigToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -1384,6 +1616,17 @@ ObjectNode toolConfigToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNo toObject)); } + if (Common.getValueByPath(fromObject, new String[] {"retrievalConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"retrievalConfig"}, + retrievalConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"retrievalConfig"})), + toObject)); + } + return toObject; } diff --git a/src/main/java/com/google/genai/types/ApiKeyConfig.java b/src/main/java/com/google/genai/types/ApiKeyConfig.java new file mode 100644 index 00000000000..e9e896607e2 --- /dev/null +++ b/src/main/java/com/google/genai/types/ApiKeyConfig.java @@ -0,0 +1,63 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.Optional; + +/** Config for authentication with API key. */ +@AutoValue +@JsonDeserialize(builder = ApiKeyConfig.Builder.class) +public abstract class ApiKeyConfig extends JsonSerializable { + /** The API key to be used in the request directly. */ + @JsonProperty("apiKeyString") + public abstract Optional apiKeyString(); + + /** Instantiates a builder for ApiKeyConfig. */ + public static Builder builder() { + return new AutoValue_ApiKeyConfig.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for ApiKeyConfig. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `ApiKeyConfig.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_ApiKeyConfig.Builder(); + } + + @JsonProperty("apiKeyString") + public abstract Builder apiKeyString(String apiKeyString); + + public abstract ApiKeyConfig build(); + } + + /** Deserializes a JSON string to a ApiKeyConfig object. */ + public static ApiKeyConfig fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, ApiKeyConfig.class); + } +} diff --git a/src/main/java/com/google/genai/types/AuthConfig.java b/src/main/java/com/google/genai/types/AuthConfig.java new file mode 100644 index 00000000000..9d3ec898152 --- /dev/null +++ b/src/main/java/com/google/genai/types/AuthConfig.java @@ -0,0 +1,99 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.Optional; + +/** Auth configuration to run the extension. */ +@AutoValue +@JsonDeserialize(builder = AuthConfig.Builder.class) +public abstract class AuthConfig extends JsonSerializable { + /** Config for API key auth. */ + @JsonProperty("apiKeyConfig") + public abstract Optional apiKeyConfig(); + + /** Type of auth scheme. */ + @JsonProperty("authType") + public abstract Optional authType(); + + /** Config for Google Service Account auth. */ + @JsonProperty("googleServiceAccountConfig") + public abstract Optional googleServiceAccountConfig(); + + /** Config for HTTP Basic auth. */ + @JsonProperty("httpBasicAuthConfig") + public abstract Optional httpBasicAuthConfig(); + + /** Config for user oauth. */ + @JsonProperty("oauthConfig") + public abstract Optional oauthConfig(); + + /** Config for user OIDC auth. */ + @JsonProperty("oidcConfig") + public abstract Optional oidcConfig(); + + /** Instantiates a builder for AuthConfig. */ + public static Builder builder() { + return new AutoValue_AuthConfig.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for AuthConfig. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `AuthConfig.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_AuthConfig.Builder(); + } + + @JsonProperty("apiKeyConfig") + public abstract Builder apiKeyConfig(ApiKeyConfig apiKeyConfig); + + @JsonProperty("authType") + public abstract Builder authType(String authType); + + @JsonProperty("googleServiceAccountConfig") + public abstract Builder googleServiceAccountConfig( + AuthConfigGoogleServiceAccountConfig googleServiceAccountConfig); + + @JsonProperty("httpBasicAuthConfig") + public abstract Builder httpBasicAuthConfig(AuthConfigHttpBasicAuthConfig httpBasicAuthConfig); + + @JsonProperty("oauthConfig") + public abstract Builder oauthConfig(AuthConfigOauthConfig oauthConfig); + + @JsonProperty("oidcConfig") + public abstract Builder oidcConfig(AuthConfigOidcConfig oidcConfig); + + public abstract AuthConfig build(); + } + + /** Deserializes a JSON string to a AuthConfig object. */ + public static AuthConfig fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, AuthConfig.class); + } +} diff --git a/src/main/java/com/google/genai/types/AuthConfigGoogleServiceAccountConfig.java b/src/main/java/com/google/genai/types/AuthConfigGoogleServiceAccountConfig.java new file mode 100644 index 00000000000..2e11e2a7524 --- /dev/null +++ b/src/main/java/com/google/genai/types/AuthConfigGoogleServiceAccountConfig.java @@ -0,0 +1,73 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.Optional; + +/** Config for Google Service Account Authentication. */ +@AutoValue +@JsonDeserialize(builder = AuthConfigGoogleServiceAccountConfig.Builder.class) +public abstract class AuthConfigGoogleServiceAccountConfig extends JsonSerializable { + /** + * Optional. The service account that the extension execution service runs as. - If the service + * account is specified, the `iam.serviceAccounts.getAccessToken` permission should be granted to + * Vertex AI Extension Service Agent + * (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents) on the + * specified service account. - If not specified, the Vertex AI Extension Service Agent will be + * used to execute the Extension. + */ + @JsonProperty("serviceAccount") + public abstract Optional serviceAccount(); + + /** Instantiates a builder for AuthConfigGoogleServiceAccountConfig. */ + public static Builder builder() { + return new AutoValue_AuthConfigGoogleServiceAccountConfig.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for AuthConfigGoogleServiceAccountConfig. */ + @AutoValue.Builder + public abstract static class Builder { + /** + * For internal usage. Please use `AuthConfigGoogleServiceAccountConfig.builder()` for + * instantiation. + */ + @JsonCreator + private static Builder create() { + return new AutoValue_AuthConfigGoogleServiceAccountConfig.Builder(); + } + + @JsonProperty("serviceAccount") + public abstract Builder serviceAccount(String serviceAccount); + + public abstract AuthConfigGoogleServiceAccountConfig build(); + } + + /** Deserializes a JSON string to a AuthConfigGoogleServiceAccountConfig object. */ + public static AuthConfigGoogleServiceAccountConfig fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, AuthConfigGoogleServiceAccountConfig.class); + } +} diff --git a/src/main/java/com/google/genai/types/AuthConfigHttpBasicAuthConfig.java b/src/main/java/com/google/genai/types/AuthConfigHttpBasicAuthConfig.java new file mode 100644 index 00000000000..9c9aafd90b6 --- /dev/null +++ b/src/main/java/com/google/genai/types/AuthConfigHttpBasicAuthConfig.java @@ -0,0 +1,71 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.Optional; + +/** Config for HTTP Basic Authentication. */ +@AutoValue +@JsonDeserialize(builder = AuthConfigHttpBasicAuthConfig.Builder.class) +public abstract class AuthConfigHttpBasicAuthConfig extends JsonSerializable { + /** + * Required. The name of the SecretManager secret version resource storing the base64 encoded + * credentials. Format: `projects/{project}/secrets/{secrete}/versions/{version}` - If specified, + * the `secretmanager.versions.access` permission should be granted to Vertex AI Extension Service + * Agent (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents) on the + * specified resource. + */ + @JsonProperty("credentialSecret") + public abstract Optional credentialSecret(); + + /** Instantiates a builder for AuthConfigHttpBasicAuthConfig. */ + public static Builder builder() { + return new AutoValue_AuthConfigHttpBasicAuthConfig.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for AuthConfigHttpBasicAuthConfig. */ + @AutoValue.Builder + public abstract static class Builder { + /** + * For internal usage. Please use `AuthConfigHttpBasicAuthConfig.builder()` for instantiation. + */ + @JsonCreator + private static Builder create() { + return new AutoValue_AuthConfigHttpBasicAuthConfig.Builder(); + } + + @JsonProperty("credentialSecret") + public abstract Builder credentialSecret(String credentialSecret); + + public abstract AuthConfigHttpBasicAuthConfig build(); + } + + /** Deserializes a JSON string to a AuthConfigHttpBasicAuthConfig object. */ + public static AuthConfigHttpBasicAuthConfig fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, AuthConfigHttpBasicAuthConfig.class); + } +} diff --git a/src/main/java/com/google/genai/types/AuthConfigOauthConfig.java b/src/main/java/com/google/genai/types/AuthConfigOauthConfig.java new file mode 100644 index 00000000000..7528e17562f --- /dev/null +++ b/src/main/java/com/google/genai/types/AuthConfigOauthConfig.java @@ -0,0 +1,79 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.Optional; + +/** Config for user oauth. */ +@AutoValue +@JsonDeserialize(builder = AuthConfigOauthConfig.Builder.class) +public abstract class AuthConfigOauthConfig extends JsonSerializable { + /** + * Access token for extension endpoint. Only used to propagate token from + * [[ExecuteExtensionRequest.runtime_auth_config]] at request time. + */ + @JsonProperty("accessToken") + public abstract Optional accessToken(); + + /** + * The service account used to generate access tokens for executing the Extension. - If the + * service account is specified, the `iam.serviceAccounts.getAccessToken` permission should be + * granted to Vertex AI Extension Service Agent + * (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents) on the provided + * service account. + */ + @JsonProperty("serviceAccount") + public abstract Optional serviceAccount(); + + /** Instantiates a builder for AuthConfigOauthConfig. */ + public static Builder builder() { + return new AutoValue_AuthConfigOauthConfig.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for AuthConfigOauthConfig. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `AuthConfigOauthConfig.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_AuthConfigOauthConfig.Builder(); + } + + @JsonProperty("accessToken") + public abstract Builder accessToken(String accessToken); + + @JsonProperty("serviceAccount") + public abstract Builder serviceAccount(String serviceAccount); + + public abstract AuthConfigOauthConfig build(); + } + + /** Deserializes a JSON string to a AuthConfigOauthConfig object. */ + public static AuthConfigOauthConfig fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, AuthConfigOauthConfig.class); + } +} diff --git a/src/main/java/com/google/genai/types/AuthConfigOidcConfig.java b/src/main/java/com/google/genai/types/AuthConfigOidcConfig.java new file mode 100644 index 00000000000..9e7b45f9fc3 --- /dev/null +++ b/src/main/java/com/google/genai/types/AuthConfigOidcConfig.java @@ -0,0 +1,81 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.Optional; + +/** Config for user OIDC auth. */ +@AutoValue +@JsonDeserialize(builder = AuthConfigOidcConfig.Builder.class) +public abstract class AuthConfigOidcConfig extends JsonSerializable { + /** + * OpenID Connect formatted ID token for extension endpoint. Only used to propagate token from + * [[ExecuteExtensionRequest.runtime_auth_config]] at request time. + */ + @JsonProperty("idToken") + public abstract Optional idToken(); + + /** + * The service account used to generate an OpenID Connect (OIDC)-compatible JWT token signed by + * the Google OIDC Provider (accounts.google.com) for extension endpoint + * (https://cloud.google.com/iam/docs/create-short-lived-credentials-direct#sa-credentials-oidc). + * - The audience for the token will be set to the URL in the server url defined in the OpenApi + * spec. - If the service account is provided, the service account should grant + * `iam.serviceAccounts.getOpenIdToken` permission to Vertex AI Extension Service Agent + * (https://cloud.google.com/vertex-ai/docs/general/access-control#service-agents). + */ + @JsonProperty("serviceAccount") + public abstract Optional serviceAccount(); + + /** Instantiates a builder for AuthConfigOidcConfig. */ + public static Builder builder() { + return new AutoValue_AuthConfigOidcConfig.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for AuthConfigOidcConfig. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `AuthConfigOidcConfig.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_AuthConfigOidcConfig.Builder(); + } + + @JsonProperty("idToken") + public abstract Builder idToken(String idToken); + + @JsonProperty("serviceAccount") + public abstract Builder serviceAccount(String serviceAccount); + + public abstract AuthConfigOidcConfig build(); + } + + /** Deserializes a JSON string to a AuthConfigOidcConfig object. */ + public static AuthConfigOidcConfig fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, AuthConfigOidcConfig.class); + } +} diff --git a/src/main/java/com/google/genai/types/AuthType.java b/src/main/java/com/google/genai/types/AuthType.java new file mode 100644 index 00000000000..d5d16b52ebd --- /dev/null +++ b/src/main/java/com/google/genai/types/AuthType.java @@ -0,0 +1,69 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** Type of auth scheme. */ +public class AuthType { + + /** Enum representing the known values for AuthType. */ + public enum Known { + AUTH_TYPE_UNSPECIFIED, + NO_AUTH, + API_KEY_AUTH, + HTTP_BASIC_AUTH, + GOOGLE_SERVICE_ACCOUNT_AUTH, + OAUTH, + OIDC_AUTH + } + + private Known authTypeEnum; + private final String value; + + @JsonCreator + public AuthType(String value) { + this.value = value; + for (Known authTypeEnum : Known.values()) { + if (authTypeEnum.toString().equalsIgnoreCase(value)) { + this.authTypeEnum = authTypeEnum; + break; + } + } + if (this.authTypeEnum == null) { + this.authTypeEnum = Known.AUTH_TYPE_UNSPECIFIED; + } + } + + public AuthType(Known knownValue) { + this.authTypeEnum = knownValue; + this.value = knownValue.toString(); + } + + @Override + @JsonValue + public String toString() { + return this.value; + } + + public Known knownEnum() { + return this.authTypeEnum; + } +} diff --git a/src/main/java/com/google/genai/types/GoogleMaps.java b/src/main/java/com/google/genai/types/GoogleMaps.java new file mode 100644 index 00000000000..8159cc68147 --- /dev/null +++ b/src/main/java/com/google/genai/types/GoogleMaps.java @@ -0,0 +1,63 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.Optional; + +/** Tool to support Google Maps in Model. */ +@AutoValue +@JsonDeserialize(builder = GoogleMaps.Builder.class) +public abstract class GoogleMaps extends JsonSerializable { + /** Optional. Auth config for the Google Maps tool. */ + @JsonProperty("authConfig") + public abstract Optional authConfig(); + + /** Instantiates a builder for GoogleMaps. */ + public static Builder builder() { + return new AutoValue_GoogleMaps.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for GoogleMaps. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `GoogleMaps.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_GoogleMaps.Builder(); + } + + @JsonProperty("authConfig") + public abstract Builder authConfig(AuthConfig authConfig); + + public abstract GoogleMaps build(); + } + + /** Deserializes a JSON string to a GoogleMaps object. */ + public static GoogleMaps fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, GoogleMaps.class); + } +} diff --git a/src/main/java/com/google/genai/types/LatLng.java b/src/main/java/com/google/genai/types/LatLng.java new file mode 100644 index 00000000000..614d44d576e --- /dev/null +++ b/src/main/java/com/google/genai/types/LatLng.java @@ -0,0 +1,77 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.Optional; + +/** + * An object that represents a latitude/longitude pair. + * + *

This is expressed as a pair of doubles to represent degrees latitude and degrees longitude. + * Unless specified otherwise, this object must conform to the WGS84 standard. + * Values must be within normalized ranges. + */ +@AutoValue +@JsonDeserialize(builder = LatLng.Builder.class) +public abstract class LatLng extends JsonSerializable { + /** The latitude in degrees. It must be in the range [-90.0, +90.0]. */ + @JsonProperty("latitude") + public abstract Optional latitude(); + + /** The longitude in degrees. It must be in the range [-180.0, +180.0] */ + @JsonProperty("longitude") + public abstract Optional longitude(); + + /** Instantiates a builder for LatLng. */ + public static Builder builder() { + return new AutoValue_LatLng.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for LatLng. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `LatLng.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_LatLng.Builder(); + } + + @JsonProperty("latitude") + public abstract Builder latitude(Double latitude); + + @JsonProperty("longitude") + public abstract Builder longitude(Double longitude); + + public abstract LatLng build(); + } + + /** Deserializes a JSON string to a LatLng object. */ + public static LatLng fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, LatLng.class); + } +} diff --git a/src/main/java/com/google/genai/types/RetrievalConfig.java b/src/main/java/com/google/genai/types/RetrievalConfig.java new file mode 100644 index 00000000000..1cf3748af50 --- /dev/null +++ b/src/main/java/com/google/genai/types/RetrievalConfig.java @@ -0,0 +1,63 @@ +/* + * 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 + * + * https://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. + */ + +// Auto-generated code. Do not edit. + +package com.google.genai.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.genai.JsonSerializable; +import java.util.Optional; + +/** Retrieval config. */ +@AutoValue +@JsonDeserialize(builder = RetrievalConfig.Builder.class) +public abstract class RetrievalConfig extends JsonSerializable { + /** Optional. The location of the user. */ + @JsonProperty("latLng") + public abstract Optional latLng(); + + /** Instantiates a builder for RetrievalConfig. */ + public static Builder builder() { + return new AutoValue_RetrievalConfig.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for RetrievalConfig. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `RetrievalConfig.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_RetrievalConfig.Builder(); + } + + @JsonProperty("latLng") + public abstract Builder latLng(LatLng latLng); + + public abstract RetrievalConfig build(); + } + + /** Deserializes a JSON string to a RetrievalConfig object. */ + public static RetrievalConfig fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, RetrievalConfig.class); + } +} diff --git a/src/main/java/com/google/genai/types/Tool.java b/src/main/java/com/google/genai/types/Tool.java index b17e25a9ae5..bbc13c08d3c 100644 --- a/src/main/java/com/google/genai/types/Tool.java +++ b/src/main/java/com/google/genai/types/Tool.java @@ -58,6 +58,10 @@ public abstract class Tool extends JsonSerializable { @JsonProperty("enterpriseWebSearch") public abstract Optional enterpriseWebSearch(); + /** Optional. Google Maps tool type. Specialized retrieval tool that is powered by Google Maps. */ + @JsonProperty("googleMaps") + public abstract Optional googleMaps(); + /** * Optional. CodeExecution tool type. Enables the model to execute code as part of generation. * This field is only used by the Gemini Developer API services. @@ -104,6 +108,9 @@ private static Builder create() { @JsonProperty("enterpriseWebSearch") public abstract Builder enterpriseWebSearch(EnterpriseWebSearch enterpriseWebSearch); + @JsonProperty("googleMaps") + public abstract Builder googleMaps(GoogleMaps googleMaps); + @JsonProperty("codeExecution") public abstract Builder codeExecution(ToolCodeExecution codeExecution); diff --git a/src/main/java/com/google/genai/types/ToolConfig.java b/src/main/java/com/google/genai/types/ToolConfig.java index e2ffb39201e..007c5a0c0fa 100644 --- a/src/main/java/com/google/genai/types/ToolConfig.java +++ b/src/main/java/com/google/genai/types/ToolConfig.java @@ -37,6 +37,10 @@ public abstract class ToolConfig extends JsonSerializable { @JsonProperty("functionCallingConfig") public abstract Optional functionCallingConfig(); + /** Optional. Retrieval config. */ + @JsonProperty("retrievalConfig") + public abstract Optional retrievalConfig(); + /** Instantiates a builder for ToolConfig. */ public static Builder builder() { return new AutoValue_ToolConfig.Builder(); @@ -57,6 +61,9 @@ private static Builder create() { @JsonProperty("functionCallingConfig") public abstract Builder functionCallingConfig(FunctionCallingConfig functionCallingConfig); + @JsonProperty("retrievalConfig") + public abstract Builder retrievalConfig(RetrievalConfig retrievalConfig); + public abstract ToolConfig build(); } From 5da0746a818218d22456bfbab9d665cde6c1540e Mon Sep 17 00:00:00 2001 From: Parth Kothari Date: Tue, 6 May 2025 09:19:28 -0700 Subject: [PATCH 15/18] feat(http): Make HttpApiClient public PiperOrigin-RevId: 755399470 --- src/main/java/com/google/genai/HttpApiClient.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/genai/HttpApiClient.java b/src/main/java/com/google/genai/HttpApiClient.java index 1e6f3dccc7e..f1363f05650 100644 --- a/src/main/java/com/google/genai/HttpApiClient.java +++ b/src/main/java/com/google/genai/HttpApiClient.java @@ -16,6 +16,7 @@ package com.google.genai; +import com.google.api.core.InternalApi; import com.google.auth.oauth2.GoogleCredentials; import com.google.common.collect.ImmutableMap; import com.google.genai.errors.GenAiIOException; @@ -30,8 +31,9 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; -/** Base client for the HTTP APIs. */ -final class HttpApiClient extends ApiClient { +/** Base client for the HTTP APIs. This is for internal use only. */ +@InternalApi +public class HttpApiClient extends ApiClient { /** Constructs an ApiClient for Google AI APIs. */ HttpApiClient(Optional apiKey, Optional httpOptions) { From 0450428a745ebb2c7ff285d16e188c729a26c470 Mon Sep 17 00:00:00 2001 From: Annie Luc Date: Tue, 6 May 2025 10:46:59 -0700 Subject: [PATCH 16/18] No public description PiperOrigin-RevId: 755433653 --- .../java/com/google/genai/LiveConverters.java | 28 ------------------- src/main/java/com/google/genai/Models.java | 28 ------------------- .../java/com/google/genai/types/Part.java | 7 ----- 3 files changed, 63 deletions(-) diff --git a/src/main/java/com/google/genai/LiveConverters.java b/src/main/java/com/google/genai/LiveConverters.java index 403f287df97..5cc4b268d86 100644 --- a/src/main/java/com/google/genai/LiveConverters.java +++ b/src/main/java/com/google/genai/LiveConverters.java @@ -44,13 +44,6 @@ ObjectNode partToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pare Common.getValueByPath(fromObject, new String[] {"thought"})); } - if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"thoughtSignature"}, - Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); - } - if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -120,13 +113,6 @@ ObjectNode partToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par Common.getValueByPath(fromObject, new String[] {"thought"})); } - if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"thoughtSignature"}, - Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); - } - if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -1860,13 +1846,6 @@ ObjectNode partFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pa Common.getValueByPath(fromObject, new String[] {"thought"})); } - if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"thoughtSignature"}, - Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); - } - if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -1936,13 +1915,6 @@ ObjectNode partFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode p Common.getValueByPath(fromObject, new String[] {"thought"})); } - if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"thoughtSignature"}, - Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); - } - if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, diff --git a/src/main/java/com/google/genai/Models.java b/src/main/java/com/google/genai/Models.java index 5837df575cf..9723360d544 100644 --- a/src/main/java/com/google/genai/Models.java +++ b/src/main/java/com/google/genai/Models.java @@ -88,13 +88,6 @@ ObjectNode partToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pare Common.getValueByPath(fromObject, new String[] {"thought"})); } - if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"thoughtSignature"}, - Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); - } - if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -1208,13 +1201,6 @@ ObjectNode partToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par Common.getValueByPath(fromObject, new String[] {"thought"})); } - if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"thoughtSignature"}, - Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); - } - if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -2888,13 +2874,6 @@ ObjectNode partFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pa Common.getValueByPath(fromObject, new String[] {"thought"})); } - if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"thoughtSignature"}, - Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); - } - if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, @@ -3456,13 +3435,6 @@ ObjectNode partFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode p Common.getValueByPath(fromObject, new String[] {"thought"})); } - if (Common.getValueByPath(fromObject, new String[] {"thoughtSignature"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"thoughtSignature"}, - Common.getValueByPath(fromObject, new String[] {"thoughtSignature"})); - } - if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { Common.setValueByPath( toObject, diff --git a/src/main/java/com/google/genai/types/Part.java b/src/main/java/com/google/genai/types/Part.java index aa5cd2e823e..7316236980a 100644 --- a/src/main/java/com/google/genai/types/Part.java +++ b/src/main/java/com/google/genai/types/Part.java @@ -43,10 +43,6 @@ public abstract class Part extends JsonSerializable { @JsonProperty("thought") public abstract Optional thought(); - /** An opaque signature for the thought so it can be reused in subsequent requests. */ - @JsonProperty("thoughtSignature") - public abstract Optional thoughtSignature(); - /** Optional. Result of executing the [ExecutableCode]. */ @JsonProperty("codeExecutionResult") public abstract Optional codeExecutionResult(); @@ -105,9 +101,6 @@ private static Builder create() { @JsonProperty("thought") public abstract Builder thought(boolean thought); - @JsonProperty("thoughtSignature") - public abstract Builder thoughtSignature(byte[] thoughtSignature); - @JsonProperty("codeExecutionResult") public abstract Builder codeExecutionResult(CodeExecutionResult codeExecutionResult); From 4cd355b51ffe5a551c54bf5e35b22ef47ad545e2 Mon Sep 17 00:00:00 2001 From: Matthew Tang Date: Tue, 6 May 2025 13:23:12 -0700 Subject: [PATCH 17/18] refactor!: Rename getVideoOperation to getVideosOperation for Java SDK PiperOrigin-RevId: 755497916 --- .../main/java/com/google/genai/examples/GenerateVideos.java | 2 +- .../java/com/google/genai/examples/GenerateVideosAsync.java | 2 +- src/main/java/com/google/genai/AsyncOperations.java | 4 ++-- src/main/java/com/google/genai/Operations.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/src/main/java/com/google/genai/examples/GenerateVideos.java b/examples/src/main/java/com/google/genai/examples/GenerateVideos.java index 02d2689f47c..1bceaac111d 100644 --- a/examples/src/main/java/com/google/genai/examples/GenerateVideos.java +++ b/examples/src/main/java/com/google/genai/examples/GenerateVideos.java @@ -77,7 +77,7 @@ public static void main(String[] args) { try { Thread.sleep(10000); // Sleep for 10 seconds. generateVideosOperation = - client.operations.getVideoOperation(generateVideosOperation, null); + client.operations.getVideosOperation(generateVideosOperation, null); System.out.println("Waiting for operation to complete..."); } catch (InterruptedException e) { System.out.println("Thread was interrupted while sleeping."); diff --git a/examples/src/main/java/com/google/genai/examples/GenerateVideosAsync.java b/examples/src/main/java/com/google/genai/examples/GenerateVideosAsync.java index 50584d8e59e..fa053ed38fe 100644 --- a/examples/src/main/java/com/google/genai/examples/GenerateVideosAsync.java +++ b/examples/src/main/java/com/google/genai/examples/GenerateVideosAsync.java @@ -83,7 +83,7 @@ public static void main(String[] args) { try { Thread.sleep(10000); // Sleep for 10 seconds. try { - operation = client.async.operations.getVideoOperation(operation, null).get(); + operation = client.async.operations.getVideosOperation(operation, null).get(); } catch (ExecutionException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/google/genai/AsyncOperations.java b/src/main/java/com/google/genai/AsyncOperations.java index b93f7a611c0..ba2710233b5 100644 --- a/src/main/java/com/google/genai/AsyncOperations.java +++ b/src/main/java/com/google/genai/AsyncOperations.java @@ -37,8 +37,8 @@ public AsyncOperations(ApiClient apiClient) { * @param config The configuration for getting the operation. * @return A GenerateVideosOperation with the updated status of the operation. */ - public CompletableFuture getVideoOperation( + public CompletableFuture getVideosOperation( GenerateVideosOperation operation, GetOperationConfig config) { - return CompletableFuture.supplyAsync(() -> operations.getVideoOperation(operation, config)); + return CompletableFuture.supplyAsync(() -> operations.getVideosOperation(operation, config)); } } diff --git a/src/main/java/com/google/genai/Operations.java b/src/main/java/com/google/genai/Operations.java index 894daf07155..9cdaef0ad04 100644 --- a/src/main/java/com/google/genai/Operations.java +++ b/src/main/java/com/google/genai/Operations.java @@ -481,7 +481,7 @@ private GenerateVideosOperation privateFetchPredictVideosOperation( * @param config The configuration for getting the operation. * @return A GenerateVideosOperation with the updated status of the operation. */ - public GenerateVideosOperation getVideoOperation( + public GenerateVideosOperation getVideosOperation( GenerateVideosOperation operation, GetOperationConfig config) { if (!operation.name().isPresent()) { From 5cc4b86de8a34399adae4fbfb53a2f4d1183fdda Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Wed, 7 May 2025 14:19:09 -0400 Subject: [PATCH 18/18] chore(main): release 0.7.0 (#223) * chore(main): release 0.7.0 * Update CHANGELOG.md --------- Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Sara Robinson --- .release-please-manifest.json | 2 +- CHANGELOG.md | 26 ++++++++++++++++++++++++++ examples/pom.xml | 2 +- pom.xml | 2 +- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index ac0317144eb..1b77f506d45 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.6.1" + ".": "0.7.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 48aa195d234..a64b55a8cc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,31 @@ # Changelog +## [0.7.0](https://github.com/googleapis/java-genai/compare/v0.6.1...v0.7.0) (2025-05-06) + + +### ⚠ BREAKING CHANGES + +* Rename getVideoOperation to getVideosOperation for Java SDK + +### Features + +* Add `Tool.enterprise_web_search` field ([919c22a](https://github.com/googleapis/java-genai/commit/919c22a79e357a4be03e98bd24b4d02282ca7a0d)) +* Add computeTokens support ([85c751e](https://github.com/googleapis/java-genai/commit/85c751e5e8e715ef26cf5524cb57a7d77953a734)) +* Add countTokens method support ([8b8fb45](https://github.com/googleapis/java-genai/commit/8b8fb4515d994b24bd1a3bb3b500f415c2dddeca)) +* Add support for Grounding with Google Maps ([24b1127](https://github.com/googleapis/java-genai/commit/24b112756b21e1b9650e434ba6f53557c8bf6531)) +* enable input transcription for Gemini API. ([9065970](https://github.com/googleapis/java-genai/commit/906597026e36c09cded0d8cb50ffe14a96c5faff)) +* **http:** Make HttpApiClient public ([5da0746](https://github.com/googleapis/java-genai/commit/5da0746a818218d22456bfbab9d665cde6c1540e)) + + +### Documentation + +* Add javadoc to public classes/methods ([78c2a39](https://github.com/googleapis/java-genai/commit/78c2a390ef7ad34dac5cf14ff10838ba9c0899c4)) + + +### Code Refactoring + +* Rename getVideoOperation to getVideosOperation for Java SDK ([4cd355b](https://github.com/googleapis/java-genai/commit/4cd355b51ffe5a551c54bf5e35b22ef47ad545e2)) + ## [0.6.1](https://github.com/googleapis/java-genai/compare/v0.6.0...v0.6.1) (2025-05-01) diff --git a/examples/pom.xml b/examples/pom.xml index 24f6937cde8..0fb4e6d906f 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ com.google.genai.examples google-genai-examples - 0.7.0-SNAPSHOT + 0.7.0 google-genai-examples diff --git a/pom.xml b/pom.xml index 037977cbfbe..87db181a86d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.google.genai google-genai google-genai - 0.7.0-SNAPSHOT + 0.7.0 jar Java idiomatic SDK for the Gemini Developer APIs and Vertex AI APIs.