Package com.mindsdb.utils
Class Utils
java.lang.Object
com.mindsdb.utils.Utils
Utility class providing static methods for validation and JSON creation
related to Minds and DataSources.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
createMindBody
(String mindName, List<String> datasources) Creates a JSON representation of a mind body for API requests.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.static String
createRequestBodyForAddDs
(String datasourceName, boolean checkConnection) Creates a JSON request body for adding a data source.static String
generateDatasourceUpdateBody
(Datasource datasource) Generates a JSON body for updating a data source.static String
Returns the base URL for OpenAI services based on the provided URL.static Datasource
parseStringToDatasource
(String dsJsonString) Parses a JSON string into a Datasource object.static List<Datasource>
parseStringToDatasourceList
(String dsListJsonString) Parses a JSON string into a list of Datasource objects.static Mind
parseStringToMind
(String mindJsonString) Parses a JSON string into a Mind object.parseStringToMindList
(String mindListJsonString) Parses a JSON string into a list of Mind objects.static void
validateDatabaseConfig
(DatabaseConfig databaseConfig) static void
validateDatasource
(Datasource datasource) Validates the properties of a Datasource object.static void
validateDatasourceList
(List<String> datasources) Validates a list of data sources.static void
validateDatasourceName
(String datasourceName) Validates the name of a data source.static void
validateMind
(Mind mind) Validates the given Mind object.static void
validateMindName
(String mindName) Validates the name of a mind.
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
createMindBody
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
Validates the given Mind object.- Parameters:
mind
- the Mind object to validate.- Throws:
Exception
- if the mind's name is invalid.
-
validateMindName
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
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
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
- Throws:
Exception
-
validateDatasourceName
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
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
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
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
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
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
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
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 Minddatasources
- a list of data sources associated with the MindmodelName
- the name of the model to be usedparameters
- a JSON object containing additional parameters for the Mindprovider
- the provider to be usedpromptTemplate
- the template for the prompt- Returns:
- a Mind object created from the provided parameters
-