Skip to content

mistral_common.experimental.app.models

EngineBackend

Bases: str, Enum

The engine backend to use.

Attributes:

Name Type Description
llama_cpp

The llama.cpp backend.

OpenAIChatCompletionRequest(**data)

Bases: BaseModel

OpenAI chat completion request.

This class is used to parse the request body for the OpenAI chat completion endpoint.

Attributes:

Name Type Description
messages list[dict[str, str | list[dict[str, str | dict[str, Any]]] | None]]

The messages to use for the chat completion.

tools list[dict[str, Any]] | None

The tools to use for the chat completion.

Note

This class accepts extra fields that are not validated.

Source code in pydantic/main.py
def __init__(self, /, **data: Any) -> None:
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.
    """
    # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    __tracebackhide__ = True
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
    if self is not validated_self:
        warnings.warn(
            'A custom validator is returning a value other than `self`.\n'
            "Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\n"
            'See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.',
            stacklevel=2,
        )

drop_extra_fields()

Drop extra fields from the model.

This method is used to drop extra fields from the model, which are not defined in the model fields.

Returns:

Type Description
dict[str, Any]

The extra fields that were dropped from the model.

Source code in src/mistral_common/experimental/app/models.py
def drop_extra_fields(self) -> dict[str, Any]:
    r"""Drop extra fields from the model.

    This method is used to drop extra fields from the model, which are not defined in the model fields.

    Returns:
        The extra fields that were dropped from the model.
    """
    extra_fields = {
        field: value for field, value in self.model_dump().items() if field not in type(self).model_fields
    }

    self.__dict__ = {k: v for k, v in self.__dict__.items() if k not in extra_fields}
    return extra_fields

Settings

Bases: BaseSettings

Settings for the Mistral-common API.

Attributes:

Name Type Description
app_name str

The name of the application.

app_version str

The version of the application.

engine_url str

The URL of the engine, with any trailing slash stripped.

engine_backend EngineBackend

The backend to use for the engine.

api_key str

The API key for the engine, or an empty string if none.

timeout int

The timeout for the engine API in seconds.

tokenizer property writable

The application's tokenizer.

Returns:

Type Description
MistralTokenizer

The loaded MistralTokenizer.

Raises:

Type Description
ValueError

If the tokenizer has not been initialized yet.

model_post_init(context)

Initialize the private tokenizer slot to None.

Source code in src/mistral_common/experimental/app/models.py
def model_post_init(self, context: Any) -> None:
    r"""Initialize the private tokenizer slot to None."""
    super().model_post_init(context)
    self._tokenizer: MistralTokenizer | None = None

get_settings()

Get the settings for the Mistral-common API.

Returns:

Type Description
Settings

A Settings instance built from the environment.

Source code in src/mistral_common/experimental/app/models.py
def get_settings() -> Settings:
    r"""Get the settings for the Mistral-common API.

    Returns:
        A Settings instance built from the environment.
    """
    return Settings()