Class Transformers
-
- All Implemented Interfaces:
@InternalApi() public final class TransformersTransformers for GenAI SDK.
-
-
Method Summary
Modifier and Type Method Description static StringtModel(ApiClient apiClient, Object origin)Transforms 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 JsonNodetExtractModels(Object origin)Extracts the models from the models.list response. static ObjecttContents(Object origin)In other languages, this transformer is used for supporting union types. static ImmutableList<Content>tContents(String text)Transforms a text string to a list of Content for the API. static ImmutableList<Content>tContents(Content content)Transforms a Content to a list of Content for the API. static ContenttContent(Object content)Transforms an object to a Content for the API. static SchematSchema(Object origin)Transforms an object to a Schema for the API. static SpeechConfigtSpeechConfig(Object speechConfig)static SpeechConfigtLiveSpeechConfig(Object origin)Transforms a SpeechConfig object for the live API, validating it. static ObjecttTools(Object origin)In other languages, this transformer is used for supporting union types. static TooltTool(Object origin)Transforms an object to a Tool for the API. static ArrayNodetBlobs(Object origin)Dummy Blobs transformer. static BlobtBlob(Object blob)static BlobtImageBlob(Object blob)Transforms a blob to an image blob, validating its mime type. static BlobtAudioBlob(Object blob)Transforms a blob to an audio blob, validating its mime type. static ObjecttBytes(Object origin)Dummy bytes transformer. static StringtCachedContentName(ApiClient apiClient, Object origin)Transforms an object to a cached content name for the API. static List<Object>tContentsForEmbed(ApiClient apiClient, Object origin)Transforms an object to a list of Content for the embedding API. static StringtCachesModel(ApiClient apiClient, Object origin)Transforms a model name to the correct format for the Caches API. static StringtFileName(Object origin)static JobStatetTuningJobStatus(Object origin)static ObjecttBatchJobSource(Object src)static ObjecttBatchJobDestination(Object dest)static ObjecttRecvBatchJobDestination(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 ObjecttJobState(Object state)Maps specific batch states to job states, otherwise returns the state as is. static voidupdateJsonNode(ObjectNode currentObject, String keyToSet, JsonNode valueNode)Updates a JSON node with a new value, handling potential conflicts. static StringcamelToSnake(String str)Converts a camelCase string to snake_case. static ArrayNodetMetrics(Object metrics)Prepares the metric payload for the evaluation request. static booleantIsVertexEmbedContentModel(String model)Checks if a given model name is a Vertex AI embed content model. -
-
Method Detail
-
tModel
static String tModel(ApiClient apiClient, Object origin)
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
static String tModelsUrl(ApiClient apiClient, @Nullable() Object baseModels)
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
@Nullable() static JsonNode tExtractModels(Object origin)
Extracts the models from the models.list response.
This is used in the converters.
-
tContents
static Object tContents(Object origin)
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
static ImmutableList<Content> tContents(String text)
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
static ImmutableList<Content> tContents(Content content)
Transforms a Content to a list of Content for the API.
Not intended to be used in converters.
- Parameters:
content- a Content to transform- Returns:
the transformed list of Content
-
tContent
static Content tContent(Object content)
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
-
tSpeechConfig
static SpeechConfig tSpeechConfig(Object speechConfig)
-
tLiveSpeechConfig
@Nullable() static SpeechConfig tLiveSpeechConfig(Object origin)
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
-
tTools
static Object tTools(Object origin)
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.
-
tImageBlob
static Blob tImageBlob(Object blob)
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.
-
tAudioBlob
static Blob tAudioBlob(Object blob)
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.
-
tCachedContentName
static String tCachedContentName(ApiClient apiClient, Object origin)
Transforms an object to a cached content name for the API.
-
tContentsForEmbed
@Nullable() static List<Object> tContentsForEmbed(ApiClient apiClient, Object origin)
Transforms an object to a list of Content for the embedding API.
-
tCachesModel
@Nullable() static String tCachesModel(ApiClient apiClient, Object origin)
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
-
tTuningJobStatus
static JobState tTuningJobStatus(Object origin)
-
tBatchJobSource
static Object tBatchJobSource(Object src)
-
tBatchJobDestination
static Object tBatchJobDestination(Object dest)
-
tRecvBatchJobDestination
static Object tRecvBatchJobDestination(Object dest)
-
tBatchJobName
static String tBatchJobName(ApiClient apiClient, Object name)
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).
-
tJobState
static Object tJobState(Object state)
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.
-
updateJsonNode
static void updateJsonNode(ObjectNode currentObject, String keyToSet, 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.
-
camelToSnake
static String camelToSnake(String str)
Converts a camelCase string to snake_case.
- Parameters:
str- The input string to convert.- Returns:
The converted string in snake_case.
-
tMetrics
static ArrayNode tMetrics(Object metrics)
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.
-
tIsVertexEmbedContentModel
static boolean tIsVertexEmbedContentModel(String model)
Checks if a given model name is a Vertex AI embed content model.
- Parameters:
model- The model name to check.- Returns:
True if the model is a Vertex AI embed content model, false otherwise.
-
-
-
-