codive_prompts/prompts/
mod.rs1use std::collections::HashMap;
4
5use crate::ProviderFamily;
6
7pub const BASE: &str = include_str!("base.txt");
9
10pub const ANTHROPIC: &str = include_str!("anthropic.txt");
12pub const OPENAI: &str = include_str!("openai.txt");
13pub const GEMINI: &str = include_str!("gemini.txt");
14pub const GENERIC: &str = include_str!("generic.txt");
15
16pub const VERIFICATION: &str = include_str!("verification.txt");
18
19pub const TOOL_BASH: &str = include_str!("tools/bash.txt");
21pub const TOOL_READ_FILE: &str = include_str!("tools/read_file.txt");
22pub const TOOL_WRITE_FILE: &str = include_str!("tools/write_file.txt");
23pub const TOOL_EDIT_FILE: &str = include_str!("tools/edit_file.txt");
24pub const TOOL_GLOB: &str = include_str!("tools/glob.txt");
25pub const TOOL_GREP: &str = include_str!("tools/grep.txt");
26pub const TOOL_LSP: &str = include_str!("tools/lsp.txt");
27
28#[derive(Debug, Clone)]
30pub struct EmbeddedPrompts {
31 pub base: &'static str,
32 pub verification: &'static str,
33 providers: HashMap<ProviderFamily, &'static str>,
34 tools: HashMap<&'static str, &'static str>,
35}
36
37impl EmbeddedPrompts {
38 pub fn load() -> Self {
40 let mut providers = HashMap::new();
41 providers.insert(ProviderFamily::Anthropic, ANTHROPIC);
42 providers.insert(ProviderFamily::OpenAI, OPENAI);
43 providers.insert(ProviderFamily::Google, GEMINI);
44 providers.insert(ProviderFamily::Generic, GENERIC);
45
46 let mut tools = HashMap::new();
47 tools.insert("bash", TOOL_BASH);
48 tools.insert("read_file", TOOL_READ_FILE);
49 tools.insert("write_file", TOOL_WRITE_FILE);
50 tools.insert("edit_file", TOOL_EDIT_FILE);
51 tools.insert("glob", TOOL_GLOB);
52 tools.insert("grep", TOOL_GREP);
53 tools.insert("lsp", TOOL_LSP);
54
55 Self {
56 base: BASE,
57 verification: VERIFICATION,
58 providers,
59 tools,
60 }
61 }
62
63 pub fn provider(&self, family: ProviderFamily) -> &'static str {
65 self.providers
66 .get(&family)
67 .copied()
68 .unwrap_or(GENERIC)
69 }
70
71 pub fn tool(&self, name: &str) -> Option<&'static str> {
73 self.tools.get(name).copied()
74 }
75
76 pub fn tool_names(&self) -> impl Iterator<Item = &&'static str> {
78 self.tools.keys()
79 }
80}
81
82impl Default for EmbeddedPrompts {
83 fn default() -> Self {
84 Self::load()
85 }
86}