pub struct Message {
pub role: Role,
pub content: Vec<MessageBlock>,
pub name: Option<String>,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
pub reasoning_content: Option<String>,
pub reasoning: Option<String>,
pub thought: Option<String>,
pub thinking: Option<String>,
}Expand description
A message in the conversation
Fields§
§role: RoleRole of the message sender
content: Vec<MessageBlock>Content of the message (supports multi-modal content)
Can contain text, images, and other content blocks
name: Option<String>Name of the message sender (optional)
tool_calls: Option<Vec<ToolCall>>Tool calls made by the assistant
tool_call_id: Option<String>Tool call ID (for tool responses)
reasoning_content: Option<String>Provider-specific reasoning content (GLM 风格)
reasoning: Option<String>Provider-specific reasoning (Qwen/DeepSeek/OpenAI o1 通用键)
thought: Option<String>Provider-specific thought (OpenAI o1 键)
thinking: Option<String>Provider-specific thinking (Anthropic 键)
Implementations§
Source§impl Message
impl Message
Sourcepub fn text(role: Role, text: impl Into<String>) -> Self
pub fn text(role: Role, text: impl Into<String>) -> Self
Create a new message with text content
§Example
use llm_connector::types::{Message, Role};
let message = Message::text(Role::User, "Hello, world!");Sourcepub fn new(role: Role, content: Vec<MessageBlock>) -> Self
pub fn new(role: Role, content: Vec<MessageBlock>) -> Self
Create a new message with multi-modal content
§Example
use llm_connector::types::{Message, Role, MessageBlock};
let message = Message::new(
Role::User,
vec![
MessageBlock::text("What's in this image?"),
MessageBlock::image_url("https://example.com/image.jpg"),
],
);Sourcepub fn reasoning_any(&self) -> Option<&str>
pub fn reasoning_any(&self) -> Option<&str>
Convenience: get the first available reasoning-like content
Sourcepub fn content_as_text(&self) -> String
pub fn content_as_text(&self) -> String
Extract all text content from message blocks
Joins multiple text blocks with newlines
Sourcepub fn is_text_only(&self) -> bool
pub fn is_text_only(&self) -> bool
Check if message contains only text (no images or other media)
Sourcepub fn has_images(&self) -> bool
pub fn has_images(&self) -> bool
Check if message contains any images
Sourcepub fn populate_reasoning_from_json(&mut self, raw: &Value)
pub fn populate_reasoning_from_json(&mut self, raw: &Value)
Provider-agnostic post-processor: populate reasoning synonyms from raw JSON Scans nested JSON objects/arrays and fills each synonym field if present.
Sourcepub fn tool(content: impl Into<String>, tool_call_id: impl Into<String>) -> Self
pub fn tool(content: impl Into<String>, tool_call_id: impl Into<String>) -> Self
Create a tool response message
Sourcepub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
pub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
Set tool calls for assistant messages