workflowAI client
Install workflowAI
npm install --save @workflowai/workflowai
Initialize client
import { WorkflowAI } from '@workflowai/workflowai'
const workflowAI = new WorkflowAI({
apiKey: '...',
})
Compile your task
import { z } from '@workflowai/workflowai'
const checkTextFollowInstructions = await workflowAI.compileTask(
{
taskId: 'CheckTextFollowInstructions',
schema: {
id: 5,
input: z.object({
text: z
.string()
.describe(
'The text to check if it follows the instructions in "instructions"',
),
instructions: z
.string()
.describe('The instructions to check if the text follows'),
}),
output: z.object({
isFollowingInstructions: z
.bool()
.describe('Whether the "text" follows all the instructions or not'),
reason: z
.string()
.describe('The reason why the text follows or not the instructions'),
}),
},
},
{
group: {
id: '...',
},
},
)
Prepare your task input
Use the TaskInput
TypeScript helper to infer the type of a task input.
Another helper, TaskOutput
, can infer the type of what you can expect as result of a task run.
import { TaskInput } from '@workflowai/workflowai'
const input: TaskInput<typeof checkTextFollowInstructions> = {
text: 'The capital of France is Barcelona',
instructions: 'The text must be written in English',
}
Run your task
const output = await checkTextFollowInstructions(input, {
group: {
id: '2',
},
})
console.log(output.isFollowingInstructions)
console.log(output.reason)