-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.js
More file actions
31 lines (25 loc) · 1.08 KB
/
Copy pathexample.js
File metadata and controls
31 lines (25 loc) · 1.08 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
/**
* Memory lives outside the model. A relevant memory only becomes
* context when something deliberately retrieves it.
*/
import { loadMemories, recall } from './memory.js';
import { startSession, shutdown } from '../../helper/llm.js';
import { section, answer, bullet, meta, blank } from '../../helper/cli.js';
const question =
'Show short code examples for parsing a CSV line. Code only - under 10 lines total.';
section('Session 1 - no memory access');
const s1 = await startSession();
answer(await s1.ask(question, { maxTokens: 120 }));
await s1.dispose();
const memories = await loadMemories();
section('Stored memories (from a previous session)');
memories.forEach((memory) => bullet(memory));
const relevant = recall(question, memories);
blank();
meta(`Retrieved for this question: ${relevant ?? '(none)'}`);
section('Session 2 - with the retrieved memory added to context');
const s2 = await startSession();
const prompt = relevant ? `Relevant memory: ${relevant}\n\n${question}` : question;
answer(await s2.ask(prompt, { maxTokens: 120 }));
await s2.dispose();
await shutdown();