Skip to main content

Message

Struct Message 

Source
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>

消息 ID(可选)

§tool_calls: Option<Vec<ToolCall>>

工具调用列表(可选)

Implementations§

Source§

impl Message

Source

pub fn system(content: impl Into<String>) -> Self

Creates a system message.

Source

pub fn human(content: impl Into<String>) -> Self

Creates a human (user) message.

Source

pub fn human_with_image( content: impl Into<String>, image_url: impl Into<String>, ) -> Self

Creates a human message with an image (vision).

Source

pub fn human_with_images( content: impl Into<String>, images: Vec<ImageContent>, ) -> Self

Creates a human message with multiple images.

Source

pub fn human_with_audio(content: impl Into<String>, audio: AudioContent) -> Self

Creates a human message with audio content.

Source

pub fn human_with_file(content: impl Into<String>, file: FileContent) -> Self

Creates a human message with file content.

Source

pub fn ai(content: impl Into<String>) -> Self

Creates an AI (assistant) message.

Source

pub fn ai_with_tool_calls( content: impl Into<String>, tool_calls: Vec<ToolCall>, ) -> Self

Creates an AI message with tool calls.

Source

pub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self

Creates a tool result message.

Source

pub fn with_name(self, name: impl Into<String>) -> Self

Sets the message name.

Source

pub fn with_id(self, id: impl Into<String>) -> Self

Sets the message ID.

Source

pub fn with_additional_kwarg(self, key: impl Into<String>, value: Value) -> Self

Adds an additional keyword argument.

Source

pub fn with_image(self, image: ImageContent) -> Self

Adds an image to the message (vision).

Source

pub fn with_audio(self, audio: AudioContent) -> Self

Adds audio content to the message.

Source

pub fn with_file(self, file: FileContent) -> Self

Adds file content to the message.

Source

pub fn has_images(&self) -> bool

Returns whether the message has images.

Source

pub fn has_audio(&self) -> bool

Returns whether the message has audio content.

Source

pub fn has_files(&self) -> bool

Returns whether the message has file content.

Source

pub fn is_multimodal(&self) -> bool

Returns whether the message has any multimodal content (images, audio, or files).

Source

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.

Source

pub fn has_tool_calls(&self) -> bool

Returns whether the message has tool calls.

Source

pub fn get_tool_calls(&self) -> Option<&[ToolCall]>

Returns the tool calls if present.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Message

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Message

Source§

fn eq(&self, other: &Message) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Message

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.