Skip to content

# `mistral_common.protocol.instruct.chunk`

## `AudioChunk(**data)`

Bases: `BaseContentChunk`

Audio chunk containing raw audio data.

Attributes:

Name | Type | Description
--- | --- | ---
`type` | `Literal[input_audio]` | The type of the chunk, which is always ChunkTypes.input_audio.
`input_audio` | `str | bytes` | The audio data as a base64-encoded string or raw bytes.

Examples:

    >>> audio_chunk = AudioChunk(input_audio="base64_encoded_audio_data")

Source code in `pydantic/main.py`

    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270

    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,
            )

### `from_audio(audio)` `classmethod`

Create an AudioChunk instance from an Audio object.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`audio` | `Audio` | An Audio object containing audio data. | required

Returns:

Type | Description
--- | ---
`AudioChunk` | An AudioChunk instance initialized with the audio data.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381

    @classmethod
    def from_audio(cls, audio: "Audio") -> "AudioChunk":
        r"""Create an AudioChunk instance from an Audio object.

        Args:
            audio: An Audio object containing audio data.

        Returns:
            An AudioChunk instance initialized with the audio data.
        """
        return cls(input_audio=audio.to_base64(audio.format, False))

### `from_openai(openai_chunk)` `classmethod`

Convert the OpenAI chunk to the Mistral format.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`openai_chunk` | `dict[str, Any]` | A dictionary representing the audio chunk in the OpenAI format. | required

Returns:

Type | Description
--- | ---
`AudioChunk` | An AudioChunk instance initialized with the data from the OpenAI chunk.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412

    @classmethod
    def from_openai(cls, openai_chunk: dict[str, Any]) -> "AudioChunk":
        r"""Convert the OpenAI chunk to the Mistral format.

        Args:
            openai_chunk: A dictionary representing the audio chunk in the OpenAI format.

        Returns:
            An AudioChunk instance initialized with the data from the OpenAI chunk.
        """
        return cls.model_validate_ignore_extra(openai_chunk)

### `should_not_be_empty(v)` `classmethod`

Validate that the audio data is not empty.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    361
    362
    363
    364
    365
    366
    367
    368
    369

    @field_validator("input_audio")
    @classmethod
    def should_not_be_empty(cls, v: str | bytes) -> str | bytes:
        r"""Validate that the audio data is not empty."""
        if isinstance(v, str) and not v.strip():
            raise ValueError("`input_audio` should not be empty.")
        if isinstance(v, bytes) and not v:
            raise ValueError("`input_audio` should not be empty.")
        return v

### `to_openai()`

Convert the chunk to the OpenAI format.

Returns:

Type | Description
--- | ---
`dict[str, Any]` | A dictionary representing the audio chunk in the OpenAI format.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400

    def to_openai(self) -> dict[str, Any]:
        r"""Convert the chunk to the OpenAI format.

        Returns:
            A dictionary representing the audio chunk in the OpenAI format.
        """
        if isinstance(self.input_audio, bytes):
            content = base64.b64encode(self.input_audio).decode("utf-8")
        else:
            content = _strip_audio_data_url_prefix(self.input_audio)
        fmt = _detect_audio_format(self.input_audio)
        return {
            "type": self.type,
            "input_audio": {
                "data": content,
                "format": fmt,
            },
        }

## `AudioURL(**data)`

Bases: `MistralBase`

Audio URL.

Attributes:

Name | Type | Description
--- | --- | ---
`url` | `str` | The URL of the audio file.

Source code in `pydantic/main.py`

    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270

    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,
            )

## `AudioURLChunk(**data)`

Bases: `BaseContentChunk`

Audio URL chunk.

Attributes:

Name | Type | Description
--- | --- | ---
`type` | `Literal[audio_url]` | The type of the chunk, which is always `ChunkTypes.audio_url`.
`audio_url` | `str | AudioURL` | The URL of the audio file.

Source code in `pydantic/main.py`

    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270

    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,
            )

### `from_openai(openai_chunk)` `classmethod`

Converts the OpenAI chunk to the Mistral format.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    322
    323
    324
    325

    @classmethod
    def from_openai(cls, openai_chunk: dict[str, Any]) -> "AudioURLChunk":
        r"""Converts the OpenAI chunk to the Mistral format."""
        return cls.model_validate_ignore_extra(openai_chunk)

### `get_url_type()`

Returns the type of the audio URL.

Note

