Skip to content

Model

Waldiez model model.

WaldiezModel

Bases: WaldiezBase

Waldiez Model class.

Attributes:

NameTypeDescription
idstr

The ID of the model.

namestr

The name of the model.

descriptionstr

The description of the model.

tagslist[str]

The tags of the model.

requirementslist[str]

The requirements of the model.

created_atstr

The date and time when the model was created.

updated_atstr

The date and time when the model was last updated.

dataWaldiezModelData

The data of the model. See waldiez.models.model.WaldiezModelData for more information.

api_key property

api_key: str

Get the model's api key.

Either from the model's data or from the environment variables:

- openai: 'OPENAI_API_KEY',
- azure: 'AZURE_API_KEY',
- deepseek: 'DEEPSEEK_API_KEY',
- google: 'GOOGLE_GEMINI_API_KEY',
- anthropic: 'ANTHROPIC_API_KEY',
- mistral: 'MISTRAL_API_KEY',
- groq: 'GROQ_API_KEY',
- together: 'TOGETHER_API_KEY',
- nim: 'NIM_API_KEY',
- cohere: 'COHERE_API_KEY',
- other: 'OPENAI_API_KEY'

api_key_env_key property

api_key_env_key: str

Get the model's api key environment key to check.

  • openai: 'OPENAI_API_KEY',
  • azure: 'AZURE_API_KEY',
  • deepseek: 'DEEPSEEK_API_KEY',
  • google: 'GOOGLE_GEMINI_API_KEY',
  • anthropic: 'ANTHROPIC_API_KEY',
  • mistral: 'MISTRAL_API_KEY',
  • groq: 'GROQ_API_KEY',
  • together: 'TOGETHER_API_KEY',
  • nim: 'NIM_API_KEY',
  • cohere: 'COHERE_API_KEY',
  • other: 'OPENAI_API_KEY'

get_llm_config

get_llm_config(skip_price: bool = False) -> dict[str, Any]

Get the model's llm config.

Parameters:

NameTypeDescriptionDefault
skip_pricebool

Whether to skip the price, by default, False

False

Returns:

TypeDescription
dict[str, Any]

The model's llm config dictionary.

Source code in waldiez/models/model/model.py
def get_llm_config(self, skip_price: bool = False) -> dict[str, Any]:
    """Get the model's llm config.

    Parameters
    ----------
    skip_price : bool, optional
        Whether to skip the price, by default, False

    Returns
    -------
    dict[str, Any]
        The model's llm config dictionary.
    """
    # noinspection PyDictCreation
    _llm_config: dict[str, Any] = {}
    _llm_config["model"] = self.name
    optionals: list[tuple[str, type]] = [
        ("base_url", str),
        ("max_tokens", int),
        # ("temperature", float),
        ("top_p", float),
        ("api_version", str),
        ("default_headers", dict),
    ]
    for attr, atr_type in optionals:
        value = getattr(self.data, attr)
        if value and isinstance(value, atr_type):
            _llm_config[attr] = value
    if self.data.api_type not in ["nim", "other"]:
        _llm_config["api_type"] = self.data.api_type
    other_attrs = ["api_key"] if skip_price else ["api_key", "price"]
    for attr in other_attrs:
        value = getattr(self, attr)
        if value:
            _llm_config[attr] = value
    if self.data.api_type == "bedrock":
        _llm_config.pop("base_url", None)
        return set_bedrock_aws_config(_llm_config, self.data.aws)
    return set_default_base_url(_llm_config, self.data.api_type)

price property

price: Optional[list[float]]

Get the model's price.

set_bedrock_aws_config

set_bedrock_aws_config(
    llm_config: dict[str, Any],
    aws_config: Optional[WaldiezModelAWS],
) -> dict[str, Any]

Set the AWS config for Bedrock.

Parameters:

NameTypeDescriptionDefault
llm_configdict[str, Any]

The llm config dictionary.

required
aws_configOptional[WaldiezModelAWS]

The passed aws config if any.

required

Returns:

TypeDescription
dict[str, Any]

The llm config dictionary with the AWS config set.

