pub struct Prompt { /* private fields */ }Expand description
统一的 Prompt 表示。
内部始终为分层结构,即使是简单文本也会转换为单层。
这保证了 API 的一致性——无论用户传入 &str 还是 PromptBuilder 的结果,
框架内部处理路径完全相同。
§示例
use lellm_core::{Prompt, PromptBuilder, CacheControl};
// 简单文本 — 自动转换
let simple: Prompt = "You are a helpful assistant.".into();
// 分层构建 — 最大化前缀缓存
let layered = Prompt::builder()
.layer_cached("核心身份…") // 永不变化
.layer_cached("工具指南…") // 极少变化
.layer_dynamic("会话上下文: …") // 每轮变化
.build();
// 合并为纯文本(用于不支持 cache_control 的 Provider)
let text = layered.build_text();Implementations§
Source§impl Prompt
impl Prompt
Sourcepub fn builder() -> PromptBuilder
pub fn builder() -> PromptBuilder
创建分层构建器。
Sourcepub fn to_content_blocks(&self) -> Vec<ContentBlock>
pub fn to_content_blocks(&self) -> Vec<ContentBlock>
将 Prompt 转换为带 cache_control 的 Vec<ContentBlock>。
供框架内部构建 Message::System 使用。
Sourcepub fn build_text(&self) -> String
pub fn build_text(&self) -> String
合并所有层为纯文本,层之间以 \n\n 分隔。
用于不支持 cache_control 的 Provider(如 OpenAI、Google)。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Prompt
impl RefUnwindSafe for Prompt
impl Send for Prompt
impl Sync for Prompt
impl Unpin for Prompt
impl UnsafeUnpin for Prompt
impl UnwindSafe for Prompt
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