URLs should be either: - a valid URL (http:// or https://) - a valid file path (e.g. /path/to/file) - a valid file URI (e.g. file:///path/to/file) - a base64 encoded audio. It is assumed to be base64 encoded if it is not a valid URL or file path.

Returns:

Type | Description
--- | ---
`AudioURLType` | The type of the audio URL.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313

    def get_url_type(self) -> AudioURLType:
        r"""Returns the type of the audio URL.

        Note:
            URLs should be either:
            - a valid URL (http:// or https://)
            - a valid file path (e.g. /path/to/file)
            - a valid file URI (e.g. file:///path/to/file)
            - a base64 encoded audio. It is assumed to be base64 encoded if it is not a valid URL or file path.

        Returns:
            The type of the audio URL.
        """
        url_scheme = urlparse(self.url).scheme
        if url_scheme in {"http", "https"}:
            return AudioURLType.url
        elif url_scheme == "data":
            return AudioURLType.base64
        elif url_scheme == "file":
            return AudioURLType.file_uri

        try:
            url_path = Path(self.url)
            exist_path = url_path.exists()
        except OSError:  # File name too long
            exist_path = False

        if exist_path:
            return AudioURLType.file

        return AudioURLType.base64

### `to_openai()`

Converts the chunk to the OpenAI format.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    315
    316
    317
    318
    319
    320

    def to_openai(self) -> dict[str, Any]:
        r"""Converts the chunk to the OpenAI format."""
        if isinstance(self.audio_url, AudioURL):
            return self.model_dump()
        else:
            return {"type": self.type, "audio_url": {"url": self.audio_url}}

## `AudioURLType`

Bases: `str`, `Enum`

Enum for the types of audio URLs.

Attributes:

Name | Type | Description
--- | --- | ---
`url` |  | A URL.
`base64` |  | A base64 encoded audio. Can be prefixed with `data:audio/<format>;base64,`.
`file` |  | A file path.
`file_uri` |  | A file URI (eg. `file:///path/to/file`).

## `BaseContentChunk(**data)`

Bases: `MistralBase`

Base class for all content chunks.

Content chunks are used to send different types of content to the model.

Attributes:

Name | Type | Description
--- | --- | ---
`type` | `Literal[text, image, image_url, input_audio, audio_url, thinking]` | The type of the chunk.

Source code in `pydantic/main.py`

    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270

    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,
            )

### `from_openai(openai_chunk)` `classmethod`

Converts the OpenAI chunk to the Mistral format.

Should be implemented by subclasses.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    107
    108
    109
    110
    111
    112
    113

    @classmethod
    def from_openai(cls, openai_chunk: dict[str, Any]) -> "BaseContentChunk":
        r"""Converts the OpenAI chunk to the Mistral format.

        Should be implemented by subclasses.
        """
        raise NotImplementedError(f"from_openai method not implemented for {cls.__name__}")

### `to_openai()`

Converts the chunk to the OpenAI format.

Should be implemented by subclasses.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    100
    101
    102
    103
    104
    105

    def to_openai(self) -> dict[str, Any]:
        r"""Converts the chunk to the OpenAI format.

        Should be implemented by subclasses.
        """
        raise NotImplementedError(f"to_openai method not implemented for {type(self).__name__}")

## `ChunkTypes`

Bases: `str`, `Enum`

Enum for the types of chunks that can be sent to the model.

Attributes:

Name | Type | Description
--- | --- | ---
`text` |  | A text chunk.
`image` |  | An image chunk.
`image_url` |  | An image url chunk.
`input_audio` |  | An input audio chunk.
`audio_url` |  | An audio url chunk.

Examples:

    >>> from mistral_common.protocol.instruct.chunk import ChunkTypes
    >>> chunk_type = ChunkTypes.text

## `ImageChunk(**data)`

Bases: `BaseContentChunk`

Image chunk.

Attributes:

Name | Type | Description
--- | --- | ---
`image` | `SerializableImage` | The image to be sent to the model.

Examples:

    >>> from PIL import Image
    >>> image_chunk = ImageChunk(image=Image.new('RGB', (200, 200), color='blue'))

Source code in `pydantic/main.py`

    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270

    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,
            )

### `from_openai(openai_chunk)` `classmethod`

Converts the OpenAI chunk to the Mistral format.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148

    @classmethod
    def from_openai(cls, openai_chunk: dict[str, Any]) -> "ImageChunk":
        r"""Converts the OpenAI chunk to the Mistral format."""
        assert openai_chunk.get("type") == "image_url", openai_chunk

        image_url_dict = openai_chunk["image_url"]
        assert isinstance(image_url_dict, dict) and "url" in image_url_dict, image_url_dict

        url = image_url_dict["url"]
        if re.match(r"^data:image/\w+;base64,", url):  # Remove the prefix if it exists
            url = url.split(",")[1]

        return cls.model_validate({"image": url})

### `to_openai()`

Converts the chunk to the OpenAI format.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    131
    132
    133
    134

    def to_openai(self) -> dict[str, Any]:
        r"""Converts the chunk to the OpenAI format."""
        base64_image = self.model_dump(include={"image"}, context={"add_format_prefix": True})["image"]
        return {"type": "image_url", "image_url": {"url": base64_image}}

