aixplain.factories.model_factory
__author__
Copyright 2022 The aiXplain SDK authors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Author: Duraikrishna Selvaraju, Thiago Castro Ferreira, Shreyas Sharma and Lucas Pavanelli Date: September 1st 2022 Description: Model Factory Class
ModelFactory Objects
class ModelFactory(ModelGetterMixin, ModelListMixin)
Factory class for creating, managing, and exploring models.
This class provides functionality for creating various types of models, managing model repositories, and interacting with the aiXplain platform's model-related features.
Attributes:
backend_urlstr - Base URL for the aiXplain backend API.
create_utility_model
@classmethod
def create_utility_model(cls,
name: Optional[Text] = None,
code: Union[Text, Callable] = None,
inputs: List[UtilityModelInput] = [],
description: Optional[Text] = None,
output_examples: Text = "",
api_key: Optional[Text] = None) -> UtilityModel
Create a new utility model for custom functionality.
This method creates a utility model that can execute custom code or functions with specified inputs and outputs.
Arguments:
nameOptional[Text] - Name of the utility model.codeUnion[Text, Callable] - Python code as string or callable function implementing the model's functionality.inputsList[UtilityModelInput], optional - List of input specifications. Defaults to empty list.descriptionOptional[Text], optional - Description of what the model does. Defaults to None.output_examplesText, optional - Examples of expected outputs. Defaults to empty string.api_keyOptional[Text], optional - API key for authentication. Defaults to None, using the configured TEAM_API_KEY.
Returns:
UtilityModel- Created and registered utility model instance.
Raises:
Exception- If model creation fails or validation fails.
list_host_machines
@classmethod
def list_host_machines(cls, api_key: Optional[Text] = None) -> List[Dict]
Lists available hosting machines for model.
Arguments:
api_keyText, optional - Team API key. Defaults to None.
Returns:
List[Dict]- List of dictionaries containing information about each hosting machine.
list_gpus
@classmethod
def list_gpus(cls, api_key: Optional[Text] = None) -> List[List[Text]]
List GPU names on which you can host your language model.
Arguments:
api_keyText, optional - Team API key. Defaults to None.
Returns:
List[List[Text]]- List of all available GPUs and their prices.
list_functions
@classmethod
def list_functions(cls,
verbose: Optional[bool] = False,
api_key: Optional[Text] = None) -> List[Dict]
Lists supported model functions on platform.
Arguments:
verboseBoolean, optional - Set to True if a detailed response is desired; is otherwise False by default.api_keyText, optional - Team API key. Defaults to None.
Returns:
List[Dict]- List of dictionaries containing information about each supported function.
create_asset_repo
@classmethod
def create_asset_repo(cls,
name: Text,
description: Text,
function: Text,
source_language: Text,
input_modality: Text,
output_modality: Text,
documentation_url: Optional[Text] = "",
api_key: Optional[Text] = None) -> Dict
Create a new model repository in the platform.
This method creates and registers a new model repository, setting up the necessary infrastructure for model deployment.
Arguments:
nameText - Name of the model.descriptionText - Description of the model's functionality.functionText - Function name from list_functions() defining model's task.source_languageText - Language code in ISO 639-1 (2-char) or 639-3 (3-char) format.input_modalityText - Type of input the model accepts (e.g., text, audio).output_modalityText - Type of output the model produces (e.g., text, audio).documentation_urlOptional[Text], optional - URL to model documentation. Defaults to empty string.api_keyOptional[Text], optional - API key for authentication. Defaults to None, using the configured TEAM_API_KEY.
Returns:
Dict- Repository creation response containing model ID and other details.
Raises:
Exception- If function name is invalid.description0 - If response status code is not 201.
asset_repo_login
@classmethod
def asset_repo_login(cls, api_key: Optional[Text] = None) -> Dict
Return login credentials for the image repository that corresponds with the given API_KEY.
Arguments:
api_keyText, optional - Team API key. Defaults to None.
Returns:
Dict- Backend response
onboard_model
@classmethod
def onboard_model(cls,
model_id: Text,
image_tag: Text,
image_hash: Text,
host_machine: Optional[Text] = "",
api_key: Optional[Text] = None) -> Dict
Onboard a model after its image has been pushed to ECR.
Arguments:
model_idText - Model ID obtained from CREATE_ASSET_REPO.image_tagText - Image tag to be onboarded.image_hashText - Image digest.host_machineText, optional - Machine on which to host model.api_keyText, optional - Team API key. Defaults to None.
Returns:
Dict- Backend response
deploy_huggingface_model
@classmethod
def deploy_huggingface_model(cls,
name: Text,
hf_repo_id: Text,
revision: Optional[Text] = "",
hf_token: Optional[Text] = "",
api_key: Optional[Text] = None) -> Dict
Deploy a model from Hugging Face Hub to the aiXplain platform.
This method handles the deployment of a Hugging Face model, including authentication and configuration setup.
Arguments:
nameText - Display name for the deployed model.hf_repo_idText - Hugging Face repository ID in 'author/model-name' format.revisionOptional[Text], optional - Specific model revision/commit hash. Defaults to empty string (latest version).hf_tokenOptional[Text], optional - Hugging Face access token for private models. Defaults to empty string.api_keyOptional[Text], optional - API key for authentication. Defaults to None, using the configured TEAM_API_KEY.
Returns:
Dict- Deployment response containing model ID and status information.
get_huggingface_model_status
@classmethod
def get_huggingface_model_status(cls,
model_id: Text,
api_key: Optional[Text] = None) -> Dict
Check the deployment status of a Hugging Face model.
This method retrieves the current status and details of a deployed Hugging Face model.
Arguments:
model_idText - Model ID returned by deploy_huggingface_model.api_keyOptional[Text], optional - API key for authentication. Defaults to None, using the configured TEAM_API_KEY.
Returns:
Dict- Status response containing:- status: Current deployment status
- name: Model name
- id: Model ID
- pricing: Pricing information