| 8 | const pipe = new Pipe(pipeItSystemsTriageAgent()); |
| 9 | |
| 10 | async function main() { |
| 11 | const initialSpinner = ora( |
| 12 | 'Connecting to it-systems-triage-agent...', |
| 13 | ).start(); |
| 14 | // Messages array for keeping track of the conversation |
| 15 | const messages: Message[] = [ |
| 16 | // Initial message to the agent |
| 17 | {role: 'user', content: 'Hello how can I use your services?'}, |
| 18 | ]; |
| 19 | |
| 20 | try { |
| 21 | const {completion} = await pipe.run({ |
| 22 | messages, |
| 23 | }); |
| 24 | |
| 25 | // Add the agent response to the messages array |
| 26 | messages.push({role: 'assistant', content: completion}); |
| 27 | |
| 28 | initialSpinner.stop(); |
| 29 | console.log(chalk.cyan('Agent response...')); |
| 30 | console.log(completion); |
| 31 | } catch (error) { |
| 32 | initialSpinner.stop(); |
| 33 | console.error(chalk.red('Error processing initial request:'), error); |
| 34 | } |
| 35 | |
| 36 | while (true) { |
| 37 | const {userMsg} = await inquirer.prompt([ |
| 38 | { |
| 39 | type: 'input', |
| 40 | name: 'userMsg', |
| 41 | message: chalk.blue( |
| 42 | 'Enter your query (or type "exit" to quit):', |
| 43 | ), |
| 44 | }, |
| 45 | ]); |
| 46 | |
| 47 | if (userMsg.toLowerCase() === 'exit') { |
| 48 | console.log(chalk.green('Goodbye!')); |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | const spinner = ora('Processing your request...').start(); |
| 53 | messages.push({role: 'user', content: userMsg}); |
| 54 | try { |
| 55 | const {completion: itSystemsTriageAgentResponse} = await pipe.run({ |
| 56 | messages, |
| 57 | }); |
| 58 | messages.push({ |
| 59 | role: 'assistant', |
| 60 | content: itSystemsTriageAgentResponse, |
| 61 | }); |
| 62 | spinner.stop(); |
| 63 | console.log(chalk.cyan('Agent:')); |
| 64 | console.log(itSystemsTriageAgentResponse); |
| 65 | } catch (error) { |
| 66 | spinner.stop(); |
| 67 | console.error(chalk.red('Error processing your request:'), error); |