forked from i-am-bee/bee-agent-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
llmMemory.ts
22 lines (19 loc) · 792 Bytes
/
llmMemory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat";
import { UnconstrainedMemory } from "bee-agent-framework/memory/unconstrainedMemory";
import { BaseMessage } from "bee-agent-framework/llms/primitives/message";
const memory = new UnconstrainedMemory();
await memory.addMany([
BaseMessage.of({
role: "system",
text: `Always respond very concisely.`,
}),
BaseMessage.of({ role: "user", text: `Give me first 5 prime numbers.` }),
]);
// Generate response
const llm = new OllamaChatLLM();
const response = await llm.generate(memory.messages);
await memory.add(BaseMessage.of({ role: "assistant", text: response.getTextContent() }));
console.log(`Conversation history`);
for (const message of memory) {
console.log(`${message.role}: ${message.text}`);
}