Package com.google.genai
Class Transformers
java.lang.Object
com.google.genai.Transformers
Transformers for GenAI SDK.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcamelToSnake(String str) Converts a camelCase string to snake_case.static BlobtAudioBlob(Object blob) Transforms a blob to an audio blob, validating its mime type.static ObjecttBatchJobDestination(Object dest) static StringtBatchJobName(ApiClient apiClient, Object name) It validates and extracts the batch job name based on the backend (Vertex AI or MLDev).static ObjecttBatchJobSource(Object src) static Blobstatic com.fasterxml.jackson.databind.node.ArrayNodeDummy Blobs transformer.static ObjectDummy bytes transformer.static StringtCachedContentName(ApiClient apiClient, Object origin) Transforms an object to a cached content name for the API.static @Nullable StringtCachesModel(ApiClient apiClient, Object origin) Transforms a model name to the correct format for the Caches API.static ContentTransforms an object to a Content for the API.static com.google.common.collect.ImmutableList<Content>Transforms a Content to a list of Content for the API.static ObjectIn other languages, this transformer is used for supporting union types.static com.google.common.collect.ImmutableList<Content>Transforms a text string to a list of Content for the API.tContentsForEmbed(ApiClient apiClient, Object origin) Transforms an object to a list of Content for the embedding API.static @Nullable com.fasterxml.jackson.databind.JsonNodetExtractModels(Object origin) Extracts the models from the models.list response.static @Nullable Stringstatic BlobtImageBlob(Object blob) Transforms a blob to an image blob, validating its mime type.static ObjectMaps specific batch states to job states, otherwise returns the state as is.static @Nullable SpeechConfigtLiveSpeechConfig(Object origin) Transforms a SpeechConfig object for the live API, validating it.static com.fasterxml.jackson.databind.node.ArrayNodePrepares the metric payload for the evaluation request.static StringTransforms a model name to the correct format for the API.static StringtModelsUrl(ApiClient apiClient, @Nullable Object baseModels) Determines the appropriate models URL based on the API client type and whether base models are requested.static Objectstatic SchemaTransforms an object to a Schema for the API.static SpeechConfigtSpeechConfig(Object speechConfig) static ToolTransforms an object to a Tool for the API.static ObjectIn other languages, this transformer is used for supporting union types.static JobStatetTuningJobStatus(Object origin) static voidupdateJsonNode(com.fasterxml.jackson.databind.node.ObjectNode currentObject, String keyToSet, com.fasterxml.jackson.databind.JsonNode valueNode) Updates a JSON node with a new value, handling potential conflicts.
-
Method Details
-
tModel
Transforms a model name to the correct format for the API.- Parameters:
apiClient- the API client to use for transformationorigin- the model name to transform, can only be a string- Returns:
- the transformed model name
-
tModelsUrl
Determines the appropriate models URL based on the API client type and whether base models are requested.- Parameters:
apiClient- the API client to use for transformationbaseModels- true or null if base models are requested, false otherwise.- Returns:
- The transformed model name
-
tExtractModels
Extracts the models from the models.list response.This is used in the converters.
-
tContents
In other languages, this transformer is used for supporting union types. Java doesn't have union types, so we define a dummy transformer here.This is used in the converters.
-
tContents
Transforms a text string to a list of Content for the API.Not intended to be used in converters.
- Parameters:
text- the text string to transform- Returns:
- the transformed list of Content
-
tContents
Transforms a Content to a list of Content for the API.Not intended to be used in converters.
- Parameters:
content- aContentto transform- Returns:
- the transformed list of Content
-
tContent
Transforms an object to a Content for the API.- Parameters:
content- the object to transform, can be a string or Content- Returns:
- the transformed Content
- Throws:
IllegalArgumentException- if the object is not a supported type
-
tSchema
Transforms an object to a Schema for the API. -
tSpeechConfig
-
tLiveSpeechConfig
Transforms a SpeechConfig object for the live API, validating it.- Parameters:
origin- the object to transform, can be a SpeechConfig or a JsonNode- Returns:
- the transformed SpeechConfig
- Throws:
IllegalArgumentException- if the object is not a supported type or if multiSpeakerVoiceConfig is present.
-
tTools
In other languages, this transformer is used for supporting union types. Java doesn't have union types, so we define a dummy transformer here. *This is used in the converters.
-
tTool
Transforms an object to a Tool for the API. -
tBlobs
Dummy Blobs transformer. -
tBlob
-
tImageBlob
Transforms a blob to an image blob, validating its mime type.- Parameters:
blob- the object to transform, can be a Blob or a dictionary.- Returns:
- the transformed Blob if it is an image.
- Throws:
IllegalArgumentException- if the blob is not an image.
-
tAudioBlob
Transforms a blob to an audio blob, validating its mime type.- Parameters:
blob- the object to transform, can be a Blob or a dictionary.- Returns:
- the transformed Blob if it is an audio.
- Throws:
IllegalArgumentException- if the blob is not an audio.
-
tBytes
Dummy bytes transformer. -
tCachedContentName
Transforms an object to a cached content name for the API. -
tContentsForEmbed
Transforms an object to a list of Content for the embedding API. -
tCachesModel
Transforms a model name to the correct format for the Caches API.- Parameters:
apiClient- the API client to use for transformationorigin- the model name to transform, can be a string or JsonNode- Returns:
- the transformed model name, or null if the input is null
- Throws:
IllegalArgumentException- if the object is not a supported type
-
tFileName
-
tTuningJobStatus
-
tBatchJobSource
-
tBatchJobDestination
-
tRecvBatchJobDestination
-
tBatchJobName
It validates and extracts the batch job name based on the backend (Vertex AI or MLDev).- Parameters:
apiClient- The ApiClient instance, used to determine the backend.name- The batch job name as an Object, expected to be a String.- Returns:
- The extracted name (e.g., job ID).
- Throws:
IllegalArgumentException- If the input name is not a String or does not match expected patterns.
-
tJobState
Maps specific batch states to job states, otherwise returns the state as is.- Parameters:
state- The input state as an Object, expected to be a String.- Returns:
- The mapped or original state string.
- Throws:
IllegalArgumentException- If the input state is not a String.
-
updateJsonNode
public static void updateJsonNode(com.fasterxml.jackson.databind.node.ObjectNode currentObject, String keyToSet, com.fasterxml.jackson.databind.JsonNode valueNode) Updates a JSON node with a new value, handling potential conflicts.- Parameters:
currentObject- The ObjectNode to update.keyToSet- The key to set in the ObjectNode.valueNode- The new JsonNode value.- Throws:
IllegalArgumentException- if a value cannot be set for an existing key.
-
camelToSnake
Converts a camelCase string to snake_case.- Parameters:
str- The input string to convert.- Returns:
- The converted string in snake_case.
-
tMetrics
Prepares the metric payload for the evaluation request.- Parameters:
metrics- An object containing the metrics to be transformed.- Returns:
- The list of transformed metric payloads.
-