-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathindex.ts
More file actions
73 lines (63 loc) · 1.77 KB
/
index.ts
File metadata and controls
73 lines (63 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import 'dotenv/config';
import {Message, Pipe} from '@baseai/core';
import inquirer from 'inquirer';
import ora from 'ora';
import chalk from 'chalk';
import pipeSoftwareArchitectureAgent from './baseai/pipes/software-architecture-agent';
const pipe = new Pipe(pipeSoftwareArchitectureAgent());
async function main() {
const initialSpinner = ora(
'Connecting to software-architecture-agent...',
).start();
// Messages array for keeping track of the conversation
const messages: Message[] = [
// Initial message to the agent
{role: 'user', content: 'Hello how can I use your services?'},
];
try {
const {completion} = await pipe.run({
messages,
});
// Add the agent response to the messages array
messages.push({role: 'assistant', content: completion});
initialSpinner.stop();
console.log(chalk.cyan('Agent response...'));
console.log(completion);
} catch (error) {
initialSpinner.stop();
console.error(chalk.red('Error processing initial request:'), error);
}
while (true) {
const {userMsg} = await inquirer.prompt([
{
type: 'input',
name: 'userMsg',
message: chalk.blue(
'Enter your query (or type "exit" to quit):',
),
},
]);
if (userMsg.toLowerCase() === 'exit') {
console.log(chalk.green('Goodbye!'));
break;
}
const spinner = ora('Processing your request...').start();
messages.push({role: 'user', content: userMsg});
try {
const {completion: swArchAgentResponse} = await pipe.run({
messages,
});
messages.push({
role: 'assistant',
content: swArchAgentResponse,
});
spinner.stop();
console.log(chalk.cyan('Agent:'));
console.log(swArchAgentResponse);
} catch (error) {
spinner.stop();
console.error(chalk.red('Error processing your request:'), error);
}
}
}
main();