Skip to content

Commit

Permalink
feat: add role %create-prompt% (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Sep 7, 2024
1 parent 555f4f5 commit 9347bb8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
33 changes: 31 additions & 2 deletions src/config/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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__";

Expand Down Expand Up @@ -40,7 +39,33 @@ 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()),
Expand Down Expand Up @@ -137,6 +162,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() {
Expand Down

0 comments on commit 9347bb8

Please sign in to comment.