Add ability to attach rules as context (#29109)
Release Notes: - agent: Added support for adding rules as context.
This commit is contained in:
parent
3b31860d52
commit
7aa0fa1543
18 changed files with 694 additions and 112 deletions
|
@ -54,14 +54,14 @@ pub struct PromptMetadata {
|
|||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(tag = "kind")]
|
||||
pub enum PromptId {
|
||||
User { uuid: Uuid },
|
||||
User { uuid: UserPromptId },
|
||||
EditWorkflow,
|
||||
}
|
||||
|
||||
impl PromptId {
|
||||
pub fn new() -> PromptId {
|
||||
PromptId::User {
|
||||
uuid: Uuid::new_v4(),
|
||||
uuid: UserPromptId::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,22 @@ impl PromptId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct UserPromptId(pub Uuid);
|
||||
|
||||
impl UserPromptId {
|
||||
pub fn new() -> UserPromptId {
|
||||
UserPromptId(Uuid::new_v4())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Uuid> for UserPromptId {
|
||||
fn from(uuid: Uuid) -> Self {
|
||||
UserPromptId(uuid)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PromptStore {
|
||||
env: heed::Env,
|
||||
metadata_cache: RwLock<MetadataCache>,
|
||||
|
@ -212,7 +228,7 @@ impl PromptStore {
|
|||
|
||||
for (prompt_id_v1, metadata_v1) in metadata_v1 {
|
||||
let prompt_id_v2 = PromptId::User {
|
||||
uuid: prompt_id_v1.0,
|
||||
uuid: UserPromptId(prompt_id_v1.0),
|
||||
};
|
||||
let Some(body_v1) = bodies_v1.remove(&prompt_id_v1) else {
|
||||
continue;
|
||||
|
@ -257,6 +273,10 @@ impl PromptStore {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn all_prompt_metadata(&self) -> Vec<PromptMetadata> {
|
||||
self.metadata_cache.read().metadata.clone()
|
||||
}
|
||||
|
||||
pub fn default_prompt_metadata(&self) -> Vec<PromptMetadata> {
|
||||
return self
|
||||
.metadata_cache
|
||||
|
@ -314,7 +334,12 @@ impl PromptStore {
|
|||
Some(metadata.id)
|
||||
}
|
||||
|
||||
pub fn search(&self, query: String, cx: &App) -> Task<Vec<PromptMetadata>> {
|
||||
pub fn search(
|
||||
&self,
|
||||
query: String,
|
||||
cancellation_flag: Arc<AtomicBool>,
|
||||
cx: &App,
|
||||
) -> Task<Vec<PromptMetadata>> {
|
||||
let cached_metadata = self.metadata_cache.read().metadata.clone();
|
||||
let executor = cx.background_executor().clone();
|
||||
cx.background_spawn(async move {
|
||||
|
@ -333,7 +358,7 @@ impl PromptStore {
|
|||
&query,
|
||||
false,
|
||||
100,
|
||||
&AtomicBool::default(),
|
||||
&cancellation_flag,
|
||||
executor,
|
||||
)
|
||||
.await;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue