mirror of
https://github.com/tcsenpai/ollamagents.git
synced 2025-06-02 17:20:09 +00:00
Added a demo and added a spinner too
This commit is contained in:
parent
023ae61cda
commit
a34bee8395
27
main.ts
27
main.ts
@ -17,6 +17,26 @@ const rl = readline.createInterface({
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
function createSpinner() {
|
||||
const spinnerFrames = ['|', '/', '-', '\\'];
|
||||
let currentFrame = 0;
|
||||
let spinnerInterval: NodeJS.Timeout;
|
||||
|
||||
return {
|
||||
start: () => {
|
||||
process.stdout.write('Processing your request... ');
|
||||
spinnerInterval = setInterval(() => {
|
||||
process.stdout.write(`\r${spinnerFrames[currentFrame]} Processing your request...`);
|
||||
currentFrame = (currentFrame + 1) % spinnerFrames.length;
|
||||
}, 100);
|
||||
},
|
||||
stop: () => {
|
||||
clearInterval(spinnerInterval);
|
||||
process.stdout.write('\r\x1b[K');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// Display welcome message
|
||||
term.terminal.bold.cyan('Welcome to the Linux Command Assistant. Type \'exit\' to quit.\n\n');
|
||||
@ -39,9 +59,16 @@ async function main() {
|
||||
const executeCommand = input.startsWith('!');
|
||||
const cleanInput = executeCommand ? input.slice(1) : input;
|
||||
|
||||
// Create and start the spinner
|
||||
const spinner = createSpinner();
|
||||
spinner.start();
|
||||
|
||||
// Send request to OllamaAPI
|
||||
const response = await ollama.chat(cleanInput, executeCommand);
|
||||
|
||||
// Stop the spinner
|
||||
spinner.stop();
|
||||
|
||||
if (response.error) {
|
||||
// Display error if any
|
||||
term.terminal.red('Error: ').white(response.error + '\n');
|
||||
|
Loading…
x
Reference in New Issue
Block a user