mirror of
https://github.com/tcsenpai/ollamagents.git
synced 2025-06-04 10:10:09 +00:00
multicommands with copypaste support
This commit is contained in:
parent
a02bc41368
commit
740150434f
27
main.ts
27
main.ts
@ -7,13 +7,20 @@ dotenv.config();
|
||||
|
||||
const ollama_url = process.env.OLLAMA_URL as string;
|
||||
const systemPrompt = `You are a Linux command interpreter. Your task is to convert natural language queries or commands into appropriate Linux commands. Always respond with a valid JSON object containing the following keys:
|
||||
1. 'command': The Linux command to execute (string). Double check the command to ensure it's correct and works.
|
||||
2. 'explanation': A brief explanation of what the command does (string).
|
||||
3. 'caution': Any warnings or cautions about using the command, if applicable (string or null).
|
||||
1. 'commands': An array of strings, each representing a Linux command to execute. If multiple commands are needed, list them in the order they should be executed.
|
||||
2. 'explanation': A brief explanation of what the command(s) do (string).
|
||||
3. 'caution': Any warnings or cautions about using the command(s), if applicable (string or null).
|
||||
|
||||
Only provide existing and working Linux commands. If you cannot interpret the input or if it's not applicable to Linux, return a JSON object with an 'error' key explaining the issue. Do not include any text outside of the JSON structure in your response.
|
||||
Guidelines:
|
||||
- Provide a single command when possible, but use multiple commands or command chains (using pipes | or && ) when necessary to achieve the desired result.
|
||||
- If suggesting multiple commands, explain how they work together.
|
||||
- Always use existing and working Linux commands.
|
||||
- If you cannot interpret the input or if it's not applicable to Linux, return a JSON object with an 'error' key explaining the issue.
|
||||
|
||||
Do not include any text outside of the JSON structure in your response.
|
||||
|
||||
The produced JSON should be valid and parseable by JSON.parse() in JavaScript. For such reason, you should not include \` and \`\`\`json in your response, or similar syntax.`;
|
||||
|
||||
The produced JSON should be valid JSON that can be parsed by JSON.parse() in JavaScript, so it cannot contain \` or headers like \`\`\`json.`;
|
||||
const ollama = new OllamaAPI(ollama_url, 'llama3.1', systemPrompt);
|
||||
|
||||
const rl = readline.createInterface({
|
||||
@ -35,15 +42,18 @@ async function main() {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
|
||||
const response = await ollama.chat(input);
|
||||
try {
|
||||
const response = await ollama.chat(input);
|
||||
const parsedResponse = JSON.parse(response);
|
||||
|
||||
if (parsedResponse.error) {
|
||||
term.terminal.red('Error: ').white(parsedResponse.error + '\n');
|
||||
} else {
|
||||
term.terminal.bold.blue('Command: ').white(parsedResponse.command + '\n');
|
||||
term.terminal.bold.blue('Command(s):\n\n');
|
||||
parsedResponse.commands.forEach((cmd: string, index: number) => {
|
||||
term.terminal.white(`${cmd}\n`);
|
||||
});
|
||||
term.terminal('\n\n');
|
||||
term.terminal.bold.magenta('Explanation: ').white(parsedResponse.explanation + '\n');
|
||||
if (parsedResponse.caution) {
|
||||
term.terminal.bold.yellow('Caution: ').white(parsedResponse.caution + '\n');
|
||||
@ -51,7 +61,6 @@ async function main() {
|
||||
}
|
||||
} catch (error) {
|
||||
term.terminal.red('An error occurred: ').white((error as Error).message + '\n');
|
||||
term.terminal.red('Response: ').white(response + '\n');
|
||||
}
|
||||
|
||||
term.terminal('\n'); // Add a blank line for readability
|
||||
|
Loading…
x
Reference in New Issue
Block a user