Skip to content

Commit 7b45ad5

Browse files
committed
--wip-- [skip ci]
1 parent 840dafa commit 7b45ad5

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

examples/knowledge-graph/generate.ts

+20-14
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,32 @@ const sampleBook = "War and Peace by Tolstoy";
77
const book = process.argv[2] || sampleBook;
88
const substrate = new Substrate({ apiKey: process.env["SUBSTRATE_API_KEY"] });
99

10+
const opts = { cache_age: 60 * 60 * 24 * 7 };
1011
async function main() {
11-
const initialList = new ComputeText({
12-
prompt: `List all the main characters in "${book}", then for all the meaningful relationships between them, provide a short label for the relationship`,
13-
model: "Llama3Instruct405B",
14-
});
15-
const graph = new ComputeJSON({
16-
prompt: sb.interpolate`Make a JSON graph composed of the characters in ${book} that illustrates the relationships between them.
12+
const initialList = new ComputeText(
13+
{
14+
prompt: `List all the main characters in "${book}", then for all the meaningful relationships between them, provide a short label for the relationship`,
15+
model: "Llama3Instruct405B",
16+
},
17+
opts,
18+
);
19+
const graph = new ComputeJSON(
20+
{
21+
prompt: sb.interpolate`Make a JSON graph composed of the characters in ${book} that illustrates the relationships between them.
1722
Use this context:
1823
${initialList.future.text}`,
19-
json_schema: jsonSchema,
20-
temperature: 0.2,
21-
model: "Llama3Instruct8B",
22-
});
24+
json_schema: jsonSchema,
25+
temperature: 0.2,
26+
model: "Llama3Instruct8B",
27+
},
28+
opts,
29+
);
2330
const res = await substrate.run(graph);
2431
const jsonOut = res.get(graph).json_object;
2532
const htmlTemplate = fs.readFileSync(`${currentDir}/index.html`, "utf8");
26-
const html = htmlTemplate.replace(
27-
'"{{ graphData }}"',
28-
JSON.stringify(jsonOut, null, 2),
29-
);
33+
const html = htmlTemplate
34+
.replace('"{{ graphData }}"', JSON.stringify(jsonOut, null, 2))
35+
.replaceAll("{{ title }}", book);
3036
fs.writeFileSync("knowledge-graph.html", html);
3137
}
3238
main();

examples/knowledge-graph/index.html

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Character Relationship Graph</title>
6+
<title>{{ title }} - Relationships</title>
77
<script src="https://d3js.org/d3.v7.min.js"></script>
88
<style>
99
body {
@@ -41,11 +41,22 @@
4141
fill: #555;
4242
pointer-events: none;
4343
}
44+
#book-title {
45+
font-size: 20px;
46+
font-weight: bold;
47+
margin-bottom: 20px;
48+
text-transform: uppercase;
49+
position: absolute;
50+
top: 18px;
51+
color: darkgray;
52+
text-align: center;
53+
font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
54+
}
4455
</style>
4556
</head>
4657
<body>
58+
<div id="book-title">{{ title }}</div>
4759
<div id="graph-container"></div>
48-
4960
<script>
5061
const graphData = "{{ graphData }}";
5162

0 commit comments

Comments
 (0)