Skip to content

Commit ebfb20e

Browse files
committed
genrate, render js actions
1 parent d9bd95e commit ebfb20e

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

action-builder.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,14 @@ const runPost = async (
128128
form.hasErrors = false;
129129
form.errors = {};
130130

131-
const fullPrompt = await getPromptFromTemplate(
131+
const partPrompt = await getPromptFromTemplate(
132132
"action-builder.txt",
133133
form.values.prompt
134134
);
135+
const fullPrompt =
136+
partPrompt +
137+
"\n\nWrite the JavaScript code to implement the following functionality:\n\n" +
138+
form.values.prompt;
135139

136140
const completion = await getCompletion("JavaScript", fullPrompt);
137141

actions/generate-js-action.js

+37-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const Table = require("@saltcorn/data/models/table");
55
const Field = require("@saltcorn/data/models/field");
66
const { apply, removeAllWhiteSpace } = require("@saltcorn/data/utils");
77
const { getActionConfigFields } = require("@saltcorn/data/plugin-helper");
8-
const { a, pre, script, div } = require("@saltcorn/markup/tags");
9-
const { fieldProperties } = require("../common");
8+
const { a, pre, script, div, code } = require("@saltcorn/markup/tags");
9+
const { fieldProperties, getPromptFromTemplate } = require("../common");
1010

1111
class GenerateJsAction {
1212
static title = "Generate JavaScript Action";
@@ -16,9 +16,9 @@ class GenerateJsAction {
1616
static async json_schema() {
1717
return {
1818
type: "object",
19-
required: ["code", "action_name"],
19+
required: ["action_javascript_code", "action_name"],
2020
properties: {
21-
code: {
21+
action_javascript_code: {
2222
description: "JavaScript code that constitutes the action",
2323
type: "string",
2424
},
@@ -28,8 +28,7 @@ class GenerateJsAction {
2828
type: "string",
2929
},
3030
action_description: {
31-
description:
32-
"A description of the purpose of the action.",
31+
description: "A description of the purpose of the action.",
3332
type: "string",
3433
},
3534
when_trigger: {
@@ -46,6 +45,38 @@ class GenerateJsAction {
4645
},
4746
};
4847
}
48+
static async system_prompt() {
49+
const partPrompt = await getPromptFromTemplate("action-builder.txt", "");
50+
return (
51+
`Use the generate_js_action to generate actions based on JavaScript code. ` +
52+
partPrompt
53+
);
54+
}
55+
static render_html({
56+
action_javascript_code,
57+
action_name,
58+
action_description,
59+
when_trigger,
60+
trigger_table,
61+
}) {
62+
return (
63+
div({class: "mb-3"},
64+
`${action_name}${when_trigger ? `: ${when_trigger}` : ""}${
65+
trigger_table ? ` on ${trigger_table}` : ""
66+
}`
67+
) + pre(code(action_javascript_code))
68+
);
69+
}
70+
static async execute(
71+
{
72+
action_javascript_code,
73+
action_name,
74+
action_description,
75+
when_trigger,
76+
trigger_table,
77+
},
78+
req
79+
) {}
4980
}
5081

5182
module.exports = GenerateJsAction;

chat-copilot.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const run = async (table_id, viewname, cfg, state, { res, req }) => {
126126
)
127127
),
128128

129-
i(small("Skills you can request: Generate Workflow, Generate Tables"))
129+
i(small("Skills you can request: "+actionClasses.map(ac=>ac.title).join(", ")))
130130
);
131131
return {
132132
widths: [3, 9],
@@ -273,6 +273,7 @@ const ellipsize = (s, nchars) => {
273273
const actionClasses = [
274274
require("./actions/generate-workflow"),
275275
require("./actions/generate-tables"),
276+
require("./actions/generate-js-action"),
276277
];
277278

278279
const getCompletionArguments = async () => {

prompts/action-builder.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,4 @@ value should be an object with keys that are field variable names. Example:
300300
return { set_fields: {
301301
zidentifier: `${name.toUpperCase()}-${id}`
302302
}
303-
}
304-
305-
Write the JavaScript code to implement the following functionality:
306-
307-
{{ userPrompt }}
303+
}

0 commit comments

Comments
 (0)