-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.ts
72 lines (58 loc) · 1.8 KB
/
index.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
64
65
66
67
68
69
70
71
72
import chalk from "chalk";
import { Daydreamer, Plugin } from "../../src/plugins/index";
import { Critic } from "./critic";
import { Generator } from "./generator";
const verbose = true;
export class ChimaeraDreamer implements Daydreamer {
generator: Generator;
critic: Critic;
done: boolean = false;
counter: number = 0;
max_iterations: number;
constructor(plugins: Plugin[] = [], max_iterations: number = 100) {
this.generator = new Generator(plugins);
this.critic = new Critic(plugins);
this.generator.init();
this.critic.init();
this.max_iterations = max_iterations;
}
async start(input: string) {
let prompt: string | false = input;
if (verbose) {
console.log(chalk.bold.green("Starting daydreaming session..."));
console.log(`Prompt: ${chalk.bold(prompt)}`);
}
this.critic.messages.push({
role: "user",
content: prompt,
});
let done = false;
let counter = 0;
while (!done) {
if (!prompt) {
console.log("Warning: received a blank prompt.");
continue;
}
if (counter % 2 === 0) {
prompt = await this.generator.run(prompt);
if (verbose) {
console.log(`${chalk.green("Generator")}\n${prompt}`);
}
} else {
prompt = await this.critic.run(prompt);
if (verbose) {
console.log(`${chalk.blueBright("Critic")}\n${prompt}`);
}
}
// EXTENSION FOR THE READER:
// You should embed the new prompt and save it in a vector store here, to make the results of the daydream self-prompting available for later retrieval and use.
counter++;
if (counter >= this.max_iterations) {
done = true;
}
}
if (verbose) {
console.log(chalk.bold.green("Daydreaming session complete."));
}
}
}