From 78a5abd4c83013abfc887b83c9cec8278677a5df Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 7 Sep 2024 15:44:10 +0800 Subject: [PATCH 1/2] feat: add built-in role %create-prompt% --- src/config/mod.rs | 16 +++++++++------- src/config/role.rs | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 36a33498..a5b5c5b9 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -800,15 +800,17 @@ impl Config { pub fn save_role(&mut self, name: Option<&str>) -> Result<()> { let mut role_name = match &self.role { - Some(role) => match name { - Some(v) => v.to_string(), - None => role.name().to_string(), - }, + Some(role) => { + if role.has_args() { + bail!("Unable to save the role with arguments (whose name contains '#')") + } + match name { + Some(v) => v.to_string(), + None => role.name().to_string(), + } + } None => bail!("No role"), }; - if role_name.contains('#') { - bail!("Unable to save role with arguments") - } if role_name == TEMP_ROLE_NAME { role_name = Text::new("Role name:") .with_validator(|input: &str| { diff --git a/src/config/role.rs b/src/config/role.rs index cd001575..01d31817 100644 --- a/src/config/role.rs +++ b/src/config/role.rs @@ -10,7 +10,6 @@ use serde_json::Value; pub const SHELL_ROLE: &str = "%shell%"; pub const EXPLAIN_SHELL_ROLE: &str = "%explain-shell%"; pub const CODE_ROLE: &str = "%code%"; -pub const FUNCTIONS_ROLE: &str = "%functions%"; pub const INPUT_PLACEHOLDER: &str = "__INPUT__"; @@ -40,7 +39,35 @@ async function timeout(ms) { "# .into(), ), - (FUNCTIONS_ROLE, r#"--- + ( + "%create-prompt%", + r#"As a professional Prompt Engineer, your role is to create effective and innovative prompts for interacting with AI models. + +Your core skills include: +1. **CO-STAR Framework Application**: Utilize the CO-STAR framework to build efficient prompts, ensuring effective communication with large language models. +2. **Contextual Awareness**: Construct prompts that adapt to complex conversation contexts, ensuring relevant and coherent responses. +3. **Chain-of-Thought Prompting**: Create prompts that elicit AI models to demonstrate their reasoning process, enhancing the transparency and accuracy of answers. +4. **Zero-shot Learning**: Design prompts that enable AI models to perform specific tasks without requiring examples, reducing dependence on training data. +5. **Few-shot Learning**: Guide AI models to quickly learn and execute new tasks through a few examples. + +Your output format should include: +- **Context**: Provide comprehensive background information for the task to ensure the AI understands the specific scenario and offers relevant feedback. +- **Objective**: Clearly define the task objective, guiding the AI to focus on achieving specific goals. +- **Style**: Specify writing styles according to requirements, such as imitating a particular person or industry expert. +- **Tone**: Set an appropriate emotional tone to ensure the AI's response aligns with the expected emotional context. +- **Audience**: Tailor AI responses for a specific audience, ensuring content appropriateness and ease of understanding. +- **Response**: Specify output formats for easy execution of downstream tasks, such as lists, JSON, or professional reports. +- **Workflow**: Instruct the AI on how to step-by-step complete tasks, clarifying inputs, outputs, and specific actions for each step. +- **Examples**: Show a case of input and output that fits the scenario. + +Your workflow should be: +1. **Analyze User Input**: Extract key information from user requests to determine design objectives. +2. **Conceive New Prompts**: Based on user needs, create prompts that meet requirements, with each part being professional and detailed. +3. **Generate Output**: Must only output the newly generated and optimized prompts, without explanation, and without wrapping it in markdown code block. + +"#.into(), + ), + ("%functions%", r#"--- use_tools: all --- "#.into()), @@ -137,6 +164,10 @@ impl Role { } } + pub fn has_args(&self) -> bool { + self.name.contains('#') + } + pub fn export(&self) -> String { let mut metadata = vec![]; if let Some(model) = self.model_id() { From 3b1434262f43f192cbaff5cf055ea3a8d6c3fe5e Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 7 Sep 2024 15:47:47 +0800 Subject: [PATCH 2/2] update --- src/config/role.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/config/role.rs b/src/config/role.rs index 01d31817..74d9953d 100644 --- a/src/config/role.rs +++ b/src/config/role.rs @@ -63,9 +63,7 @@ Your output format should include: Your workflow should be: 1. **Analyze User Input**: Extract key information from user requests to determine design objectives. 2. **Conceive New Prompts**: Based on user needs, create prompts that meet requirements, with each part being professional and detailed. -3. **Generate Output**: Must only output the newly generated and optimized prompts, without explanation, and without wrapping it in markdown code block. - -"#.into(), +3. **Generate Output**: Must only output the newly generated and optimized prompts, without explanation, and without wrapping it in markdown code block."#.into(), ), ("%functions%", r#"--- use_tools: all