Class Transformers

java.lang.Object
com.google.genai.Transformers

@InternalApi public final class Transformers extends Object
Transformers for GenAI SDK.
  • Method Details

    • tModel

      public 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 transformation
      origin - the model name to transform, can only be a string
      Returns:
      the transformed model name
    • tModelsUrl

      public 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 transformation
      baseModels - true or null if base models are requested, false otherwise.
      Returns:
      The transformed model name
    • tExtractModels

      public static @Nullable com.fasterxml.jackson.databind.JsonNode tExtractModels(Object origin)
      Extracts the models from the models.list response.

      This is used in the converters.

    • tContents

      public 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

      public static com.google.common.collect.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

      public static com.google.common.collect.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

      public 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
      Throws:
      IllegalArgumentException - if the object is not a supported type
    • tSchema

      public static Schema tSchema(Object origin)
      Transforms an object to a Schema for the API.
    • tSpeechConfig

      public static SpeechConfig tSpeechConfig(Object speechConfig)
    • tLiveSpeechConfig

      public static @Nullable 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
      Throws:
      IllegalArgumentException - if the object is not a supported type or if multiSpeakerVoiceConfig is present.
    • tTools

      public 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.

    • tTool

      public static Tool tTool(Object origin)
      Transforms an object to a Tool for the API.
    • tBlobs

      public static com.fasterxml.jackson.databind.node.ArrayNode tBlobs(Object origin)
      Dummy Blobs transformer.
    • tBlob

      public static Blob tBlob(Object blob)
    • tImageBlob

      public 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.
      Throws:
      IllegalArgumentException - if the blob is not an image.
    • tAudioBlob

      public 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.
      Throws:
      IllegalArgumentException - if the blob is not an audio.
    • tBytes

      public static Object tBytes(Object origin)
      Dummy bytes transformer.
    • tCachedContentName

      public static String tCachedContentName(ApiClient apiClient, Object origin)
      Transforms an object to a cached content name for the API.
    • tContentsForEmbed

      public static @Nullable List<Object> tContentsForEmbed(ApiClient apiClient, Object origin)
      Transforms an object to a list of Content for the embedding API.
    • tCachesModel

      public static @Nullable 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 transformation
      origin - 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

      public static @Nullable String tFileName(Object origin)
    • tTuningJobStatus

      public static JobState tTuningJobStatus(Object origin)
    • tBatchJobSource

      public static Object tBatchJobSource(Object src)
    • tBatchJobDestination

      public static Object tBatchJobDestination(Object dest)
    • tRecvBatchJobDestination

      public static Object tRecvBatchJobDestination(Object dest)
    • tBatchJobName

      public 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).
      Throws:
      IllegalArgumentException - If the input name is not a String or does not match expected patterns.
    • tJobState

      public 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.
      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

      public 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

      public static com.fasterxml.jackson.databind.node.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.