-
Notifications
You must be signed in to change notification settings - Fork 3
/
stephen-king.ts
64 lines (63 loc) · 1.94 KB
/
stephen-king.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
import { Agent } from "@hyv/core";
import { GPTModelAdapter, createInstructionPersona } from "@hyv/openai";
import { createFileWriter } from "@hyv/utils";
import path from "node:path";
const dir = path.join(process.cwd(), `examples/output/stephen-king/${Date.now()}`);
const fileWriter = createFileWriter(dir, "utf-8");
// Define Stephen King's persona
const stephenKing = {
name: "Stephen King",
profession: "Author",
characteristics: ["Horror novelist", "Master of suspense", "Detailed descriptions"],
};
// Define the rules for the Stephen King persona
const rules = [
{ importance: "high", rule: "Always stay in character as Stephen King" },
{ importance: "ultra high", rule: "Write in a suspenseful and detailed manner" },
{
importance: "ultra high",
rule: "Write the chapter in the desired {{files}} format and use the desired format and {{wordCount}}",
},
];
// Define Stephen King's response format
const responseFormat = {
thoughts: "Describe your thoughts about the plot",
assurance: "Describe how you stay in character as Stephen King and meet the criteria",
files: [
{
path: "chapter-name.md",
content: "the content of the chapter, very detailed",
},
],
};
// Create the Stephen King persona
const stephenKingPersona = createInstructionPersona(stephenKing, rules, responseFormat, {
format: "json",
});
// Create a new agent with the Stephen King persona
const stephenKingAgent = new Agent(
new GPTModelAdapter({
model: "gpt-4",
historySize: 3,
maxTokens: 2048,
systemInstruction: stephenKingPersona,
}),
{
verbosity: 1,
sideEffects: [fileWriter],
}
);
// Assign tasks to the agent
const tasks = [
"Write the first chapter of a horror novel",
"Write the second chapter of the novel",
"Write the third and final chapter of the novel",
];
for (const task of tasks) {
try {
// eslint-disable-next-line no-await-in-loop
await stephenKingAgent.assign({ task, wordCount: ">=500" });
} catch (error) {
console.log(error);
}
}