diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 2aca35ae2f0..4208b5cb79b 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.5.0" + ".": "0.6.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 87abd304d52..f37b76c209a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,35 @@ # Changelog +## [0.6.0](https://github.com/googleapis/java-genai/compare/v0.5.0...v0.6.0) (2025-04-30) + + +### ⚠ BREAKING CHANGES + +* add streaming support for Chat + +### Features + +* add streaming support for Chat ([59eca52](https://github.com/googleapis/java-genai/commit/59eca52caf9f6a6f0a6d02959e3a41db0270c5d1)) +* add support for live grounding metadata ([e90dd15](https://github.com/googleapis/java-genai/commit/e90dd15f58fcbab954c915a89619a035f5edb7ca)) +* Enable configurable speech detection in live SDK ([d6bfa76](https://github.com/googleapis/java-genai/commit/d6bfa76599df688dcaf3178cf70a86b292af461a)) +* introduce FunctionDeclaration.fromMethod class method to parse a FunctionDeclaration instance from a java.lang.reflect.Method instance. ([aeb63b4](https://github.com/googleapis/java-genai/commit/aeb63b448714026c531aa321369f2272ffc8e3ae)) +* make min_property, max_property, min_length, max_length, example, patter fields available for Schema class when calling Gemini API ([8527db5](https://github.com/googleapis/java-genai/commit/8527db52795b1281f3a3de54bb6351e67d5d5229)) +* Support continuous window compression in the Live API ([7acb98c](https://github.com/googleapis/java-genai/commit/7acb98c59774282a7c9bad131c5a3ec3ebd93324)) +* Support setting the default base URL in clients via Client.setDefaultBaseUrls() ([c119778](https://github.com/googleapis/java-genai/commit/c119778c3cf573e9eeefc0c540313162f1abf3ae)) + + +### Bug Fixes + +* do not raise error for `default` field in Schema for Gemini API calls ([8bb1c64](https://github.com/googleapis/java-genai/commit/8bb1c640f4f710b7cd4a1a5a248ced14683bcd0d)) +* Throw IllegalArgumentException rather than general Error when an invalid parameter is passed to Gemini/Vertex backend ([1bd4485](https://github.com/googleapis/java-genai/commit/1bd44850b251560cdc4b513aea43bb037f7016b1)) +* Update error message when a service from an unsupported backend is called ([4cd81ea](https://github.com/googleapis/java-genai/commit/4cd81ea374f756b418629f25c78d5d8e7d914d20)) +* Update Live API websocket base url in java SDK ([8c97572](https://github.com/googleapis/java-genai/commit/8c97572ce6b2b12e5d597ee42bd454ef20f2ad75)) + + +### Documentation + +* add a link for where to find the Google Cloud project id, API key and location ([3ac726c](https://github.com/googleapis/java-genai/commit/3ac726c6122bc8fad1cbfd0959ba62d4ba05f489)) + ## [0.5.0](https://github.com/googleapis/java-genai/compare/v0.4.0...v0.5.0) (2025-04-22) diff --git a/README.md b/README.md index 82592b666a0..f48e133c555 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.3.0 + 0.5.0 ``` diff --git a/examples/pom.xml b/examples/pom.xml index 29e39558c1f..ecd4cddf4a7 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,14 +5,14 @@ com.google.genai.examples google-genai-examples - 0.5.0 + 0.6.0 google-genai-examples UTF-8 1.8 1.8 - 0.5.0-SNAPSHOT + 0.6.0-SNAPSHOT diff --git a/examples/src/main/java/com/google/genai/examples/LiveAudioConfigurableSpeechDetectionAsync.java b/examples/src/main/java/com/google/genai/examples/LiveAudioConfigurableSpeechDetectionAsync.java new file mode 100644 index 00000000000..c5b43b122b1 --- /dev/null +++ b/examples/src/main/java/com/google/genai/examples/LiveAudioConfigurableSpeechDetectionAsync.java @@ -0,0 +1,311 @@ +/* + * 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. You might need to grant microphone + * permissions. + * + *

mvn clean compile exec:java + * -Dexec.mainClass="com.google.genai.examples.LiveAudioConfigurableSpeechDetectionAsync" + * + *

3. Speak into the microphone. Press Ctrl+C to exit. Important: This example uses the system + * default audio input and output, which often won't include echo cancellation. So to prevent the + * model from interrupting itself it is important that you use headphones. + */ +package com.google.genai.examples; + +import com.google.common.collect.ImmutableList; +import com.google.genai.AsyncSession; +import com.google.genai.Client; +import com.google.genai.types.ActivityStart; +import com.google.genai.types.Blob; +import com.google.genai.types.HttpOptions; +import com.google.genai.types.LiveConnectConfig; +import com.google.genai.types.LiveSendRealtimeInputParameters; +import com.google.genai.types.LiveServerMessage; +import com.google.genai.types.RealtimeInputConfig; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.DataLine; +import javax.sound.sampled.Line; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.SourceDataLine; +import javax.sound.sampled.TargetDataLine; + +/** + * Example of using the live module for a streaming audio conversation with configurable speech + * detection. + */ +public class LiveAudioConfigurableSpeechDetectionAsync { + + // --- Audio Configuration --- + private static final AudioFormat MIC_AUDIO_FORMAT = + new AudioFormat(16000.0f, 16, 1, true, false); // 16kHz, 16-bit, mono, signed, little-endian + private static final AudioFormat SPEAKER_AUDIO_FORMAT = + new AudioFormat(24000.0f, 16, 1, true, false); // 24kHz, 16-bit, mono, signed, little-endian + + // How many bytes to read from mic/send to API at a time + private static final int CHUNK_SIZE = 4096; + // -------------------------- + + private static volatile boolean running = true; + private static volatile boolean speakerPlaying = false; + private static TargetDataLine microphoneLine; + private static SourceDataLine speakerLine; + private static AsyncSession session; + private static ExecutorService micExecutor = Executors.newSingleThreadExecutor(); + + /** Creates the parameters for sending an audio chunk. */ + public static LiveSendRealtimeInputParameters createAudioContent(byte[] audioData) { + + if (audioData == null) { + System.err.println("Error: Audio is null"); + return null; + } + + Blob media = Blob.builder().mimeType("audio/pcm").data(audioData).build(); + + return LiveSendRealtimeInputParameters.builder() + .media(media) + .activityStart(ActivityStart.builder().build()) + .build(); + } + + /** Reads audio from the microphone and sends it to the API session. Runs in a separate thread. */ + private static void sendMicrophoneAudio() { + byte[] buffer = new byte[CHUNK_SIZE]; + int bytesRead; + + while (running && microphoneLine != null && microphoneLine.isOpen()) { + bytesRead = microphoneLine.read(buffer, 0, buffer.length); + + if (bytesRead > 0 && !speakerPlaying) { + // Create a copy of the buffer with the actual bytes read + byte[] audioChunk = new byte[bytesRead]; + System.arraycopy(buffer, 0, audioChunk, 0, bytesRead); + + // Send the audio chunk asynchronously + if (session != null) { + session + .sendRealtimeInput(createAudioContent(audioChunk)) + .exceptionally( + e -> { + System.err.println("Error sending audio chunk: " + e.getMessage()); + return null; + }); + } + } else if (bytesRead == -1) { + System.err.println("Microphone stream ended unexpectedly."); + running = false; // Stop the loop if stream ends + } + } + System.out.println("Microphone reading stopped."); + } + + public static void main(String[] args) throws LineUnavailableException { + + // Instantiates the client. + Client client = + Client.builder().httpOptions(HttpOptions.builder().apiVersion("v1beta").build()).build(); + + // --- Audio Line Setup --- + microphoneLine = getMicrophoneLine(); + speakerLine = getSpeakerLine(); + + // --- Live API Config for Audio --- + LiveConnectConfig config = + LiveConnectConfig.builder() + .responseModalities(ImmutableList.of("AUDIO")) + .realtimeInputConfig( + RealtimeInputConfig.builder() + .activityHandling("NO_INTERRUPTION") + .turnCoverage("TURN_INCLUDES_ALL_INPUT") + .build()) + .build(); + + // --- Shutdown Hook for Cleanup --- + Runtime.getRuntime() + .addShutdownHook( + new Thread( + () -> { + System.out.println("\nShutting down..."); + running = false; // Signal mic thread to stop + micExecutor.shutdown(); + try { + if (!micExecutor.awaitTermination(5, TimeUnit.SECONDS)) { + System.err.println("Mic executor did not terminate gracefully."); + micExecutor.shutdownNow(); + } + } catch (InterruptedException e) { + micExecutor.shutdownNow(); + Thread.currentThread().interrupt(); + } + + // Close session first + if (session != null) { + try { + System.out.println("Closing API session..."); + session.close().get(5, TimeUnit.SECONDS); // Wait with timeout + System.out.println("API session closed."); + } catch (Exception e) { + System.err.println("Error closing API session: " + e.getMessage()); + } + } + // Close audio lines + closeAudioLine(microphoneLine); + closeAudioLine(speakerLine); + System.out.println("Audio lines closed."); + })); + + try { + // --- Connect to Gemini Live API --- + System.out.println("Connecting to Gemini Live API..."); + + if (client.vertexAI()) { + session = client.async.live.connect("gemini-2.0-flash-live-preview-04-09", config).get(); + } else { + session = client.async.live.connect("gemini-2.0-flash-live-001", config).get(); + } + System.out.println("Connected."); + + // --- Start Audio Lines --- + microphoneLine.start(); + speakerLine.start(); + System.out.println("Microphone and speakers started. Speak now (Press Ctrl+C to exit)..."); + + // --- Start Receiving Audio Responses --- + CompletableFuture receiveFuture = + session.receive(LiveAudioConfigurableSpeechDetectionAsync::handleAudioResponse); + System.err.println("Receive stream started."); // Add this line + + // --- Start Sending Microphone Audio --- + CompletableFuture sendFuture = + CompletableFuture.runAsync( + LiveAudioConfigurableSpeechDetectionAsync::sendMicrophoneAudio, micExecutor); + + // Keep the main thread alive. Wait for sending or receiving to finish (or + // error). + // In this continuous streaming case, we rely on the shutdown hook triggered by + // Ctrl+C. + // We can wait on the futures, but they might not complete normally in this + // design. + CompletableFuture.anyOf(receiveFuture, sendFuture) + .handle( + (res, err) -> { + if (err != null) { + System.err.println("An error occurred in sending/receiving: " + err.getMessage()); + // Trigger shutdown if needed + System.exit(1); + } + return null; + }) + .get(); // Wait indefinitely or until an error occurs in send/receive + + } catch (InterruptedException | ExecutionException e) { + System.err.println("An error occurred during setup or connection: " + e.getMessage()); + e.printStackTrace(); + System.exit(1); + } + // Note: Normal exit is handled by the shutdown hook when Ctrl+C is pressed. + } + + /** Gets and opens the microphone line. */ + private static TargetDataLine getMicrophoneLine() throws LineUnavailableException { + DataLine.Info micInfo = new DataLine.Info(TargetDataLine.class, MIC_AUDIO_FORMAT); + if (!AudioSystem.isLineSupported(micInfo)) { + throw new LineUnavailableException( + "Microphone line not supported for format: " + MIC_AUDIO_FORMAT); + } + TargetDataLine line = (TargetDataLine) AudioSystem.getLine(micInfo); + line.open(MIC_AUDIO_FORMAT); + System.out.println("Microphone line opened."); + return line; + } + + /** Gets and opens the speaker line. */ + private static SourceDataLine getSpeakerLine() throws LineUnavailableException { + DataLine.Info speakerInfo = new DataLine.Info(SourceDataLine.class, SPEAKER_AUDIO_FORMAT); + if (!AudioSystem.isLineSupported(speakerInfo)) { + throw new LineUnavailableException( + "Speaker line not supported for format: " + SPEAKER_AUDIO_FORMAT); + } + SourceDataLine line = (SourceDataLine) AudioSystem.getLine(speakerInfo); + line.open(SPEAKER_AUDIO_FORMAT); + System.out.println("Speaker line opened."); + return line; + } + + /** Closes an audio line safely. */ + private static void closeAudioLine(Line line) { + if (line != null && line.isOpen()) { + line.close(); + } + } + + /** Callback function to handle incoming audio messages from the server. */ + public static void handleAudioResponse(LiveServerMessage message) { + message + .serverContent() + .ifPresent( + content -> { + if (content.turnComplete().orElse(false)) { + // when interrupted, Gemini sends a turn_compete with + // Stop the speaker if the turn is complete + if (speakerLine != null && speakerLine.isOpen()) { + speakerLine.flush(); + } + } else { + content + .modelTurn() + .flatMap(modelTurn -> modelTurn.parts()) + .ifPresent( + parts -> + parts.forEach( + part -> + part.inlineData() + .flatMap(Blob::data) + .ifPresent( + audioBytes -> { + if (speakerLine != null && speakerLine.isOpen()) { + // Write audio data to the speaker + speakerLine.write(audioBytes, 0, audioBytes.length); + } + }))); + } + }); + } +} diff --git a/examples/src/main/java/com/google/genai/examples/LiveTextContextWindowCompressionAsync.java b/examples/src/main/java/com/google/genai/examples/LiveTextContextWindowCompressionAsync.java new file mode 100644 index 00000000000..0b91703eb5e --- /dev/null +++ b/examples/src/main/java/com/google/genai/examples/LiveTextContextWindowCompressionAsync.java @@ -0,0 +1,143 @@ +/* + * 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.LiveTextContextWindowCompressionAsync" + */ +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.ContextWindowCompressionConfig; +import com.google.genai.types.LiveConnectConfig; +import com.google.genai.types.LiveSendClientContentParameters; +import com.google.genai.types.LiveServerContent; +import com.google.genai.types.LiveServerMessage; +import com.google.genai.types.Part; +import com.google.genai.types.SlidingWindow; +import java.util.concurrent.CompletableFuture; +import com.google.genai.types.GroundingChunk; +import com.google.genai.types.GroundingChunkWeb; +import java.util.List; +import java.util.Optional; + +/** Example of using the live module to set up context window compression. */ +public class LiveTextContextWindowCompressionAsync { + + public static void main(String[] args) { + // Instantiates the client using Vertex AI, and sets the project and location in the builder. + Client client = + Client.builder() + .vertexAI(true) + .project(System.getenv("GOOGLE_CLOUD_PROJECT")) + .location(System.getenv("GOOGLE_CLOUD_LOCATION")) + .build(); + + LiveConnectConfig config = + LiveConnectConfig.builder() + .responseModalities(ImmutableList.of("TEXT")) + .contextWindowCompression( + ContextWindowCompressionConfig.builder() + .triggerTokens(1000L) + .slidingWindow(SlidingWindow.builder().targetTokens(500L).build()) + .build()) + .build(); + + CompletableFuture allDone = new CompletableFuture<>(); + + String modelName; + if (client.vertexAI()) { + modelName = "gemini-2.0-flash-live-preview-04-09"; + } else { + modelName = "gemini-2.0-flash-live-001"; + } + + client + .async + .live + .connect(modelName, config) + .thenCompose( + session -> { + String inputText = "Why is the sky blue?"; + System.out.println("\n**Input**\n" + inputText); + + return session + // Send the input message. + .sendClientContent(clientContentFromText(inputText)) + .thenCompose( + unused -> { + System.out.print("\n**Response**\n"); + // Receive messages from the live session. + return session.receive(message -> printLiveServerMessage(message, allDone)); + }) + .thenCompose(unused -> allDone) + .thenCompose(unused -> session.close()); + }); + } + + public static LiveSendClientContentParameters clientContentFromText(String text) { + return LiveSendClientContentParameters.builder() + .turnComplete(true) + .turns( + ImmutableList.of( + Content.builder() + .parts(ImmutableList.of(Part.builder().text(text).build())) + .build())) + .build(); + } + + public static void printLiveServerMessage( + LiveServerMessage message, CompletableFuture allDone) { + if (message.serverContent().isPresent()) { + LiveServerContent content = message.serverContent().get(); + if (content.modelTurn().isPresent()) { + Content modelTurn = content.modelTurn().get(); + for (Part part : modelTurn.parts().orElse(ImmutableList.of())) { + if (part.inlineData().isPresent()) { + // Print some text to indicate that audio is returned. + System.out.print("Some audio bytes in inline_data..."); + } else if (part.text().isPresent()) { + System.out.print(part.text().get()); + } + } + } + if (content.turnComplete().orElse(false)) { + System.out.println(); + allDone.complete(null); + } + } + } +} 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 7868d1d877f..f3b9431adec 100644 --- a/examples/src/main/java/com/google/genai/examples/LiveTextToAudioTranscriptionAsync.java +++ b/examples/src/main/java/com/google/genai/examples/LiveTextToAudioTranscriptionAsync.java @@ -34,7 +34,7 @@ *

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

mvn clean compile exec:java - * -Dexec.mainClass="com.google.genai.examples.LiveTextToTextGenerationAsync" + * -Dexec.mainClass="com.google.genai.examples.LiveTextToAudioTranscriptionAsync" */ package com.google.genai.examples; @@ -43,6 +43,7 @@ import com.google.genai.types.AudioTranscriptionConfig; import com.google.genai.types.Content; import com.google.genai.types.GoogleSearch; +import com.google.genai.types.GroundingMetadata; import com.google.genai.types.LiveConnectConfig; import com.google.genai.types.LiveSendClientContentParameters; import com.google.genai.types.LiveServerContent; @@ -52,6 +53,10 @@ import com.google.genai.types.Tool; import com.google.genai.types.Transcription; import java.util.concurrent.CompletableFuture; +import com.google.genai.types.GroundingChunk; +import com.google.genai.types.GroundingChunkWeb; +import java.util.List; +import java.util.Optional; /** Example of using the live module to send and receive messages asynchronously. */ public class LiveTextToAudioTranscriptionAsync { @@ -135,6 +140,26 @@ public static void printLiveServerMessage( } } } + if (content.groundingMetadata().isPresent()) { + GroundingMetadata groundingMetadata = content.groundingMetadata().get(); + + Optional> groundingChunksOptional = + groundingMetadata.groundingChunks(); + + if (groundingChunksOptional.isPresent()) { + List groundingChunks = groundingChunksOptional.get(); + for (GroundingChunk chunk : groundingChunks) { + if (chunk.web().isPresent()) { + GroundingChunkWeb web = chunk.web().get(); + if (web.uri().isPresent()) { + String uri = web.uri().get(); + System.out.println("\n\nGrounding URI: " + uri); + } + } + } + } + } + // Print audio transcription. if (content.outputTranscription().isPresent()) { Transcription transcription = content.outputTranscription().get(); diff --git a/examples/src/main/java/com/google/genai/examples/StreamingChatWithHistory.java b/examples/src/main/java/com/google/genai/examples/StreamingChatWithHistory.java new file mode 100644 index 00000000000..7f62d2f25a4 --- /dev/null +++ b/examples/src/main/java/com/google/genai/examples/StreamingChatWithHistory.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. + */ + +/** + * 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.GenerateContent" + */ +package com.google.genai.examples; + +import com.google.genai.Chat; +import com.google.genai.Client; +import com.google.genai.ResponseStream; +import com.google.genai.types.GenerateContentResponse; + +/** An example of using the Unified Gen AI Java SDK to generate content. */ +public class StreamingChatWithHistory { + 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(); + + // Create a chat session. + Chat chatSession = client.chats.create("gemini-2.0-flash-001"); + + ResponseStream responseStream = + chatSession.sendMessageStream("Can you tell me a story about cheese in 100 words?", null); + + while (responseStream.iterator().hasNext()) { + GenerateContentResponse response = responseStream.iterator().next(); + System.out.println("Streaming response 1: " + response.text()); + } + + ResponseStream responseStream2 = + chatSession.sendMessageStream( + "Can you modify the story to be written for a 5 year old?", null); + + while (responseStream2.iterator().hasNext()) { + GenerateContentResponse response = responseStream2.iterator().next(); + System.out.println("Streaming response 2: " + response.text()); + } + + // Get the history of the chat session. + // History is added after the stream is consumed and includes the aggregated response from the + // stream, so chatSession.getHistory(false) here returns 4 items (2 user-model message pairs) + System.out.println("History: " + chatSession.getHistory(false)); + } +} diff --git a/pom.xml b/pom.xml index 85974723082..012f564943c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.google.genai google-genai google-genai - 0.5.0 + 0.6.0 jar Java idiomatic SDK for the Gemini Developer APIs and Vertex AI APIs. diff --git a/src/main/java/com/google/genai/AsyncLive.java b/src/main/java/com/google/genai/AsyncLive.java index 5a048372fd5..09df8c1babb 100644 --- a/src/main/java/com/google/genai/AsyncLive.java +++ b/src/main/java/com/google/genai/AsyncLive.java @@ -18,11 +18,12 @@ import static java.nio.charset.StandardCharsets.UTF_8; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.auth.oauth2.GoogleCredentials; import com.google.genai.errors.GenAiIOException; -import com.google.genai.types.LiveClientSetup; import com.google.genai.types.LiveConnectConfig; +import com.google.genai.types.LiveConnectParameters; import com.google.genai.types.LiveServerMessage; import java.io.IOException; import java.net.URI; @@ -94,14 +95,14 @@ private URI getWebSocketUri() { if (!apiClient.vertexAI()) { return new URI( String.format( - "%sws/google.ai.generativelanguage.%s.GenerativeService.BidiGenerateContent?key=%s", + "%s/ws/google.ai.generativelanguage.%s.GenerativeService.BidiGenerateContent?key=%s", wsBaseUrl, apiClient.httpOptions.apiVersion().orElse("v1beta"), apiClient.apiKey())); } else { return new URI( String.format( - "%sws/google.cloud.aiplatform.%s.LlmBidiService/BidiGenerateContent", + "%s/ws/google.cloud.aiplatform.%s.LlmBidiService/BidiGenerateContent", wsBaseUrl, apiClient.httpOptions.apiVersion().orElse("v1beta1"))); } } catch (URISyntaxException e) { @@ -129,75 +130,37 @@ private Map getWebSocketHeaders() { /** Gets the request message for the initial setup. */ private String getSetupRequest(String model, LiveConnectConfig config) { - LiveClientSetup.Builder setupBuilder = LiveClientSetup.builder(); String transformedModel = Transformers.tModel(apiClient, model); + // Vertex requires the full resource path for the model. if (apiClient.vertexAI() && transformedModel.startsWith("publishers/")) { - transformedModel = + model = String.format( "projects/%s/locations/%s/%s", apiClient.project(), apiClient.location(), transformedModel); } - setupBuilder.model(transformedModel); - if (config == null) { - return setupBuilder.build().toJson(); - } - - config.systemInstruction().ifPresent(setupBuilder::systemInstruction); - config.tools().ifPresent(setupBuilder::tools); - config.inputAudioTranscription().ifPresent(setupBuilder::inputAudioTranscription); - config.outputAudioTranscription().ifPresent(setupBuilder::outputAudioTranscription); - - // responseModalities and speechConfig are missing in the LiveClientSetup. - // we need to manually add them to the request message. - ObjectNode generationConfigNode = JsonSerializable.objectMapper.createObjectNode(); - if (config.temperature().isPresent()) { - generationConfigNode.set( - "temperature", JsonSerializable.toJsonNode(config.temperature().get())); - } - - if (config.topP().isPresent()) { - generationConfigNode.set("topP", JsonSerializable.toJsonNode(config.topP().get())); - } - - if (config.topK().isPresent()) { - generationConfigNode.set("topK", - JsonSerializable.toJsonNode(config.topK().get()).deepCopy()); - } - - if (config.maxOutputTokens().isPresent()) { - generationConfigNode.set( - "maxOutputTokens", - JsonSerializable.toJsonNode(config.maxOutputTokens().get()).deepCopy()); - } - if (config.mediaResolution().isPresent()) { - generationConfigNode.set( - "mediaResolution", - JsonSerializable.toJsonNode(config.mediaResolution().get()).deepCopy()); + LiveConverters liveConverters = new LiveConverters(apiClient); + LiveConnectParameters.Builder parameterBuilder = LiveConnectParameters.builder(); + if (!Common.isZero(model)) { + parameterBuilder.model(model); } - - if (config.seed().isPresent()) { - generationConfigNode.set( - "seed", JsonSerializable.toJsonNode(config.seed().get()).deepCopy()); + if (!Common.isZero(config)) { + parameterBuilder.config(config); } + JsonNode parameterNode = JsonSerializable.toJsonNode(parameterBuilder.build()); - if (config.responseModalities().isPresent()) { - generationConfigNode.set( - "responseModalities", JsonSerializable.toJsonNode(config.responseModalities().get())); + ObjectNode body; + if (this.apiClient.vertexAI()) { + body = liveConverters.liveConnectParametersToVertex(this.apiClient, parameterNode, null); + } else { + body = liveConverters.liveConnectParametersToMldev(this.apiClient, parameterNode, null); } - if (config.speechConfig().isPresent()) { - generationConfigNode.set( - "speechConfig", JsonSerializable.toJsonNode(config.speechConfig().get())); - } - - ObjectNode setupNode = JsonSerializable.toJsonNode(setupBuilder.build()).deepCopy(); - if (!generationConfigNode.isEmpty()) { - setupNode.set("generationConfig", generationConfigNode); - } + // TODO: Remove the hack that removes config. + body.remove("config"); - return String.format("{'setup':%s}", JsonSerializable.toJsonString(setupNode)); + return JsonSerializable.toJsonString(body); } static class GenAiWebSocketClient extends WebSocketClient { diff --git a/src/main/java/com/google/genai/AsyncSession.java b/src/main/java/com/google/genai/AsyncSession.java index 87fcd206cab..1ad002bc5ac 100644 --- a/src/main/java/com/google/genai/AsyncSession.java +++ b/src/main/java/com/google/genai/AsyncSession.java @@ -16,6 +16,8 @@ package com.google.genai; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.ImmutableList; import com.google.genai.types.Blob; import com.google.genai.types.LiveClientContent; @@ -100,7 +102,18 @@ public CompletableFuture sendToolResponse(LiveSendToolResponseParameters t * will fail if the message cannot be sent. */ private CompletableFuture send(LiveClientMessage input) { - return CompletableFuture.runAsync(() -> websocket.send(input.toJson())); + + LiveConverters liveConverters = new LiveConverters(apiClient); + JsonNode parameterNode = JsonSerializable.toJsonNode(input); + + ObjectNode body; + if (this.apiClient.vertexAI()) { + body = liveConverters.liveClientMessageToVertex(this.apiClient, parameterNode, null); + } else { + body = liveConverters.liveClientMessageToMldev(this.apiClient, parameterNode, null); + } + + return CompletableFuture.runAsync(() -> websocket.send(JsonSerializable.toJsonString(body))); } /** diff --git a/src/main/java/com/google/genai/Chat.java b/src/main/java/com/google/genai/Chat.java index ccd3de182e6..1099ff49650 100644 --- a/src/main/java/com/google/genai/Chat.java +++ b/src/main/java/com/google/genai/Chat.java @@ -29,7 +29,7 @@ *

