Skip to main content
Version: 1.0

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)

[view_source]

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_url str - 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

[view_source]

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:

  • name Optional[Text] - Name of the utility model.
  • code Union[Text, Callable] - Python code as string or callable function implementing the model's functionality.
  • inputs List[UtilityModelInput], optional - List of input specifications. Defaults to empty list.
  • description Optional[Text], optional - Description of what the model does. Defaults to None.
  • output_examples Text, optional - Examples of expected outputs. Defaults to empty string.
  • api_key Optional[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]

[view_source]

Lists available hosting machines for model.

Arguments:

  • api_key Text, 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]]

[view_source]

List GPU names on which you can host your language model.

Arguments:

  • api_key Text, 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]

[view_source]

Lists supported model functions on platform.

Arguments:

  • verbose Boolean, optional - Set to True if a detailed response is desired; is otherwise False by default.
  • api_key Text, 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

[view_source]

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:

  • name Text - Name of the model.
  • description Text - Description of the model's functionality.
  • function Text - Function name from list_functions() defining model's task.
  • source_language Text - Language code in ISO 639-1 (2-char) or 639-3 (3-char) format.
  • input_modality Text - Type of input the model accepts (e.g., text, audio).
  • output_modality Text - Type of output the model produces (e.g., text, audio).
  • documentation_url Optional[Text], optional - URL to model documentation. Defaults to empty string.
  • api_key Optional[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

[view_source]

Return login credentials for the image repository that corresponds with the given API_KEY.

Arguments:

  • api_key Text, 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

[view_source]

Onboard a model after its image has been pushed to ECR.

Arguments:

  • model_id Text - Model ID obtained from CREATE_ASSET_REPO.
  • image_tag Text - Image tag to be onboarded.
  • image_hash Text - Image digest.
  • host_machine Text, optional - Machine on which to host model.
  • api_key Text, 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

[view_source]

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:

  • name Text - Display name for the deployed model.
  • hf_repo_id Text - Hugging Face repository ID in 'author/model-name' format.
  • revision Optional[Text], optional - Specific model revision/commit hash. Defaults to empty string (latest version).
  • hf_token Optional[Text], optional - Hugging Face access token for private models. Defaults to empty string.
  • api_key Optional[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

[view_source]

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_id Text - Model ID returned by deploy_huggingface_model.
  • api_key Optional[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