ModelFactory

class ModelFactory:

create

def create(
    model_platform: Union[ModelPlatformType, str],
    model_type: Union[ModelType, str, UnifiedModelType],
    model_config_dict: Optional[Dict] = None,
    token_counter: Optional[BaseTokenCounter] = None,
    api_key: Optional[str] = None,
    url: Optional[str] = None,
    timeout: Optional[float] = None,
    **kwargs
):

Creates an instance of BaseModelBackend of the specified type.

Parameters:

  • model_platform (Union[ModelPlatformType, str]): Platform from which the model originates. Can be a string or ModelPlatformType enum.
  • model_type (Union[ModelType, str, UnifiedModelType]): Model for which a backend is created. Can be a string, ModelType enum, or UnifiedModelType.
  • model_config_dict (Optional[Dict]): A dictionary that will be fed into the backend constructor. (default: :obj:None)
  • token_counter (Optional[BaseTokenCounter], optional): Token counter to use for the model. If not provided, :obj:OpenAITokenCounter(ModelType.GPT_4O_MINI) will be used if the model platform didn’t provide official token counter. (default: :obj:None)
  • api_key (Optional[str], optional): The API key for authenticating with the model service. (default: :obj:None)
  • url (Optional[str], optional): The url to the model service. (default: :obj:None)
  • timeout (Optional[float], optional): The timeout value in seconds for API calls. (default: :obj:None) **kwargs: Additional model-specific parameters that will be passed to the model constructor. For example, Azure OpenAI models may require api_version, azure_deployment_name, azure_ad_token_provider, and azure_ad_token.

Returns:

BaseModelBackend: The initialized backend.

__parse_model_platform

def __parse_model_platform(cls, model_platform_str: str):

Parses a string and returns the corresponding ModelPlatformType enum.

Parameters:

  • model_platform_str (str): The platform name as a string. Can be in the form “ModelPlatformType.<NAME>” or simply “<NAME>”.

Returns:

ModelPlatformType: The matching enum value.

__load_yaml

def __load_yaml(cls, filepath: str):

__load_json

def __load_json(cls, filepath: str):

Loads and parses a JSON file into a dictionary.

Parameters:

  • filepath (str): Path to the JSON configuration file.

Returns:

Dict: The parsed JSON content as a dictionary.

create_from_yaml

def create_from_yaml(cls, filepath: str):

Creates and returns a model base backend instance from a YAML configuration file.

Parameters:

  • filepath (str): Path to the YAML file containing model configuration.

Returns:

BaseModelBackend: An instance of the model backend based on the configuration.

create_from_json

def create_from_json(cls, filepath: str):

Creates and returns a base model backend instance from a JSON configuration file.

Parameters:

  • filepath (str): Path to the JSON file containing model configuration.

Returns:

BaseModelBackend: An instance of the model backend based on the configuration.