pub struct ChatMessage {
pub role: Role,
pub content: Option<MessageContent>,
pub name: Option<String>,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
}Expand description
聊天消息
Fields§
§role: Role消息角色
content: Option<MessageContent>消息内容(可以是字符串或多部分内容)
name: Option<String>消息名称(用于区分多个相同角色的消息)
tool_calls: Option<Vec<ToolCall>>工具调用列表(仅 assistant 角色)
tool_call_id: Option<String>工具调用 ID(仅 tool 角色)
Implementations§
Source§impl ChatMessage
impl ChatMessage
Sourcepub fn system(content: impl Into<String>) -> ChatMessage
pub fn system(content: impl Into<String>) -> ChatMessage
创建系统消息
Sourcepub fn user(content: impl Into<String>) -> ChatMessage
pub fn user(content: impl Into<String>) -> ChatMessage
创建用户消息
Sourcepub fn user_with_content(content: MessageContent) -> ChatMessage
pub fn user_with_content(content: MessageContent) -> ChatMessage
创建用户消息(结构化内容)
Sourcepub fn user_with_parts(parts: Vec<ContentPart>) -> ChatMessage
pub fn user_with_parts(parts: Vec<ContentPart>) -> ChatMessage
创建用户消息(多部分内容)
Sourcepub fn assistant(content: impl Into<String>) -> ChatMessage
pub fn assistant(content: impl Into<String>) -> ChatMessage
创建助手消息
Sourcepub fn assistant_with_tool_calls(tool_calls: Vec<ToolCall>) -> ChatMessage
pub fn assistant_with_tool_calls(tool_calls: Vec<ToolCall>) -> ChatMessage
创建带工具调用的助手消息
Sourcepub fn tool_result(
tool_call_id: impl Into<String>,
content: impl Into<String>,
) -> ChatMessage
pub fn tool_result( tool_call_id: impl Into<String>, content: impl Into<String>, ) -> ChatMessage
创建工具结果消息
Sourcepub fn user_with_image(
text: impl Into<String>,
image_url: impl Into<String>,
) -> ChatMessage
pub fn user_with_image( text: impl Into<String>, image_url: impl Into<String>, ) -> ChatMessage
创建带图片的用户消息
Sourcepub fn text_content(&self) -> Option<&str>
pub fn text_content(&self) -> Option<&str>
获取文本内容
Trait Implementations§
Source§impl Clone for ChatMessage
impl Clone for ChatMessage
Source§fn clone(&self) -> ChatMessage
fn clone(&self) -> ChatMessage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ChatMessage
impl Debug for ChatMessage
Source§impl<'de> Deserialize<'de> for ChatMessage
impl<'de> Deserialize<'de> for ChatMessage
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ChatMessage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ChatMessage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for ChatMessage
impl Serialize for ChatMessage
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for ChatMessage
impl RefUnwindSafe for ChatMessage
impl Send for ChatMessage
impl Sync for ChatMessage
impl Unpin for ChatMessage
impl UnsafeUnpin for ChatMessage
impl UnwindSafe for ChatMessage
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage