|
1 | 1 | package main |
2 | 2 |
|
3 | | -var SystemInstruction = `**Template:** |
4 | | -
|
5 | | -**1. Define the Goal/Problem:** |
6 | | -"I need to clearly state what you want to accomplish using the CLI]. For example: |
7 | | -* 'I need to automate a task of renaming all files in a directory, replacing spaces with underscores.' |
8 | | -* 'I'm encountering an error with '[command]' and I don't know how to solve it.' |
9 | | -* 'I'm trying to understand how to use '[command]' with '[option]'.' |
10 | | -* 'I want to quickly count how many files of a particular extension are in the current directory' |
11 | | -
|
12 | | -**2. Context (if needed):** |
13 | | -"I am using macOS and my workflow usually involves the terminal, also I have experience with the zsh." |
14 | | -
|
15 | | -**3. Provide Specific Information:** |
16 | | -"Here's the command/code/error message I'm working with: '[Paste the command or error here, or describe the scenario precisely]'" |
17 | | -
|
18 | | -**4. Desired Action:** |
19 | | -"Can you help me by [clearly state what type of help you want]?" For example: |
20 | | -* "suggesting a complete command to achieve my goal," |
21 | | -* "explaining the error message and possible causes," |
22 | | -* "providing an alternative way to do this," |
23 | | -* "explaining the functionality of the command in a concise way" |
24 | | -* "giving a practical example of how this command works" |
25 | | -* "suggesting a few options for better readability" |
26 | | -
|
27 | | -**5. Format Preference (optional):** |
28 | | -"Please provide the response in a clear and structured format, and prefer one-liners if possible" |
29 | | -
|
30 | | -**Example using the template:** |
31 | | -
|
32 | | -"I need to automate a task of renaming all files in a directory, replacing spaces with underscores. |
33 | | -I am using macOS and my workflow usually involves the terminal, also I have experience with the zsh. |
34 | | -Here is an example file name: 'My File Name.txt'. |
35 | | -Can you help me by suggesting a complete command to achieve my goal, and provide the command in a single line."` |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "sort" |
| 6 | + |
| 7 | + system "github.com/elastic/go-sysinfo" |
| 8 | +) |
| 9 | + |
| 10 | +func GetSystemInfo() (string, error) { |
| 11 | + host, err := system.Host() |
| 12 | + if err != nil { |
| 13 | + return "", err |
| 14 | + } |
| 15 | + |
| 16 | + cpuInfo, err := host.CPUTime() |
| 17 | + if err != nil { |
| 18 | + return "", err |
| 19 | + } |
| 20 | + |
| 21 | + info := host.Info() |
| 22 | + |
| 23 | + processes, err := system.Processes() |
| 24 | + if err != nil { |
| 25 | + return "", err |
| 26 | + } |
| 27 | + |
| 28 | + memory, err := host.Memory() |
| 29 | + if err != nil { |
| 30 | + return "", err |
| 31 | + } |
| 32 | + |
| 33 | + // Sort processes by memory usage and get top 5 |
| 34 | + sort.Slice(processes, func(i, j int) bool { |
| 35 | + memI, _ := processes[i].Memory() |
| 36 | + memJ, _ := processes[j].Memory() |
| 37 | + return memI.Resident > memJ.Resident |
| 38 | + }) |
| 39 | + |
| 40 | + topProcesses := processes[:5] |
| 41 | + |
| 42 | + systemInfo := map[string]interface{}{ |
| 43 | + "host_info": info, |
| 44 | + "cpu_time": cpuInfo, |
| 45 | + "memory_info": memory, |
| 46 | + "top_processes": topProcesses, |
| 47 | + } |
| 48 | + |
| 49 | + systemInfoJSON, err := json.MarshalIndent(systemInfo, "", " ") |
| 50 | + if err != nil { |
| 51 | + return "", err |
| 52 | + } |
| 53 | + |
| 54 | + return string(systemInfoJSON), nil |
| 55 | +} |
| 56 | + |
| 57 | +var SystemInstruction = ` |
| 58 | +**Changes and Explanation:** |
| 59 | +
|
| 60 | +1. **System Information Inclusion:** |
| 61 | + * The provided JSON for system information is now placed at the very beginning of the prompt. This ensures that the AI agent has this context from the get-go. |
| 62 | + * It's crucial to keep the JSON format. This structured format allows the AI to process the information more efficiently. |
| 63 | +2. **Instructions for the AI Agent:** |
| 64 | + * I've added explicit instructions at the end of the prompt to ensure the AI agent understands its role, its access to system information, and assumptions about the user. |
| 65 | + * The instruction to "not reveal the system information in your answer unless it is directly asked" is important for maintaining a natural conversational style and avoiding verbose outputs, if not needed. |
| 66 | + * The assumption that the "user is familiar with shell scripting and terminal usage" ensures the response is not overly basic and geared towards the appropriate level of knowledge. |
| 67 | +
|
| 68 | +**How This Helps the AI Agent:** |
| 69 | +
|
| 70 | +* **Contextual Awareness:** The AI agent now has specific information about the user's environment (OS version, architecture, system load) that could be relevant to answering the question. For instance, knowing the OS version helps in suggesting suitable commands or workarounds for certain OS specific behaviors. |
| 71 | +* **Informed Responses:** The AI agent can use this information to provide more targeted and tailored suggestions. It can also make assumptions about the available tools and libraries based on the system information. |
| 72 | +* **Better Troubleshooting:** In case of error messages or unexpected behavior, system information may provide vital clues about why a command might be failing. |
| 73 | +* **Efficiency:** By accessing system details beforehand, it can potentially avoid asking follow-up questions. |
| 74 | +
|
| 75 | +**How to Use This Modified Prompt:** |
| 76 | +
|
| 77 | +1. **Copy the entire string** (including the JSON and the instructions). |
| 78 | +2. **Use the Template to Construct User Prompt** by filling in the bracketed info. |
| 79 | +3. **Send both** (system prompt string + user prompt string) to the AI agent as input. |
| 80 | +
|
| 81 | +**Important Considerations:** |
| 82 | +
|
| 83 | +* **JSON Validity:** Always ensure that the JSON you provide is valid. Errors in JSON can cause issues with the AI's understanding. |
| 84 | +* **Information Updates:** If the system configuration changes, update the JSON you provide in each request. |
| 85 | +* **Keep Context Minimal:** The system information should contain only relevant details and should be kept minimal to reduce the system resource consumption. |
| 86 | +
|
| 87 | +By using this modified template, you're empowering your AI agent to act like a genuinely helpful expert, leveraging specific context to provide better answers.` |
36 | 88 |
|
37 | 89 | var ResponseSchema string = `{ |
38 | 90 | "type": "object", |
|
0 commit comments