pub struct Prompt { /* private fields */ }Expand description
统一的 Prompt 表示 — 同时是 Builder。
Prompt::new() 创建空 Prompt,链式添加层后 build() 产出 Message::System。
简单文本通过 From<&str> / From<String> 自动转换。
§示例
use lellm_core::{Prompt, Message};
// 分层构建 — 最大化前缀缓存
let msg = Prompt::new()
.stable("核心身份…")
.stable("工具指南…")
.dynamic("会话上下文: …")
.build();
// 简单文本 — 自动转换
let msg: Message = Prompt::from("hello").build();Implementations§
Source§impl Prompt
impl Prompt
Sourcepub fn stable(self, text: impl Into<String>) -> Prompt
pub fn stable(self, text: impl Into<String>) -> Prompt
添加稳定层 — 内容不常变化,参与缓存前缀。
用于核心身份、工具指南、项目规则等。
最后一个 stable 层会自动获得 CacheControl::Breakpoint。
Sourcepub fn dynamic(self, text: impl Into<String>) -> Prompt
pub fn dynamic(self, text: impl Into<String>) -> Prompt
添加动态层 — 内容频繁变化,不参与缓存前缀。
用于会话上下文、临时注入信息等。
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