-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
88 lines (70 loc) · 1.82 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env node
import { GenerateTask, Plugin, Assistant, Kernel } from "@stencila/plugin";
import { CodeBlock, Heading, Text, softwareApplication } from "@stencila/types";
/**
* An echoing kernel which just echos back the supplied code as a string output
*/
class EchoKernel extends Kernel {
async info() {
return softwareApplication("echo-node");
}
async execute(code: string) {
return {
outputs: [code],
messages: [],
};
}
}
/**
* An echoing assistant which just echos back the task as a JSON code block
* and the rendered system prompt as a Markdown code block
*/
class EchoAssistant extends Assistant {
async systemPrompt() {
return `
You are an assistant that echos back the task given to you.
This system prompt is a template which is rendered against the
task itself. Here are some of the parts of the task rendered into
the system prompt:
Instruction:
{{ instruction | to_yaml }}
Instruction text:
{{ instruction_text }}
Instruction content formatted:
{{ content_formatted if content_formatted else "none" }}
Document context:
{{ context | to_yaml }}
`;
}
async performTask(task: GenerateTask) {
return {
nodes: [
new Heading(1, [new Text("Task")]),
new CodeBlock(JSON.stringify(task, null, " "), {
programmingLanguage: "json",
}),
new Heading(1, [new Text("System prompt")]),
new CodeBlock(task.system_prompt ?? "", {
programmingLanguage: "markdown",
}),
],
};
}
}
/**
* An example Stencila plugin
*/
class EchoPlugin extends Plugin {
constructor() {
super();
this.kernels = {
"echo-node": EchoKernel,
};
this.assistants = {
"stencila/echo-node": new EchoAssistant(),
};
}
}
if (require.main === module) {
new EchoPlugin().run().catch(console.error);
}