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: str property

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: str property

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(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.
    """
    _llm_config: Dict[str, Any] = {}
    _llm_config["model"] = self.name
    for attr, atr_type in [
        ("base_url", str),
        ("max_tokens", int),
        ("temperature", float),
        ("top_p", float),
        ("api_version", str),
        ("default_headers", dict),
    ]:
        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
    return set_default_base_url(_llm_config, self.data.api_type)

price: Optional[List[float]] property

Get the model's price.

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):
            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
    ):
        dict_copy.pop("base_url", None)
    return dict_copy

Waldiez Model Data.

WaldiezModelAPIType = Literal['openai', 'azure', 'deepseek', 'google', 'anthropic', 'mistral', 'groq', 'together', 'nim', 'cohere', 'other'] module-attribute

Possible API types for the model.

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.

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.