Skip to content

Commit 099b74e

Browse files
committed
chore: rename parameter to prompts
1 parent cc4d201 commit 099b74e

File tree

6 files changed

+44
-42
lines changed

6 files changed

+44
-42
lines changed

packages/backend/src/apps/aisay/__tests__/common/schema.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ describe('AISAY schema', () => {
1212
beforeEach(() => {
1313
generalisedModelPayload = {
1414
file: 's3:plumber-test-bucket:123456/789abc/plumber-logo.jpg',
15-
infoToExtract: [
15+
prompts: [
1616
{
17-
infoToExtract: 'What is your name?',
17+
prompt: 'What is your name?',
1818
},
1919
{
20-
infoToExtract: 'What is your age?',
20+
prompt: 'What is your age?',
2121
},
2222
],
2323
}
@@ -36,13 +36,13 @@ describe('AISAY schema', () => {
3636
result.data.file ===
3737
's3:plumber-test-bucket:123456/789abc/plumber-logo.jpg',
3838
)
39-
assert(Object.keys(result.data.infoToExtract).length === 2)
39+
assert(Object.keys(result.data.prompts).length === 2)
4040
assert(
41-
result.data.infoToExtract['additionalProp0'].description ===
41+
result.data.prompts['additionalProp0'].description ===
4242
'Extract the What is your name?',
4343
)
4444
assert(
45-
result.data.infoToExtract['additionalProp1'].description ===
45+
result.data.prompts['additionalProp1'].description ===
4646
'Extract the What is your age?',
4747
)
4848
})

packages/backend/src/apps/aisay/actions/use-generalised-model/get-data-out-metadata.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IDataOutMetadata, IExecutionStep } from '@plumber/types'
22

3-
import { getInfoToExtract } from '../../common/info-to-extract'
3+
import { getPrompts } from '../../common/get-prompts'
44

55
async function getDataOutMetadata(
66
executionStep: IExecutionStep,
@@ -11,23 +11,29 @@ async function getDataOutMetadata(
1111
return null
1212
}
1313

14-
const infoToExtract = await getInfoToExtract(stepId)
14+
const prompts = await getPrompts(stepId)
1515

1616
const fieldsMetadata: Record<string, IDataOutMetadata> = {}
1717
Object.keys(dataOut.fields).forEach((key) => {
1818
const index = parseInt(key.split('additionalProp')[1])
19-
const fieldName = infoToExtract[index]
19+
const fieldName = prompts[index]
2020
fieldsMetadata[key] = {
2121
label: fieldName,
2222
}
2323
})
2424

25+
const otherMetadata: Record<string, IDataOutMetadata> = {}
26+
Object.keys(dataOut).forEach((key) => {
27+
if (key !== 'fields') {
28+
otherMetadata[key] = {
29+
isHidden: true,
30+
}
31+
}
32+
})
33+
2534
return {
26-
quota: {
27-
label: 'Quota',
28-
isHidden: true,
29-
},
3035
fields: fieldsMetadata,
36+
...otherMetadata,
3137
}
3238
}
3339

packages/backend/src/apps/aisay/actions/use-generalised-model/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ const action: IRawAction = {
2828
label: 'Prompts',
2929
description:
3030
'Enter prompts to specify how the data should be interpreted and extracted',
31-
key: 'infoToExtract',
31+
key: 'prompts',
3232
type: 'multirow' as const,
3333
required: true,
3434
variables: true,
3535
addRowButtonText: 'Add prompt',
3636
subFields: [
3737
{
3838
placeholder: 'E.g. Return the price of individual line items',
39-
key: 'infoToExtract',
39+
key: 'prompt',
4040
type: 'string' as const,
4141
required: true,
4242
variables: false,
@@ -50,9 +50,9 @@ const action: IRawAction = {
5050
getDataOutMetadata,
5151

5252
async run($) {
53-
const { file, infoToExtract } = $.step.parameters as {
53+
const { file, prompts } = $.step.parameters as {
5454
file: string
55-
infoToExtract: Array<{ infoToExtract: string }>
55+
prompts: Array<{ prompt: string }>
5656
}
5757

5858
if (!$.auth.data?.clientId || !$.auth.data?.clientSecret) {
@@ -64,7 +64,7 @@ const action: IRawAction = {
6464
)
6565
}
6666

67-
const result = generalisedModelSchema.safeParse({ file, infoToExtract })
67+
const result = generalisedModelSchema.safeParse({ file, prompts })
6868
if (!result.success) {
6969
const { stepErrorName, stepErrorSolution } = getValidationError(result)
7070

@@ -93,7 +93,7 @@ const action: IRawAction = {
9393
Authorization: `Bearer ${token}`,
9494
},
9595
data: {
96-
gpt_query: result.data.infoToExtract,
96+
gpt_query: result.data.prompts,
9797
image: attachment.data,
9898
},
9999
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Step from '@/models/step'
2+
3+
export const getPrompts = async (stepId: string) => {
4+
const step = await Step.query().findById(stepId)
5+
if (!Array.isArray(step.parameters.prompts)) {
6+
return []
7+
}
8+
return step.parameters.prompts.map((i: { prompt: string }) => i.prompt)
9+
}

packages/backend/src/apps/aisay/common/info-to-extract.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/backend/src/apps/aisay/common/schema.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,16 @@ export const fileSchema = z.string().transform((value, context) => {
2626

2727
export const generalisedModelSchema = z.object({
2828
file: fileSchema,
29-
infoToExtract: z
30-
.array(z.object({ infoToExtract: z.string() }))
31-
.transform((array) => {
32-
const result: Record<string, { description: string; type: string }> = {}
33-
array.forEach((a, index) => {
34-
result[`additionalProp${index}`] = {
35-
description: `Extract the ${a.infoToExtract}`,
36-
type: 'string',
37-
}
38-
})
39-
return result
40-
}),
29+
prompts: z.array(z.object({ prompt: z.string() })).transform((array) => {
30+
const result: Record<string, { description: string; type: string }> = {}
31+
array.forEach((a, index) => {
32+
result[`additionalProp${index}`] = {
33+
description: `Extract the ${a.prompt}`,
34+
type: 'string',
35+
}
36+
})
37+
return result
38+
}),
4139
})
4240

4341
export const documentTypeEnum = z.enum(DOCUMENT_TYPES as [string, ...string[]])

0 commit comments

Comments
 (0)