forked from vaporware-fun/replicant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic-chat.ts
63 lines (51 loc) · 1.49 KB
/
basic-chat.ts
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
import { Agent, AnthropicProvider } from '../';
import { createInterface } from 'readline';
import dotenv from 'dotenv';
dotenv.config();
async function main() {
// Initialize the agent
const agent = new Agent({
domain: 'chat',
userId: 'cli-user',
platform: 'cli',
capabilities: ['text-generation'],
permissions: ['read', 'write']
});
// Set up AI provider
const aiProvider = new AnthropicProvider({
apiKey: process.env.ANTHROPIC_API_KEY!,
model: 'claude-3-opus-20240229'
});
await agent.setAIProvider(aiProvider);
// Initialize the agent
await agent.initialize();
// Set up CLI interface
const rl = createInterface({
input: process.stdin,
output: process.stdout
});
console.log('Chat initialized. Type "exit" to quit.\n');
// Main chat loop
while (true) {
const input = await new Promise<string>(resolve => {
rl.question('You: ', resolve);
});
if (input.toLowerCase() === 'exit') {
break;
}
// Process user message
const response = await agent.processMessage({
role: 'user',
content: input,
metadata: {
timestamp: new Date().toISOString(),
platform: 'cli'
}
});
console.log('\nAssistant:', response.content, '\n');
}
// Cleanup
rl.close();
await agent.shutdown();
}
main().catch(console.error);