pub struct InMemoryPromptStore { /* private fields */ }Expand description
内存 Prompt 存储
线程安全的内存存储实现,适用于:
- 开发和测试环境
- 不需要持久化的场景
- 与预置模板库配合使用
§示例
ⓘ
use mofa_foundation::prompt::{InMemoryPromptStore, PromptEntity, PromptTemplate};
let store = InMemoryPromptStore::new();
// 保存模板
let template = PromptTemplate::new("greeting")
.with_content("Hello, {name}!");
let entity = PromptEntity::from_template(&template);
store.save_template(&entity).await?;
// 查询模板
let found = store.get_template("greeting").await?;Implementations§
Source§impl InMemoryPromptStore
impl InMemoryPromptStore
Sourcepub fn new() -> InMemoryPromptStore
pub fn new() -> InMemoryPromptStore
创建新的内存存储
创建共享实例
Sourcepub fn template_count(&self) -> usize
pub fn template_count(&self) -> usize
获取模板数量
Trait Implementations§
Source§impl Default for InMemoryPromptStore
impl Default for InMemoryPromptStore
Source§fn default() -> InMemoryPromptStore
fn default() -> InMemoryPromptStore
Returns the “default value” for a type. Read more
Source§impl PromptStore for InMemoryPromptStore
impl PromptStore for InMemoryPromptStore
Source§fn save_template<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 PromptEntity,
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn save_template<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 PromptEntity,
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
保存模板
Source§fn get_template_by_id<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Option<PromptEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn get_template_by_id<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<Option<PromptEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
InMemoryPromptStore: 'async_trait,
获取模板(按 UUID)
Source§fn get_template<'life0, 'life1, 'async_trait>(
&'life0 self,
template_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<PromptEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn get_template<'life0, 'life1, 'async_trait>(
&'life0 self,
template_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<PromptEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
获取模板(按模板 ID)
Source§fn query_templates<'life0, 'life1, 'async_trait>(
&'life0 self,
filter: &'life1 PromptFilter,
) -> Pin<Box<dyn Future<Output = Result<Vec<PromptEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn query_templates<'life0, 'life1, 'async_trait>(
&'life0 self,
filter: &'life1 PromptFilter,
) -> Pin<Box<dyn Future<Output = Result<Vec<PromptEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
查询模板列表
Source§fn find_by_tag<'life0, 'life1, 'async_trait>(
&'life0 self,
tag: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<PromptEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn find_by_tag<'life0, 'life1, 'async_trait>(
&'life0 self,
tag: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<PromptEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
按标签查找模板
Source§fn search_templates<'life0, 'life1, 'async_trait>(
&'life0 self,
keyword: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<PromptEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn search_templates<'life0, 'life1, 'async_trait>(
&'life0 self,
keyword: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<PromptEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
搜索模板
Source§fn update_template<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 PromptEntity,
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn update_template<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 PromptEntity,
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
更新模板
Source§fn delete_template_by_id<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<bool, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn delete_template_by_id<'life0, 'async_trait>(
&'life0 self,
id: Uuid,
) -> Pin<Box<dyn Future<Output = Result<bool, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
InMemoryPromptStore: 'async_trait,
删除模板(按 UUID)
Source§fn delete_template<'life0, 'life1, 'async_trait>(
&'life0 self,
template_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn delete_template<'life0, 'life1, 'async_trait>(
&'life0 self,
template_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
删除模板(按模板 ID)
Source§fn set_template_enabled<'life0, 'life1, 'async_trait>(
&'life0 self,
template_id: &'life1 str,
enabled: bool,
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn set_template_enabled<'life0, 'life1, 'async_trait>(
&'life0 self,
template_id: &'life1 str,
enabled: bool,
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
启用/禁用模板
Source§fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
template_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
template_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
检查模板是否存在
Source§fn count<'life0, 'life1, 'async_trait>(
&'life0 self,
filter: &'life1 PromptFilter,
) -> Pin<Box<dyn Future<Output = Result<i64, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn count<'life0, 'life1, 'async_trait>(
&'life0 self,
filter: &'life1 PromptFilter,
) -> Pin<Box<dyn Future<Output = Result<i64, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
统计模板数量
获取所有标签
Source§fn save_composition<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 PromptCompositionEntity,
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn save_composition<'life0, 'life1, 'async_trait>(
&'life0 self,
entity: &'life1 PromptCompositionEntity,
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
保存组合
Source§fn get_composition<'life0, 'life1, 'async_trait>(
&'life0 self,
composition_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<PromptCompositionEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn get_composition<'life0, 'life1, 'async_trait>(
&'life0 self,
composition_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<PromptCompositionEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
获取组合
Source§fn query_compositions<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<PromptCompositionEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn query_compositions<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<PromptCompositionEntity>, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
InMemoryPromptStore: 'async_trait,
查询所有组合
Source§fn delete_composition<'life0, 'life1, 'async_trait>(
&'life0 self,
composition_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
fn delete_composition<'life0, 'life1, 'async_trait>(
&'life0 self,
composition_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
InMemoryPromptStore: 'async_trait,
删除组合
Source§fn save_templates<'life0, 'life1, 'async_trait>(
&'life0 self,
entities: &'life1 [PromptEntity],
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn save_templates<'life0, 'life1, 'async_trait>(
&'life0 self,
entities: &'life1 [PromptEntity],
) -> Pin<Box<dyn Future<Output = Result<(), PromptError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
批量保存模板
Auto Trait Implementations§
impl !Freeze for InMemoryPromptStore
impl RefUnwindSafe for InMemoryPromptStore
impl Send for InMemoryPromptStore
impl Sync for InMemoryPromptStore
impl Unpin for InMemoryPromptStore
impl UnsafeUnpin for InMemoryPromptStore
impl UnwindSafe for InMemoryPromptStore
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage