Skip to main content

module aixplain.factories.model_factory


class ModelFactory

A static class for creating and exploring Model Objects.

Attributes:

  • backend_url (str): The URL for the backend.

classmethod asset_repo_login

asset_repo_login(api_key: Optional[str] = None) → Dict

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

Args:

  • api_key (Text, optional): Team API key. Defaults to None.

Returns:

  • Dict: Backend response

classmethod create_asset_repo

create_asset_repo(
name: str,
description: str,
function: str,
source_language: str,
input_modality: str,
output_modality: str,
documentation_url: Optional[str] = '',
api_key: Optional[str] = None
) → Dict

Creates an image repository for this model and registers it in the platform backend.

Args:

  • name (Text): Model name
  • hosting_machine (Text): Hosting machine ID obtained via list_host_machines
  • always_on (bool): Whether the model should always be on
  • version (Text): Model version
  • description (Text): Model description
  • function (Text): Model function name obtained via LIST_HOST_MACHINES
  • is_async (bool): Whether the model is asynchronous or not (False in first release)
  • source_language (Text): 2-character 639-1 code or 3-character 639-3 language code.
  • api_key (Text, optional): Team API key. Defaults to None.

Returns:

  • Dict: Backend response

classmethod create_utility_model

create_utility_model(
name: str,
code: Union[str, Callable],
inputs: List[UtilityModelInput] = [],
description: Optional[str] = None,
output_examples: str = ''
) → UtilityModel

Create a utility model

Args:

  • name (Text): name of the model
  • code (Union[Text, Callable]): code of the model
  • description (Text, optional): description of the model
  • inputs (List[UtilityModelInput], optional): inputs of the model
  • output_examples (Text, optional): output examples

Returns:

  • UtilityModel: created utility model

classmethod deploy_huggingface_model

deploy_huggingface_model(
name: str,
hf_repo_id: str,
revision: Optional[str] = '',
hf_token: Optional[str] = '',
api_key: Optional[str] = None
) → Dict

Onboards and deploys a Hugging Face large language model.

Args:

  • name (Text): The user's name for the model.
  • hf_repo_id (Text): The Hugging Face repository ID for this model ({author}/{model name}).
  • hf_token (Text, optional): Hugging Face access token. Defaults to None.
  • api_key (Text, optional): Team API key. Defaults to None.

Returns:

  • Dict: Backend response

classmethod get

get(model_id: str, api_key: Optional[str] = None) → Model

Create a 'Model' object from model id

Args:

  • model_id (Text): Model ID of required model.
  • api_key (Optional[Text], optional): Model API key. Defaults to None.

Returns:

  • Model: Created 'Model' object

classmethod get_huggingface_model_status

get_huggingface_model_status(model_id: str, api_key: Optional[str] = None)

Gets the on-boarding status of a Hugging Face model with ID MODEL_ID.

Args:

  • model_id (Text): The model's ID as returned by DEPLOY_HUGGINGFACE_MODEL
  • api_key (Text, optional): Team API key. Defaults to None.

Returns:

  • Dict: Backend response

classmethod list

list(
function: Optional[Function] = None,
query: Optional[str] = '',
suppliers: Optional[Supplier, List[Supplier]] = None,
source_languages: Optional[Language, List[Language]] = None,
target_languages: Optional[Language, List[Language]] = None,
is_finetunable: Optional[bool] = None,
ownership: Optional[Tuple[OwnershipType, List[OwnershipType]]] = None,
sort_by: Optional[SortBy] = None,
sort_order: SortOrder = <SortOrder.ASCENDING: 1>,
page_number: int = 0,
page_size: int = 20
) → List[Model]

Gets the first k given models based on the provided task and language filters

Args:

  • function (Function): function filter.
  • source_languages (Optional[Union[Language, List[Language]]], optional): language filter of input data. Defaults to None.
  • target_languages (Optional[Union[Language, List[Language]]], optional): language filter of output data. Defaults to None.
  • is_finetunable (Optional[bool], optional): can be finetuned or not. Defaults to None.
  • ownership (Optional[Tuple[OwnershipType, List[OwnershipType]]], optional): Ownership filters (e.g. SUBSCRIBED, OWNER). Defaults to None.
  • sort_by (Optional[SortBy], optional): sort the retrived models by a specific attribute,
  • page_number (int, optional): page number. Defaults to 0.
  • page_size (int, optional): page size. Defaults to 20.

Returns:

  • List[Model]: List of models based on given filters

classmethod list_functions

list_functions(
verbose: Optional[bool] = False,
api_key: Optional[str] = None
) → List[Dict]

Lists supported model functions on platform.

Args:

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

classmethod list_gpus

list_gpus(api_key: Optional[str] = None) → List[List[str]]

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

Args:

  • api_key (Text, optional): Team API key. Defaults to None.

Returns:

  • List[List[Text]]: List of all available GPUs and their prices.

classmethod list_host_machines

list_host_machines(api_key: Optional[str] = None) → List[Dict]

Lists available hosting machines for model.

Args:

  • api_key (Text, optional): Team API key. Defaults to None.

Returns:

  • List[Dict]: List of dictionaries containing information about each hosting machine.

classmethod onboard_model

onboard_model(
model_id: str,
image_tag: str,
image_hash: str,
host_machine: Optional[str] = '',
api_key: Optional[str] = None
) → Dict

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

Args:

  • 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