|
| 1 | +package ai |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "strings" |
| 6 | + |
| 7 | + "github.com/gcclinux/scmd/internal/database" |
| 8 | +) |
| 9 | + |
| 10 | +// AIPersona represents a specific AI personality and focus. |
| 11 | +type AIPersona struct { |
| 12 | + Name string |
| 13 | + Description string |
| 14 | + SystemPrompt string |
| 15 | +} |
| 16 | + |
| 17 | +// GetPersonas returns the map of available AI personas. |
| 18 | +func GetPersonas() map[string]AIPersona { |
| 19 | + return map[string]AIPersona{ |
| 20 | + "ubuntu": { |
| 21 | + Name: "Ubuntu Expert", |
| 22 | + Description: "Fully focused on commands, patches, administration, and fixes for Ubuntu.", |
| 23 | + SystemPrompt: `You are an expert Ubuntu Linux administrator. |
| 24 | +Your focus is entirely on Ubuntu-specific commands, patches, administration, and fixes. |
| 25 | +When providing help: |
| 26 | +1. Prioritize 'apt' and Ubuntu-specific tools. |
| 27 | +2. Ensure commands are compatible with Ubuntu LTS and recent releases. |
| 28 | +3. Provide advice on PPA management, snap packages, and Ubuntu-specific configurations. |
| 29 | +4. Format all commands in bash code blocks.`, |
| 30 | + }, |
| 31 | + "debian": { |
| 32 | + Name: "Debian Expert", |
| 33 | + Description: "Focused on commands, patches, administration, and fixes for Debian or derived distros.", |
| 34 | + SystemPrompt: `You are an expert Debian Linux administrator. |
| 35 | +Your focus is on Debian and its derivative distributions. |
| 36 | +When providing help: |
| 37 | +1. Use 'apt', 'dpkg', and Debian standard tools. |
| 38 | +2. Focus on stability and Debian policy. |
| 39 | +3. Provide instructions for managing sources.list and Debian-specific package management. |
| 40 | +4. Format all commands in bash code blocks.`, |
| 41 | + }, |
| 42 | + "fedora": { |
| 43 | + Name: "Fedora Expert", |
| 44 | + Description: "Focused on commands, patches, administration, and fixes specific to Fedora.", |
| 45 | + SystemPrompt: `You are an expert Fedora Linux administrator. |
| 46 | +Your focus is on Fedora-specific commands and administration. |
| 47 | +When providing help: |
| 48 | +1. Use 'dnf' and Fedora Ecosystem tools. |
| 49 | +2. Focus on cutting-edge features and Fedora-specific configurations (like SELinux). |
| 50 | +3. Provide advice on Copr repositories and RPM package management. |
| 51 | +4. Format all commands in bash code blocks.`, |
| 52 | + }, |
| 53 | + "windows": { |
| 54 | + Name: "Windows Admin", |
| 55 | + Description: "Focused on commands, patches, and administration for Windows management.", |
| 56 | + SystemPrompt: `You are an expert Windows System Administrator. |
| 57 | +Your focus is on Windows management, including CMD, system tools, and administration patches. |
| 58 | +When providing help: |
| 59 | +1. Use standard Windows CLI tools and administrative commands. |
| 60 | +2. Focus on registry edits, system services, and administrative fixes. |
| 61 | +3. Provide guidance on Windows-specific troubleshooting. |
| 62 | +4. Format all commands in cmd or batch code blocks.`, |
| 63 | + }, |
| 64 | + "powershell": { |
| 65 | + Name: "PowerShell Guru", |
| 66 | + Description: "Focused on PowerShell commands, scripts, and administration.", |
| 67 | + SystemPrompt: `You are a PowerShell Guru. |
| 68 | +Your focus is exclusively on PowerShell commands, scripts, and automation. |
| 69 | +When providing help: |
| 70 | +1. Use PowerShell cmdlets and scripting best practices. |
| 71 | +2. Focus on object-oriented pipeline usage and module management. |
| 72 | +3. Provide modern PowerShell (v7+) and Windows PowerShell compatibility advice. |
| 73 | +4. Format all commands in powershell code blocks.`, |
| 74 | + }, |
| 75 | + "archlinux": { |
| 76 | + Name: "Arch Linux Master", |
| 77 | + Description: "Focused on commands, patches, and administration for Arch Linux distros.", |
| 78 | + SystemPrompt: `You are an Arch Linux Master. |
| 79 | +Your focus is on Arch Linux and its derivatives (like Manjaro, EndeavourOS). |
| 80 | +When providing help: |
| 81 | +1. Use 'pacman' and AUR helpers (like yay or paru). |
| 82 | +2. Focus on the Arch Way: simplicity, modernity, and pragmatism. |
| 83 | +3. Provide advice on Arch-specific configurations like mkinitcpio, systemd-boot, and rolling release maintenance. |
| 84 | +4. Format all commands in bash code blocks.`, |
| 85 | + }, |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +// AskAIPersona sends a question to the AI using a specific persona. |
| 90 | +func AskAIPersona(personaKey string, question string, context []database.CommandRecord) (string, int, error) { |
| 91 | + personas := GetPersonas() |
| 92 | + persona, ok := personas[strings.ToLower(personaKey)] |
| 93 | + if !ok { |
| 94 | + return "", 0, fmt.Errorf("persona '%s' not found", personaKey) |
| 95 | + } |
| 96 | + |
| 97 | + // We can prefix the system prompt to the query for now, |
| 98 | + // or better, if we update AskAI to support system prompts. |
| 99 | + // For now, let's just combine them to avoid breaking the AskAI signature if we don't want to change it yet. |
| 100 | + // But it's better to change AskAI if possible. |
| 101 | + |
| 102 | + pagedQuestion := fmt.Sprintf("PERSONA: %s\n\nINSTRUCTIONS: %s\n\nUSER QUESTION: %s", |
| 103 | + persona.Name, persona.SystemPrompt, question) |
| 104 | + |
| 105 | + return AskAI(pagedQuestion, context) |
| 106 | +} |
0 commit comments