-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworkflow-gen.js
45 lines (40 loc) · 1.46 KB
/
workflow-gen.js
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
const { getState } = require("@saltcorn/data/db/state");
const WorkflowStep = require("@saltcorn/data/models/workflow_step");
const Trigger = require("@saltcorn/data/models/trigger");
const { getActionConfigFields } = require("@saltcorn/data/plugin-helper");
const GenerateWorkflow = require("./actions/generate-workflow");
const workflow_function = async () => ({
type: "function",
function: {
name: "generate_workflow",
description: "Generate the steps in a workflow",
parameters: await GenerateWorkflow.json_schema(),
},
});
module.exports = {
run: async (description) => {
const rnd = Math.round(100 * Math.random());
const systemPrompt = await GenerateWorkflow.system_prompt();
const toolargs = {
tools: [await workflow_function()],
tool_choice: {
type: "function",
function: { name: "generate_workflow" },
},
systemPrompt,
};
const prompt = `Design a workflow to implement a workflow accorfing to the following specification: ${description}`;
console.log(prompt);
console.log(JSON.stringify(toolargs, null, 2));
const answer = await getState().functions.llm_generate.run(
prompt,
toolargs
);
const resp = JSON.parse(answer.tool_calls[0].function.arguments);
const scsteps = resp.workflow_steps.map(GenerateWorkflow.to_saltcorn_step);
return scsteps;
},
isAsync: true,
description: "Generate a workflow",
arguments: [{ name: "description", type: "String" }],
};