mistral_common.protocol.instruct.messages
AssistantMessage(**data)
Bases: BaseMessage
Assistant message.
Attributes:
Name | Type | Description |
---|---|---|
role |
Literal[assistant]
|
The role of the message. |
content |
Optional[str]
|
The content of the message. |
tool_calls |
Optional[List[ToolCall]]
|
The tool calls of the message. |
prefix |
bool
|
Whether the message is a prefix. |
Examples:
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
from_openai(openai_message)
classmethod
Converts the OpenAI message to the Mistral format.
Source code in src/mistral_common/protocol/instruct/messages.py
to_openai()
Converts the message to the OpenAI format.
Source code in src/mistral_common/protocol/instruct/messages.py
AudioChunk(**data)
Bases: BaseContentChunk
Audio chunk containing raw audio data.
This class represents a chunk of audio data that can be used as input.
Attributes:
Name | Type | Description |
---|---|---|
type |
Literal[input_audio]
|
The type of the chunk, which is always ChunkTypes.input_audio. |
input_audio |
RawAudio
|
The RawAudio object containing the audio data. |
Examples:
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
from_audio(audio)
classmethod
Creates 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/messages.py
from_openai(openai_chunk)
classmethod
Converts the OpenAI chunk to the Mistral format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
openai_chunk
|
Dict[str, Union[str, Dict[str, str]]]
|
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/messages.py
to_openai()
Converts the chunk to the OpenAI format.
Returns:
Type | Description |
---|---|
Dict[str, Union[str, Dict[str, str]]]
|
A dictionary representing the audio chunk in the OpenAI format. |
Source code in src/mistral_common/protocol/instruct/messages.py
AudioURL(**data)
Bases: MistralBase
Audio URL.
Attributes:
Name | Type | Description |
---|---|---|
url |
str
|
The URL of the audio file. |
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
AudioURLChunk(**data)
Bases: BaseContentChunk
Audio URL chunk.
Attributes:
Name | Type | Description |
---|---|---|
type |
Literal[audio_url]
|
The type of the chunk, which is always |
audio_url |
Union[str, AudioURL]
|
The URL of the audio file. |
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
from_openai(openai_chunk)
classmethod
Converts the OpenAI chunk to the Mistral format.
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/messages.py
to_openai()
Converts the chunk to the OpenAI format.
Source code in src/mistral_common/protocol/instruct/messages.py
AudioURLType
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]
|
The type of the chunk. |
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
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/messages.py
to_openai()
Converts the chunk to the OpenAI format.
Should be implemented by subclasses.
Source code in src/mistral_common/protocol/instruct/messages.py
BaseMessage(**data)
Bases: MistralBase
Base class for all messages.
Attributes:
Name | Type | Description |
---|---|---|
role |
Literal[system, user, assistant, tool]
|
The role of the message. |
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
from_openai(openai_message)
classmethod
Converts the OpenAI message to the Mistral format.
Should be implemented by subclasses.
Source code in src/mistral_common/protocol/instruct/messages.py
to_openai()
Converts the message to the OpenAI format.
Should be implemented by subclasses.
Source code in src/mistral_common/protocol/instruct/messages.py
ChunkTypes
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.messages import ChunkTypes
>>> chunk_type = ChunkTypes.text
FinetuningAssistantMessage(**data)
Bases: AssistantMessage
Assistant message for finetuning.
Attributes:
Name | Type | Description |
---|---|---|
weight |
Optional[float]
|
The weight of the message to train on. |
Examples:
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
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 .venv/lib/python3.13/site-packages/pydantic/main.py
from_openai(openai_chunk)
classmethod
Converts the OpenAI chunk to the Mistral format.
Source code in src/mistral_common/protocol/instruct/messages.py
to_openai()
Converts the chunk to the OpenAI format.
Source code in src/mistral_common/protocol/instruct/messages.py
ImageURL(**data)
Bases: MistralBase
Image URL or a base64 encoded image.
Attributes:
Name | Type | Description |
---|---|---|
url |
str
|
The URL of the image. |
detail |
Optional[str]
|
The detail of the image. |
Examples:
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
ImageURLChunk(**data)
Bases: BaseContentChunk
Image URL chunk.
Attributes:
Name | Type | Description |
---|---|---|
image_url |
Union[ImageURL, str]
|
The URL of the image or a base64 encoded image to be sent to the model. |
Examples:
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
from_openai(openai_chunk)
classmethod
Converts the OpenAI chunk to the Mistral format.
Source code in src/mistral_common/protocol/instruct/messages.py
to_openai()
Converts the chunk to the OpenAI format.
Source code in src/mistral_common/protocol/instruct/messages.py
RawAudio(**data)
Bases: MistralBase
Base64 encoded audio data.
This class represents raw audio data encoded in base64 format.
Attributes:
Name | Type | Description |
---|---|---|
data |
Union[str, bytes]
|
The base64 encoded audio data, which can be a string or bytes. |
format |
str
|
The format of the audio data. |
Examples:
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
from_audio(audio)
classmethod
Creates 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
|
An AudioChunk instance initialized with the audio data. |
Source code in src/mistral_common/protocol/instruct/messages.py
Roles
SystemMessage(**data)
Bases: BaseMessage
System message.
Attributes:
Name | Type | Description |
---|---|---|
content |
str
|
The content of the message. |
Examples:
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
from_openai(openai_message)
classmethod
Converts the OpenAI message to the Mistral format.
Source code in src/mistral_common/protocol/instruct/messages.py
TextChunk(**data)
Bases: BaseContentChunk
Text chunk.
Attributes:
Name | Type | Description |
---|---|---|
text |
str
|
The text to be sent to the model. |
Examples:
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
from_openai(openai_chunk)
classmethod
Converts the OpenAI chunk to the Mistral format.
ToolMessage(**data)
Bases: BaseMessage
Tool message.
Attributes:
Name | Type | Description |
---|---|---|
content |
str
|
The content of the message. |
tool_call_id |
Optional[str]
|
The tool call id of the message. |
name |
Optional[str]
|
The name of the tool. (Deprecated in V3 tokenization) |
Examples:
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
from_openai(messages)
classmethod
Converts the OpenAI message to the Mistral format.
Source code in src/mistral_common/protocol/instruct/messages.py
to_openai()
Converts the message to the OpenAI format.
Source code in src/mistral_common/protocol/instruct/messages.py
UserMessage(**data)
Bases: BaseMessage
User message.
Attributes:
Name | Type | Description |
---|---|---|
content |
Union[str, List[ContentChunk]]
|
The content of the message. |
Examples:
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
from_openai(openai_message)
classmethod
Converts the OpenAI message to the Mistral format.
Source code in src/mistral_common/protocol/instruct/messages.py
to_openai()
Converts the message to the OpenAI format.