use super::config::SystemPromptConfig;
use super::context::PromptContext;
use super::templates::PromptTemplates;
pub struct SystemPromptGenerator {
config: SystemPromptConfig,
context: PromptContext,
}
impl SystemPromptGenerator {
pub fn new(config: SystemPromptConfig, context: PromptContext) -> Self {
Self { config, context }
}
pub fn generate(&self) -> String {
let mut prompt_parts = Vec::new();
prompt_parts.push(PromptTemplates::base_system_prompt().to_string());
if let Some(custom) = &self.config.custom_instruction {
prompt_parts.push(custom.clone());
}
prompt_parts
.push(PromptTemplates::personality_prompt(&self.config.personality).to_string());
prompt_parts
.push(PromptTemplates::response_style_prompt(&self.config.response_style).to_string());
if self.config.include_tools && !self.context.available_tools.is_empty() {
prompt_parts.push(PromptTemplates::tool_usage_prompt().to_string());
prompt_parts.push(format!(
"Available tools: {}",
self.context.available_tools.join(", ")
));
}
if self.config.include_workspace {
if let Some(workspace) = &self.context.workspace {
prompt_parts.push(PromptTemplates::workspace_context_prompt().to_string());
prompt_parts.push(format!("Current workspace: {}", workspace.display()));
}
if !self.context.languages.is_empty() {
prompt_parts.push(format!(
"Detected languages: {}",
self.context.languages.join(", ")
));
}
if let Some(project_type) = &self.context.project_type {
prompt_parts.push(format!("Project type: {}", project_type));
}
}
prompt_parts.push(PromptTemplates::safety_guidelines_prompt().to_string());
prompt_parts.join("\n\n")
}
}
pub fn generate_system_instruction_with_config(
config: &SystemPromptConfig,
context: &PromptContext,
) -> String {
let generator = SystemPromptGenerator::new(config.clone(), context.clone());
generator.generate()
}