pub struct Message {
pub content: String,
pub images: Vec<ImageContent>,
pub audio: Vec<AudioContent>,
pub files: Vec<FileContent>,
pub message_type: MessageType,
pub name: Option<String>,
pub additional_kwargs: HashMap<String, Value>,
pub id: Option<String>,
pub tool_calls: Option<Vec<ToolCall>>,
}Expand description
Complete message structure for chat interactions.
Fields§
§content: String§images: Vec<ImageContent>图片内容(多模态 vision)
audio: Vec<AudioContent>音频内容(多模态 audio)
files: Vec<FileContent>文件内容(多模态 document)
message_type: MessageType§name: Option<String>§additional_kwargs: HashMap<String, Value>§id: Option<String>§tool_calls: Option<Vec<ToolCall>>Implementations§
Source§impl Message
impl Message
Sourcepub fn human_with_image(
content: impl Into<String>,
image_url: impl Into<String>,
) -> Self
pub fn human_with_image( content: impl Into<String>, image_url: impl Into<String>, ) -> Self
Creates a human message with an image (vision).
Sourcepub fn human_with_images(
content: impl Into<String>,
images: Vec<ImageContent>,
) -> Self
pub fn human_with_images( content: impl Into<String>, images: Vec<ImageContent>, ) -> Self
Creates a human message with multiple images.
Sourcepub fn human_with_audio(content: impl Into<String>, audio: AudioContent) -> Self
pub fn human_with_audio(content: impl Into<String>, audio: AudioContent) -> Self
Creates a human message with audio content.
Sourcepub fn human_with_file(content: impl Into<String>, file: FileContent) -> Self
pub fn human_with_file(content: impl Into<String>, file: FileContent) -> Self
Creates a human message with file content.
Sourcepub fn ai_with_tool_calls(
content: impl Into<String>,
tool_calls: Vec<ToolCall>,
) -> Self
pub fn ai_with_tool_calls( content: impl Into<String>, tool_calls: Vec<ToolCall>, ) -> Self
Creates an AI message with tool calls.
Sourcepub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
pub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
Creates a tool result message.
Sourcepub fn with_additional_kwarg(self, key: impl Into<String>, value: Value) -> Self
pub fn with_additional_kwarg(self, key: impl Into<String>, value: Value) -> Self
Adds an additional keyword argument.
Sourcepub fn with_image(self, image: ImageContent) -> Self
pub fn with_image(self, image: ImageContent) -> Self
Adds an image to the message (vision).
Sourcepub fn with_audio(self, audio: AudioContent) -> Self
pub fn with_audio(self, audio: AudioContent) -> Self
Adds audio content to the message.
Sourcepub fn with_file(self, file: FileContent) -> Self
pub fn with_file(self, file: FileContent) -> Self
Adds file content to the message.
Sourcepub fn has_images(&self) -> bool
pub fn has_images(&self) -> bool
Returns whether the message has images.
Sourcepub fn is_multimodal(&self) -> bool
pub fn is_multimodal(&self) -> bool
Returns whether the message has any multimodal content (images, audio, or files).
Sourcepub fn type_str(&self) -> String
pub fn type_str(&self) -> String
Returns the message type as a string.
Tool messages include their tool_call_id (e.g. "tool:call_123") so
the type string is unambiguous about which tool result the message holds.
Sourcepub fn has_tool_calls(&self) -> bool
pub fn has_tool_calls(&self) -> bool
Returns whether the message has tool calls.
Sourcepub fn get_tool_calls(&self) -> Option<&[ToolCall]>
pub fn get_tool_calls(&self) -> Option<&[ToolCall]>
Returns the tool calls if present.