## `ImageURL(**data)`

Bases: `MistralBase`

Image URL or a base64 encoded image.

Attributes:

Name | Type | Description
--- | --- | ---
`url` | `str` | The URL of the image.
`detail` | `str | None` | The detail of the image.

Examples:

    >>> image_url = ImageURL(url="https://example.com/image.png")

Source code in `pydantic/main.py`

    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270

    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,
            )

## `ImageURLChunk(**data)`

Bases: `BaseContentChunk`

Image URL chunk.

Attributes:

Name | Type | Description
--- | --- | ---
`image_url` | `ImageURL | str` | The URL of the image or a base64 encoded image to be sent to the model.

Examples:

    >>> image_url_chunk = ImageURLChunk(image_url="data:image/png;base64,iVBORw0")

Source code in `pydantic/main.py`

    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270

    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,
            )

### `from_openai(openai_chunk)` `classmethod`

Converts the OpenAI chunk to the Mistral format.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    198
    199
    200
    201

    @classmethod
    def from_openai(cls, openai_chunk: dict[str, Any]) -> "ImageURLChunk":
        r"""Converts the OpenAI chunk to the Mistral format."""
        return cls.model_validate({"image_url": openai_chunk["image_url"]})

### `to_openai()`

Converts the chunk to the OpenAI format.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196

    def to_openai(self) -> dict[str, Any]:
        r"""Converts the chunk to the OpenAI format."""
        image_url_dict = {"url": self.get_url()}
        if isinstance(self.image_url, ImageURL) and self.image_url.detail is not None:
            image_url_dict["detail"] = self.image_url.detail

        out_dict: dict[str, Any] = {
            "type": "image_url",
            "image_url": image_url_dict,
        }
        return out_dict

## `RawAudio(**data)`

Bases: `MistralBase`

Deprecated: Use `str | bytes` directly. Will be removed in 1.13.0.

Source code in `pydantic/main.py`

    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270

    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,
            )

### `from_audio(audio)` `classmethod`

Create a RawAudio instance from an Audio object.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`audio` | `Audio` | An Audio object containing audio data, format, and duration. | required

Returns:

Type | Description
--- | ---
`RawAudio` | A RawAudio instance initialized with the audio data.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230

    @classmethod
    def from_audio(cls, audio: "Audio") -> "RawAudio":
        r"""Create a RawAudio instance from an Audio object.

        Args:
            audio: An Audio object containing audio data, format, and duration.

        Returns:
            A RawAudio instance initialized with the audio data.
        """
        format = audio.format
        data = audio.to_base64(format, False)
        return cls(data=data, format=format)

## `TextChunk(**data)`

Bases: `BaseContentChunk`

Text chunk.

Attributes:

Name | Type | Description
--- | --- | ---
`text` | `str` | The text to be sent to the model.

Examples:

    >>> text_chunk = TextChunk(text="Hello, how can I help you?")

Source code in `pydantic/main.py`

    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270

    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,
            )

### `from_openai(openai_chunk)` `classmethod`

Converts the OpenAI chunk to the Mistral format.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    432
    433
    434
    435

    @classmethod
    def from_openai(cls, openai_chunk: dict[str, Any]) -> "TextChunk":
        r"""Converts the OpenAI chunk to the Mistral format."""
        return cls.model_validate_ignore_extra(openai_chunk)

### `to_openai()`

Converts the chunk to the OpenAI format.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    428
    429
    430

    def to_openai(self) -> dict[str, Any]:
        r"""Converts the chunk to the OpenAI format."""
        return self.model_dump()

## `ThinkChunk(**data)`

Bases: `BaseContentChunk`

Thinking chunk.

Attributes:

Name | Type | Description
--- | --- | ---
`type` | `Literal[thinking]` | The type of the chunk, which is always ChunkTypes.thinking.
`thinking` | `str` | The list of text chunks of the thinking.
`closed` | `bool` | Whether the thinking chunk is closed or not.

Source code in `pydantic/main.py`

    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270

    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,
            )

### `from_openai(openai_chunk)` `classmethod`

Converts the OpenAI chunk to the Mistral format.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    455
    456
    457
    458

    @classmethod
    def from_openai(cls, openai_chunk: dict[str, Any]) -> "ThinkChunk":
        r"""Converts the OpenAI chunk to the Mistral format."""
        return cls.model_validate_ignore_extra(openai_chunk)

### `to_openai()`

Converts the chunk to the OpenAI format.

Source code in `src/mistral_common/protocol/instruct/chunk.py`

    451
    452
    453

    def to_openai(self) -> dict[str, Any]:
        r"""Converts the chunk to the OpenAI format."""
        return self.model_dump()