Class Transformers

  • All Implemented Interfaces:

    @InternalApi() 
    public final class Transformers
    
                        

    Transformers for GenAI SDK.

    • Constructor Detail

    • 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 transformation
        origin - 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 transformation
        baseModels - 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

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

      • tTool

         static Tool tTool(Object origin)

        Transforms an object to a Tool for the API.

      • tBlobs

         static ArrayNode tBlobs(Object origin)

        Dummy Blobs transformer.

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

      • 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 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

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