pub enum ContentBlock {
Text(TextBlock),
Thinking(ThinkingBlock),
Image {
source: ImageSource,
},
ToolCall(ToolCall),
}Expand description
内容块 — Message 和 ChatResponse 的基本组成单元。 核心层极简,无 provider 特有标记。
Variants§
Implementations§
Source§impl ContentBlock
impl ContentBlock
Sourcepub fn text_with_cache(s: String, cache: CacheControl) -> Self
pub fn text_with_cache(s: String, cache: CacheControl) -> Self
创建带缓存标记的文本块。
pub fn as_text(&self) -> Option<&str>
Sourcepub fn flatten_text(blocks: &[ContentBlock]) -> String
pub fn flatten_text(blocks: &[ContentBlock]) -> String
将多个 ContentBlock 拼接为纯文本,忽略非 Text 类型和 cache_control。
用于不支持 cache_control 的 Provider(OpenAI、Google)。
所有 Provider 共享同一份实现,避免各自拼接。
分隔符为 \n\n,与 Anthropic 块之间的隐式换行行为一致。
Trait Implementations§
Source§impl Clone for ContentBlock
impl Clone for ContentBlock
Source§fn clone(&self) -> ContentBlock
fn clone(&self) -> ContentBlock
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 ContentBlock
impl Debug for ContentBlock
Source§impl<'de> Deserialize<'de> for ContentBlock
impl<'de> Deserialize<'de> for ContentBlock
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 PartialEq for ContentBlock
impl PartialEq for ContentBlock
Source§fn eq(&self, other: &ContentBlock) -> bool
fn eq(&self, other: &ContentBlock) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for ContentBlock
impl Serialize for ContentBlock
impl StructuralPartialEq for ContentBlock
Auto Trait Implementations§
impl Freeze for ContentBlock
impl RefUnwindSafe for ContentBlock
impl Send for ContentBlock
impl Sync for ContentBlock
impl Unpin for ContentBlock
impl UnsafeUnpin for ContentBlock
impl UnwindSafe for ContentBlock
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