Skip to content

mistral_common.protocol.instruct.response

ChatCompletionResponse(**data)

Bases: MistralBase

A chat completion response.

See ChatCompletionRequest for the request.

Attributes:

Name Type Description
id str

The id of the response.

object str

The object of the response.

created int

The creation time of the response.

model str

The model of the response.

choices List[ChatCompletionResponseChoice]

The choices of the response.

usage UsageInfo

The usage of the response.

Examples:

>>> response = ChatCompletionResponse(
...     id="chatcmpl-123",
...     object="chat.completion",
...     created=1677652288,
...     model="mistral-tiny",
...     choices=[
...         ChatCompletionResponseChoice(index=0, message=DeltaMessage(role="user", content="Hello, world!"))
...     ],
...     usage=UsageInfo(prompt_tokens=10, total_tokens=20, completion_tokens=10),
... )
Source code in .venv/lib/python3.13/site-packages/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,
        )

ChatCompletionResponseChoice(**data)

Bases: MistralBase

A choice in a chat completion.

Attributes:

Name Type Description
index int

The index of the choice.

message DeltaMessage

The message of the choice.

finish_reason Optional[FinishReason]

The finish reason of the choice.

logprobs Optional[ChatCompletionResponseChoiceLogprobs]

The log probabilities of the choice.

Examples:

>>> choice = ChatCompletionResponseChoice(index=0, message=DeltaMessage(role="user", content="Hello, world!"))
Source code in .venv/lib/python3.13/site-packages/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,
        )

ChatCompletionResponseChoiceLogprobs(**data)

Bases: MistralBase

Log probabilities for a choice.

Attributes:

Name Type Description
content List[ChatCompletionTokenLogprobs]

The log probabilities for the content.

Examples:

>>> choice_logprobs = ChatCompletionResponseChoiceLogprobs(
...     content=[ChatCompletionTokenLogprobs(token="hello", logprob=-0.5, bytes=[104, 101, 108, 108, 111])]
... )
Source code in .venv/lib/python3.13/site-packages/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,
        )

ChatCompletionResponseStreamChoice(**data)

Bases: MistralBase

A choice in a chat completion stream response.

Attributes:

Name Type Description
index int

The index of the choice.

delta DeltaMessage

The delta of the choice.

finish_reason Optional[FinishReason]

The finish reason of the choice.

logprobs Optional[ChatCompletionResponseChoiceLogprobs]

The log probabilities of the choice.

Examples:

>>> choice = ChatCompletionResponseStreamChoice(
...     index=0, delta=DeltaMessage(role="user", content="Hello, world!")
... )
Source code in .venv/lib/python3.13/site-packages/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,
        )

ChatCompletionStreamResponse(**data)

Bases: MistralBase

A chat completion stream response.

See ChatCompletionRequest for the request.

Attributes:

Name Type Description
id str

The id of the response.

object str

The object of the response.

created int

The creation time of the response.

model str

The model of the response.

choices List[ChatCompletionResponseStreamChoice]

The choices of the response.

usage Optional[UsageInfo]

The usage of the response.

Examples:

>>> response = ChatCompletionStreamResponse(
...     id="chatcmpl-123",
...     object="chat.completion.chunk",
...     created=1677652288,
...     model="mistral-tiny",
...     choices=[
...         ChatCompletionResponseStreamChoice(index=0, delta=DeltaMessage(role="user", content="Hello, world!"))
...     ],
...     usage=UsageInfo(prompt_tokens=10, total_tokens=20, completion_tokens=10),
... )
Source code in .venv/lib/python3.13/site-packages/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,
        )

ChatCompletionTokenLogprobs(**data)

Bases: MistralBase

Log probabilities for a token.

Attributes:

Name Type Description
token str

The token.

logprob float

The log probability of the token.

bytes List[int]

The bytes of the token.

Examples:

>>> token_logprobs = ChatCompletionTokenLogprobs(token="hello", logprob=-0.5, bytes=[104, 101, 108, 108, 111])
Source code in .venv/lib/python3.13/site-packages/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,
        )

DeltaMessage(**data)

Bases: MistralBase

A message in a chat completion.

Attributes:

Name Type Description
role Optional[str]

The role of the message.

content Optional[str]

The content of the message.

tool_calls Optional[List[ToolCall]]

The tool calls in the message.

Examples:

>>> message = DeltaMessage(role="user", content="Hello, world!")
Source code in .venv/lib/python3.13/site-packages/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,
        )

FinishReason

Bases: str, Enum

Possible finish reasons.

Attributes:

Name Type Description
stop

The model hit a natural stop point or a provided stop sequence.

length

The maximum number of tokens specified in the request was reached.

model_length

The model hit its context length limit.

error

An error occurred during generation.

tool_calls

The model called a tool.

Examples:

>>> reason = FinishReason.stop