Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 11 additions & 119 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"node-cache": "^5.1.2",
"nodemailer": "^6.9.16",
"oauth4webapi": "^3.6.0",
"openai": "^4.70.3",
"openai": "^6.16.0",
"openid-client": "^6.6.2",
"openid-client-legacy": "npm:openid-client@^5.7.1",
"opossum": "^8.1.4",
Expand Down
126 changes: 124 additions & 2 deletions src/app/modules/form/admin-form/admin-form.assistance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ const generateAndsendTextPromptToModel = ({
formId,
options: {
response_format: {
type: 'json_object',
type: 'json_schema',
json_schema: suggestedFormFieldsLlmSchema,
},
},
}).mapErr((error) => {
Expand Down Expand Up @@ -445,6 +446,126 @@ const generateFormCreationVisionPrompt = ({
] as Message[]
}

const suggestedFormFieldsLlmSchema = {
Copy link
Copy Markdown
Contributor Author

@kevin9foong kevin9foong Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: To see if can find a way to reuse the schema defined in TS.

name: 'suggested_form_fields',
strict: true,
schema: {
type: 'object',
properties: {
fields: {
type: 'array',
minItems: 1,
items: {
anyOf: [
// 1. Base field schema
{
type: 'object',
properties: {
title: { type: 'string', minLength: 1 },
fieldType: {
type: 'string',
enum: [
'Section',
'Email',
'Mobile',
'HomeNo',
'Number',
'Decimal',
'ShortText',
'LongText',
'CountryRegion',
'YesNo',
'Attachment',
'Date',
'Rating',
'Nric',
'Uen',
'Address',
'Signature',
],
},
required: { type: 'boolean' },
description: { type: 'string' },
},
required: ['title', 'fieldType', 'required', 'description'], // description must be required in Strict Mode if defined
additionalProperties: false,
},
// 2. Table field schema
{
type: 'object',
properties: {
title: { type: 'string', minLength: 1 },
fieldType: { type: 'string', const: 'Table' },
required: { type: 'boolean' },
description: { type: 'string' },
columns: {
type: 'array',
items: { type: 'string', minLength: 1 },
minItems: 1,
},
minimumRows: { type: 'integer', minimum: 1 },
maximumRows: { type: 'integer', minimum: 1 },
addMoreRows: { type: 'boolean' },
},
required: [
'title',
'fieldType',
'required',
'description',
'columns',
'minimumRows',
'maximumRows',
'addMoreRows',
],
additionalProperties: false,
},
// 3. Statement field schema
{
type: 'object',
properties: {
title: { type: 'string' },
fieldType: { type: 'string', const: 'Statement' },
required: { type: 'boolean' },
description: { type: 'string', minLength: 1 },
},
required: ['title', 'fieldType', 'required', 'description'],
additionalProperties: false,
},
// 4. Choices field schema
{
type: 'object',
properties: {
title: { type: 'string', minLength: 1 },
fieldType: {
type: 'string',
enum: ['Checkbox', 'Radio', 'Dropdown'],
},
required: { type: 'boolean' },
description: { type: 'string' },
fieldOptions: {
type: 'array',
items: { type: 'string', minLength: 1 },
minItems: 1,
},
},
required: [
'title',
'fieldType',
'required',
'description',
'fieldOptions',
],
additionalProperties: false,
},
],
},
},
},
required: ['fields'],
additionalProperties: false,
},
}

const generateAndSendVisionPromptToModel = ({
formId,
imageDataUrls,
Expand All @@ -458,7 +579,8 @@ const generateAndSendVisionPromptToModel = ({
formId,
options: {
response_format: {
type: 'json_object',
type: 'json_schema',
json_schema: suggestedFormFieldsLlmSchema,
},
},
}).mapErr((error) => {
Expand Down
Loading