Models
Camel.models.model factory
ModelFactory
create
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 requireapi_version
,azure_deployment_name
,azure_ad_token_provider
, andazure_ad_token
.
Returns:
BaseModelBackend: The initialized backend.
__parse_model_platform
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
__load_json
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
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
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.