mirror of
https://github.com/tcsenpai/ollamagents.git
synced 2025-06-04 10:10: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
|
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() {
|
async function main() {
|
||||||
// Display welcome message
|
// Display welcome message
|
||||||
term.terminal.bold.cyan('Welcome to the Linux Command Assistant. Type \'exit\' to quit.\n\n');
|
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 executeCommand = input.startsWith('!');
|
||||||
const cleanInput = executeCommand ? input.slice(1) : input;
|
const cleanInput = executeCommand ? input.slice(1) : input;
|
||||||
|
|
||||||
|
// Create and start the spinner
|
||||||
|
const spinner = createSpinner();
|
||||||
|
spinner.start();
|
||||||
|
|
||||||
// Send request to OllamaAPI
|
// Send request to OllamaAPI
|
||||||
const response = await ollama.chat(cleanInput, executeCommand);
|
const response = await ollama.chat(cleanInput, executeCommand);
|
||||||
|
|
||||||
|
// Stop the spinner
|
||||||
|
spinner.stop();
|
||||||
|
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
// Display error if any
|
// Display error if any
|
||||||
term.terminal.red('Error: ').white(response.error + '\n');
|
term.terminal.red('Error: ').white(response.error + '\n');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user