Class Utils

java.lang.Object
com.mindsdb.utils.Utils

public class Utils extends Object
Utility class providing static methods for validation and JSON creation related to Minds and DataSources.
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • createMindBody

      public static String createMindBody(String mindName, List<String> datasources)
      Creates a JSON representation of a mind body for API requests.
      Parameters:
      mindName - the name of the mind.
      datasources - a list of data source names associated with the mind.
      Returns:
      a JSON string representing the mind body.
    • validateMind

      public static void validateMind(Mind mind) throws Exception
      Validates the given Mind object.
      Parameters:
      mind - the Mind object to validate.
      Throws:
      Exception - if the mind's name is invalid.
    • validateMindName

      public static void validateMindName(String mindName) throws Exception
      Validates the name of a mind.
      Parameters:
      mindName - the name of the mind to validate.
      Throws:
      Exception - if the mind name is null or empty.
    • validateDatasourceList

      public static void validateDatasourceList(List<String> datasources) throws Exception
      Validates a list of data sources.
      Parameters:
      datasources - the list of data sources to validate.
      Throws:
      Exception - if the list is null or empty.
    • validateDatasource

      public static void validateDatasource(Datasource datasource) throws Exception
      Validates the properties of a Datasource object.
      Parameters:
      datasource - the Datasource object to validate.
      Throws:
      Exception - if the datasource's name, description, engine, or connection data is invalid.
    • validateDatabaseConfig

      public static void validateDatabaseConfig(DatabaseConfig databaseConfig) throws Exception
      Throws:
      Exception
    • validateDatasourceName

      public static void validateDatasourceName(String datasourceName) throws Exception
      Validates the name of a data source.
      Parameters:
      datasourceName - the name of the data source to validate.
      Throws:
      Exception - if the datasource name is empty.
    • createRequestBodyForAddDs

      public static String createRequestBodyForAddDs(String datasourceName, boolean checkConnection)
      Creates a JSON request body for adding a data source.
      Parameters:
      datasourceName - the name of the data source to add.
      checkConnection - a boolean indicating whether to check the connection.
      Returns:
      a JSON string representing the request body for adding a data source.
    • generateDatasourceUpdateBody

      public static String generateDatasourceUpdateBody(Datasource datasource)
      Generates a JSON body for updating a data source.
      Parameters:
      datasource - the Datasource object to convert to JSON.
      Returns:
      a JSON string representing the update body for the data source.
    • parseStringToMind

      public static Mind parseStringToMind(String mindJsonString)
      Parses a JSON string into a Mind object.
      Parameters:
      mindJsonString - The JSON string representing a Mind object.
      Returns:
      A Mind object parsed from the provided JSON string.
    • parseStringToDatasource

      public static Datasource parseStringToDatasource(String dsJsonString)
      Parses a JSON string into a Datasource object.
      Parameters:
      dsJsonString - The JSON string representing a Datasource object.
      Returns:
      A Datasource object parsed from the provided JSON string.
    • parseStringToMindList

      public static List<Mind> parseStringToMindList(String mindListJsonString)
      Parses a JSON string into a list of Mind objects.
      Parameters:
      mindListJsonString - The JSON string representing a list of Mind objects.
      Returns:
      A List of Mind objects parsed from the provided JSON string.
    • parseStringToDatasourceList

      public static List<Datasource> parseStringToDatasourceList(String dsListJsonString)
      Parses a JSON string into a list of Datasource objects.
      Parameters:
      dsListJsonString - The JSON string representing a list of Datasource objects.
      Returns:
      A List of Datasource objects parsed from the provided JSON string.
    • getBaseUrlForOpenAI

      public static String getBaseUrlForOpenAI(String url) throws URISyntaxException
      Returns the base URL for OpenAI services based on the provided URL. The method modifies the host based on specific conditions and constructs a new URI.
      Parameters:
      url - the original URL to be modified
      Returns:
      the new base URL for OpenAI services as a String
      Throws:
      URISyntaxException - if the given URL is not a valid URI
    • createMindFromParams

      public static Mind createMindFromParams(String name, List<String> datasources, String modelName, com.google.gson.JsonObject parameters, String provider, String promptTemplate)
      Creates a Mind object from the provided parameters. This method utilizes the Builder pattern to construct a Mind object based on the specified attributes.
      Parameters:
      name - the name of the Mind
      datasources - a list of data sources associated with the Mind
      modelName - the name of the model to be used
      parameters - a JSON object containing additional parameters for the Mind
      provider - the provider to be used
      promptTemplate - the template for the prompt
      Returns:
      a Mind object created from the provided parameters