Skip to content

Commit

Permalink
fix: improving prompt to openAI and removing char limit for pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
kathleenkhy committed Apr 9, 2024
1 parent 1982bb4 commit e81cbce
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ export const MagicFormBuilderPdfDetailsScreen = (): JSX.Element => {
return combinedText.trim()
}

const isError = pdfFileText.length > 3000

return (
<>
<ModalHeader color="secondary.700">
Expand All @@ -97,15 +95,15 @@ export const MagicFormBuilderPdfDetailsScreen = (): JSX.Element => {
</ModalHeader>
<ModalBody whiteSpace="pre-wrap">
<Container maxW={'42.5rem'} p={0}>
<FormControl isInvalid={isError || !!errors.pdfFileText}>
<FormControl isInvalid={!!errors.pdfFileText}>
<FormLabel>
Upload a PDF - The PDF should not be a scanned copy and should not
contain any restricted or sensitive information.
</FormLabel>
<Controller
rules={{
validate: (pdfFileText) => {
if (pdfFileText && pdfFileText.length < 3001) return true
if (pdfFileText) return true
return 'This PDF file cannot be processed. Please ensure that the PDF uploaded contains selectable text and is not a scanned copy.'
},
}}
Expand All @@ -127,15 +125,11 @@ export const MagicFormBuilderPdfDetailsScreen = (): JSX.Element => {
/>

<FormErrorMessage alignItems="top">
{(isError || !pdfFileText) && (
<FormErrorIcon h="1.5rem" as={BxsErrorCircle} />
)}
{!pdfFileText && <FormErrorIcon h="1.5rem" as={BxsErrorCircle} />}
{!pdfFileText &&
(pdfFile
? `${errors.pdfFileText?.message}`
: 'Please upload a PDF.')}
{isError &&
`The PDF uploaded exceeds the character limit acceptable (${pdfFileText.length}/3000). Please try another form.`}
</FormErrorMessage>
</FormControl>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ const generateQuestionsSchema = Joi.object({
type: Joi.string()
.valid(...Object.values(ContentTypes))
.required(),
content: Joi.alternatives().conditional('type', {
content: Joi.string().when('type', {
is: ContentTypes.PROMPT,
then: Joi.string().max(300).required(),
otherwise: Joi.string().max(3000).required(), // max character of 3000 to cater for PDF uploads
}),
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const questionListPromptBuilder = (purpose: string) => {

export const formFieldsPromptBuilder = (questions: string) => {
return `Help me generate a form with the following list of questions: ${questions}
Present the questions as FormSG form fields in JSON (list of form field schemas), in the form of "${expectedFormFieldSchemaFormat}" as defined by the system, without any code blocks. Format the JSON as a single line.`
Present the questions as FormSG form fields in JSON (strictly following the list of form field schemas), in the form of "${expectedFormFieldSchemaFormat}" as defined by the system, without any code blocks. Format the JSON as a single line. Ensure the JSON generated does not contain form fields which do not exist in the schema provided.`
}
export const migratePromptBuilder = (parsedContent: string) => {
return `Help me generate the corresponding JSON form fields from content parsed from a PDF document.
Expand Down

0 comments on commit e81cbce

Please sign in to comment.