pub enum OpenAIContentPart {
Text {
text: String,
},
ImageUrl {
image_url: OpenAIImageUrl,
},
}Expand description
A single content part in an OpenAI message.
Can be either text or an image URL. This is a tagged enum that prevents invalid states (e.g., having both text and image_url, or neither).
Variants§
Text
Text content part
ImageUrl
Image URL content part
Fields
image_url: OpenAIImageUrlThe image URL details
Implementations§
Source§impl OpenAIContentPart
impl OpenAIContentPart
Sourcepub fn text(text: impl Into<String>) -> Self
pub fn text(text: impl Into<String>) -> Self
Creates a text content part.
§Example
use open_agent::OpenAIContentPart;
let part = OpenAIContentPart::text("Hello world");Sourcepub fn from_image(image: &ImageBlock) -> Self
pub fn from_image(image: &ImageBlock) -> Self
Creates an image content part from a validated ImageBlock.
This is the preferred way to create image content parts as it ensures the image URL has been validated against security issues (XSS, file disclosure, etc.)
§Example
use open_agent::{OpenAIContentPart, ImageBlock, ImageDetail};
let image = ImageBlock::from_url("https://example.com/img.jpg")
.expect("Valid URL");
let part = OpenAIContentPart::from_image(&image);Sourcepub fn image_url(url: impl Into<String>, detail: ImageDetail) -> Self
👎Deprecated since 0.6.0: Use from_image() instead to ensure proper validation
pub fn image_url(url: impl Into<String>, detail: ImageDetail) -> Self
from_image() instead to ensure proper validationCreates an image URL content part directly (DEPRECATED).
§Security Warning
This method bypasses validation checks performed by ImageBlock::from_url()
and ImageBlock::from_base64(). Prefer using from_image() instead.
§Deprecation
This method is deprecated and will be removed in v1.0. Use from_image() instead.
§Example
use open_agent::{OpenAIContentPart, ImageDetail};
// Deprecated approach:
let part = OpenAIContentPart::image_url("https://example.com/img.jpg", ImageDetail::High);
// Preferred approach:
use open_agent::ImageBlock;
let image = ImageBlock::from_url("https://example.com/img.jpg").expect("Valid URL");
let part = OpenAIContentPart::from_image(&image);Trait Implementations§
Source§impl Clone for OpenAIContentPart
impl Clone for OpenAIContentPart
Source§fn clone(&self) -> OpenAIContentPart
fn clone(&self) -> OpenAIContentPart
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more