pub struct Message {
pub role: MessageRole,
pub content: String,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
}
Expand description
Universal message structure
Fields§
§role: MessageRole
§content: String
§tool_calls: Option<Vec<ToolCall>>
§tool_call_id: Option<String>
Implementations§
Source§impl Message
impl Message
Sourcepub fn assistant_with_tools(content: String, tool_calls: Vec<ToolCall>) -> Self
pub fn assistant_with_tools(content: String, tool_calls: Vec<ToolCall>) -> Self
Create an assistant message with tool calls Based on OpenAI Cookbook patterns for function calling
Sourcepub fn tool_response(tool_call_id: String, content: String) -> Self
pub fn tool_response(tool_call_id: String, content: String) -> Self
Create a tool response message This follows the exact pattern from OpenAI Cookbook:
{
"role": "tool",
"tool_call_id": "call_123",
"content": "Function result"
}
Sourcepub fn tool_response_with_name(
tool_call_id: String,
_function_name: String,
content: String,
) -> Self
pub fn tool_response_with_name( tool_call_id: String, _function_name: String, content: String, ) -> Self
Create a tool response message with function name (for compatibility) Some providers might need the function name in addition to tool_call_id
Sourcepub fn validate_for_provider(&self, provider: &str) -> Result<(), String>
pub fn validate_for_provider(&self, provider: &str) -> Result<(), String>
Validate this message for a specific provider Based on official API documentation constraints
Sourcepub fn has_tool_calls(&self) -> bool
pub fn has_tool_calls(&self) -> bool
Check if this message has tool calls
Sourcepub fn get_tool_calls(&self) -> Option<&[ToolCall]>
pub fn get_tool_calls(&self) -> Option<&[ToolCall]>
Get the tool calls if present
Sourcepub fn is_tool_response(&self) -> bool
pub fn is_tool_response(&self) -> bool
Check if this is a tool response message
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
Source§impl From<&Message> for SessionMessage
impl From<&Message> for SessionMessage
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin 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
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 more