Source code in waldiez/models/model/model.py
def set_bedrock_aws_config(
    llm_config: dict[str, Any],
    aws_config: Optional[WaldiezModelAWS],
) -> dict[str, Any]:
    """Set the AWS config for Bedrock.

    Parameters
    ----------
    llm_config : dict[str, Any]
        The llm config dictionary.
    aws_config : Optional[WaldiezModelAWS]
        The passed aws config if any.

    Returns
    -------
    dict[str, Any]
        The llm config dictionary with the AWS config set.
    """
    dict_copy = llm_config.copy()
    aws_params = [
        "access_key",
        "secret_key",
        "session_token",
        "profile_name",
        "region",
    ]

    extra_args: dict[str, Any] = {}
    for param in aws_params:
        config_key = f"aws_{param}"
        env_var = f"AWS_{param.upper()}"

        # First try to get from aws_config
        value = getattr(aws_config, param, "") if aws_config else ""

        # If not found, try environment variable
        if not value:  # pragma: no cover
            value = os.environ.get(env_var, "")

        # Add to extra_args if value exists
        if value:  # pragma: no branch
            extra_args[config_key] = value

    # Update llm_config with extra_args
    if extra_args:  # pragma: no branch
        dict_copy.update(extra_args)

    return dict_copy

set_default_base_url

set_default_base_url(
    llm_config: dict[str, Any],
    api_type: WaldiezModelAPIType,
) -> dict[str, Any]

Set the default base url if not provided.

Parameters:

NameTypeDescriptionDefault
llm_configdict[str, Any]

The llm config dictionary.

required
api_typestr

The api type.

required

Returns:

TypeDescription
dict[str, Any]

The llm config dictionary with the default base url set.

Source code in waldiez/models/model/model.py
def set_default_base_url(
    llm_config: dict[str, Any], api_type: WaldiezModelAPIType
) -> dict[str, Any]:
    """Set the default base url if not provided.

    Parameters
    ----------
    llm_config : dict[str, Any]
        The llm config dictionary.
    api_type : str
        The api type.

    Returns
    -------
    dict[str, Any]
        The llm config dictionary with the default base url set.
    """
    dict_copy = llm_config.copy()
    if "base_url" not in llm_config or not llm_config["base_url"]:
        if MODEL_NEEDS_BASE_URL.get(api_type, True):  # pragma: no branch
            dict_copy["base_url"] = DEFAULT_BASE_URLS.get(api_type, "")
    if (
        not llm_config.get("base_url", "")
        and MODEL_NEEDS_BASE_URL.get(api_type, True) is False
    ):  # pragma: no cover
        dict_copy.pop("base_url", None)
    return dict_copy

Waldiez Model Data.

WaldiezModelAPIType module-attribute

WaldiezModelAPIType = Literal[
    "openai",
    "azure",
    "deepseek",
    "google",
    "anthropic",
    "mistral",
    "groq",
    "together",
    "nim",
    "cohere",
    "bedrock",
    "other",
]

Possible API types for the model.

WaldiezModelAWS

Bases: WaldiezBase

AWS related parameters.

Attributes:

NameTypeDescription
regionOptional[str]

The AWS region, by default None.

access_keyOptional[str]

The AWS access key, by default None.

secret_keyOptional[str]

The AWS secret access key, by default None.

session_tokenOptional[str]

The AWS session token, by default None.

profile_nameOptional[str]

The AWS profile name, by default Nonde.

WaldiezModelData

Bases: WaldiezBase

Waldiez Model Data.

Attributes:

NameTypeDescription
base_urlOptional[str]

The base url of the model, by default None.

api_keyOptional[str]

The api key to use with the model, by default None.

api_typeWaldiezModelAPIType

The api type of the model.

api_versionOptional[str]

The api version of the model, by default None.

temperatureOptional[float]

The temperature of the model, by default None.

top_pOptional[float]

The top p of the model, by default None.

max_tokensOptional[int]

The max tokens of the model, by default None.

awsOptional[WaldiezModelAWS]
extrasdict[str, str]

Any extra attributes to include in the LLM Config.

default_headersdict[str, str]

The default headers of the model.

priceOptional[WaldiezModelPrice]

The price of the model, by default None.

WaldiezModelPrice

Bases: WaldiezBase

Model Price.

Attributes:

NameTypeDescription
prompt_price_per_1kfloat

The prompt price per 1k tokens.

completion_token_price_per_1kfloat

The completion token price per 1k tokens.