This class provides a way to interact with a generative model in a multi-turn chat session. It * keeps track of the chat history and uses it to provide context for subsequent messages. */ -public final class Chat extends ChatBase { +public class Chat extends ChatBase { private final ApiClient apiClient; private final Models models; private final String model; @@ -128,7 +128,6 @@ public GenerateContentResponse sendMessage(List contents, GenerateConte * chats.create() before calling sendMessage. * * @param contents a {@link List} to send to the generative model - * the optional configurations */ public GenerateContentResponse sendMessage(List contents) { return privateSendMessage(contents, null); @@ -137,6 +136,8 @@ public GenerateContentResponse sendMessage(List contents) { private GenerateContentResponse privateSendMessage( List contents, GenerateContentConfig config) { + throwIfStreamNotConsumed(); + // Validate user input before sending to the model. if (!validateContents(contents)) { throw new IllegalArgumentException("The content of the message is invalid."); @@ -153,8 +154,6 @@ private GenerateContentResponse privateSendMessage( GenerateContentResponse response = this.models.generateContent(this.model, requestContents, config); - response.checkFinishReason(); - List responseContents = new ArrayList<>(); for (Candidate candidate : response.candidates().get()) { responseContents.add(candidate.content().get()); @@ -162,7 +161,130 @@ private GenerateContentResponse privateSendMessage( List currentHistory = new ArrayList<>(); currentHistory.addAll(contents); currentHistory.addAll(responseContents); - recordHistory(currentHistory); + recordHistory(currentHistory, response); return response; } + + /** + * Sends a message to the model in the current multi-turn chat session and returns a stream of + * responses. + * + *

This appends the message and the model's response to the chat history in *subsequent* calls + * to sendMessage or sendMessageStream. Be sure to initialize a chat session using chats.create() + * before calling sendMessageStream. + * + * @param text the text to send to the generative model + * @param config a {@link com.google.genai.types.GenerateContentConfig} instance that specifies + * the optional configurations * + */ + public ResponseStream sendMessageStream( + String text, GenerateContentConfig config) { + return privateSendMessageStream(Transformers.tContents(this.apiClient, (Object) text), config); + } + + /** + * Sends a message to the model in the current multi-turn chat session and returns a stream of + * responses. + * + *

This appends the message and the model's response to the chat history in *subsequent* calls + * to sendMessage or sendMessageStream. Be sure to initialize a chat session using chats.create() + * before calling sendMessageStream. + * + * @param text the text to send to the generative model + */ + public ResponseStream sendMessageStream(String text) { + return privateSendMessageStream(Transformers.tContents(this.apiClient, (Object) text), null); + } + + /** + * Sends a message to the model in the current multi-turn chat session and returns a stream of + * responses. + * + *

This appends the message and the model's response to the chat history in *subsequent* calls + * to sendMessage or sendMessageStream. Be sure to initialize a chat session using chats.create() + * before calling sendMessageStream. + * + * @param content a {@link com.google.genai.types.Content} to send to the generative model + * @param config a {@link com.google.genai.types.GenerateContentConfig} instance that specifies + * the optional configurations * + */ + public ResponseStream sendMessageStream( + Content content, GenerateContentConfig config) { + return privateSendMessageStream( + Transformers.tContents(this.apiClient, (Object) content), config); + } + + /** + * Sends a message to the model in the current multi-turn chat session and returns a stream of + * responses. + * + *

This appends the message and the model's response to the chat history, which is sent back to + * the model in subsequent calls to sendMessage or sendMessageStream. Be sure to initialize a chat + * session using chats.create() before calling sendMessageStream. + * + * @param content a {@link com.google.genai.types.Content} to send to the generative model + */ + public ResponseStream sendMessageStream(Content content) { + return privateSendMessageStream(Transformers.tContents(this.apiClient, (Object) content), null); + } + + /** + * Sends a message to the model in the current multi-turn chat session and returns a stream of + * responses. + * + *

This appends the message and the model's response to the chat history, which is sent back to + * the model in subsequent calls to sendMessage or sendMessageStream. Be sure to initialize a chat + * session using chats.create() before calling sendMessageStream. + * + * @param contents a {@link List} to send to the generative model + * @param config a {@link com.google.genai.types.GenerateContentConfig} instance that specifies + * the optional configurations + */ + public ResponseStream sendMessageStream( + List contents, GenerateContentConfig config) { + return privateSendMessageStream(contents, config); + } + + /** + * Sends a message to the model in the current multi-turn chat session and returns the model's + * response. + * + *

This appends the message and the model's response to the chat history, which is sent back to + * the model in subsequent calls to sendMessage. Be sure to initialize a chat session using + * chats.create() before calling sendMessage. + * + * @param contents a {@link List} to send to the generative model + * the optional configurations + */ + public ResponseStream sendMessageStream(List contents) { + return privateSendMessageStream(contents, null); + } + + private ResponseStream privateSendMessageStream( + List contents, GenerateContentConfig config) { + + throwIfStreamNotConsumed(); + + // Validate user input before sending to the model. + if (!validateContents(contents)) { + throw new IllegalArgumentException("The content of the message is invalid."); + } + + List requestContents = new ArrayList<>(); + requestContents.addAll(this.curatedHistory); + requestContents.addAll(contents); + + if (this.config != null && config == null) { + config = this.config; + } + + ResponseStream responseStream = + this.models.generateContentStream(this.model, requestContents, config); + responseStream.recordingHistory = true; + responseStream.chatSession = this; + this.currentUserMessage = contents; + this.currentResponseStream = responseStream; + + return responseStream; + } } diff --git a/src/main/java/com/google/genai/ChatBase.java b/src/main/java/com/google/genai/ChatBase.java index 37bc6d55a43..4afa17b09be 100644 --- a/src/main/java/com/google/genai/ChatBase.java +++ b/src/main/java/com/google/genai/ChatBase.java @@ -16,16 +16,25 @@ package com.google.genai; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; +import com.google.genai.types.Candidate; import com.google.genai.types.Content; +import com.google.genai.types.GenerateContentResponse; import com.google.genai.types.Part; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.logging.Logger; /** Base class for chat sessions, used for history management. */ class ChatBase { protected final List comprehensiveHistory; protected final List curatedHistory; + protected ResponseStream currentResponseStream; + protected List currentUserMessage; + + private static final Logger logger = Logger.getLogger(ChatBase.class.getName()); ChatBase(List comprehensiveHistory, List curatedHistory) { this.comprehensiveHistory = new ArrayList<>(); @@ -37,10 +46,26 @@ class ChatBase { * * @param currentHistory The current history of messages. */ - protected void recordHistory(List currentHistory) { + protected void recordHistory(List currentHistory, GenerateContentResponse response) { + this.comprehensiveHistory.addAll(currentHistory); + + // This will throw for invalid history List validatedHistory = validateHistory(currentHistory); - this.curatedHistory.addAll(validatedHistory); + + // Catch exception on checkFinishReason() and only add to curated history if checkFinishReason() + // doesn't throw + try { + 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."); + } + } } /** @@ -90,9 +115,15 @@ protected List validateHistory(List history) { List currentOutput = new ArrayList<>(); List validRoles = Arrays.asList("user", "model"); for (int i = 0; i < history.size(); i++) { - if (i == 0 - && history.get(i).role().isPresent() - && !history.get(i).role().get().equals("user")) { + // The second condition handles the case where the history is empty and we are validating the + // first message in a streaming call + if ((i == 0 + && history.get(i).role().isPresent() + && !history.get(i).role().get().equals("user")) + || (curatedHistory.isEmpty() + && !history.isEmpty() + && history.get(0).role().isPresent() + && !history.get(0).role().get().equals("user"))) { throw new IllegalArgumentException( "The first message in the history must be from the user."); } @@ -133,11 +164,77 @@ protected List validateHistory(List history) { * Comprehensive history includes all messages, including empty or invalid parts. Curated * history excludes empty or invalid parts. */ - public List getHistory(boolean curated) { + public ImmutableList getHistory(boolean curated) { + throwIfStreamNotConsumed(); + if (curated) { - return this.curatedHistory; + return ImmutableList.copyOf(this.curatedHistory); } else { - return this.comprehensiveHistory; + return ImmutableList.copyOf(this.comprehensiveHistory); + } + } + + private Content aggregateStreamingResponse(List responseChunks) { + + if (responseChunks == null || responseChunks.isEmpty()) { + return Content.builder().build(); + } + + List aggregatedParts = new ArrayList<>(); + String aggregatedText = ""; + + for (GenerateContentResponse responseChunk : responseChunks) { + if (responseChunk == null) { + continue; + } + Candidate candidate = responseChunk.candidates().get().get(0); + if (candidate.content().isPresent() && candidate.content().get().parts().isPresent()) { + List parts = candidate.content().get().parts().get(); + for (Part part : parts) { + if (part.text().isPresent()) { + aggregatedText += part.text().get(); + } else { + boolean hasOtherContentParts = + part.functionCall().isPresent() + || part.functionResponse().isPresent() + || part.codeExecutionResult().isPresent() + || part.executableCode().isPresent() + || part.fileData().isPresent() + || part.videoMetadata().isPresent() + || part.thought().isPresent() + || part.inlineData().isPresent(); + if (hasOtherContentParts) { + aggregatedParts.add(part); + } + } + } + } + } + + // Construct the final response + aggregatedParts.add(Part.fromText(aggregatedText)); + return Content.builder().parts(aggregatedParts).role("model").build(); + } + + protected void checkStreamResponseAndUpdateHistory() { + if (this.currentResponseStream != null && this.currentUserMessage != null) { + throwIfStreamNotConsumed(); + List streamingResponseContents = new ArrayList<>(); + streamingResponseContents.addAll(this.currentUserMessage); + Content aggregatedResponse = aggregateStreamingResponse(this.currentResponseStream.history); + streamingResponseContents.add(aggregatedResponse); + recordHistory( + streamingResponseContents, Iterables.getLast(this.currentResponseStream.history)); + } + this.currentUserMessage = null; + this.currentResponseStream = null; + } + + protected void throwIfStreamNotConsumed() { + if (this.currentResponseStream != null && this.currentUserMessage != null) { + if (!this.currentResponseStream.isConsumed()) { + throw new IllegalStateException("Response stream is not consumed"); + } } } } diff --git a/src/main/java/com/google/genai/ChatSession.java b/src/main/java/com/google/genai/Chats.java similarity index 95% rename from src/main/java/com/google/genai/ChatSession.java rename to src/main/java/com/google/genai/Chats.java index f6765eb128a..fc9657edfc7 100644 --- a/src/main/java/com/google/genai/ChatSession.java +++ b/src/main/java/com/google/genai/Chats.java @@ -19,10 +19,10 @@ import com.google.genai.types.GenerateContentConfig; /** A class for creating chat sessions. */ -public final class ChatSession { +public class Chats { private final ApiClient apiClient; - ChatSession(ApiClient apiClient) { + Chats(ApiClient apiClient) { this.apiClient = apiClient; } diff --git a/src/main/java/com/google/genai/Client.java b/src/main/java/com/google/genai/Client.java index 3eab41640ca..5c7f5396fbd 100644 --- a/src/main/java/com/google/genai/Client.java +++ b/src/main/java/com/google/genai/Client.java @@ -22,10 +22,33 @@ import com.google.genai.errors.GenAiIOException; import com.google.genai.types.HttpOptions; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; /** Client class for GenAI. */ public final class Client implements AutoCloseable { + private static Optional geminiBaseUrl = Optional.empty(); + private static Optional vertexBaseUrl = Optional.empty(); + + public static Map defaultEnvironmentVariables() { + Map variables = new HashMap<>(); + String value; + value = System.getenv("GOOGLE_GENAI_USE_VERTEXAI"); + if (value != null) { + variables.put("GOOGLE_GENAI_USE_VERTEXAI", value); + } + value = System.getenv("GOOGLE_GEMINI_BASE_URL"); + if (value != null) { + variables.put("GOOGLE_GEMINI_BASE_URL", value); + } + value = System.getenv("GOOGLE_VERTEX_BASE_URL"); + if (value != null) { + variables.put("GOOGLE_VERTEX_BASE_URL", value); + } + + return variables; + } /** Async class for GenAI. */ public final class Async { @@ -44,7 +67,7 @@ public Async(ApiClient apiClient) { private final ApiClient apiClient; public final Models models; public final Operations operations; - public final ChatSession chats; + public final Chats chats; public final Async async; /** Builder for {@link Client}. */ @@ -56,10 +79,19 @@ public static class Builder { private Optional httpOptions = Optional.empty(); private Optional vertexAI = Optional.empty(); private Optional debugConfig = Optional.empty(); + private Optional> environmentVariables = Optional.empty(); /** Builds the {@link Client} instance. */ public Client build() { - return new Client(apiKey, project, location, credentials, httpOptions, vertexAI, debugConfig); + return new Client( + apiKey, + project, + location, + credentials, + httpOptions, + vertexAI, + debugConfig, + environmentVariables); } /** Sets the API key for Google AI APIs. */ @@ -112,6 +144,12 @@ Builder debugConfig(DebugConfig debugConfig) { this.debugConfig = Optional.of(debugConfig); return this; } + + /** Sets the environment variables for the API client. This is for internal use only. */ + Builder environmentVariables(Map environmentVariables) { + this.environmentVariables = Optional.of(environmentVariables); + return this; + } } /** Returns a {@link Builder} for {@link Client}. */ @@ -128,20 +166,25 @@ public Client() { /* credentials= */ Optional.empty(), /* httpOptions= */ Optional.empty(), /* vertexAI= */ Optional.empty(), - /* debugConfig= */ Optional.empty()); + /* debugConfig= */ Optional.empty(), + /* environmentVariables= */ Optional.empty()); } /** * Constructs a Client instance with the given parameters. * - * @param apiKey Optional String for the API key. Google AI APIs only. + * @param apiKey Optional String for the API key. + * Google AI APIs only. * @param project Optional String for the project ID. Vertex AI APIs only. - * @param location Optional String for the location. Vertex AI APIs only. + * Find your project ID + * @param location Optional String for the location. + * Vertex AI APIs only. * @param credentials Optional {@link GoogleCredentials}. Vertex AI APIs only. * @param httpOptions Optional {@link HttpOptions} for sending HTTP requests. * @param vertexAI Optional Boolean for whether to use Vertex AI APIs. If not specified here nor * in the environment variable, default to false. * @param debugConfig Optional {@link DebugConfig} for debugging or testing the Client. + * @param environmentVariables Optional Map of environment variables. * @throws IllegalArgumentException if the project/location and API key are set together. */ private Client( @@ -151,15 +194,19 @@ private Client( Optional credentials, Optional httpOptions, Optional vertexAI, - Optional debugConfig) { + Optional debugConfig, + Optional> environmentVariables) { checkNotNull(vertexAI, "vertexAI cannot be null"); checkNotNull(debugConfig, "debugConfig cannot be null"); + if (!environmentVariables.isPresent()) { + environmentVariables = Optional.of(defaultEnvironmentVariables()); + } boolean useVertexAI; if (vertexAI.isPresent()) { useVertexAI = vertexAI.get(); } else { - String envVar = System.getenv("GOOGLE_GENAI_USE_VERTEXAI"); + String envVar = environmentVariables.get().get("GOOGLE_GENAI_USE_VERTEXAI"); useVertexAI = envVar != null && envVar.equalsIgnoreCase("true"); } @@ -178,6 +225,15 @@ private Client( throw new IllegalArgumentException("Vertex AI APIs do not support API key."); } + Optional baseUrl = Client.inferBaseUrl(useVertexAI, httpOptions, environmentVariables); + if (baseUrl.isPresent()) { + if (httpOptions.isPresent()) { + httpOptions = Optional.of(httpOptions.get().toBuilder().baseUrl(baseUrl.get()).build()); + } else { + httpOptions = Optional.of(HttpOptions.builder().baseUrl(baseUrl.get()).build()); + } + } + this.debugConfig = debugConfig.orElse(new DebugConfig()); if (this.debugConfig.clientMode().equals("replay") || this.debugConfig.clientMode().equals("auto")) { @@ -218,7 +274,7 @@ private Client( models = new Models(this.apiClient); operations = new Operations(this.apiClient); - chats = new ChatSession(this.apiClient); + chats = new Chats(this.apiClient); async = new Async(this.apiClient); } @@ -253,6 +309,14 @@ String clientMode() { return debugConfig.clientMode(); } + /** Returns the base URL for the API client. */ + Optional baseUrl() { + if (apiClient.httpOptions.baseUrl().isPresent()) { + return apiClient.httpOptions.baseUrl(); + } + return Optional.empty(); + } + /** Closes the Client instance together with its instantiated http client. */ @Override public void close() { @@ -262,4 +326,50 @@ public void close() { throw new GenAiIOException("Failed to close the HTTP client.", e); } } + + /** + * Overrides the base URLs for the Gemini API and Vertex AI API. + * + *

Note: This function should be called before initializing the SDK. If the base URLs are set + * after initializing the SDK, the base URLs will not be updated. + */ + public static void setDefaultBaseUrls( + Optional geminiBaseUrl, Optional vertexBaseUrl) { + Client.geminiBaseUrl = geminiBaseUrl; + Client.vertexBaseUrl = vertexBaseUrl; + } + + /** + * Returns the base URL for the Gemini API or Vertex AI API based on the following priority. + * + *

1. Base URL set via HttpOptions. + * + *

2. Base URL set via the latest call to setDefaultBaseUrls. + * + *

3. Base URL set via environment variables. + */ + static Optional inferBaseUrl( + boolean vertexAI, + Optional httpOptions, + Optional> environmentVariables) { + if (httpOptions.isPresent() && httpOptions.get().baseUrl().isPresent()) { + return httpOptions.get().baseUrl(); + } + + if (vertexAI) { + if (Client.vertexBaseUrl.isPresent()) { + return Client.vertexBaseUrl; + } else if (environmentVariables.isPresent()) { + return Optional.ofNullable(environmentVariables.get().get("GOOGLE_VERTEX_BASE_URL")); + } + } else { + if (Client.geminiBaseUrl.isPresent()) { + return Client.geminiBaseUrl; + } else if (environmentVariables.isPresent()) { + return Optional.ofNullable(environmentVariables.get().get("GOOGLE_GEMINI_BASE_URL")); + } + } + + return Optional.empty(); + } } diff --git a/src/main/java/com/google/genai/LiveConverters.java b/src/main/java/com/google/genai/LiveConverters.java new file mode 100644 index 00000000000..852ed9f50c4 --- /dev/null +++ b/src/main/java/com/google/genai/LiveConverters.java @@ -0,0 +1,2584 @@ +/* + * 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; + +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; + +final class LiveConverters { + private final ApiClient apiClient; + + public LiveConverters(ApiClient apiClient) { + this.apiClient = apiClient; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode partToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"videoMetadata"}))) { + throw new IllegalArgumentException("videoMetadata parameter is not supported in Gemini API."); + } + + if (Common.getValueByPath(fromObject, new String[] {"thought"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thought"}, + Common.getValueByPath(fromObject, new String[] {"thought"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"codeExecutionResult"}, + Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"executableCode"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"executableCode"}, + Common.getValueByPath(fromObject, new String[] {"executableCode"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"fileData"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"fileData"}, + Common.getValueByPath(fromObject, new String[] {"fileData"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionCall"}, + Common.getValueByPath(fromObject, new String[] {"functionCall"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"functionResponse"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionResponse"}, + Common.getValueByPath(fromObject, new String[] {"functionResponse"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"inlineData"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"inlineData"}, + Common.getValueByPath(fromObject, new String[] {"inlineData"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"text"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"text"}, + Common.getValueByPath(fromObject, new String[] {"text"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode partToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"videoMetadata"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"videoMetadata"}, + Common.getValueByPath(fromObject, new String[] {"videoMetadata"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"thought"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thought"}, + Common.getValueByPath(fromObject, new String[] {"thought"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"codeExecutionResult"}, + Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"executableCode"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"executableCode"}, + Common.getValueByPath(fromObject, new String[] {"executableCode"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"fileData"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"fileData"}, + Common.getValueByPath(fromObject, new String[] {"fileData"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionCall"}, + Common.getValueByPath(fromObject, new String[] {"functionCall"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"functionResponse"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionResponse"}, + Common.getValueByPath(fromObject, new String[] {"functionResponse"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"inlineData"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"inlineData"}, + Common.getValueByPath(fromObject, new String[] {"inlineData"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"text"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"text"}, + Common.getValueByPath(fromObject, new String[] {"text"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode contentToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"parts"}) != null) { + ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"parts"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add(partToMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"parts"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"role"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"role"}, + Common.getValueByPath(fromObject, new String[] {"role"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode contentToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"parts"}) != null) { + ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"parts"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add(partToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"parts"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"role"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"role"}, + Common.getValueByPath(fromObject, new String[] {"role"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode googleSearchToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode googleSearchToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode dynamicRetrievalConfigToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"mode"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"mode"}, + Common.getValueByPath(fromObject, new String[] {"mode"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"dynamicThreshold"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"dynamicThreshold"}, + Common.getValueByPath(fromObject, new String[] {"dynamicThreshold"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode dynamicRetrievalConfigToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"mode"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"mode"}, + Common.getValueByPath(fromObject, new String[] {"mode"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"dynamicThreshold"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"dynamicThreshold"}, + Common.getValueByPath(fromObject, new String[] {"dynamicThreshold"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode googleSearchRetrievalToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"dynamicRetrievalConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"dynamicRetrievalConfig"}, + dynamicRetrievalConfigToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"dynamicRetrievalConfig"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode googleSearchRetrievalToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"dynamicRetrievalConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"dynamicRetrievalConfig"}, + dynamicRetrievalConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"dynamicRetrievalConfig"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode toolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"retrieval"}))) { + throw new IllegalArgumentException("retrieval parameter is not supported in Gemini API."); + } + + if (Common.getValueByPath(fromObject, new String[] {"googleSearch"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"googleSearch"}, + googleSearchToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"googleSearch"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"googleSearchRetrieval"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"googleSearchRetrieval"}, + googleSearchRetrievalToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"googleSearchRetrieval"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"codeExecution"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"codeExecution"}, + Common.getValueByPath(fromObject, new String[] {"codeExecution"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"functionDeclarations"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionDeclarations"}, + Common.getValueByPath(fromObject, new String[] {"functionDeclarations"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode toolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"retrieval"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"retrieval"}, + Common.getValueByPath(fromObject, new String[] {"retrieval"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"googleSearch"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"googleSearch"}, + googleSearchToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"googleSearch"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"googleSearchRetrieval"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"googleSearchRetrieval"}, + googleSearchRetrievalToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"googleSearchRetrieval"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"codeExecution"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"codeExecution"}, + Common.getValueByPath(fromObject, new String[] {"codeExecution"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"functionDeclarations"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionDeclarations"}, + Common.getValueByPath(fromObject, new String[] {"functionDeclarations"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode sessionResumptionConfigToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"handle"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"handle"}, + Common.getValueByPath(fromObject, new String[] {"handle"})); + } + + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"transparent"}))) { + throw new IllegalArgumentException("transparent parameter is not supported in Gemini API."); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode sessionResumptionConfigToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"handle"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"handle"}, + Common.getValueByPath(fromObject, new String[] {"handle"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"transparent"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"transparent"}, + Common.getValueByPath(fromObject, new String[] {"transparent"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode audioTranscriptionConfigToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode audioTranscriptionConfigToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode automaticActivityDetectionToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"disabled"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"disabled"}, + Common.getValueByPath(fromObject, new String[] {"disabled"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"startOfSpeechSensitivity"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"startOfSpeechSensitivity"}, + Common.getValueByPath(fromObject, new String[] {"startOfSpeechSensitivity"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"endOfSpeechSensitivity"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"endOfSpeechSensitivity"}, + Common.getValueByPath(fromObject, new String[] {"endOfSpeechSensitivity"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"prefixPaddingMs"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"prefixPaddingMs"}, + Common.getValueByPath(fromObject, new String[] {"prefixPaddingMs"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"silenceDurationMs"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"silenceDurationMs"}, + Common.getValueByPath(fromObject, new String[] {"silenceDurationMs"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode automaticActivityDetectionToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"disabled"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"disabled"}, + Common.getValueByPath(fromObject, new String[] {"disabled"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"startOfSpeechSensitivity"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"startOfSpeechSensitivity"}, + Common.getValueByPath(fromObject, new String[] {"startOfSpeechSensitivity"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"endOfSpeechSensitivity"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"endOfSpeechSensitivity"}, + Common.getValueByPath(fromObject, new String[] {"endOfSpeechSensitivity"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"prefixPaddingMs"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"prefixPaddingMs"}, + Common.getValueByPath(fromObject, new String[] {"prefixPaddingMs"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"silenceDurationMs"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"silenceDurationMs"}, + Common.getValueByPath(fromObject, new String[] {"silenceDurationMs"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode realtimeInputConfigToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"automaticActivityDetection"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"automaticActivityDetection"}, + automaticActivityDetectionToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"automaticActivityDetection"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"activityHandling"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"activityHandling"}, + Common.getValueByPath(fromObject, new String[] {"activityHandling"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"turnCoverage"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"turnCoverage"}, + Common.getValueByPath(fromObject, new String[] {"turnCoverage"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode realtimeInputConfigToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"automaticActivityDetection"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"automaticActivityDetection"}, + automaticActivityDetectionToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"automaticActivityDetection"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"activityHandling"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"activityHandling"}, + Common.getValueByPath(fromObject, new String[] {"activityHandling"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"turnCoverage"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"turnCoverage"}, + Common.getValueByPath(fromObject, new String[] {"turnCoverage"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode slidingWindowToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"targetTokens"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"targetTokens"}, + Common.getValueByPath(fromObject, new String[] {"targetTokens"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode slidingWindowToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"targetTokens"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"targetTokens"}, + Common.getValueByPath(fromObject, new String[] {"targetTokens"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode contextWindowCompressionConfigToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"triggerTokens"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"triggerTokens"}, + Common.getValueByPath(fromObject, new String[] {"triggerTokens"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"slidingWindow"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"slidingWindow"}, + slidingWindowToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"slidingWindow"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode contextWindowCompressionConfigToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"triggerTokens"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"triggerTokens"}, + Common.getValueByPath(fromObject, new String[] {"triggerTokens"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"slidingWindow"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"slidingWindow"}, + slidingWindowToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"slidingWindow"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveConnectConfigToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + if (Common.getValueByPath(fromObject, new String[] {"responseModalities"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "responseModalities"}, + Common.getValueByPath(fromObject, new String[] {"responseModalities"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"temperature"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "temperature"}, + Common.getValueByPath(fromObject, new String[] {"temperature"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"topP"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "topP"}, + Common.getValueByPath(fromObject, new String[] {"topP"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"topK"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "topK"}, + Common.getValueByPath(fromObject, new String[] {"topK"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"maxOutputTokens"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "maxOutputTokens"}, + Common.getValueByPath(fromObject, new String[] {"maxOutputTokens"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"mediaResolution"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "mediaResolution"}, + Common.getValueByPath(fromObject, new String[] {"mediaResolution"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"seed"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "seed"}, + Common.getValueByPath(fromObject, new String[] {"seed"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"speechConfig"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "speechConfig"}, + Common.getValueByPath(fromObject, new String[] {"speechConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"systemInstruction"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "systemInstruction"}, + contentToMldev( + 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( + toolToMldev( + apiClient, + JsonSerializable.toJsonNode(Transformers.tTool(this.apiClient, item)), + toObject)); + }); + 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[] {"outputAudioTranscription"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "outputAudioTranscription"}, + audioTranscriptionConfigToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"outputAudioTranscription"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"realtimeInputConfig"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "realtimeInputConfig"}, + realtimeInputConfigToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"realtimeInputConfig"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"contextWindowCompression"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "contextWindowCompression"}, + contextWindowCompressionConfigToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"contextWindowCompression"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveConnectConfigToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + if (Common.getValueByPath(fromObject, new String[] {"responseModalities"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "responseModalities"}, + Common.getValueByPath(fromObject, new String[] {"responseModalities"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"temperature"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "temperature"}, + Common.getValueByPath(fromObject, new String[] {"temperature"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"topP"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "topP"}, + Common.getValueByPath(fromObject, new String[] {"topP"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"topK"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "topK"}, + Common.getValueByPath(fromObject, new String[] {"topK"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"maxOutputTokens"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "maxOutputTokens"}, + Common.getValueByPath(fromObject, new String[] {"maxOutputTokens"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"mediaResolution"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "mediaResolution"}, + Common.getValueByPath(fromObject, new String[] {"mediaResolution"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"seed"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "seed"}, + Common.getValueByPath(fromObject, new String[] {"seed"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"speechConfig"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "generationConfig", "speechConfig"}, + Common.getValueByPath(fromObject, new String[] {"speechConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"systemInstruction"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "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(Transformers.tTool(this.apiClient, item)), + toObject)); + }); + Common.setValueByPath(parentObject, new String[] {"setup", "tools"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"inputAudioTranscription"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "inputAudioTranscription"}, + audioTranscriptionConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"inputAudioTranscription"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"outputAudioTranscription"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "outputAudioTranscription"}, + audioTranscriptionConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"outputAudioTranscription"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"realtimeInputConfig"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "realtimeInputConfig"}, + realtimeInputConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"realtimeInputConfig"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"contextWindowCompression"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"setup", "contextWindowCompression"}, + contextWindowCompressionConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"contextWindowCompression"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveConnectParametersToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"setup", "model"}, + Transformers.tModel( + this.apiClient, Common.getValueByPath(fromObject, new String[] {"model"}))); + } + + if (Common.getValueByPath(fromObject, new String[] {"config"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"config"}, + liveConnectConfigToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"config"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveConnectParametersToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"setup", "model"}, + Transformers.tModel( + this.apiClient, Common.getValueByPath(fromObject, new String[] {"model"}))); + } + + if (Common.getValueByPath(fromObject, new String[] {"config"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"config"}, + liveConnectConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"config"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode activityStartToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode activityStartToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode activityEndToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode activityEndToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveSendRealtimeInputParametersToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"media"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"mediaChunks"}, + Transformers.tBlobs( + this.apiClient, Common.getValueByPath(fromObject, new String[] {"media"}))); + } + + if (Common.getValueByPath(fromObject, new String[] {"activityStart"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"activityStart"}, + activityStartToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"activityStart"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"activityEnd"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"activityEnd"}, + activityEndToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"activityEnd"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveSendRealtimeInputParametersToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"media"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"mediaChunks"}, + Transformers.tBlobs( + this.apiClient, Common.getValueByPath(fromObject, new String[] {"media"}))); + } + + if (Common.getValueByPath(fromObject, new String[] {"activityStart"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"activityStart"}, + activityStartToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"activityStart"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"activityEnd"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"activityEnd"}, + activityEndToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"activityEnd"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveClientSetupToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"model"}, + Common.getValueByPath(fromObject, new String[] {"model"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"generationConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"generationConfig"}, + Common.getValueByPath(fromObject, new String[] {"generationConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"systemInstruction"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"systemInstruction"}, + contentToMldev( + 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( + toolToMldev( + apiClient, + JsonSerializable.toJsonNode(Transformers.tTool(this.apiClient, item)), + toObject)); + }); + Common.setValueByPath(toObject, new String[] {"tools"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"realtimeInputConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"realtimeInputConfig"}, + realtimeInputConfigToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"realtimeInputConfig"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"contextWindowCompression"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"contextWindowCompression"}, + contextWindowCompressionConfigToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"contextWindowCompression"})), + 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[] {"outputAudioTranscription"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"outputAudioTranscription"}, + audioTranscriptionConfigToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"outputAudioTranscription"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveClientSetupToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"model"}, + Common.getValueByPath(fromObject, new String[] {"model"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"generationConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"generationConfig"}, + Common.getValueByPath(fromObject, new String[] {"generationConfig"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"systemInstruction"}) != null) { + Common.setValueByPath( + toObject, + 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(Transformers.tTool(this.apiClient, item)), + toObject)); + }); + Common.setValueByPath(toObject, new String[] {"tools"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"realtimeInputConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"realtimeInputConfig"}, + realtimeInputConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"realtimeInputConfig"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"contextWindowCompression"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"contextWindowCompression"}, + contextWindowCompressionConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"contextWindowCompression"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"inputAudioTranscription"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"inputAudioTranscription"}, + audioTranscriptionConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"inputAudioTranscription"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"outputAudioTranscription"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"outputAudioTranscription"}, + audioTranscriptionConfigToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"outputAudioTranscription"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveClientContentToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"turns"}) != null) { + ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"turns"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add(contentToMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"turns"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"turnComplete"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"turnComplete"}, + Common.getValueByPath(fromObject, new String[] {"turnComplete"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveClientContentToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"turns"}) != null) { + ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"turns"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add(contentToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"turns"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"turnComplete"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"turnComplete"}, + Common.getValueByPath(fromObject, new String[] {"turnComplete"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveClientRealtimeInputToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"mediaChunks"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"mediaChunks"}, + Common.getValueByPath(fromObject, new String[] {"mediaChunks"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"activityStart"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"activityStart"}, + activityStartToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"activityStart"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"activityEnd"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"activityEnd"}, + activityEndToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"activityEnd"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveClientRealtimeInputToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"mediaChunks"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"mediaChunks"}, + Common.getValueByPath(fromObject, new String[] {"mediaChunks"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"activityStart"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"activityStart"}, + activityStartToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"activityStart"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"activityEnd"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"activityEnd"}, + activityEndToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"activityEnd"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode functionResponseToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"id"}) != null) { + Common.setValueByPath( + toObject, new String[] {"id"}, Common.getValueByPath(fromObject, new String[] {"id"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"name"}, + Common.getValueByPath(fromObject, new String[] {"name"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"response"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"response"}, + Common.getValueByPath(fromObject, new String[] {"response"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode functionResponseToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"id"}))) { + throw new IllegalArgumentException("id parameter is not supported in Vertex AI."); + } + + if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"name"}, + Common.getValueByPath(fromObject, new String[] {"name"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"response"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"response"}, + Common.getValueByPath(fromObject, new String[] {"response"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveClientToolResponseToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"functionResponses"}) != null) { + ArrayNode keyArray = + (ArrayNode) Common.getValueByPath(fromObject, new String[] {"functionResponses"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + functionResponseToMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"functionResponses"}, result); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveClientToolResponseToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"functionResponses"}) != null) { + ArrayNode keyArray = + (ArrayNode) Common.getValueByPath(fromObject, new String[] {"functionResponses"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + functionResponseToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"functionResponses"}, result); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveClientMessageToMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"setup"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"setup"}, + liveClientSetupToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"setup"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"clientContent"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"clientContent"}, + liveClientContentToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"clientContent"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"realtimeInput"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"realtimeInput"}, + liveClientRealtimeInputToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"realtimeInput"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"toolResponse"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"toolResponse"}, + liveClientToolResponseToMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"toolResponse"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveClientMessageToVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"setup"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"setup"}, + liveClientSetupToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"setup"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"clientContent"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"clientContent"}, + liveClientContentToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"clientContent"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"realtimeInput"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"realtimeInput"}, + liveClientRealtimeInputToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"realtimeInput"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"toolResponse"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"toolResponse"}, + liveClientToolResponseToVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"toolResponse"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerSetupCompleteFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerSetupCompleteFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode partFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + if (Common.getValueByPath(fromObject, new String[] {"thought"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thought"}, + Common.getValueByPath(fromObject, new String[] {"thought"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"codeExecutionResult"}, + Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"executableCode"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"executableCode"}, + Common.getValueByPath(fromObject, new String[] {"executableCode"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"fileData"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"fileData"}, + Common.getValueByPath(fromObject, new String[] {"fileData"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionCall"}, + Common.getValueByPath(fromObject, new String[] {"functionCall"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"functionResponse"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionResponse"}, + Common.getValueByPath(fromObject, new String[] {"functionResponse"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"inlineData"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"inlineData"}, + Common.getValueByPath(fromObject, new String[] {"inlineData"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"text"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"text"}, + Common.getValueByPath(fromObject, new String[] {"text"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode partFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"videoMetadata"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"videoMetadata"}, + Common.getValueByPath(fromObject, new String[] {"videoMetadata"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"thought"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thought"}, + Common.getValueByPath(fromObject, new String[] {"thought"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"codeExecutionResult"}, + Common.getValueByPath(fromObject, new String[] {"codeExecutionResult"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"executableCode"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"executableCode"}, + Common.getValueByPath(fromObject, new String[] {"executableCode"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"fileData"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"fileData"}, + Common.getValueByPath(fromObject, new String[] {"fileData"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"functionCall"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionCall"}, + Common.getValueByPath(fromObject, new String[] {"functionCall"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"functionResponse"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionResponse"}, + Common.getValueByPath(fromObject, new String[] {"functionResponse"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"inlineData"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"inlineData"}, + Common.getValueByPath(fromObject, new String[] {"inlineData"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"text"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"text"}, + Common.getValueByPath(fromObject, new String[] {"text"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode contentFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"parts"}) != null) { + ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"parts"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add(partFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"parts"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"role"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"role"}, + Common.getValueByPath(fromObject, new String[] {"role"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode contentFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"parts"}) != null) { + ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"parts"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add(partFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"parts"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"role"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"role"}, + Common.getValueByPath(fromObject, new String[] {"role"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode transcriptionFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"text"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"text"}, + Common.getValueByPath(fromObject, new String[] {"text"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"finished"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"finished"}, + Common.getValueByPath(fromObject, new String[] {"finished"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode transcriptionFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"text"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"text"}, + Common.getValueByPath(fromObject, new String[] {"text"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"finished"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"finished"}, + Common.getValueByPath(fromObject, new String[] {"finished"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerContentFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"modelTurn"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"modelTurn"}, + contentFromMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"modelTurn"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"turnComplete"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"turnComplete"}, + Common.getValueByPath(fromObject, new String[] {"turnComplete"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"interrupted"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"interrupted"}, + Common.getValueByPath(fromObject, new String[] {"interrupted"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"groundingMetadata"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"groundingMetadata"}, + Common.getValueByPath(fromObject, new String[] {"groundingMetadata"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"generationComplete"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"generationComplete"}, + Common.getValueByPath(fromObject, new String[] {"generationComplete"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"inputTranscription"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"inputTranscription"}, + transcriptionFromMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"inputTranscription"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"outputTranscription"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"outputTranscription"}, + transcriptionFromMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"outputTranscription"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerContentFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"modelTurn"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"modelTurn"}, + contentFromVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"modelTurn"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"turnComplete"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"turnComplete"}, + Common.getValueByPath(fromObject, new String[] {"turnComplete"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"interrupted"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"interrupted"}, + Common.getValueByPath(fromObject, new String[] {"interrupted"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"groundingMetadata"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"groundingMetadata"}, + Common.getValueByPath(fromObject, new String[] {"groundingMetadata"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"generationComplete"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"generationComplete"}, + Common.getValueByPath(fromObject, new String[] {"generationComplete"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"inputTranscription"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"inputTranscription"}, + transcriptionFromVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"inputTranscription"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"outputTranscription"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"outputTranscription"}, + transcriptionFromVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"outputTranscription"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode functionCallFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"id"}) != null) { + Common.setValueByPath( + toObject, new String[] {"id"}, Common.getValueByPath(fromObject, new String[] {"id"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"args"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"args"}, + Common.getValueByPath(fromObject, new String[] {"args"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"name"}, + Common.getValueByPath(fromObject, new String[] {"name"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode functionCallFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + + if (Common.getValueByPath(fromObject, new String[] {"args"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"args"}, + Common.getValueByPath(fromObject, new String[] {"args"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"name"}, + Common.getValueByPath(fromObject, new String[] {"name"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerToolCallFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"functionCalls"}) != null) { + ArrayNode keyArray = + (ArrayNode) Common.getValueByPath(fromObject, new String[] {"functionCalls"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + functionCallFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"functionCalls"}, result); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerToolCallFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"functionCalls"}) != null) { + ArrayNode keyArray = + (ArrayNode) Common.getValueByPath(fromObject, new String[] {"functionCalls"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + functionCallFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"functionCalls"}, result); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerToolCallCancellationFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"ids"}) != null) { + Common.setValueByPath( + toObject, new String[] {"ids"}, Common.getValueByPath(fromObject, new String[] {"ids"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerToolCallCancellationFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"ids"}) != null) { + Common.setValueByPath( + toObject, new String[] {"ids"}, Common.getValueByPath(fromObject, new String[] {"ids"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode modalityTokenCountFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"modality"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"modality"}, + Common.getValueByPath(fromObject, new String[] {"modality"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"tokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"tokenCount"}, + Common.getValueByPath(fromObject, new String[] {"tokenCount"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode modalityTokenCountFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"modality"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"modality"}, + Common.getValueByPath(fromObject, new String[] {"modality"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"tokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"tokenCount"}, + Common.getValueByPath(fromObject, new String[] {"tokenCount"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode usageMetadataFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"promptTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"promptTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"promptTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"cachedContentTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"cachedContentTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"cachedContentTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"responseTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"responseTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"responseTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"toolUsePromptTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"toolUsePromptTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"toolUsePromptTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"thoughtsTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thoughtsTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"thoughtsTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"totalTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"totalTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"totalTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"promptTokensDetails"}) != null) { + ArrayNode keyArray = + (ArrayNode) Common.getValueByPath(fromObject, new String[] {"promptTokensDetails"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + modalityTokenCountFromMldev( + apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"promptTokensDetails"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"cacheTokensDetails"}) != null) { + ArrayNode keyArray = + (ArrayNode) Common.getValueByPath(fromObject, new String[] {"cacheTokensDetails"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + modalityTokenCountFromMldev( + apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"cacheTokensDetails"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"responseTokensDetails"}) != null) { + ArrayNode keyArray = + (ArrayNode) Common.getValueByPath(fromObject, new String[] {"responseTokensDetails"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + modalityTokenCountFromMldev( + apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"responseTokensDetails"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"toolUsePromptTokensDetails"}) != null) { + ArrayNode keyArray = + (ArrayNode) + Common.getValueByPath(fromObject, new String[] {"toolUsePromptTokensDetails"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + modalityTokenCountFromMldev( + apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"toolUsePromptTokensDetails"}, result); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode usageMetadataFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"promptTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"promptTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"promptTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"cachedContentTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"cachedContentTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"cachedContentTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"candidatesTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"responseTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"candidatesTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"toolUsePromptTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"toolUsePromptTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"toolUsePromptTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"thoughtsTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"thoughtsTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"thoughtsTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"totalTokenCount"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"totalTokenCount"}, + Common.getValueByPath(fromObject, new String[] {"totalTokenCount"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"promptTokensDetails"}) != null) { + ArrayNode keyArray = + (ArrayNode) Common.getValueByPath(fromObject, new String[] {"promptTokensDetails"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + modalityTokenCountFromVertex( + apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"promptTokensDetails"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"cacheTokensDetails"}) != null) { + ArrayNode keyArray = + (ArrayNode) Common.getValueByPath(fromObject, new String[] {"cacheTokensDetails"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + modalityTokenCountFromVertex( + apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"cacheTokensDetails"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"candidatesTokensDetails"}) != null) { + ArrayNode keyArray = + (ArrayNode) Common.getValueByPath(fromObject, new String[] {"candidatesTokensDetails"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + modalityTokenCountFromVertex( + apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"responseTokensDetails"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"toolUsePromptTokensDetails"}) != null) { + ArrayNode keyArray = + (ArrayNode) + Common.getValueByPath(fromObject, new String[] {"toolUsePromptTokensDetails"}); + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode result = objectMapper.createArrayNode(); + + keyArray.forEach( + item -> { + result.add( + modalityTokenCountFromVertex( + apiClient, JsonSerializable.toJsonNode(item), toObject)); + }); + Common.setValueByPath(toObject, new String[] {"toolUsePromptTokensDetails"}, result); + } + + if (Common.getValueByPath(fromObject, new String[] {"trafficType"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"trafficType"}, + Common.getValueByPath(fromObject, new String[] {"trafficType"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerGoAwayFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"timeLeft"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"timeLeft"}, + Common.getValueByPath(fromObject, new String[] {"timeLeft"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerGoAwayFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"timeLeft"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"timeLeft"}, + Common.getValueByPath(fromObject, new String[] {"timeLeft"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerSessionResumptionUpdateFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"newHandle"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"newHandle"}, + Common.getValueByPath(fromObject, new String[] {"newHandle"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"resumable"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"resumable"}, + Common.getValueByPath(fromObject, new String[] {"resumable"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"lastConsumedClientMessageIndex"}) + != null) { + Common.setValueByPath( + toObject, + new String[] {"lastConsumedClientMessageIndex"}, + Common.getValueByPath(fromObject, new String[] {"lastConsumedClientMessageIndex"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerSessionResumptionUpdateFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"newHandle"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"newHandle"}, + Common.getValueByPath(fromObject, new String[] {"newHandle"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"resumable"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"resumable"}, + Common.getValueByPath(fromObject, new String[] {"resumable"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"lastConsumedClientMessageIndex"}) + != null) { + Common.setValueByPath( + toObject, + new String[] {"lastConsumedClientMessageIndex"}, + Common.getValueByPath(fromObject, new String[] {"lastConsumedClientMessageIndex"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerMessageFromMldev( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"setupComplete"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"setupComplete"}, + liveServerSetupCompleteFromMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"setupComplete"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"serverContent"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"serverContent"}, + liveServerContentFromMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"serverContent"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"toolCall"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"toolCall"}, + liveServerToolCallFromMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"toolCall"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"toolCallCancellation"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"toolCallCancellation"}, + liveServerToolCallCancellationFromMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"toolCallCancellation"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"usageMetadata"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"usageMetadata"}, + usageMetadataFromMldev( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"usageMetadata"})), + toObject)); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode liveServerMessageFromVertex( + ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"setupComplete"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"setupComplete"}, + liveServerSetupCompleteFromVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"setupComplete"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"serverContent"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"serverContent"}, + liveServerContentFromVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"serverContent"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"toolCall"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"toolCall"}, + liveServerToolCallFromVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"toolCall"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"toolCallCancellation"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"toolCallCancellation"}, + liveServerToolCallCancellationFromVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"toolCallCancellation"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"usageMetadata"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"usageMetadata"}, + usageMetadataFromVertex( + apiClient, + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"usageMetadata"})), + toObject)); + } + + return toObject; + } +} diff --git a/src/main/java/com/google/genai/Models.java b/src/main/java/com/google/genai/Models.java index 2768a26eb76..b1872b118cb 100644 --- a/src/main/java/com/google/genai/Models.java +++ b/src/main/java/com/google/genai/Models.java @@ -64,10 +64,10 @@ public Models(ApiClient apiClient) { } @ExcludeFromGeneratedCoverageReport - ObjectNode PartToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode partToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"videoMetadata"}))) { - throw new Error("videoMetadata parameter is not supported in Gemini API."); + throw new IllegalArgumentException("videoMetadata parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"thought"}) != null) { @@ -130,7 +130,7 @@ ObjectNode PartToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pare } @ExcludeFromGeneratedCoverageReport - ObjectNode ContentToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode contentToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"parts"}) != null) { ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"parts"}); @@ -139,7 +139,7 @@ ObjectNode ContentToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode p keyArray.forEach( item -> { - result.add(PartToMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + result.add(partToMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"parts"}, result); } @@ -155,162 +155,24 @@ ObjectNode ContentToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode p } @ExcludeFromGeneratedCoverageReport - ObjectNode SchemaToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { - ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); - if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"example"}))) { - throw new Error("example parameter is not supported in Gemini API."); - } - - if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"pattern"}))) { - throw new Error("pattern parameter is not supported in Gemini API."); - } - - if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"default"}))) { - throw new Error("default parameter is not supported in Gemini API."); - } - - if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"maxLength"}))) { - throw new Error("maxLength parameter is not supported in Gemini API."); - } - - if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"minLength"}))) { - throw new Error("minLength parameter is not supported in Gemini API."); - } - - if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"minProperties"}))) { - throw new Error("minProperties parameter is not supported in Gemini API."); - } - - if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"maxProperties"}))) { - throw new Error("maxProperties parameter is not supported in Gemini API."); - } - - if (Common.getValueByPath(fromObject, new String[] {"anyOf"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"anyOf"}, - Common.getValueByPath(fromObject, new String[] {"anyOf"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"description"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"description"}, - Common.getValueByPath(fromObject, new String[] {"description"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"enum"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"enum"}, - Common.getValueByPath(fromObject, new String[] {"enum"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"format"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"format"}, - Common.getValueByPath(fromObject, new String[] {"format"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"items"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"items"}, - Common.getValueByPath(fromObject, new String[] {"items"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"maxItems"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"maxItems"}, - Common.getValueByPath(fromObject, new String[] {"maxItems"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"maximum"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"maximum"}, - Common.getValueByPath(fromObject, new String[] {"maximum"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"minItems"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"minItems"}, - Common.getValueByPath(fromObject, new String[] {"minItems"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"minimum"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"minimum"}, - Common.getValueByPath(fromObject, new String[] {"minimum"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"nullable"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"nullable"}, - Common.getValueByPath(fromObject, new String[] {"nullable"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"properties"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"properties"}, - Common.getValueByPath(fromObject, new String[] {"properties"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"propertyOrdering"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"propertyOrdering"}, - Common.getValueByPath(fromObject, new String[] {"propertyOrdering"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"required"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"required"}, - Common.getValueByPath(fromObject, new String[] {"required"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"title"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"title"}, - Common.getValueByPath(fromObject, new String[] {"title"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"type"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"type"}, - Common.getValueByPath(fromObject, new String[] {"type"})); - } - - return toObject; - } - - @ExcludeFromGeneratedCoverageReport - ObjectNode ModelSelectionConfigToMldev( + ObjectNode modelSelectionConfigToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (!Common.isZero( Common.getValueByPath(fromObject, new String[] {"featureSelectionPreference"}))) { - throw new Error("featureSelectionPreference parameter is not supported in Gemini API."); + throw new IllegalArgumentException( + "featureSelectionPreference parameter is not supported in Gemini API."); } return toObject; } @ExcludeFromGeneratedCoverageReport - ObjectNode SafetySettingToMldev( + ObjectNode safetySettingToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"method"}))) { - throw new Error("method parameter is not supported in Gemini API."); + throw new IllegalArgumentException("method parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"category"}) != null) { @@ -331,47 +193,15 @@ ObjectNode SafetySettingToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode FunctionDeclarationToMldev( + ObjectNode googleSearchToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); - if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"response"}))) { - throw new Error("response parameter is not supported in Gemini API."); - } - - if (Common.getValueByPath(fromObject, new String[] {"description"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"description"}, - Common.getValueByPath(fromObject, new String[] {"description"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"name"}, - Common.getValueByPath(fromObject, new String[] {"name"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"parameters"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"parameters"}, - Common.getValueByPath(fromObject, new String[] {"parameters"})); - } return toObject; } @ExcludeFromGeneratedCoverageReport - ObjectNode GoogleSearchToMldev( - ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { - ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); - - return toObject; - } - - @ExcludeFromGeneratedCoverageReport - ObjectNode DynamicRetrievalConfigToMldev( + ObjectNode dynamicRetrievalConfigToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"mode"}) != null) { @@ -392,14 +222,14 @@ ObjectNode DynamicRetrievalConfigToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode GoogleSearchRetrievalToMldev( + ObjectNode googleSearchRetrievalToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"dynamicRetrievalConfig"}) != null) { Common.setValueByPath( toObject, new String[] {"dynamicRetrievalConfig"}, - DynamicRetrievalConfigToMldev( + dynamicRetrievalConfigToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"dynamicRetrievalConfig"})), @@ -410,31 +240,17 @@ ObjectNode GoogleSearchRetrievalToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode ToolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); - if (Common.getValueByPath(fromObject, new String[] {"functionDeclarations"}) != null) { - ArrayNode keyArray = - (ArrayNode) Common.getValueByPath(fromObject, new String[] {"functionDeclarations"}); - ObjectMapper objectMapper = new ObjectMapper(); - ArrayNode result = objectMapper.createArrayNode(); - - keyArray.forEach( - item -> { - result.add( - FunctionDeclarationToMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); - }); - Common.setValueByPath(toObject, new String[] {"functionDeclarations"}, result); - } - if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"retrieval"}))) { - throw new Error("retrieval parameter is not supported in Gemini API."); + throw new IllegalArgumentException("retrieval parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"googleSearch"}) != null) { Common.setValueByPath( toObject, new String[] {"googleSearch"}, - GoogleSearchToMldev( + googleSearchToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"googleSearch"})), @@ -445,7 +261,7 @@ ObjectNode ToolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pare Common.setValueByPath( toObject, new String[] {"googleSearchRetrieval"}, - GoogleSearchRetrievalToMldev( + googleSearchRetrievalToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"googleSearchRetrieval"})), @@ -459,11 +275,18 @@ ObjectNode ToolToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pare Common.getValueByPath(fromObject, new String[] {"codeExecution"})); } + if (Common.getValueByPath(fromObject, new String[] {"functionDeclarations"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionDeclarations"}, + Common.getValueByPath(fromObject, new String[] {"functionDeclarations"})); + } + return toObject; } @ExcludeFromGeneratedCoverageReport - ObjectNode FunctionCallingConfigToMldev( + ObjectNode functionCallingConfigToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"mode"}) != null) { @@ -484,13 +307,13 @@ ObjectNode FunctionCallingConfigToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode ToolConfigToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toolConfigToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"functionCallingConfig"}) != null) { Common.setValueByPath( toObject, new String[] {"functionCallingConfig"}, - FunctionCallingConfigToMldev( + functionCallingConfigToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"functionCallingConfig"})), @@ -501,7 +324,7 @@ ObjectNode ToolConfigToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNod } @ExcludeFromGeneratedCoverageReport - ObjectNode PrebuiltVoiceConfigToMldev( + ObjectNode prebuiltVoiceConfigToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"voiceName"}) != null) { @@ -515,13 +338,13 @@ ObjectNode PrebuiltVoiceConfigToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode VoiceConfigToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode voiceConfigToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"prebuiltVoiceConfig"}) != null) { Common.setValueByPath( toObject, new String[] {"prebuiltVoiceConfig"}, - PrebuiltVoiceConfigToMldev( + prebuiltVoiceConfigToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"prebuiltVoiceConfig"})), @@ -532,14 +355,14 @@ ObjectNode VoiceConfigToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNo } @ExcludeFromGeneratedCoverageReport - ObjectNode SpeechConfigToMldev( + ObjectNode speechConfigToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"voiceConfig"}) != null) { Common.setValueByPath( toObject, new String[] {"voiceConfig"}, - VoiceConfigToMldev( + voiceConfigToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"voiceConfig"})), @@ -557,7 +380,7 @@ ObjectNode SpeechConfigToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode ThinkingConfigToMldev( + ObjectNode thinkingConfigToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"includeThoughts"}) != null) { @@ -578,7 +401,7 @@ ObjectNode ThinkingConfigToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateContentConfigToMldev( + ObjectNode generateContentConfigToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -586,7 +409,7 @@ ObjectNode GenerateContentConfigToMldev( Common.setValueByPath( parentObject, new String[] {"systemInstruction"}, - ContentToMldev( + contentToMldev( apiClient, JsonSerializable.toJsonNode( Transformers.tContent( @@ -683,21 +506,17 @@ ObjectNode GenerateContentConfigToMldev( Common.setValueByPath( toObject, new String[] {"responseSchema"}, - SchemaToMldev( - apiClient, - JsonSerializable.toJsonNode( - Transformers.tSchema( - this.apiClient, - Common.getValueByPath(fromObject, new String[] {"responseSchema"}))), - toObject)); + Transformers.tSchema( + this.apiClient, Common.getValueByPath(fromObject, new String[] {"responseSchema"}))); } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"routingConfig"}))) { - throw new Error("routingConfig parameter is not supported in Gemini API."); + throw new IllegalArgumentException("routingConfig parameter is not supported in Gemini API."); } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"modelSelectionConfig"}))) { - throw new Error("modelSelectionConfig parameter is not supported in Gemini API."); + throw new IllegalArgumentException( + "modelSelectionConfig parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"safetySettings"}) != null) { @@ -709,7 +528,7 @@ ObjectNode GenerateContentConfigToMldev( keyArray.forEach( item -> { result.add( - SafetySettingToMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + safetySettingToMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(parentObject, new String[] {"safetySettings"}, result); } @@ -722,7 +541,7 @@ ObjectNode GenerateContentConfigToMldev( keyArray.forEach( item -> { result.add( - ToolToMldev( + toolToMldev( apiClient, JsonSerializable.toJsonNode(Transformers.tTool(this.apiClient, item)), toObject)); @@ -734,7 +553,7 @@ ObjectNode GenerateContentConfigToMldev( Common.setValueByPath( parentObject, new String[] {"toolConfig"}, - ToolConfigToMldev( + toolConfigToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"toolConfig"})), @@ -742,7 +561,7 @@ ObjectNode GenerateContentConfigToMldev( } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"labels"}))) { - throw new Error("labels parameter is not supported in Gemini API."); + throw new IllegalArgumentException("labels parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"cachedContent"}) != null) { @@ -771,7 +590,7 @@ ObjectNode GenerateContentConfigToMldev( Common.setValueByPath( toObject, new String[] {"speechConfig"}, - SpeechConfigToMldev( + speechConfigToMldev( apiClient, JsonSerializable.toJsonNode( Transformers.tSpeechConfig( @@ -781,14 +600,15 @@ ObjectNode GenerateContentConfigToMldev( } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"audioTimestamp"}))) { - throw new Error("audioTimestamp parameter is not supported in Gemini API."); + throw new IllegalArgumentException( + "audioTimestamp parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"thinkingConfig"}) != null) { Common.setValueByPath( toObject, new String[] {"thinkingConfig"}, - ThinkingConfigToMldev( + thinkingConfigToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"thinkingConfig"})), @@ -799,7 +619,7 @@ ObjectNode GenerateContentConfigToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateContentParametersToMldev( + ObjectNode generateContentParametersToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { @@ -817,7 +637,7 @@ ObjectNode GenerateContentParametersToMldev( keyArray.forEach( item -> { - result.add(ContentToMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + result.add(contentToMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"contents"}, result); } @@ -826,7 +646,7 @@ ObjectNode GenerateContentParametersToMldev( Common.setValueByPath( toObject, new String[] {"generationConfig"}, - GenerateContentConfigToMldev( + generateContentConfigToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"config"})), @@ -837,7 +657,7 @@ ObjectNode GenerateContentParametersToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode EmbedContentConfigToMldev( + ObjectNode embedContentConfigToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -863,18 +683,18 @@ ObjectNode EmbedContentConfigToMldev( } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"mimeType"}))) { - throw new Error("mimeType parameter is not supported in Gemini API."); + throw new IllegalArgumentException("mimeType parameter is not supported in Gemini API."); } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"autoTruncate"}))) { - throw new Error("autoTruncate parameter is not supported in Gemini API."); + throw new IllegalArgumentException("autoTruncate parameter is not supported in Gemini API."); } return toObject; } @ExcludeFromGeneratedCoverageReport - ObjectNode EmbedContentParametersToMldev( + ObjectNode embedContentParametersToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { @@ -897,7 +717,7 @@ ObjectNode EmbedContentParametersToMldev( Common.setValueByPath( toObject, new String[] {"config"}, - EmbedContentConfigToMldev( + embedContentConfigToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"config"})), @@ -913,16 +733,17 @@ ObjectNode EmbedContentParametersToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateImagesConfigToMldev( + ObjectNode generateImagesConfigToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"outputGcsUri"}))) { - throw new Error("outputGcsUri parameter is not supported in Gemini API."); + throw new IllegalArgumentException("outputGcsUri parameter is not supported in Gemini API."); } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"negativePrompt"}))) { - throw new Error("negativePrompt parameter is not supported in Gemini API."); + throw new IllegalArgumentException( + "negativePrompt parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"numberOfImages"}) != null) { @@ -947,7 +768,7 @@ ObjectNode GenerateImagesConfigToMldev( } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"seed"}))) { - throw new Error("seed parameter is not supported in Gemini API."); + throw new IllegalArgumentException("seed parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"safetyFilterLevel"}) != null) { @@ -1000,18 +821,18 @@ ObjectNode GenerateImagesConfigToMldev( } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"addWatermark"}))) { - throw new Error("addWatermark parameter is not supported in Gemini API."); + throw new IllegalArgumentException("addWatermark parameter is not supported in Gemini API."); } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"enhancePrompt"}))) { - throw new Error("enhancePrompt parameter is not supported in Gemini API."); + throw new IllegalArgumentException("enhancePrompt parameter is not supported in Gemini API."); } return toObject; } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateImagesParametersToMldev( + ObjectNode generateImagesParametersToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { @@ -1033,7 +854,7 @@ ObjectNode GenerateImagesParametersToMldev( Common.setValueByPath( toObject, new String[] {"config"}, - GenerateImagesConfigToMldev( + generateImagesConfigToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"config"})), @@ -1044,10 +865,10 @@ ObjectNode GenerateImagesParametersToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode ImageToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode imageToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"gcsUri"}))) { - throw new Error("gcsUri parameter is not supported in Gemini API."); + throw new IllegalArgumentException("gcsUri parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"imageBytes"}) != null) { @@ -1069,7 +890,7 @@ ObjectNode ImageToMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode par } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosConfigToMldev( + ObjectNode generateVideosConfigToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -1081,11 +902,11 @@ ObjectNode GenerateVideosConfigToMldev( } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"outputGcsUri"}))) { - throw new Error("outputGcsUri parameter is not supported in Gemini API."); + throw new IllegalArgumentException("outputGcsUri parameter is not supported in Gemini API."); } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"fps"}))) { - throw new Error("fps parameter is not supported in Gemini API."); + throw new IllegalArgumentException("fps parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"durationSeconds"}) != null) { @@ -1096,7 +917,7 @@ ObjectNode GenerateVideosConfigToMldev( } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"seed"}))) { - throw new Error("seed parameter is not supported in Gemini API."); + throw new IllegalArgumentException("seed parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"aspectRatio"}) != null) { @@ -1107,7 +928,7 @@ ObjectNode GenerateVideosConfigToMldev( } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"resolution"}))) { - throw new Error("resolution parameter is not supported in Gemini API."); + throw new IllegalArgumentException("resolution parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"personGeneration"}) != null) { @@ -1118,7 +939,7 @@ ObjectNode GenerateVideosConfigToMldev( } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"pubsubTopic"}))) { - throw new Error("pubsubTopic parameter is not supported in Gemini API."); + throw new IllegalArgumentException("pubsubTopic parameter is not supported in Gemini API."); } if (Common.getValueByPath(fromObject, new String[] {"negativePrompt"}) != null) { @@ -1129,14 +950,14 @@ ObjectNode GenerateVideosConfigToMldev( } if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"enhancePrompt"}))) { - throw new Error("enhancePrompt parameter is not supported in Gemini API."); + throw new IllegalArgumentException("enhancePrompt parameter is not supported in Gemini API."); } return toObject; } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosParametersToMldev( + ObjectNode generateVideosParametersToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { @@ -1158,7 +979,7 @@ ObjectNode GenerateVideosParametersToMldev( Common.setValueByPath( toObject, new String[] {"instances[0]", "image"}, - ImageToMldev( + imageToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"image"})), @@ -1169,7 +990,7 @@ ObjectNode GenerateVideosParametersToMldev( Common.setValueByPath( toObject, new String[] {"config"}, - GenerateVideosConfigToMldev( + generateVideosConfigToMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"config"})), @@ -1180,7 +1001,7 @@ ObjectNode GenerateVideosParametersToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode PartToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode partToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"videoMetadata"}) != null) { Common.setValueByPath( @@ -1249,7 +1070,7 @@ ObjectNode PartToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par } @ExcludeFromGeneratedCoverageReport - ObjectNode ContentToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode contentToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"parts"}) != null) { ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"parts"}); @@ -1258,7 +1079,7 @@ ObjectNode ContentToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode keyArray.forEach( item -> { - result.add(PartToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + result.add(partToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"parts"}, result); } @@ -1274,167 +1095,7 @@ ObjectNode ContentToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode } @ExcludeFromGeneratedCoverageReport - ObjectNode SchemaToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { - ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); - if (Common.getValueByPath(fromObject, new String[] {"example"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"example"}, - Common.getValueByPath(fromObject, new String[] {"example"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"pattern"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"pattern"}, - Common.getValueByPath(fromObject, new String[] {"pattern"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"default"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"default"}, - Common.getValueByPath(fromObject, new String[] {"default"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"maxLength"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"maxLength"}, - Common.getValueByPath(fromObject, new String[] {"maxLength"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"minLength"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"minLength"}, - Common.getValueByPath(fromObject, new String[] {"minLength"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"minProperties"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"minProperties"}, - Common.getValueByPath(fromObject, new String[] {"minProperties"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"maxProperties"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"maxProperties"}, - Common.getValueByPath(fromObject, new String[] {"maxProperties"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"anyOf"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"anyOf"}, - Common.getValueByPath(fromObject, new String[] {"anyOf"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"description"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"description"}, - Common.getValueByPath(fromObject, new String[] {"description"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"enum"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"enum"}, - Common.getValueByPath(fromObject, new String[] {"enum"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"format"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"format"}, - Common.getValueByPath(fromObject, new String[] {"format"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"items"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"items"}, - Common.getValueByPath(fromObject, new String[] {"items"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"maxItems"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"maxItems"}, - Common.getValueByPath(fromObject, new String[] {"maxItems"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"maximum"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"maximum"}, - Common.getValueByPath(fromObject, new String[] {"maximum"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"minItems"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"minItems"}, - Common.getValueByPath(fromObject, new String[] {"minItems"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"minimum"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"minimum"}, - Common.getValueByPath(fromObject, new String[] {"minimum"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"nullable"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"nullable"}, - Common.getValueByPath(fromObject, new String[] {"nullable"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"properties"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"properties"}, - Common.getValueByPath(fromObject, new String[] {"properties"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"propertyOrdering"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"propertyOrdering"}, - Common.getValueByPath(fromObject, new String[] {"propertyOrdering"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"required"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"required"}, - Common.getValueByPath(fromObject, new String[] {"required"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"title"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"title"}, - Common.getValueByPath(fromObject, new String[] {"title"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"type"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"type"}, - Common.getValueByPath(fromObject, new String[] {"type"})); - } - - return toObject; - } - - @ExcludeFromGeneratedCoverageReport - ObjectNode ModelSelectionConfigToVertex( + ObjectNode modelSelectionConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"featureSelectionPreference"}) != null) { @@ -1448,7 +1109,7 @@ ObjectNode ModelSelectionConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode SafetySettingToVertex( + ObjectNode safetySettingToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"method"}) != null) { @@ -1476,54 +1137,15 @@ ObjectNode SafetySettingToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode FunctionDeclarationToVertex( + ObjectNode googleSearchToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); - if (Common.getValueByPath(fromObject, new String[] {"response"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"response"}, - SchemaToVertex( - apiClient, - JsonSerializable.toJsonNode( - Common.getValueByPath(fromObject, new String[] {"response"})), - toObject)); - } - - if (Common.getValueByPath(fromObject, new String[] {"description"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"description"}, - Common.getValueByPath(fromObject, new String[] {"description"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"name"}, - Common.getValueByPath(fromObject, new String[] {"name"})); - } - - if (Common.getValueByPath(fromObject, new String[] {"parameters"}) != null) { - Common.setValueByPath( - toObject, - new String[] {"parameters"}, - Common.getValueByPath(fromObject, new String[] {"parameters"})); - } return toObject; } @ExcludeFromGeneratedCoverageReport - ObjectNode GoogleSearchToVertex( - ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { - ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); - - return toObject; - } - - @ExcludeFromGeneratedCoverageReport - ObjectNode DynamicRetrievalConfigToVertex( + ObjectNode dynamicRetrievalConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"mode"}) != null) { @@ -1544,14 +1166,14 @@ ObjectNode DynamicRetrievalConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GoogleSearchRetrievalToVertex( + ObjectNode googleSearchRetrievalToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"dynamicRetrievalConfig"}) != null) { Common.setValueByPath( toObject, new String[] {"dynamicRetrievalConfig"}, - DynamicRetrievalConfigToVertex( + dynamicRetrievalConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"dynamicRetrievalConfig"})), @@ -1562,23 +1184,8 @@ ObjectNode GoogleSearchRetrievalToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode ToolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); - if (Common.getValueByPath(fromObject, new String[] {"functionDeclarations"}) != null) { - ArrayNode keyArray = - (ArrayNode) Common.getValueByPath(fromObject, new String[] {"functionDeclarations"}); - ObjectMapper objectMapper = new ObjectMapper(); - ArrayNode result = objectMapper.createArrayNode(); - - keyArray.forEach( - item -> { - result.add( - FunctionDeclarationToVertex( - apiClient, JsonSerializable.toJsonNode(item), toObject)); - }); - Common.setValueByPath(toObject, new String[] {"functionDeclarations"}, result); - } - if (Common.getValueByPath(fromObject, new String[] {"retrieval"}) != null) { Common.setValueByPath( toObject, @@ -1590,7 +1197,7 @@ ObjectNode ToolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par Common.setValueByPath( toObject, new String[] {"googleSearch"}, - GoogleSearchToVertex( + googleSearchToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"googleSearch"})), @@ -1601,7 +1208,7 @@ ObjectNode ToolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par Common.setValueByPath( toObject, new String[] {"googleSearchRetrieval"}, - GoogleSearchRetrievalToVertex( + googleSearchRetrievalToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"googleSearchRetrieval"})), @@ -1615,11 +1222,18 @@ ObjectNode ToolToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode par Common.getValueByPath(fromObject, new String[] {"codeExecution"})); } + if (Common.getValueByPath(fromObject, new String[] {"functionDeclarations"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"functionDeclarations"}, + Common.getValueByPath(fromObject, new String[] {"functionDeclarations"})); + } + return toObject; } @ExcludeFromGeneratedCoverageReport - ObjectNode FunctionCallingConfigToVertex( + ObjectNode functionCallingConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"mode"}) != null) { @@ -1640,13 +1254,13 @@ ObjectNode FunctionCallingConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode ToolConfigToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toolConfigToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"functionCallingConfig"}) != null) { Common.setValueByPath( toObject, new String[] {"functionCallingConfig"}, - FunctionCallingConfigToVertex( + functionCallingConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"functionCallingConfig"})), @@ -1657,7 +1271,7 @@ ObjectNode ToolConfigToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNo } @ExcludeFromGeneratedCoverageReport - ObjectNode PrebuiltVoiceConfigToVertex( + ObjectNode prebuiltVoiceConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"voiceName"}) != null) { @@ -1671,14 +1285,14 @@ ObjectNode PrebuiltVoiceConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode VoiceConfigToVertex( + ObjectNode voiceConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"prebuiltVoiceConfig"}) != null) { Common.setValueByPath( toObject, new String[] {"prebuiltVoiceConfig"}, - PrebuiltVoiceConfigToVertex( + prebuiltVoiceConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"prebuiltVoiceConfig"})), @@ -1689,14 +1303,14 @@ ObjectNode VoiceConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode SpeechConfigToVertex( + ObjectNode speechConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"voiceConfig"}) != null) { Common.setValueByPath( toObject, new String[] {"voiceConfig"}, - VoiceConfigToVertex( + voiceConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"voiceConfig"})), @@ -1714,7 +1328,7 @@ ObjectNode SpeechConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode ThinkingConfigToVertex( + ObjectNode thinkingConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"includeThoughts"}) != null) { @@ -1735,7 +1349,7 @@ ObjectNode ThinkingConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateContentConfigToVertex( + ObjectNode generateContentConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -1743,7 +1357,7 @@ ObjectNode GenerateContentConfigToVertex( Common.setValueByPath( parentObject, new String[] {"systemInstruction"}, - ContentToVertex( + contentToVertex( apiClient, JsonSerializable.toJsonNode( Transformers.tContent( @@ -1840,13 +1454,8 @@ ObjectNode GenerateContentConfigToVertex( Common.setValueByPath( toObject, new String[] {"responseSchema"}, - SchemaToVertex( - apiClient, - JsonSerializable.toJsonNode( - Transformers.tSchema( - this.apiClient, - Common.getValueByPath(fromObject, new String[] {"responseSchema"}))), - toObject)); + Transformers.tSchema( + this.apiClient, Common.getValueByPath(fromObject, new String[] {"responseSchema"}))); } if (Common.getValueByPath(fromObject, new String[] {"routingConfig"}) != null) { @@ -1860,7 +1469,7 @@ ObjectNode GenerateContentConfigToVertex( Common.setValueByPath( toObject, new String[] {"modelConfig"}, - ModelSelectionConfigToVertex( + modelSelectionConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"modelSelectionConfig"})), @@ -1876,7 +1485,7 @@ ObjectNode GenerateContentConfigToVertex( keyArray.forEach( item -> { result.add( - SafetySettingToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + safetySettingToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(parentObject, new String[] {"safetySettings"}, result); } @@ -1889,7 +1498,7 @@ ObjectNode GenerateContentConfigToVertex( keyArray.forEach( item -> { result.add( - ToolToVertex( + toolToVertex( apiClient, JsonSerializable.toJsonNode(Transformers.tTool(this.apiClient, item)), toObject)); @@ -1901,7 +1510,7 @@ ObjectNode GenerateContentConfigToVertex( Common.setValueByPath( parentObject, new String[] {"toolConfig"}, - ToolConfigToVertex( + toolConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"toolConfig"})), @@ -1941,7 +1550,7 @@ ObjectNode GenerateContentConfigToVertex( Common.setValueByPath( toObject, new String[] {"speechConfig"}, - SpeechConfigToVertex( + speechConfigToVertex( apiClient, JsonSerializable.toJsonNode( Transformers.tSpeechConfig( @@ -1961,7 +1570,7 @@ ObjectNode GenerateContentConfigToVertex( Common.setValueByPath( toObject, new String[] {"thinkingConfig"}, - ThinkingConfigToVertex( + thinkingConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"thinkingConfig"})), @@ -1972,7 +1581,7 @@ ObjectNode GenerateContentConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateContentParametersToVertex( + ObjectNode generateContentParametersToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { @@ -1990,7 +1599,7 @@ ObjectNode GenerateContentParametersToVertex( keyArray.forEach( item -> { - result.add(ContentToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + result.add(contentToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"contents"}, result); } @@ -1999,7 +1608,7 @@ ObjectNode GenerateContentParametersToVertex( Common.setValueByPath( toObject, new String[] {"generationConfig"}, - GenerateContentConfigToVertex( + generateContentConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"config"})), @@ -2010,7 +1619,7 @@ ObjectNode GenerateContentParametersToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode EmbedContentConfigToVertex( + ObjectNode embedContentConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -2053,7 +1662,7 @@ ObjectNode EmbedContentConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode EmbedContentParametersToVertex( + ObjectNode embedContentParametersToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { @@ -2076,7 +1685,7 @@ ObjectNode EmbedContentParametersToVertex( Common.setValueByPath( toObject, new String[] {"config"}, - EmbedContentConfigToVertex( + embedContentConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"config"})), @@ -2087,7 +1696,7 @@ ObjectNode EmbedContentParametersToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateImagesConfigToVertex( + ObjectNode generateImagesConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -2200,7 +1809,7 @@ ObjectNode GenerateImagesConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateImagesParametersToVertex( + ObjectNode generateImagesParametersToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { @@ -2222,7 +1831,7 @@ ObjectNode GenerateImagesParametersToVertex( Common.setValueByPath( toObject, new String[] {"config"}, - GenerateImagesConfigToVertex( + generateImagesConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"config"})), @@ -2233,7 +1842,7 @@ ObjectNode GenerateImagesParametersToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode ImageToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode imageToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"gcsUri"}) != null) { Common.setValueByPath( @@ -2261,7 +1870,7 @@ ObjectNode ImageToVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode pa } @ExcludeFromGeneratedCoverageReport - ObjectNode MaskReferenceConfigToVertex( + ObjectNode maskReferenceConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"maskMode"}) != null) { @@ -2289,7 +1898,7 @@ ObjectNode MaskReferenceConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode ControlReferenceConfigToVertex( + ObjectNode controlReferenceConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"controlType"}) != null) { @@ -2310,7 +1919,7 @@ ObjectNode ControlReferenceConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode StyleReferenceConfigToVertex( + ObjectNode styleReferenceConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"styleDescription"}) != null) { @@ -2324,7 +1933,7 @@ ObjectNode StyleReferenceConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode SubjectReferenceConfigToVertex( + ObjectNode subjectReferenceConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"subjectType"}) != null) { @@ -2345,14 +1954,14 @@ ObjectNode SubjectReferenceConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode ReferenceImageAPIToVertex( + ObjectNode referenceImageAPIToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"referenceImage"}) != null) { Common.setValueByPath( toObject, new String[] {"referenceImage"}, - ImageToVertex( + imageToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"referenceImage"})), @@ -2377,7 +1986,7 @@ ObjectNode ReferenceImageAPIToVertex( Common.setValueByPath( toObject, new String[] {"maskImageConfig"}, - MaskReferenceConfigToVertex( + maskReferenceConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"maskImageConfig"})), @@ -2388,7 +1997,7 @@ ObjectNode ReferenceImageAPIToVertex( Common.setValueByPath( toObject, new String[] {"controlImageConfig"}, - ControlReferenceConfigToVertex( + controlReferenceConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"controlImageConfig"})), @@ -2399,7 +2008,7 @@ ObjectNode ReferenceImageAPIToVertex( Common.setValueByPath( toObject, new String[] {"styleImageConfig"}, - StyleReferenceConfigToVertex( + styleReferenceConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"styleImageConfig"})), @@ -2410,7 +2019,7 @@ ObjectNode ReferenceImageAPIToVertex( Common.setValueByPath( toObject, new String[] {"subjectImageConfig"}, - SubjectReferenceConfigToVertex( + subjectReferenceConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"subjectImageConfig"})), @@ -2421,7 +2030,7 @@ ObjectNode ReferenceImageAPIToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode EditImageConfigToVertex( + ObjectNode editImageConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -2534,7 +2143,7 @@ ObjectNode EditImageConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode EditImageParametersToVertex( + ObjectNode editImageParametersToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { @@ -2561,7 +2170,7 @@ ObjectNode EditImageParametersToVertex( keyArray.forEach( item -> { result.add( - ReferenceImageAPIToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + referenceImageAPIToVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"instances[0]", "referenceImages"}, result); } @@ -2570,7 +2179,7 @@ ObjectNode EditImageParametersToVertex( Common.setValueByPath( toObject, new String[] {"config"}, - EditImageConfigToVertex( + editImageConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"config"})), @@ -2581,7 +2190,7 @@ ObjectNode EditImageParametersToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode UpscaleImageAPIConfigToVertex( + ObjectNode upscaleImageAPIConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -2624,7 +2233,7 @@ ObjectNode UpscaleImageAPIConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode UpscaleImageAPIParametersToVertex( + ObjectNode upscaleImageAPIParametersToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { @@ -2639,7 +2248,7 @@ ObjectNode UpscaleImageAPIParametersToVertex( Common.setValueByPath( toObject, new String[] {"instances[0]", "image"}, - ImageToVertex( + imageToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"image"})), @@ -2657,7 +2266,7 @@ ObjectNode UpscaleImageAPIParametersToVertex( Common.setValueByPath( toObject, new String[] {"config"}, - UpscaleImageAPIConfigToVertex( + upscaleImageAPIConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"config"})), @@ -2668,7 +2277,7 @@ ObjectNode UpscaleImageAPIParametersToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosConfigToVertex( + ObjectNode generateVideosConfigToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -2753,7 +2362,7 @@ ObjectNode GenerateVideosConfigToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosParametersToVertex( + ObjectNode generateVideosParametersToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"model"}) != null) { @@ -2775,7 +2384,7 @@ ObjectNode GenerateVideosParametersToVertex( Common.setValueByPath( toObject, new String[] {"instances[0]", "image"}, - ImageToVertex( + imageToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"image"})), @@ -2786,7 +2395,7 @@ ObjectNode GenerateVideosParametersToVertex( Common.setValueByPath( toObject, new String[] {"config"}, - GenerateVideosConfigToVertex( + generateVideosConfigToVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"config"})), @@ -2797,7 +2406,7 @@ ObjectNode GenerateVideosParametersToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode PartFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode partFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"thought"}) != null) { @@ -2860,7 +2469,7 @@ ObjectNode PartFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode pa } @ExcludeFromGeneratedCoverageReport - ObjectNode ContentFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode contentFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"parts"}) != null) { ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"parts"}); @@ -2869,7 +2478,7 @@ ObjectNode ContentFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode keyArray.forEach( item -> { - result.add(PartFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + result.add(partFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"parts"}, result); } @@ -2885,7 +2494,7 @@ ObjectNode ContentFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode } @ExcludeFromGeneratedCoverageReport - ObjectNode CitationMetadataFromMldev( + ObjectNode citationMetadataFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"citationSources"}) != null) { @@ -2899,13 +2508,13 @@ ObjectNode CitationMetadataFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode CandidateFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode candidateFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"content"}) != null) { Common.setValueByPath( toObject, new String[] {"content"}, - ContentFromMldev( + contentFromMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"content"})), @@ -2916,7 +2525,7 @@ ObjectNode CandidateFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNo Common.setValueByPath( toObject, new String[] {"citationMetadata"}, - CitationMetadataFromMldev( + citationMetadataFromMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"citationMetadata"})), @@ -2976,7 +2585,7 @@ ObjectNode CandidateFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNo } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateContentResponseFromMldev( + ObjectNode generateContentResponseFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"candidates"}) != null) { @@ -2987,7 +2596,7 @@ ObjectNode GenerateContentResponseFromMldev( keyArray.forEach( item -> { - result.add(CandidateFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + result.add(candidateFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"candidates"}, result); } @@ -3017,7 +2626,7 @@ ObjectNode GenerateContentResponseFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode ContentEmbeddingStatisticsFromMldev( + ObjectNode contentEmbeddingStatisticsFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -3025,7 +2634,7 @@ ObjectNode ContentEmbeddingStatisticsFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode ContentEmbeddingFromMldev( + ObjectNode contentEmbeddingFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"values"}) != null) { @@ -3039,7 +2648,7 @@ ObjectNode ContentEmbeddingFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode EmbedContentMetadataFromMldev( + ObjectNode embedContentMetadataFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); @@ -3047,7 +2656,7 @@ ObjectNode EmbedContentMetadataFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode EmbedContentResponseFromMldev( + ObjectNode embedContentResponseFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"embeddings"}) != null) { @@ -3059,7 +2668,7 @@ ObjectNode EmbedContentResponseFromMldev( keyArray.forEach( item -> { result.add( - ContentEmbeddingFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + contentEmbeddingFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"embeddings"}, result); } @@ -3068,7 +2677,7 @@ ObjectNode EmbedContentResponseFromMldev( Common.setValueByPath( toObject, new String[] {"metadata"}, - EmbedContentMetadataFromMldev( + embedContentMetadataFromMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"metadata"})), @@ -3079,7 +2688,7 @@ ObjectNode EmbedContentResponseFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode ImageFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode imageFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"bytesBase64Encoded"}) != null) { @@ -3102,7 +2711,7 @@ ObjectNode ImageFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode p } @ExcludeFromGeneratedCoverageReport - ObjectNode SafetyAttributesFromMldev( + ObjectNode safetyAttributesFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"safetyAttributes", "categories"}) @@ -3131,14 +2740,14 @@ ObjectNode SafetyAttributesFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode GeneratedImageFromMldev( + ObjectNode generatedImageFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"_self"}) != null) { Common.setValueByPath( toObject, new String[] {"image"}, - ImageFromMldev( + imageFromMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"_self"})), @@ -3156,7 +2765,7 @@ ObjectNode GeneratedImageFromMldev( Common.setValueByPath( toObject, new String[] {"safetyAttributes"}, - SafetyAttributesFromMldev( + safetyAttributesFromMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"_self"})), @@ -3167,7 +2776,7 @@ ObjectNode GeneratedImageFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateImagesResponseFromMldev( + ObjectNode generateImagesResponseFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"predictions"}) != null) { @@ -3179,7 +2788,7 @@ ObjectNode GenerateImagesResponseFromMldev( keyArray.forEach( item -> { result.add( - GeneratedImageFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + generatedImageFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"generatedImages"}, result); } @@ -3189,7 +2798,7 @@ ObjectNode GenerateImagesResponseFromMldev( Common.setValueByPath( toObject, new String[] {"positivePromptSafetyAttributes"}, - SafetyAttributesFromMldev( + safetyAttributesFromMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath( @@ -3201,7 +2810,7 @@ ObjectNode GenerateImagesResponseFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode VideoFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode videoFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"video", "uri"}) != null) { Common.setValueByPath( @@ -3230,14 +2839,14 @@ ObjectNode VideoFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode p } @ExcludeFromGeneratedCoverageReport - ObjectNode GeneratedVideoFromMldev( + ObjectNode generatedVideoFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"_self"}) != null) { Common.setValueByPath( toObject, new String[] {"video"}, - VideoFromMldev( + videoFromMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"_self"})), @@ -3248,7 +2857,7 @@ ObjectNode GeneratedVideoFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosResponseFromMldev( + ObjectNode generateVideosResponseFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"generatedSamples"}) != null) { @@ -3260,7 +2869,7 @@ ObjectNode GenerateVideosResponseFromMldev( keyArray.forEach( item -> { result.add( - GeneratedVideoFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + generatedVideoFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"generatedVideos"}, result); } @@ -3283,7 +2892,7 @@ ObjectNode GenerateVideosResponseFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosOperationFromMldev( + ObjectNode generateVideosOperationFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) { @@ -3319,7 +2928,7 @@ ObjectNode GenerateVideosOperationFromMldev( Common.setValueByPath( toObject, new String[] {"response"}, - GenerateVideosResponseFromMldev( + generateVideosResponseFromMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath( @@ -3331,7 +2940,7 @@ ObjectNode GenerateVideosOperationFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode PartFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode partFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"videoMetadata"}) != null) { Common.setValueByPath( @@ -3400,7 +3009,7 @@ ObjectNode PartFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode p } @ExcludeFromGeneratedCoverageReport - ObjectNode ContentFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode contentFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"parts"}) != null) { ArrayNode keyArray = (ArrayNode) Common.getValueByPath(fromObject, new String[] {"parts"}); @@ -3409,7 +3018,7 @@ ObjectNode ContentFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNod keyArray.forEach( item -> { - result.add(PartFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + result.add(partFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"parts"}, result); } @@ -3425,7 +3034,7 @@ ObjectNode ContentFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNod } @ExcludeFromGeneratedCoverageReport - ObjectNode CitationMetadataFromVertex( + ObjectNode citationMetadataFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"citations"}) != null) { @@ -3439,14 +3048,14 @@ ObjectNode CitationMetadataFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode CandidateFromVertex( + ObjectNode candidateFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"content"}) != null) { Common.setValueByPath( toObject, new String[] {"content"}, - ContentFromVertex( + contentFromVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"content"})), @@ -3457,7 +3066,7 @@ ObjectNode CandidateFromVertex( Common.setValueByPath( toObject, new String[] {"citationMetadata"}, - CitationMetadataFromVertex( + citationMetadataFromVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"citationMetadata"})), @@ -3517,7 +3126,7 @@ ObjectNode CandidateFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateContentResponseFromVertex( + ObjectNode generateContentResponseFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"candidates"}) != null) { @@ -3528,7 +3137,7 @@ ObjectNode GenerateContentResponseFromVertex( keyArray.forEach( item -> { - result.add(CandidateFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + result.add(candidateFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"candidates"}, result); } @@ -3572,7 +3181,7 @@ ObjectNode GenerateContentResponseFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode ContentEmbeddingStatisticsFromVertex( + ObjectNode contentEmbeddingStatisticsFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"truncated"}) != null) { @@ -3593,7 +3202,7 @@ ObjectNode ContentEmbeddingStatisticsFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode ContentEmbeddingFromVertex( + ObjectNode contentEmbeddingFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"values"}) != null) { @@ -3607,7 +3216,7 @@ ObjectNode ContentEmbeddingFromVertex( Common.setValueByPath( toObject, new String[] {"statistics"}, - ContentEmbeddingStatisticsFromVertex( + contentEmbeddingStatisticsFromVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"statistics"})), @@ -3618,7 +3227,7 @@ ObjectNode ContentEmbeddingFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode EmbedContentMetadataFromVertex( + ObjectNode embedContentMetadataFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"billableCharacterCount"}) != null) { @@ -3632,7 +3241,7 @@ ObjectNode EmbedContentMetadataFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode EmbedContentResponseFromVertex( + ObjectNode embedContentResponseFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"predictions[]", "embeddings"}) != null) { @@ -3645,7 +3254,7 @@ ObjectNode EmbedContentResponseFromVertex( keyArray.forEach( item -> { result.add( - ContentEmbeddingFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + contentEmbeddingFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"embeddings"}, result); } @@ -3654,7 +3263,7 @@ ObjectNode EmbedContentResponseFromVertex( Common.setValueByPath( toObject, new String[] {"metadata"}, - EmbedContentMetadataFromVertex( + embedContentMetadataFromVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"metadata"})), @@ -3665,7 +3274,7 @@ ObjectNode EmbedContentResponseFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode ImageFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode imageFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"gcsUri"}) != null) { Common.setValueByPath( @@ -3694,7 +3303,7 @@ ObjectNode ImageFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode } @ExcludeFromGeneratedCoverageReport - ObjectNode SafetyAttributesFromVertex( + ObjectNode safetyAttributesFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"safetyAttributes", "categories"}) @@ -3723,14 +3332,14 @@ ObjectNode SafetyAttributesFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GeneratedImageFromVertex( + ObjectNode generatedImageFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"_self"}) != null) { Common.setValueByPath( toObject, new String[] {"image"}, - ImageFromVertex( + imageFromVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"_self"})), @@ -3748,7 +3357,7 @@ ObjectNode GeneratedImageFromVertex( Common.setValueByPath( toObject, new String[] {"safetyAttributes"}, - SafetyAttributesFromVertex( + safetyAttributesFromVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"_self"})), @@ -3766,7 +3375,7 @@ ObjectNode GeneratedImageFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateImagesResponseFromVertex( + ObjectNode generateImagesResponseFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"predictions"}) != null) { @@ -3778,7 +3387,7 @@ ObjectNode GenerateImagesResponseFromVertex( keyArray.forEach( item -> { result.add( - GeneratedImageFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + generatedImageFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"generatedImages"}, result); } @@ -3788,7 +3397,7 @@ ObjectNode GenerateImagesResponseFromVertex( Common.setValueByPath( toObject, new String[] {"positivePromptSafetyAttributes"}, - SafetyAttributesFromVertex( + safetyAttributesFromVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath( @@ -3800,7 +3409,7 @@ ObjectNode GenerateImagesResponseFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode EditImageResponseFromVertex( + ObjectNode editImageResponseFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"predictions"}) != null) { @@ -3812,7 +3421,7 @@ ObjectNode EditImageResponseFromVertex( keyArray.forEach( item -> { result.add( - GeneratedImageFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + generatedImageFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"generatedImages"}, result); } @@ -3821,7 +3430,7 @@ ObjectNode EditImageResponseFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode UpscaleImageResponseFromVertex( + ObjectNode upscaleImageResponseFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"predictions"}) != null) { @@ -3833,7 +3442,7 @@ ObjectNode UpscaleImageResponseFromVertex( keyArray.forEach( item -> { result.add( - GeneratedImageFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + generatedImageFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"generatedImages"}, result); } @@ -3842,7 +3451,7 @@ ObjectNode UpscaleImageResponseFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode VideoFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode videoFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"gcsUri"}) != null) { Common.setValueByPath( @@ -3871,14 +3480,14 @@ ObjectNode VideoFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode } @ExcludeFromGeneratedCoverageReport - ObjectNode GeneratedVideoFromVertex( + ObjectNode generatedVideoFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"_self"}) != null) { Common.setValueByPath( toObject, new String[] {"video"}, - VideoFromVertex( + videoFromVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"_self"})), @@ -3889,7 +3498,7 @@ ObjectNode GeneratedVideoFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosResponseFromVertex( + ObjectNode generateVideosResponseFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"videos"}) != null) { @@ -3900,7 +3509,7 @@ ObjectNode GenerateVideosResponseFromVertex( keyArray.forEach( item -> { result.add( - GeneratedVideoFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + generatedVideoFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"generatedVideos"}, result); } @@ -3923,7 +3532,7 @@ ObjectNode GenerateVideosResponseFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosOperationFromVertex( + ObjectNode generateVideosOperationFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) { @@ -3958,7 +3567,7 @@ ObjectNode GenerateVideosOperationFromVertex( Common.setValueByPath( toObject, new String[] {"response"}, - GenerateVideosResponseFromVertex( + generateVideosResponseFromVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"response"})), @@ -3987,10 +3596,10 @@ private GenerateContentResponse privateGenerateContent( ObjectNode body; String path; if (this.apiClient.vertexAI()) { - body = GenerateContentParametersToVertex(this.apiClient, parameterNode, null); + body = generateContentParametersToVertex(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:generateContent", body.get("_url")); } else { - body = GenerateContentParametersToMldev(this.apiClient, parameterNode, null); + body = generateContentParametersToMldev(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:generateContent", body.get("_url")); } body.remove("_url"); @@ -4011,9 +3620,9 @@ private GenerateContentResponse privateGenerateContent( } JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString); if (this.apiClient.vertexAI()) { - responseNode = GenerateContentResponseFromVertex(this.apiClient, responseNode, null); + responseNode = generateContentResponseFromVertex(this.apiClient, responseNode, null); } else { - responseNode = GenerateContentResponseFromMldev(this.apiClient, responseNode, null); + responseNode = generateContentResponseFromMldev(this.apiClient, responseNode, null); } return JsonSerializable.fromJsonNode(responseNode, GenerateContentResponse.class); } @@ -4038,10 +3647,10 @@ private ResponseStream privateGenerateContentStream( ObjectNode body; String path; if (this.apiClient.vertexAI()) { - body = GenerateContentParametersToVertex(this.apiClient, parameterNode, null); + body = generateContentParametersToVertex(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:streamGenerateContent?alt=sse", body.get("_url")); } else { - body = GenerateContentParametersToMldev(this.apiClient, parameterNode, null); + body = generateContentParametersToMldev(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:streamGenerateContent?alt=sse", body.get("_url")); } body.remove("_url"); @@ -4082,10 +3691,10 @@ private EmbedContentResponse privateEmbedContent( ObjectNode body; String path; if (this.apiClient.vertexAI()) { - body = EmbedContentParametersToVertex(this.apiClient, parameterNode, null); + body = embedContentParametersToVertex(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:predict", body.get("_url")); } else { - body = EmbedContentParametersToMldev(this.apiClient, parameterNode, null); + body = embedContentParametersToMldev(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:batchEmbedContents", body.get("_url")); } body.remove("_url"); @@ -4106,9 +3715,9 @@ private EmbedContentResponse privateEmbedContent( } JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString); if (this.apiClient.vertexAI()) { - responseNode = EmbedContentResponseFromVertex(this.apiClient, responseNode, null); + responseNode = embedContentResponseFromVertex(this.apiClient, responseNode, null); } else { - responseNode = EmbedContentResponseFromMldev(this.apiClient, responseNode, null); + responseNode = embedContentResponseFromMldev(this.apiClient, responseNode, null); } return JsonSerializable.fromJsonNode(responseNode, EmbedContentResponse.class); } @@ -4133,10 +3742,10 @@ private GenerateImagesResponse privateGenerateImages( ObjectNode body; String path; if (this.apiClient.vertexAI()) { - body = GenerateImagesParametersToVertex(this.apiClient, parameterNode, null); + body = generateImagesParametersToVertex(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:predict", body.get("_url")); } else { - body = GenerateImagesParametersToMldev(this.apiClient, parameterNode, null); + body = generateImagesParametersToMldev(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:predict", body.get("_url")); } body.remove("_url"); @@ -4157,9 +3766,9 @@ private GenerateImagesResponse privateGenerateImages( } JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString); if (this.apiClient.vertexAI()) { - responseNode = GenerateImagesResponseFromVertex(this.apiClient, responseNode, null); + responseNode = generateImagesResponseFromVertex(this.apiClient, responseNode, null); } else { - responseNode = GenerateImagesResponseFromMldev(this.apiClient, responseNode, null); + responseNode = generateImagesResponseFromMldev(this.apiClient, responseNode, null); } return JsonSerializable.fromJsonNode(responseNode, GenerateImagesResponse.class); } @@ -4190,11 +3799,11 @@ private EditImageResponse privateEditImage( ObjectNode body; String path; if (this.apiClient.vertexAI()) { - body = EditImageParametersToVertex(this.apiClient, parameterNode, null); + body = editImageParametersToVertex(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:predict", body.get("_url")); } else { throw new UnsupportedOperationException( - "This method is only supported by the Gemini Developer API."); + "This method is not supported by the Gemini Developer API."); } body.remove("_url"); @@ -4214,10 +3823,10 @@ private EditImageResponse privateEditImage( } JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString); if (this.apiClient.vertexAI()) { - responseNode = EditImageResponseFromVertex(this.apiClient, responseNode, null); + responseNode = editImageResponseFromVertex(this.apiClient, responseNode, null); } else { throw new UnsupportedOperationException( - "This method is only supported by the Gemini Developer API."); + "This method is not supported by the Gemini Developer API."); } return JsonSerializable.fromJsonNode(responseNode, EditImageResponse.class); } @@ -4245,11 +3854,11 @@ private UpscaleImageResponse privateUpscaleImage( ObjectNode body; String path; if (this.apiClient.vertexAI()) { - body = UpscaleImageAPIParametersToVertex(this.apiClient, parameterNode, null); + body = upscaleImageAPIParametersToVertex(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:predict", body.get("_url")); } else { throw new UnsupportedOperationException( - "This method is only supported by the Gemini Developer API."); + "This method is not supported by the Gemini Developer API."); } body.remove("_url"); @@ -4269,10 +3878,10 @@ private UpscaleImageResponse privateUpscaleImage( } JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString); if (this.apiClient.vertexAI()) { - responseNode = UpscaleImageResponseFromVertex(this.apiClient, responseNode, null); + responseNode = upscaleImageResponseFromVertex(this.apiClient, responseNode, null); } else { throw new UnsupportedOperationException( - "This method is only supported by the Gemini Developer API."); + "This method is not supported by the Gemini Developer API."); } return JsonSerializable.fromJsonNode(responseNode, UpscaleImageResponse.class); } @@ -4300,10 +3909,10 @@ public GenerateVideosOperation generateVideos( ObjectNode body; String path; if (this.apiClient.vertexAI()) { - body = GenerateVideosParametersToVertex(this.apiClient, parameterNode, null); + body = generateVideosParametersToVertex(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:predictLongRunning", body.get("_url")); } else { - body = GenerateVideosParametersToMldev(this.apiClient, parameterNode, null); + body = generateVideosParametersToMldev(this.apiClient, parameterNode, null); path = Common.formatMap("{model}:predictLongRunning", body.get("_url")); } body.remove("_url"); @@ -4324,9 +3933,9 @@ public GenerateVideosOperation generateVideos( } JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString); if (this.apiClient.vertexAI()) { - responseNode = GenerateVideosOperationFromVertex(this.apiClient, responseNode, null); + responseNode = generateVideosOperationFromVertex(this.apiClient, responseNode, null); } else { - responseNode = GenerateVideosOperationFromMldev(this.apiClient, responseNode, null); + responseNode = generateVideosOperationFromMldev(this.apiClient, responseNode, null); } return JsonSerializable.fromJsonNode(responseNode, GenerateVideosOperation.class); } diff --git a/src/main/java/com/google/genai/Operations.java b/src/main/java/com/google/genai/Operations.java index 3ccbef6a07a..32aacdab812 100644 --- a/src/main/java/com/google/genai/Operations.java +++ b/src/main/java/com/google/genai/Operations.java @@ -40,7 +40,7 @@ public Operations(ApiClient apiClient) { } @ExcludeFromGeneratedCoverageReport - ObjectNode GetOperationParametersToMldev( + ObjectNode getOperationParametersToMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"operationName"}) != null) { @@ -61,7 +61,7 @@ ObjectNode GetOperationParametersToMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode GetOperationParametersToVertex( + ObjectNode getOperationParametersToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"operationName"}) != null) { @@ -82,7 +82,7 @@ ObjectNode GetOperationParametersToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode FetchPredictOperationParametersToVertex( + ObjectNode fetchPredictOperationParametersToVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"operationName"}) != null) { @@ -110,7 +110,7 @@ ObjectNode FetchPredictOperationParametersToVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode VideoFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode videoFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"video", "uri"}) != null) { Common.setValueByPath( @@ -139,14 +139,14 @@ ObjectNode VideoFromMldev(ApiClient apiClient, JsonNode fromObject, ObjectNode p } @ExcludeFromGeneratedCoverageReport - ObjectNode GeneratedVideoFromMldev( + ObjectNode generatedVideoFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"_self"}) != null) { Common.setValueByPath( toObject, new String[] {"video"}, - VideoFromMldev( + videoFromMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"_self"})), @@ -157,7 +157,7 @@ ObjectNode GeneratedVideoFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosResponseFromMldev( + ObjectNode generateVideosResponseFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"generatedSamples"}) != null) { @@ -169,7 +169,7 @@ ObjectNode GenerateVideosResponseFromMldev( keyArray.forEach( item -> { result.add( - GeneratedVideoFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); + generatedVideoFromMldev(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"generatedVideos"}, result); } @@ -192,7 +192,7 @@ ObjectNode GenerateVideosResponseFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosOperationFromMldev( + ObjectNode generateVideosOperationFromMldev( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) { @@ -228,7 +228,7 @@ ObjectNode GenerateVideosOperationFromMldev( Common.setValueByPath( toObject, new String[] {"response"}, - GenerateVideosResponseFromMldev( + generateVideosResponseFromMldev( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath( @@ -240,7 +240,7 @@ ObjectNode GenerateVideosOperationFromMldev( } @ExcludeFromGeneratedCoverageReport - ObjectNode VideoFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { + ObjectNode videoFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"gcsUri"}) != null) { Common.setValueByPath( @@ -269,14 +269,14 @@ ObjectNode VideoFromVertex(ApiClient apiClient, JsonNode fromObject, ObjectNode } @ExcludeFromGeneratedCoverageReport - ObjectNode GeneratedVideoFromVertex( + ObjectNode generatedVideoFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"_self"}) != null) { Common.setValueByPath( toObject, new String[] {"video"}, - VideoFromVertex( + videoFromVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"_self"})), @@ -287,7 +287,7 @@ ObjectNode GeneratedVideoFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosResponseFromVertex( + ObjectNode generateVideosResponseFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"videos"}) != null) { @@ -298,7 +298,7 @@ ObjectNode GenerateVideosResponseFromVertex( keyArray.forEach( item -> { result.add( - GeneratedVideoFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); + generatedVideoFromVertex(apiClient, JsonSerializable.toJsonNode(item), toObject)); }); Common.setValueByPath(toObject, new String[] {"generatedVideos"}, result); } @@ -321,7 +321,7 @@ ObjectNode GenerateVideosResponseFromVertex( } @ExcludeFromGeneratedCoverageReport - ObjectNode GenerateVideosOperationFromVertex( + ObjectNode generateVideosOperationFromVertex( ApiClient apiClient, JsonNode fromObject, ObjectNode parentObject) { ObjectNode toObject = JsonSerializable.objectMapper.createObjectNode(); if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) { @@ -356,7 +356,7 @@ ObjectNode GenerateVideosOperationFromVertex( Common.setValueByPath( toObject, new String[] {"response"}, - GenerateVideosResponseFromVertex( + generateVideosResponseFromVertex( apiClient, JsonSerializable.toJsonNode( Common.getValueByPath(fromObject, new String[] {"response"})), @@ -382,10 +382,10 @@ private GenerateVideosOperation privateGetVideosOperation( ObjectNode body; String path; if (this.apiClient.vertexAI()) { - body = GetOperationParametersToVertex(this.apiClient, parameterNode, null); + body = getOperationParametersToVertex(this.apiClient, parameterNode, null); path = Common.formatMap("{operationName}", body.get("_url")); } else { - body = GetOperationParametersToMldev(this.apiClient, parameterNode, null); + body = getOperationParametersToMldev(this.apiClient, parameterNode, null); path = Common.formatMap("{operationName}", body.get("_url")); } body.remove("_url"); @@ -406,9 +406,9 @@ private GenerateVideosOperation privateGetVideosOperation( } JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString); if (this.apiClient.vertexAI()) { - responseNode = GenerateVideosOperationFromVertex(this.apiClient, responseNode, null); + responseNode = generateVideosOperationFromVertex(this.apiClient, responseNode, null); } else { - responseNode = GenerateVideosOperationFromMldev(this.apiClient, responseNode, null); + responseNode = generateVideosOperationFromMldev(this.apiClient, responseNode, null); } return JsonSerializable.fromJsonNode(responseNode, GenerateVideosOperation.class); } @@ -434,11 +434,11 @@ private GenerateVideosOperation privateFetchPredictVideosOperation( ObjectNode body; String path; if (this.apiClient.vertexAI()) { - body = FetchPredictOperationParametersToVertex(this.apiClient, parameterNode, null); + body = fetchPredictOperationParametersToVertex(this.apiClient, parameterNode, null); path = Common.formatMap("{resourceName}:fetchPredictOperation", body.get("_url")); } else { throw new UnsupportedOperationException( - "This method is only supported by the Gemini Developer API."); + "This method is not supported by the Gemini Developer API."); } body.remove("_url"); @@ -458,10 +458,10 @@ private GenerateVideosOperation privateFetchPredictVideosOperation( } JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString); if (this.apiClient.vertexAI()) { - responseNode = GenerateVideosOperationFromVertex(this.apiClient, responseNode, null); + responseNode = generateVideosOperationFromVertex(this.apiClient, responseNode, null); } else { throw new UnsupportedOperationException( - "This method is only supported by the Gemini Developer API."); + "This method is not supported by the Gemini Developer API."); } return JsonSerializable.fromJsonNode(responseNode, GenerateVideosOperation.class); } diff --git a/src/main/java/com/google/genai/ResponseStream.java b/src/main/java/com/google/genai/ResponseStream.java index 74fa4038f2a..addd8f67f09 100644 --- a/src/main/java/com/google/genai/ResponseStream.java +++ b/src/main/java/com/google/genai/ResponseStream.java @@ -26,13 +26,22 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; +import java.util.logging.Logger; import java.util.NoSuchElementException; import org.apache.http.HttpEntity; /** An iterable of datatype objects. */ public class ResponseStream implements Iterable, AutoCloseable { + boolean recordingHistory = false; + List history = new ArrayList<>(); + Chat chatSession = null; + + private static final Logger logger = Logger.getLogger(ChatBase.class.getName()); + /** Iterator for the ResponseStream. */ class ResponseStreamIterator implements Iterator { private final BufferedReader reader; @@ -40,6 +49,7 @@ class ResponseStreamIterator implements Iterator { private final Object obj; private final Method converter; private String nextJson; + private boolean consumed = false; ResponseStreamIterator( Class clazz, BufferedReader reader, Object obj, String converterName) { @@ -59,6 +69,18 @@ class ResponseStreamIterator implements Iterator { @Override public boolean hasNext() { + if (nextJson == null) { + consumed = true; + if (recordingHistory) { + try { + chatSession.checkStreamResponseAndUpdateHistory(); + recordingHistory = false; + } catch (IllegalStateException e) { + logger.info( + "Error while updating history: " + e.getMessage() + ". Continuing execution..."); + } + } + } return nextJson != null; } @@ -72,6 +94,11 @@ public T next() { try { JsonNode currentJsonNode = JsonSerializable.stringToJsonNode(currentJson); currentJsonNode = (JsonNode) converter.invoke(obj, null, currentJsonNode, null); + if (recordingHistory) { + T response = JsonSerializable.fromJsonNode(currentJsonNode, clazz); + history.add(response); + return response; + } return JsonSerializable.fromJsonNode(currentJsonNode, clazz); } catch (IllegalAccessException | InvocationTargetException e) { throw new IllegalStateException("Failed to convert JSON object " + currentJson, e); @@ -138,4 +165,8 @@ public void close() { } } } + + boolean isConsumed() { + return iterator.consumed; + } } diff --git a/src/main/java/com/google/genai/Transformers.java b/src/main/java/com/google/genai/Transformers.java index d3f66f208ee..55b8fc7cb26 100644 --- a/src/main/java/com/google/genai/Transformers.java +++ b/src/main/java/com/google/genai/Transformers.java @@ -191,6 +191,12 @@ public static Tool tTool(ApiClient apiClient, Object origin) { throw new IllegalArgumentException("Unsupported tool type: " + origin.getClass()); } + /** Dummy Blobs transformer. */ + public static Object tBlobs(ApiClient apiClient, Object origin) { + // TODO(b/413689280): Remove dummy blobs converter. + return origin; + } + /** Dummy bytes transformer. */ public static Object tBytes(ApiClient apiClient, Object origin) { // TODO(b/389133914): Remove dummy bytes converter. diff --git a/src/main/java/com/google/genai/types/FunctionDeclaration.java b/src/main/java/com/google/genai/types/FunctionDeclaration.java index de7a77ab163..1e4306eabdb 100644 --- a/src/main/java/com/google/genai/types/FunctionDeclaration.java +++ b/src/main/java/com/google/genai/types/FunctionDeclaration.java @@ -23,20 +23,25 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.auto.value.AutoValue; import com.google.genai.JsonSerializable; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.Parameter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Optional; /** - * Defines a function that the model can generate JSON inputs for. - * - *

The inputs are based on `OpenAPI 3.0 specifications `_. + * Structured representation of a function declaration as defined by the [OpenAPI 3.0 + * specification](https://spec.openapis.org/oas/v3.0.3). Included in this declaration are the + * function name, description, parameters and response type. This FunctionDeclaration is a + * representation of a block of code that can be used as a `Tool` by the model and executed by the + * client. */ @AutoValue @JsonDeserialize(builder = FunctionDeclaration.Builder.class) public abstract class FunctionDeclaration extends JsonSerializable { - /** Describes the output from the function in the OpenAPI JSON Schema Object format. */ - @JsonProperty("response") - public abstract Optional response(); - /** * Optional. Description and purpose of the function. Model uses it to decide how and whether to * call the function. @@ -63,6 +68,13 @@ public abstract class FunctionDeclaration extends JsonSerializable { @JsonProperty("parameters") public abstract Optional parameters(); + /** + * Optional. Describes the output from this function in JSON Schema format. Reflects the Open API + * 3.03 Response Object. The Schema defines the type used for the response value of the function. + */ + @JsonProperty("response") + public abstract Optional response(); + /** Instantiates a builder for FunctionDeclaration. */ public static Builder builder() { return new AutoValue_FunctionDeclaration.Builder(); @@ -80,9 +92,6 @@ private static Builder create() { return new AutoValue_FunctionDeclaration.Builder(); } - @JsonProperty("response") - public abstract Builder response(Schema response); - @JsonProperty("description") public abstract Builder description(String description); @@ -92,6 +101,9 @@ private static Builder create() { @JsonProperty("parameters") public abstract Builder parameters(Schema parameters); + @JsonProperty("response") + public abstract Builder response(Schema response); + public abstract FunctionDeclaration build(); } @@ -99,4 +111,106 @@ private static Builder create() { public static FunctionDeclaration fromJson(String jsonString) { return JsonSerializable.fromJsonString(jsonString, FunctionDeclaration.class); } + + /** + * Creates a FunctionDeclaration instance from a {@link Method} instance. + * + * @param method The {@link Method} instance to be parsed into the FunctionDeclaration instance. + * Only static method is supported. + * @param orderedParameterNames Optional ordered parameter names. If not provided, parameter names + * will be retrieved via reflection. + * @return A FunctionDeclaration instance. + */ + public static FunctionDeclaration fromMethod(Method method, String... orderedParameterNames) { + return fromMethod("", method, orderedParameterNames); + } + + /** + * Creates a FunctionDeclaration instance from a {@link Method} instance. + * + * @param functionDescription Description of the function. + * @param method The {@link Method} instance to be parsed into the FunctionDeclaration instance. + * Only static method is supported. + * @param orderedParameterNames Optional ordered parameter names. If not provided, parameter names + * will be retrieved via reflection. + * @return A FunctionDeclaration instance. + */ + public static FunctionDeclaration fromMethod( + String functionDescription, Method method, String... orderedParameterNames) { + if (!Modifier.isStatic(method.getModifiers())) { + throw new IllegalArgumentException( + "Instance methods are not supported. Please use static methods."); + } + + Schema.Builder parametersBuilder = Schema.builder().type("OBJECT"); + + Parameter[] parameters = method.getParameters(); + + if (orderedParameterNames.length > 0 && orderedParameterNames.length != parameters.length) { + throw new IllegalArgumentException( + "The number of parameter names passed to the orderedParameterNames argument " + + "does not match the number of parameters in the method."); + } + + Map properties = new HashMap<>(); + List required = new ArrayList<>(); + for (int i = 0; i < parameters.length; i++) { + String parameterName; + if (orderedParameterNames.length == 0) { + + if (!parameters[i].isNamePresent()) { + throw new IllegalStateException( + "Failed to retrieve the parameter name from reflection. Please compile your" + + " code with the \"-parameters\" flag or provide parameter names manually."); + } + parameterName = parameters[i].getName(); + } else { + parameterName = orderedParameterNames[i]; + } + properties.put(parameterName, buildTypeSchema(parameterName, parameters[i].getType())); + required.add(parameterName); + } + parametersBuilder.properties(properties).required(required); + + return FunctionDeclaration.builder() + .name(method.getName()) + .description(functionDescription) + .parameters(parametersBuilder.build()) + .build(); + } + + /** + * Builds a Schema object for a given parameter name and type. + * + * @param parameterName The name of the parameter. + * @param parameterType The type of the parameter as a Class object. + * @return A Schema object representing the parameter's type and metadata. + * @throws IllegalArgumentException If the parameter type is unsupported. + */ + 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"); + break; + case "boolean": + parameterSchemaBuilder.type("BOOLEAN"); + break; + case "int": + parameterSchemaBuilder.type("INTEGER"); + break; + case "double": + case "float": + parameterSchemaBuilder.type("NUMBER"); + break; + default: + throw new IllegalArgumentException( + "Unsupported parameter type " + + parameterType.getName() + + " for parameter " + + parameterName + + ". Currently, supported types are String, boolean, int, double, float."); + } + return parameterSchemaBuilder.build(); + } } diff --git a/src/main/java/com/google/genai/types/GenerateContentResponse.java b/src/main/java/com/google/genai/types/GenerateContentResponse.java index 330c42f6205..1bca0cdc61f 100644 --- a/src/main/java/com/google/genai/types/GenerateContentResponse.java +++ b/src/main/java/com/google/genai/types/GenerateContentResponse.java @@ -248,7 +248,7 @@ public static GenerateContentResponse fromJson(String jsonString) { } /** Gets the finish reason in a GenerateContentResponse. */ - private String finishReason() { + public String finishReason() { List candidates = candidates().orElse(Arrays.asList(Candidate.builder().build())); if (candidates.size() > 1) { logger.warning( diff --git a/src/main/java/com/google/genai/types/LiveClientRealtimeInput.java b/src/main/java/com/google/genai/types/LiveClientRealtimeInput.java index edf8ddca168..434bf5b71f1 100644 --- a/src/main/java/com/google/genai/types/LiveClientRealtimeInput.java +++ b/src/main/java/com/google/genai/types/LiveClientRealtimeInput.java @@ -46,6 +46,14 @@ public abstract class LiveClientRealtimeInput extends JsonSerializable { @JsonProperty("mediaChunks") public abstract Optional> mediaChunks(); + /** Marks the start of user activity. */ + @JsonProperty("activityStart") + public abstract Optional activityStart(); + + /** Marks the end of user activity. */ + @JsonProperty("activityEnd") + public abstract Optional activityEnd(); + /** Instantiates a builder for LiveClientRealtimeInput. */ public static Builder builder() { return new AutoValue_LiveClientRealtimeInput.Builder(); @@ -66,6 +74,12 @@ private static Builder create() { @JsonProperty("mediaChunks") public abstract Builder mediaChunks(List mediaChunks); + @JsonProperty("activityStart") + public abstract Builder activityStart(ActivityStart activityStart); + + @JsonProperty("activityEnd") + public abstract Builder activityEnd(ActivityEnd activityEnd); + public abstract LiveClientRealtimeInput build(); } diff --git a/src/main/java/com/google/genai/types/LiveClientSetup.java b/src/main/java/com/google/genai/types/LiveClientSetup.java index 1f3cf481e25..48a7e1076f7 100644 --- a/src/main/java/com/google/genai/types/LiveClientSetup.java +++ b/src/main/java/com/google/genai/types/LiveClientSetup.java @@ -54,6 +54,18 @@ public abstract class LiveClientSetup extends JsonSerializable { @JsonProperty("tools") public abstract Optional> tools(); + /** Configures the realtime input behavior in BidiGenerateContent. */ + @JsonProperty("realtimeInputConfig") + public abstract Optional realtimeInputConfig(); + + /** + * Configures context window compression mechanism. + * + *

If included, server will compress context window to fit into given length. + */ + @JsonProperty("contextWindowCompression") + public abstract Optional contextWindowCompression(); + /** The transcription of the input aligns with the input audio language. */ @JsonProperty("inputAudioTranscription") public abstract Optional inputAudioTranscription(); @@ -93,6 +105,13 @@ private static Builder create() { @JsonProperty("tools") public abstract Builder tools(List tools); + @JsonProperty("realtimeInputConfig") + public abstract Builder realtimeInputConfig(RealtimeInputConfig realtimeInputConfig); + + @JsonProperty("contextWindowCompression") + public abstract Builder contextWindowCompression( + ContextWindowCompressionConfig contextWindowCompression); + @JsonProperty("inputAudioTranscription") public abstract Builder inputAudioTranscription( AudioTranscriptionConfig inputAudioTranscription); diff --git a/src/main/java/com/google/genai/types/LiveConnectConfig.java b/src/main/java/com/google/genai/types/LiveConnectConfig.java index 1f09b201a0b..f7eeed7a7d7 100644 --- a/src/main/java/com/google/genai/types/LiveConnectConfig.java +++ b/src/main/java/com/google/genai/types/LiveConnectConfig.java @@ -107,6 +107,18 @@ public abstract class LiveConnectConfig extends JsonSerializable { @JsonProperty("outputAudioTranscription") public abstract Optional outputAudioTranscription(); + /** Configures the realtime input behavior in BidiGenerateContent. */ + @JsonProperty("realtimeInputConfig") + public abstract Optional realtimeInputConfig(); + + /** + * Configures context window compression mechanism. + * + *

If included, server will compress context window to fit into given length. + */ + @JsonProperty("contextWindowCompression") + public abstract Optional contextWindowCompression(); + /** Instantiates a builder for LiveConnectConfig. */ public static Builder builder() { return new AutoValue_LiveConnectConfig.Builder(); @@ -162,6 +174,13 @@ public abstract Builder inputAudioTranscription( public abstract Builder outputAudioTranscription( AudioTranscriptionConfig outputAudioTranscription); + @JsonProperty("realtimeInputConfig") + public abstract Builder realtimeInputConfig(RealtimeInputConfig realtimeInputConfig); + + @JsonProperty("contextWindowCompression") + public abstract Builder contextWindowCompression( + ContextWindowCompressionConfig contextWindowCompression); + public abstract LiveConnectConfig build(); } diff --git a/src/main/java/com/google/genai/types/LiveConnectParameters.java b/src/main/java/com/google/genai/types/LiveConnectParameters.java new file mode 100644 index 00000000000..8443215e2df --- /dev/null +++ b/src/main/java/com/google/genai/types/LiveConnectParameters.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; + +/** Parameters for connecting to the live API. */ +@AutoValue +@JsonDeserialize(builder = LiveConnectParameters.Builder.class) +public abstract class LiveConnectParameters extends JsonSerializable { + /** + * ID of the model to use. For a list of models, see `Google models + * `_. + */ + @JsonProperty("model") + public abstract Optional model(); + + /** Optional configuration parameters for the request. */ + @JsonProperty("config") + public abstract Optional config(); + + /** Instantiates a builder for LiveConnectParameters. */ + public static Builder builder() { + return new AutoValue_LiveConnectParameters.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for LiveConnectParameters. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `LiveConnectParameters.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_LiveConnectParameters.Builder(); + } + + @JsonProperty("model") + public abstract Builder model(String model); + + @JsonProperty("config") + public abstract Builder config(LiveConnectConfig config); + + public abstract LiveConnectParameters build(); + } + + /** Deserializes a JSON string to a LiveConnectParameters object. */ + public static LiveConnectParameters fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, LiveConnectParameters.class); + } +} diff --git a/src/main/java/com/google/genai/types/LiveSendRealtimeInputParameters.java b/src/main/java/com/google/genai/types/LiveSendRealtimeInputParameters.java index 07862504a16..e8fcd34f522 100644 --- a/src/main/java/com/google/genai/types/LiveSendRealtimeInputParameters.java +++ b/src/main/java/com/google/genai/types/LiveSendRealtimeInputParameters.java @@ -33,6 +33,14 @@ public abstract class LiveSendRealtimeInputParameters extends JsonSerializable { @JsonProperty("media") public abstract Optional media(); + /** Marks the start of user activity. */ + @JsonProperty("activityStart") + public abstract Optional activityStart(); + + /** Marks the end of user activity. */ + @JsonProperty("activityEnd") + public abstract Optional activityEnd(); + /** Instantiates a builder for LiveSendRealtimeInputParameters. */ public static Builder builder() { return new AutoValue_LiveSendRealtimeInputParameters.Builder(); @@ -55,6 +63,12 @@ private static Builder create() { @JsonProperty("media") public abstract Builder media(Blob media); + @JsonProperty("activityStart") + public abstract Builder activityStart(ActivityStart activityStart); + + @JsonProperty("activityEnd") + public abstract Builder activityEnd(ActivityEnd activityEnd); + public abstract LiveSendRealtimeInputParameters build(); } diff --git a/src/main/java/com/google/genai/types/LiveServerContent.java b/src/main/java/com/google/genai/types/LiveServerContent.java index 6c0eab033d4..fa4bd881aff 100644 --- a/src/main/java/com/google/genai/types/LiveServerContent.java +++ b/src/main/java/com/google/genai/types/LiveServerContent.java @@ -54,6 +54,10 @@ public abstract class LiveServerContent extends JsonSerializable { @JsonProperty("interrupted") public abstract Optional interrupted(); + /** Metadata returned to client when grounding is enabled. */ + @JsonProperty("groundingMetadata") + public abstract Optional groundingMetadata(); + /** * If true, indicates that the model is done generating. When model is interrupted while * generating there will be no generation_complete message in interrupted turn, it will go through @@ -105,6 +109,9 @@ private static Builder create() { @JsonProperty("interrupted") public abstract Builder interrupted(boolean interrupted); + @JsonProperty("groundingMetadata") + public abstract Builder groundingMetadata(GroundingMetadata groundingMetadata); + @JsonProperty("generationComplete") public abstract Builder generationComplete(boolean generationComplete); diff --git a/src/main/java/com/google/genai/types/Schema.java b/src/main/java/com/google/genai/types/Schema.java index 12b193f2c53..b067fbcdfe8 100644 --- a/src/main/java/com/google/genai/types/Schema.java +++ b/src/main/java/com/google/genai/types/Schema.java @@ -28,41 +28,13 @@ import java.util.Optional; /** - * Schema that defines the format of input and output data. - * - *

Represents a select subset of an OpenAPI 3.0 schema object. + * Schema is used to define the format of input/output data. Represents a select subset of an + * [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema-object). More fields may + * be added in the future as needed. */ @AutoValue @JsonDeserialize(builder = Schema.Builder.class) public abstract class Schema extends JsonSerializable { - /** Optional. Example of the object. Will only populated when the object is the root. */ - @JsonProperty("example") - public abstract Optional example(); - - /** Optional. Pattern of the Type.STRING to restrict a string to a regular expression. */ - @JsonProperty("pattern") - public abstract Optional pattern(); - - /** Optional. Default value of the data. */ - @JsonProperty("default") - public abstract Optional default_(); - - /** Optional. Maximum length of the Type.STRING */ - @JsonProperty("maxLength") - public abstract Optional maxLength(); - - /** Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING */ - @JsonProperty("minLength") - public abstract Optional minLength(); - - /** Optional. Minimum number of the properties for Type.OBJECT. */ - @JsonProperty("minProperties") - public abstract Optional minProperties(); - - /** Optional. Maximum number of the properties for Type.OBJECT. */ - @JsonProperty("maxProperties") - public abstract Optional maxProperties(); - /** * Optional. The value should be validated against any (one or more) of the subschemas in the * list. @@ -70,6 +42,10 @@ public abstract class Schema extends JsonSerializable { @JsonProperty("anyOf") public abstract Optional> anyOf(); + /** Optional. Default value of the data. */ + @JsonProperty("default") + public abstract Optional default_(); + /** Optional. The description of the data. */ @JsonProperty("description") public abstract Optional description(); @@ -82,6 +58,10 @@ public abstract class Schema extends JsonSerializable { @JsonProperty("enum") public abstract Optional> enum_(); + /** Optional. Example of the object. Will only populated when the object is the root. */ + @JsonProperty("example") + public abstract Optional example(); + /** * Optional. The format of the data. Supported formats: for NUMBER type: "float", "double" for * INTEGER type: "int32", "int64" for STRING type: "email", "byte", etc @@ -97,6 +77,14 @@ public abstract class Schema extends JsonSerializable { @JsonProperty("maxItems") public abstract Optional maxItems(); + /** Optional. Maximum length of the Type.STRING */ + @JsonProperty("maxLength") + public abstract Optional maxLength(); + + /** Optional. Maximum number of the properties for Type.OBJECT. */ + @JsonProperty("maxProperties") + public abstract Optional maxProperties(); + /** Optional. Maximum value of the Type.INTEGER and Type.NUMBER */ @JsonProperty("maximum") public abstract Optional maximum(); @@ -105,6 +93,14 @@ public abstract class Schema extends JsonSerializable { @JsonProperty("minItems") public abstract Optional minItems(); + /** Optional. SCHEMA FIELDS FOR TYPE STRING Minimum length of the Type.STRING */ + @JsonProperty("minLength") + public abstract Optional minLength(); + + /** Optional. Minimum number of the properties for Type.OBJECT. */ + @JsonProperty("minProperties") + public abstract Optional minProperties(); + /** * Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER Minimum value of the Type.INTEGER and * Type.NUMBER @@ -116,6 +112,10 @@ public abstract class Schema extends JsonSerializable { @JsonProperty("nullable") public abstract Optional nullable(); + /** Optional. Pattern of the Type.STRING to restrict a string to a regular expression. */ + @JsonProperty("pattern") + public abstract Optional pattern(); + /** Optional. SCHEMA FIELDS FOR TYPE OBJECT Properties of Type.OBJECT. */ @JsonProperty("properties") public abstract Optional> properties(); @@ -156,36 +156,21 @@ private static Builder create() { return new AutoValue_Schema.Builder(); } - @JsonProperty("example") - public abstract Builder example(Object example); - - @JsonProperty("pattern") - public abstract Builder pattern(String pattern); + @JsonProperty("anyOf") + public abstract Builder anyOf(List anyOf); @JsonProperty("default") public abstract Builder default_(Object default_); - @JsonProperty("maxLength") - public abstract Builder maxLength(Long maxLength); - - @JsonProperty("minLength") - public abstract Builder minLength(Long minLength); - - @JsonProperty("minProperties") - public abstract Builder minProperties(Long minProperties); - - @JsonProperty("maxProperties") - public abstract Builder maxProperties(Long maxProperties); - - @JsonProperty("anyOf") - public abstract Builder anyOf(List anyOf); - @JsonProperty("description") public abstract Builder description(String description); @JsonProperty("enum") public abstract Builder enum_(List enum_); + @JsonProperty("example") + public abstract Builder example(Object example); + @JsonProperty("format") public abstract Builder format(String format); @@ -195,18 +180,33 @@ private static Builder create() { @JsonProperty("maxItems") public abstract Builder maxItems(Long maxItems); + @JsonProperty("maxLength") + public abstract Builder maxLength(Long maxLength); + + @JsonProperty("maxProperties") + public abstract Builder maxProperties(Long maxProperties); + @JsonProperty("maximum") public abstract Builder maximum(Double maximum); @JsonProperty("minItems") public abstract Builder minItems(Long minItems); + @JsonProperty("minLength") + public abstract Builder minLength(Long minLength); + + @JsonProperty("minProperties") + public abstract Builder minProperties(Long minProperties); + @JsonProperty("minimum") public abstract Builder minimum(Double minimum); @JsonProperty("nullable") public abstract Builder nullable(boolean nullable); + @JsonProperty("pattern") + public abstract Builder pattern(String pattern); + @JsonProperty("properties") public abstract Builder properties(Map properties); diff --git a/src/main/java/com/google/genai/types/Tool.java b/src/main/java/com/google/genai/types/Tool.java index f34d6e43875..b135e4663b5 100644 --- a/src/main/java/com/google/genai/types/Tool.java +++ b/src/main/java/com/google/genai/types/Tool.java @@ -30,10 +30,6 @@ @AutoValue @JsonDeserialize(builder = Tool.Builder.class) public abstract class Tool extends JsonSerializable { - /** List of function declarations that the tool supports. */ - @JsonProperty("functionDeclarations") - public abstract Optional> functionDeclarations(); - /** * Optional. Retrieval tool type. System will always execute the provided retrieval tool(s) to get * external knowledge to answer the prompt. Retrieval results are presented to the model for @@ -62,6 +58,16 @@ public abstract class Tool extends JsonSerializable { @JsonProperty("codeExecution") public abstract Optional codeExecution(); + /** + * Optional. Function tool type. One or more function declarations to be passed to the model along + * with the current user query. Model may decide to call a subset of these functions by populating + * FunctionCall in the response. User should provide a FunctionResponse for each function call in + * the next turn. Based on the function responses, Model will generate the final response back to + * the user. Maximum 128 function declarations can be provided. + */ + @JsonProperty("functionDeclarations") + public abstract Optional> functionDeclarations(); + /** Instantiates a builder for Tool. */ public static Builder builder() { return new AutoValue_Tool.Builder(); @@ -79,9 +85,6 @@ private static Builder create() { return new AutoValue_Tool.Builder(); } - @JsonProperty("functionDeclarations") - public abstract Builder functionDeclarations(List functionDeclarations); - @JsonProperty("retrieval") public abstract Builder retrieval(Retrieval retrieval); @@ -94,6 +97,9 @@ private static Builder create() { @JsonProperty("codeExecution") public abstract Builder codeExecution(ToolCodeExecution codeExecution); + @JsonProperty("functionDeclarations") + public abstract Builder functionDeclarations(List functionDeclarations); + public abstract Tool build(); } diff --git a/src/test/java/com/google/genai/ChatTest.java b/src/test/java/com/google/genai/ChatTest.java index 984a2be7b52..a22313150d8 100644 --- a/src/test/java/com/google/genai/ChatTest.java +++ b/src/test/java/com/google/genai/ChatTest.java @@ -21,12 +21,19 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; +import com.google.genai.types.Candidate; import com.google.genai.types.Content; import com.google.genai.types.GenerateContentConfig; import com.google.genai.types.GenerateContentResponse; +import com.google.genai.types.GenerateContentResponseUsageMetadata; import com.google.genai.types.Part; +import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.entity.StringEntity; @@ -39,7 +46,96 @@ public class ChatTest { ApiClient mockedClient; ApiResponse mockedResponse; HttpEntity mockedEntity; + ApiResponse mockedResponse1; + ApiResponse mockedResponse2; + ApiResponse mockedResponse3; + HttpEntity mockedEntity1; + HttpEntity mockedEntity2; + HttpEntity mockedEntity3; Client client; + Chats chatSession; + + private static final String STREAMING_RESPONSE_CHUNK_1 = "Once upon "; + private static final String STREAMING_RESPONSE_CHUNK_2 = "a time, in a land"; + private static final String STREAMING_RESPONSE_CHUNK_3 = " far, far away..."; + private static final String NON_STREAMING_RESPONSE = "This is a non-streaming response."; + private Iterator mockStreamIterator; + + GenerateContentResponse responseChunk1 = + GenerateContentResponse.builder() + .candidates( + Arrays.asList( + Candidate.builder() + .content( + Content.builder() + .parts( + Arrays.asList( + Part.builder().text(STREAMING_RESPONSE_CHUNK_1).build())) + .role("model") + .build()) + .build())) + .build(); + + GenerateContentResponse responseChunk2 = + GenerateContentResponse.builder() + .candidates( + Arrays.asList( + Candidate.builder() + .content( + Content.builder() + .parts( + Arrays.asList( + Part.builder().text(STREAMING_RESPONSE_CHUNK_2).build())) + .role("model") + .build()) + .build())) + .build(); + + GenerateContentResponse responseChunk3 = + GenerateContentResponse.builder() + .candidates( + Arrays.asList( + Candidate.builder() + .content( + Content.builder() + .parts( + Arrays.asList( + Part.builder().text(STREAMING_RESPONSE_CHUNK_3).build())) + .role("model") + .build()) + .finishReason("STOP") + .build())) + .usageMetadata( + GenerateContentResponseUsageMetadata.builder() + .promptTokenCount(10) + .candidatesTokenCount(25) + .totalTokenCount(35) + .build()) + .build(); + + String jsonChunk1 = responseChunk1.toJson(); + String jsonChunk2 = responseChunk2.toJson(); + String jsonChunk3 = responseChunk3.toJson(); + + String streamData = + "data: " + jsonChunk1 + "\n" + "data: " + jsonChunk2 + "\n" + "data: " + jsonChunk3 + "\n"; + String streamData2 = "data: " + jsonChunk1 + "\n" + "data: " + jsonChunk2 + "\n"; + + GenerateContentResponse nonStreamingResponse = + GenerateContentResponse.builder() + .candidates( + Arrays.asList( + Candidate.builder() + .content( + Content.builder() + .parts( + Arrays.asList( + Part.builder().text(NON_STREAMING_RESPONSE).build())) + .role("model") + .build()) + .build())) + .build(); + String nonStreamData = nonStreamingResponse.toJson(); @BeforeEach void setUp() { @@ -49,6 +145,17 @@ void setUp() { mockedEntity = Mockito.mock(HttpEntity.class); client = Client.builder().build(); + + mockedResponse1 = Mockito.mock(ApiResponse.class); + mockedResponse2 = Mockito.mock(ApiResponse.class); + mockedResponse3 = Mockito.mock(ApiResponse.class); + mockedEntity1 = Mockito.mock(HttpEntity.class); + mockedEntity2 = Mockito.mock(HttpEntity.class); + mockedEntity3 = Mockito.mock(HttpEntity.class); + + client = Client.builder().build(); + + mockStreamIterator = Mockito.mock(ResponseStream.ResponseStreamIterator.class); } @Test @@ -56,7 +163,7 @@ public void testCreateChatSession() throws Exception { // 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 = ChatSession.class.getDeclaredField("apiClient"); + Field apiClientField = Chats.class.getDeclaredField("apiClient"); apiClientField.setAccessible(true); apiClientField.set(client.chats, mockedClient); @@ -75,7 +182,7 @@ public void testGetHistory() throws Exception { when(mockedResponse.getEntity()).thenReturn(content); // 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 = ChatSession.class.getDeclaredField("apiClient"); + Field apiClientField = Chats.class.getDeclaredField("apiClient"); apiClientField.setAccessible(true); apiClientField.set(client.chats, mockedClient); @@ -99,7 +206,7 @@ public void testMultiTurnChat() throws Exception { // 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 = ChatSession.class.getDeclaredField("apiClient"); + Field apiClientField = Chats.class.getDeclaredField("apiClient"); apiClientField.setAccessible(true); apiClientField.set(client.chats, mockedClient); @@ -126,7 +233,7 @@ public void testChatWithConfig() throws Exception { // 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 = ChatSession.class.getDeclaredField("apiClient"); + Field apiClientField = Chats.class.getDeclaredField("apiClient"); apiClientField.setAccessible(true); apiClientField.set(client.chats, mockedClient); @@ -150,7 +257,7 @@ public void testInitConfigIsUsedWhenSendMessageConfigIsNull() throws Exception { // 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 = ChatSession.class.getDeclaredField("apiClient"); + Field apiClientField = Chats.class.getDeclaredField("apiClient"); apiClientField.setAccessible(true); apiClientField.set(client.chats, mockedClient); GenerateContentConfig config = GenerateContentConfig.builder().candidateCount(2).build(); @@ -171,7 +278,7 @@ public void testSendMessageContent() throws Exception { when(mockedResponse.getEntity()).thenReturn(content); // 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 = ChatSession.class.getDeclaredField("apiClient"); + Field apiClientField = Chats.class.getDeclaredField("apiClient"); apiClientField.setAccessible(true); apiClientField.set(client.chats, mockedClient); @@ -199,7 +306,7 @@ public void testSendMessageContentList() throws Exception { when(mockedResponse.getEntity()).thenReturn(content); // 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 = ChatSession.class.getDeclaredField("apiClient"); + Field apiClientField = Chats.class.getDeclaredField("apiClient"); apiClientField.setAccessible(true); apiClientField.set(client.chats, mockedClient); @@ -220,7 +327,7 @@ public void testSendMessageContentList() throws Exception { } @Test - public void testInvalidFinishReasonThrows() throws Exception { + public void testUnexpectedFinishReasonDoesNotAddToCuratedHistory() throws Exception { StringEntity content = new StringEntity( "{\"candidates\":[{\"content\":{\"parts\":[{\"text\":\"It's better with" @@ -229,18 +336,20 @@ public void testInvalidFinishReasonThrows() throws Exception { // 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 = ChatSession.class.getDeclaredField("apiClient"); + Field apiClientField = Chats.class.getDeclaredField("apiClient"); apiClientField.setAccessible(true); apiClientField.set(client.chats, mockedClient); Chat chatSession = client.chats.create("gemini-2.0-flash-exp"); List emptyParts = new ArrayList<>(); - emptyParts.add(Part.builder().build()); + emptyParts.add(Part.builder().build().fromText("Tell me something about cheese.")); Content messageContent = Content.builder().parts(emptyParts).role("user").build(); + chatSession.sendMessage(messageContent); - IllegalArgumentException exception = - assertThrows(IllegalArgumentException.class, () -> chatSession.sendMessage(messageContent)); + // Curated history should be empty because the response has a finish reason of BLOCKLIST. + assert chatSession.getHistory(true).size() == 0; + assert chatSession.getHistory(false).size() == 2; } @Test @@ -255,7 +364,7 @@ public void testInvalidRoleThrows() throws Exception { // 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 = ChatSession.class.getDeclaredField("apiClient"); + Field apiClientField = Chats.class.getDeclaredField("apiClient"); apiClientField.setAccessible(true); apiClientField.set(client.chats, mockedClient); Chat chatSession = client.chats.create("gemini-2.0-flash-exp"); @@ -282,7 +391,7 @@ public void testInvalidHistoryThrows() throws Exception { // 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 = ChatSession.class.getDeclaredField("apiClient"); + Field apiClientField = Chats.class.getDeclaredField("apiClient"); apiClientField.setAccessible(true); apiClientField.set(client.chats, mockedClient); Chat chatSession = client.chats.create("gemini-2.0-flash-exp"); @@ -299,4 +408,132 @@ public void testInvalidHistoryThrows() throws Exception { .getMessage() .equals("The first message in the history must be from the user.")); } + + @Test + public void testIterateOverResponseStream() throws Exception { + + Field apiClientField = Chats.class.getDeclaredField("apiClient"); + apiClientField.setAccessible(true); + apiClientField.set(client.chats, mockedClient); + + Chat chatSession = client.chats.create("gemini-2.0-flash-exp", null); + + InputStream inputStream1 = + new ByteArrayInputStream(streamData.getBytes(StandardCharsets.UTF_8)); + InputStream inputStream2 = + new ByteArrayInputStream(streamData2.getBytes(StandardCharsets.UTF_8)); + + InputStream inputStream3 = + new ByteArrayInputStream(nonStreamData.getBytes(StandardCharsets.UTF_8)); + + when(mockedResponse1.getEntity()).thenReturn(mockedEntity1); + when(mockedResponse2.getEntity()).thenReturn(mockedEntity2); + when(mockedResponse3.getEntity()).thenReturn(mockedEntity3); + when(mockedEntity1.getContent()).thenReturn(inputStream1); + when(mockedEntity2.getContent()).thenReturn(inputStream2); + when(mockedEntity3.getContent()).thenReturn(inputStream3); + when(mockedClient.request(anyString(), anyString(), anyString())) + .thenReturn(mockedResponse1, mockedResponse2, mockedResponse3); + + assert chatSession.getHistory(false).size() == 0; + + ResponseStream responseStream = + chatSession.sendMessageStream("Tell me a story.", null); + + assertNotNull(responseStream); + + int chunkCount = 0; + // Iterate over the stream + while (responseStream.iterator().hasNext()) { + GenerateContentResponse responseChunk = responseStream.iterator().next(); + assertNotNull(responseChunk.text()); + if (chunkCount == 0) { + assert (responseChunk.text().equals(STREAMING_RESPONSE_CHUNK_1)); + } + chunkCount++; + } + + assert chunkCount == 3; + + // History is updated after the stream is consumed + assert chatSession.getHistory(false).size() == 2; + ResponseStream responseStream2 = + chatSession.sendMessageStream("Tell me another story.", null); + + // Iterate over the second stream so we can add it to history + while (responseStream2.iterator().hasNext()) { + GenerateContentResponse responseChunk = responseStream2.iterator().next(); + assertNotNull(responseChunk); + assertNotNull(responseChunk.text()); + } + + List historyAfterSecondStreamCall = chatSession.getHistory(false); + assert historyAfterSecondStreamCall.size() == 4; + + // Second item in history should be the aggregated model response from the stream chunks + assert historyAfterSecondStreamCall + .get(1) + .parts() + .get() + .get(0) + .text() + .orElse(null) + .equals( + STREAMING_RESPONSE_CHUNK_1 + STREAMING_RESPONSE_CHUNK_2 + STREAMING_RESPONSE_CHUNK_3); + + // Test that subsequent non-streaming sendMessage calls also include updated history + chatSession.sendMessage("Tell me a third story.", null); + List historyAfterThirdMessageCall = chatSession.getHistory(false); + + // Since this was a non-streaming call, the history should include the second aggregated stream + // response as well as the new non-streaming response. + assert historyAfterThirdMessageCall.size() == 6; + assert historyAfterThirdMessageCall + .get(5) + .parts() + .get() + .get(0) + .text() + .orElse(null) + .equals(NON_STREAMING_RESPONSE); + } + + @Test + public void testThrowsIfStreamResponseIsNotConsumed() throws Exception { + /* Tests that an exception is thrown if the response stream is not consumed before calling + * getHistory() or sendMessage* again. */ + + Field apiClientField = Chats.class.getDeclaredField("apiClient"); + apiClientField.setAccessible(true); + apiClientField.set(client.chats, mockedClient); + + Chat chatSession = client.chats.create("gemini-2.0-flash-exp", null); + + InputStream inputStream1 = + new ByteArrayInputStream(streamData.getBytes(StandardCharsets.UTF_8)); + InputStream inputStream2 = + new ByteArrayInputStream(streamData2.getBytes(StandardCharsets.UTF_8)); + + when(mockedResponse1.getEntity()).thenReturn(mockedEntity1); + when(mockedResponse2.getEntity()).thenReturn(mockedEntity2); + when(mockedEntity1.getContent()).thenReturn(inputStream1); + when(mockedEntity2.getContent()).thenReturn(inputStream2); + when(mockedClient.request(anyString(), anyString(), anyString())) + .thenReturn(mockedResponse1, mockedResponse2); + + assert chatSession.getHistory(false).size() == 0; + + ResponseStream responseStream = + chatSession.sendMessageStream("Tell me a story.", null); + + IllegalStateException exception = + assertThrows(IllegalStateException.class, () -> chatSession.getHistory(false)); + + assert (exception.getMessage().equals("Response stream is not consumed")); + + IllegalStateException exception2 = + assertThrows( + IllegalStateException.class, + () -> chatSession.sendMessageStream("Tell me another story.")); + } } diff --git a/src/test/java/com/google/genai/HttpApiClientTest.java b/src/test/java/com/google/genai/HttpApiClientTest.java index acaa127523b..c36d69ff26c 100644 --- a/src/test/java/com/google/genai/HttpApiClientTest.java +++ b/src/test/java/com/google/genai/HttpApiClientTest.java @@ -428,4 +428,70 @@ public void testProxySetup() throws Exception { wireMockServer.stop(); } } + + @Test + public void testClientInitializationWithBaseUrlFromHttpOptions() throws Exception { + HttpOptions httpOptions = + HttpOptions.builder().baseUrl("https://custom-base-url.googleapis.com/").build(); + Client client = Client.builder().httpOptions(httpOptions).build(); + + assertTrue(client.baseUrl().isPresent()); + assertEquals(client.baseUrl().get(), "https://custom-base-url.googleapis.com/"); + } + + @Test + public void testClientInitializationWithBaseUrlFromHttpOptionsOverridesSetDefaultBaseUrls() + throws Exception { + HttpOptions httpOptions = + HttpOptions.builder().baseUrl("https://custom-base-url.googleapis.com/").build(); + Client.setDefaultBaseUrls( + Optional.of("https://gemini-base-url.googleapis.com/"), Optional.empty()); + Client client = Client.builder().httpOptions(httpOptions).build(); + + assertTrue(client.baseUrl().isPresent()); + assertEquals(client.baseUrl().get(), "https://custom-base-url.googleapis.com/"); + } + + @Test + public void testClientInitializationWithBaseUrlFromSetBaseUrls() throws Exception { + Client.setDefaultBaseUrls( + Optional.of("https://custom-base-url.googleapis.com/"), Optional.empty()); + Client client = Client.builder().build(); + + assertTrue(client.baseUrl().isPresent()); + assertEquals(client.baseUrl().get(), "https://custom-base-url.googleapis.com/"); + + Client.setDefaultBaseUrls(Optional.empty(), Optional.empty()); + } + + @Test + public void testClientInitializationWithBaseUrlFromSetBaseUrlsOverridesEnvironment() + throws Exception { + Client.setDefaultBaseUrls( + Optional.of("https://custom-base-url.googleapis.com/"), Optional.empty()); + Client client = + Client.builder() + .environmentVariables( + ImmutableMap.of( + "GOOGLE_GEMINI_BASE_URL", "https://gemini-base-url.googleapis.com/")) + .build(); + + assertTrue(client.baseUrl().isPresent()); + assertEquals(client.baseUrl().get(), "https://custom-base-url.googleapis.com/"); + + Client.setDefaultBaseUrls(Optional.empty(), Optional.empty()); + } + + @Test + public void testClientInitializationWithBaseUrlFromEnvironment() throws Exception { + Client client = + Client.builder() + .environmentVariables( + ImmutableMap.of( + "GOOGLE_GEMINI_BASE_URL", "https://custom-base-url.googleapis.com/")) + .build(); + + assertTrue(client.baseUrl().isPresent()); + assertEquals(client.baseUrl().get(), "https://custom-base-url.googleapis.com/"); + } } diff --git a/src/test/java/com/google/genai/types/FunctionDeclarationTest.java b/src/test/java/com/google/genai/types/FunctionDeclarationTest.java new file mode 100644 index 00000000000..5c741b21846 --- /dev/null +++ b/src/test/java/com/google/genai/types/FunctionDeclarationTest.java @@ -0,0 +1,176 @@ +/* + * 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. + */ + +package com.google.genai.types; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import com.google.common.collect.ImmutableList; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Test; + +public class FunctionDeclarationTest { + private static final String FUNCTION_NAME = "functionName"; + private static final String FUNCTION_DESCRIPTION = "functionDescription"; + private static final String STRING_PARAM_NAME = "stringParam"; + private static final String INTEGER_PARAM_NAME = "integerParam"; + private static final String DOUBLE_PARAM_NAME = "doubleParam"; + private static final String FLOAT_PARAM_NAME = "floatParam"; + private static final String BOOLEAN_PARAM_NAME = "booleanParam"; + private static final ImmutableList REQUIRED_PARAM_NAMES = + ImmutableList.of( + STRING_PARAM_NAME, + INTEGER_PARAM_NAME, + DOUBLE_PARAM_NAME, + FLOAT_PARAM_NAME, + BOOLEAN_PARAM_NAME); + + private static final FunctionDeclaration EXPECTED_FUNCTION_DECLARATION = + FunctionDeclaration.builder() + .name(FUNCTION_NAME) + .description(FUNCTION_DESCRIPTION) + .parameters( + Schema.builder() + .type("OBJECT") + .properties(buildPropertiesMap()) + .required(REQUIRED_PARAM_NAMES) + .build()) + .build(); + + /** Helper method to build the properties map. */ + private static Map buildPropertiesMap() { + Map properties = new HashMap<>(); + properties.put( + STRING_PARAM_NAME, Schema.builder().type("STRING").title(STRING_PARAM_NAME).build()); + properties.put( + INTEGER_PARAM_NAME, Schema.builder().type("INTEGER").title(INTEGER_PARAM_NAME).build()); + properties.put( + DOUBLE_PARAM_NAME, Schema.builder().type("NUMBER").title(DOUBLE_PARAM_NAME).build()); + properties.put( + FLOAT_PARAM_NAME, Schema.builder().type("NUMBER").title(FLOAT_PARAM_NAME).build()); + properties.put( + BOOLEAN_PARAM_NAME, Schema.builder().type("BOOLEAN").title(BOOLEAN_PARAM_NAME).build()); + return properties; + } + + /** A function (static method) to test fromMethod functionalities. */ + public static int functionName( + String stringParam, + int integerParam, + double doubleParam, + float floatParam, + boolean booleanParam) { + return 0; + } + + /** An instance method to test fromMethod. */ + public int instanceMethod(String stringParam) { + return 1; + } + + /** A function with invalid parameter type to test fromMethod. */ + public static int functionWithInvalidType(Object objectParam) { + return 2; + } + + @Test + public void fromMethodWithoutParameterNamesWithoutReflection_throwsIllegalStateException() + throws NoSuchMethodException { + Method method = + FunctionDeclarationTest.class.getMethod( + FUNCTION_NAME, String.class, int.class, double.class, float.class, boolean.class); + + IllegalStateException thrown = + assertThrows( + IllegalStateException.class, + () -> FunctionDeclaration.fromMethod(FUNCTION_DESCRIPTION, method)); + assertEquals( + "Failed to retrieve the parameter name from reflection. Please compile your" + + " code with the \"-parameters\" flag or provide parameter names manually.", + thrown.getMessage()); + } + + @Test + public void fromMethodWithParameterNames_returnsFunctionDeclaration() + throws NoSuchMethodException { + Method method = + FunctionDeclarationTest.class.getMethod( + FUNCTION_NAME, String.class, int.class, double.class, float.class, boolean.class); + + FunctionDeclaration functionDeclaration = + FunctionDeclaration.fromMethod( + FUNCTION_DESCRIPTION, + method, + STRING_PARAM_NAME, + INTEGER_PARAM_NAME, + DOUBLE_PARAM_NAME, + FLOAT_PARAM_NAME, + BOOLEAN_PARAM_NAME); + + assertEquals(EXPECTED_FUNCTION_DECLARATION, functionDeclaration); + } + + @Test + public void fromMethodWithInstanceMethod_throwsIllegalArgumentException() + throws NoSuchMethodException { + Method method = FunctionDeclarationTest.class.getMethod("instanceMethod", String.class); + + IllegalArgumentException thrown = + assertThrows( + IllegalArgumentException.class, + () -> FunctionDeclaration.fromMethod(FUNCTION_DESCRIPTION, method, STRING_PARAM_NAME)); + assertEquals( + "Instance methods are not supported. Please use static methods.", thrown.getMessage()); + } + + @Test + public void fromMethodWithInvalidParameterType_throwsIllegalArgumentException() + throws NoSuchMethodException { + Method method = + FunctionDeclarationTest.class.getMethod("functionWithInvalidType", Object.class); + + IllegalArgumentException thrown = + assertThrows( + IllegalArgumentException.class, + () -> FunctionDeclaration.fromMethod(FUNCTION_DESCRIPTION, method, "objectParam")); + assertEquals( + "Unsupported parameter type " + + Object.class.getName() + + " for parameter objectParam." + + " Currently, supported types are String, boolean, int, double, float.", + thrown.getMessage()); + } + + @Test + public void fromMethodWithUnmatchedParameterNames_throwsIllegalArgumentException() + throws NoSuchMethodException { + Method method = + FunctionDeclarationTest.class.getMethod( + FUNCTION_NAME, String.class, int.class, double.class, float.class, boolean.class); + + IllegalArgumentException thrown = + assertThrows( + IllegalArgumentException.class, + () -> FunctionDeclaration.fromMethod(FUNCTION_DESCRIPTION, method, STRING_PARAM_NAME)); + assertEquals( + "The number of parameter names passed to the orderedParameterNames" + + " argument does not match the number of parameters in the method.", + thrown.getMessage()); + } +}