-
Notifications
You must be signed in to change notification settings - Fork 19
(feat) Add initial documentation and prompt management API #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DarkStarStrix
wants to merge
3
commits into
llmkit-ai:master
Choose a base branch
from
DarkStarStrix:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
b98f410
(feat) Add initial documentation and prompt management API
DarkStarStrix a323c7d
(feat) Add prompt_directories and prompt_components tables with direc…
DarkStarStrix 3936f44
(feat) Implement CRUD operations for prompt directories and components
DarkStarStrix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -557,6 +557,152 @@ impl PromptRepository { | |
| // Return the updated prompt | ||
| self.get_prompt(prompt_id).await | ||
| } | ||
|
|
||
| // --- Prompt Directory CRUD --- | ||
| pub async fn create_directory(&self, name: &str, parent_id: Option<i64>) -> Result<i64> { | ||
| let rec = sqlx::query!( | ||
| r#"INSERT INTO prompt_directory (name, parent_id) VALUES (?, ?)"#, | ||
| name, | ||
| parent_id | ||
| ) | ||
| .execute(&self.pool) | ||
| .await?; | ||
| Ok(rec.last_insert_rowid()) | ||
| } | ||
|
|
||
| pub async fn get_directory(&self, id: i64) -> Result<Option<PromptDirectory>> { | ||
| let rec = sqlx::query_as!(PromptDirectory, | ||
| r#"SELECT id, name, parent_id, created_at, updated_at FROM prompt_directory WHERE id = ?"#, | ||
| id | ||
| ) | ||
| .fetch_optional(&self.pool) | ||
| .await?; | ||
| Ok(rec) | ||
| } | ||
|
|
||
| pub async fn list_directories(&self, parent_id: Option<i64>) -> Result<Vec<PromptDirectory>> { | ||
| let recs = sqlx::query_as!(PromptDirectory, | ||
| r#"SELECT id, name, parent_id, created_at, updated_at FROM prompt_directory WHERE parent_id IS ?"#, | ||
| parent_id | ||
| ) | ||
| .fetch_all(&self.pool) | ||
| .await?; | ||
| Ok(recs) | ||
| } | ||
|
|
||
| pub async fn update_directory(&self, id: i64, name: &str, parent_id: Option<i64>) -> Result<bool> { | ||
| let rows = sqlx::query!( | ||
| r#"UPDATE prompt_directory SET name = ?, parent_id = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?"#, | ||
| name, parent_id, id | ||
| ) | ||
| .execute(&self.pool) | ||
| .await? | ||
| .rows_affected(); | ||
| Ok(rows > 0) | ||
| } | ||
|
|
||
| pub async fn delete_directory(&self, id: i64) -> Result<bool> { | ||
| let rows = sqlx::query!( | ||
| r#"DELETE FROM prompt_directory WHERE id = ?"#, | ||
| id | ||
| ) | ||
| .execute(&self.pool) | ||
| .await? | ||
| .rows_affected(); | ||
| Ok(rows > 0) | ||
| } | ||
|
|
||
| // --- Prompt Component CRUD --- | ||
| pub async fn create_component(&self, name: &str, content: &str, description: Option<&str>) -> Result<i64> { | ||
|
||
| let rec = sqlx::query!( | ||
| r#"INSERT INTO prompt_component (name, content, description) VALUES (?, ?, ?)"#, | ||
| name, content, description | ||
| ) | ||
| .execute(&self.pool) | ||
| .await?; | ||
| Ok(rec.last_insert_rowid()) | ||
| } | ||
|
|
||
| pub async fn get_component(&self, id: i64) -> Result<Option<PromptComponent>> { | ||
| let rec = sqlx::query_as!(PromptComponent, | ||
| r#"SELECT id, name, content, description, created_at, updated_at FROM prompt_component WHERE id = ?"#, | ||
| id | ||
| ) | ||
| .fetch_optional(&self.pool) | ||
| .await?; | ||
| Ok(rec) | ||
| } | ||
|
|
||
| pub async fn list_components(&self) -> Result<Vec<PromptComponent>> { | ||
| let recs = sqlx::query_as!(PromptComponent, | ||
| r#"SELECT id, name, content, description, created_at, updated_at FROM prompt_component ORDER BY created_at DESC"# | ||
| ) | ||
| .fetch_all(&self.pool) | ||
| .await?; | ||
| Ok(recs) | ||
| } | ||
|
|
||
| pub async fn update_component(&self, id: i64, name: &str, content: &str, description: Option<&str>) -> Result<bool> { | ||
| let rows = sqlx::query!( | ||
| r#"UPDATE prompt_component SET name = ?, content = ?, description = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?"#, | ||
| name, content, description, id | ||
| ) | ||
| .execute(&self.pool) | ||
| .await? | ||
| .rows_affected(); | ||
| Ok(rows > 0) | ||
| } | ||
|
|
||
| pub async fn delete_component(&self, id: i64) -> Result<bool> { | ||
| let rows = sqlx::query!( | ||
| r#"DELETE FROM prompt_component WHERE id = ?"#, | ||
| id | ||
| ) | ||
| .execute(&self.pool) | ||
| .await? | ||
| .rows_affected(); | ||
| Ok(rows > 0) | ||
| } | ||
|
|
||
| // Utility: Recursively resolve {{component:component_name}} in prompt content | ||
| pub async fn resolve_components_in_text(&self, text: &str) -> Result<String> { | ||
| use regex::Regex; | ||
| let re = Regex::new(r"\{\{component:([a-zA-Z0-9_\- ]+)}}")?; | ||
| let mut resolved = text.to_string(); | ||
| let mut changed = true; | ||
| while changed { | ||
| changed = false; | ||
| let mut new_text = resolved.clone(); | ||
| for cap in re.captures_iter(&resolved) { | ||
| let comp_name = &cap[1]; | ||
| let comp = sqlx::query!( | ||
| r#"SELECT content FROM prompt_component WHERE name = ? LIMIT 1"#, | ||
| comp_name | ||
| ) | ||
| .fetch_optional(&self.pool) | ||
| .await?; | ||
| if let Some(row) = comp { | ||
| let comp_content = row.content; | ||
| new_text = new_text.replace(&cap[0], &comp_content); | ||
| changed = true; | ||
| } | ||
| } | ||
| resolved = new_text; | ||
| } | ||
| Ok(resolved) | ||
| } | ||
|
|
||
| // Wrap get_prompt to resolve components in system/user fields | ||
| pub async fn get_prompt_with_components(&self, id: i64) -> Result<PromptRowWithModel> { | ||
| let mut prompt = self.get_prompt(id).await?; | ||
| if let Some(system) = &prompt.system { | ||
| prompt.system = Some(self.resolve_components_in_text(system).await?); | ||
| } | ||
| if let Some(user) = &prompt.user { | ||
| prompt.user = Some(self.resolve_components_in_text(user).await?); | ||
| } | ||
| Ok(prompt) | ||
| } | ||
| } | ||
|
|
||
| fn generate_diff(text1: &str, text2: &str) -> String { | ||
|
|
@@ -573,4 +719,3 @@ fn generate_diff(text1: &str, text2: &str) -> String { | |
|
|
||
| diff_string | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
directories and components should be their own distinct and separate controllers.