pub enum ContentPart {
Text(TextContentPart),
Image(ImageContentPart),
ImageFile(ImageFileContentPart),
File(FileContentPart),
ToolCall(ToolCallContentPart),
ToolResult(ToolResultContentPart),
Reasoning(ReasoningContentPart),
}Expand description
A part of message content - can be text, image, image_file, tool_call, or tool_result
This is the canonical content part type used across the system. API layer enables the “openapi” feature to add ToSchema derive.
Variants§
Text(TextContentPart)
Text content
Image(ImageContentPart)
Image content (base64 or URL)
ImageFile(ImageFileContentPart)
Image file content (reference to uploaded image by ID)
File(FileContentPart)
File content (reference to uploaded file, e.g. PDF, by ID)
ToolCall(ToolCallContentPart)
Tool call content (assistant requesting tool execution)
ToolResult(ToolResultContentPart)
Tool result content (result of tool execution)
Reasoning(ReasoningContentPart)
Provider reasoning artifact, ordered against the text and tool calls it was interleaved with.
Implementations§
Source§impl ContentPart
impl ContentPart
Sourcepub fn tool_result_text(value: &Value) -> Self
pub fn tool_result_text(value: &Value) -> Self
Convert a JSON tool result into text without JSON-quoting string values. Structured values retain their JSON representation for transport and details views.
Sourcepub fn image_file(image_id: ImageId) -> Self
pub fn image_file(image_id: ImageId) -> Self
Create an image file content part (reference to uploaded image)
Sourcepub fn file(file_id: FileId) -> Self
pub fn file(file_id: FileId) -> Self
Create a generic file content part (reference to an uploaded file).
Sourcepub fn tool_call(
id: impl Into<String>,
name: impl Into<String>,
arguments: Value,
) -> Self
pub fn tool_call( id: impl Into<String>, name: impl Into<String>, arguments: Value, ) -> Self
Create a tool call content part
Sourcepub fn tool_result(
tool_call_id: impl Into<String>,
result: Option<Value>,
error: Option<String>,
) -> Self
pub fn tool_result( tool_call_id: impl Into<String>, result: Option<Value>, error: Option<String>, ) -> Self
Create a tool result content part
Sourcepub fn reasoning(part: ReasoningContentPart) -> Self
pub fn reasoning(part: ReasoningContentPart) -> Self
Create a reasoning content part
Sourcepub fn as_reasoning(&self) -> Option<&ReasoningContentPart>
pub fn as_reasoning(&self) -> Option<&ReasoningContentPart>
Get the reasoning artifact if this is a reasoning part
Sourcepub fn is_reasoning(&self) -> bool
pub fn is_reasoning(&self) -> bool
Whether this part is a reasoning artifact.
Sourcepub fn is_image_file(&self) -> bool
pub fn is_image_file(&self) -> bool
Check if this is an ImageFile part
Sourcepub fn content_type(&self) -> ContentType
pub fn content_type(&self) -> ContentType
Get the content type
Sourcepub fn to_openai_format(&self) -> Option<Value>
pub fn to_openai_format(&self) -> Option<Value>
Convert content part to OpenAI-compatible format
Returns None for content types that aren’t valid in user/system messages
(ImageFile, ToolCall, ToolResult are handled at message level).
Trait Implementations§
Source§impl Clone for ContentPart
impl Clone for ContentPart
Source§fn clone(&self) -> ContentPart
fn clone(&self) -> ContentPart
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more