-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic-chat.ts
More file actions
56 lines (51 loc) · 1.6 KB
/
Copy pathbasic-chat.ts
File metadata and controls
56 lines (51 loc) · 1.6 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
import type { MarkdownArtifactBundle } from "goodmemory";
import { createGoodMemory } from "goodmemory";
export async function runBasicChatExample(): Promise<{
artifacts: MarkdownArtifactBundle;
memoryContext: string;
answer: string;
}> {
const memory = createGoodMemory({
storage: { provider: "memory" },
});
await memory.remember({
scope: { userId: "example-user", sessionId: "chat-s1", workspaceId: "example-chat" },
messages: [
{
role: "user",
content: "My name is Lin. Remember that the migration rollout is blocked on prod verification.",
},
{
role: "assistant",
content: "Noted.",
},
{
role: "user",
content: "I prefer bullet points in project summaries.",
},
],
});
const recall = await memory.recall({
scope: { userId: "example-user", sessionId: "chat-s2", workspaceId: "example-chat" },
query: "How should I answer this user about the current project?",
retrievalProfile: "general_chat",
});
const context = await memory.buildContext({
recall,
output: "markdown",
maxTokens: 160,
});
const exported = await memory.exportMemory({
scope: { userId: "example-user", workspaceId: "example-chat", sessionId: "chat-s1" },
});
return {
artifacts: exported.artifacts,
memoryContext: context.content,
answer:
"Bullet summary: the migration rollout is still blocked on prod verification, so I would answer in concise bullet points.",
};
}
if (import.meta.main) {
const result = await runBasicChatExample();
console.log(JSON.stringify(result, null, 2));
}