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 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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more