diff --git a/packages/api/src/functions/gptHandlers.ts b/packages/api/src/functions/gptHandlers.ts index a54bb975..22a52daa 100644 --- a/packages/api/src/functions/gptHandlers.ts +++ b/packages/api/src/functions/gptHandlers.ts @@ -40,10 +40,13 @@ Points: [Select from the following options based on how difficult you think the (points) => points.title, ).join(", ")}]`; -export const generateChoicesPrompt = (numChoices: number) => { +export const generateChoicesPrompt = ( + numChoices: number, + maxCharsForChoice = 50, +) => { let choicesPrompt = ""; for (let i = 1; i <= numChoices; i++) { - choicesPrompt += `Option ${i}: [Choice ${i}]\n`; + choicesPrompt += `Option ${i}: [Choice ${i}, must not exceed ${maxCharsForChoice} characters]\n`; } return choicesPrompt.trim(); }; @@ -64,7 +67,7 @@ export const promptGenerators: { ) => `Create a multiple choice question (maximum of ${maxCharsForQuestion} characters) about: "${message}" with ${numChoices} choices. Each choice must not exceed ${maxCharsForChoice} characters and there must be only 1 correct answer. Format as: Question: [Your question here] -${generateChoicesPrompt(numChoices)} +${generateChoicesPrompt(numChoices, maxCharsForChoice)} Correct Answer: Option [Correct option number] ${timeAndPointsPrompt}`, @@ -73,7 +76,7 @@ ${timeAndPointsPrompt}`, maxCharsForQuestion = 100, maxCharsForChoice = 50, ) => - `Create an identification question (maximum of ${maxCharsForQuestion} characters) based on: "${message}". The answer must not exceed ${maxCharsForChoice} characters. Format as: + `Create an identification question (maximum of ${maxCharsForQuestion} characters) based on: "${message}". The answer should be concise and straight to the point and must not include unnesessary words or phrases, and must not exceed ${maxCharsForChoice} characters. Format as: Question: [Your question here] Answer: [Your answer here] ${timeAndPointsPrompt}`, @@ -92,7 +95,7 @@ ${timeAndPointsPrompt}`, ) => `Create a multiselect question (maximum of ${maxCharsForQuestion} characters) about: "${message}" with ${numChoices} choices. The choices must not exceed ${maxCharsForChoice} characters and there must be atleast 1 correct answer. Multiple answers can be correct. Format as: Question: [Your question here] -${generateChoicesPrompt(numChoices)} +${generateChoicesPrompt(numChoices, maxCharsForChoice)} All Correct Answers: Options [Correct option numbers separated by commas, e.g., 1,3] ${timeAndPointsPrompt}`, }; diff --git a/packages/api/src/functions/randomQuestionsHandlers.ts b/packages/api/src/functions/randomQuestionsHandlers.ts index 6efd2b0d..58c8b14d 100644 --- a/packages/api/src/functions/randomQuestionsHandlers.ts +++ b/packages/api/src/functions/randomQuestionsHandlers.ts @@ -49,23 +49,22 @@ export const questionFormatGenerators: { numChoices = 4, maxCharsForQuestion = 100, maxCharsForChoice = 50, - ) => `separator\nQuestion: [Your question here, max ${maxCharsForQuestion} characters, and each choice below must not exceed ${maxCharsForChoice} characters] - ${generateChoicesPrompt( - numChoices, - )}\nCorrect Answer: Option [Correct option number and only 1 correct answer] ${timeAndPointsPrompt}`, - + ) => `separator\nQuestion: [Your question here, max ${maxCharsForQuestion} characters] +${generateChoicesPrompt( + numChoices, + maxCharsForChoice, +)}\nCorrect Answer: Option [Correct option number and only 1 correct answer] ${timeAndPointsPrompt}`, multiselect: ( numChoices = 4, maxCharsForQuestion = 100, maxCharsForChoice = 50, - ) => `separator\nQuestion: [Your question here, max ${maxCharsForQuestion} characters, and each choice below must not exceed ${maxCharsForChoice} characters] - ${generateChoicesPrompt( - numChoices, - )}\nAll Correct Answers: Options [Correct option numbers separated by commas (e.g., 1,3) and at least one correct answer] ${timeAndPointsPrompt}`, - + ) => `separator\nQuestion: [Your question here, max ${maxCharsForQuestion} characters] +${generateChoicesPrompt( + numChoices, + maxCharsForChoice, +)}\nAll Correct Answers: Options [Correct option numbers separated by commas (e.g., 1,3) and at least one correct answer] ${timeAndPointsPrompt}`, identification: (maxCharsForQuestion = 100, maxCharsForChoice = 50) => - `separator\nQuestion: [Your question here, max ${maxCharsForQuestion} characters]\nAnswer: [Your answer here, max ${maxCharsForChoice} characters] ${timeAndPointsPrompt}`, - + `separator\nQuestion: [Your question here, max ${maxCharsForQuestion} characters]\nAnswer: [Your answer here, max ${maxCharsForChoice} characters, and the answer should be concise and straight to the point and must not include unnesessary words or phrases] ${timeAndPointsPrompt}`, trueOrFalse: (maxCharsForQuestion = 100) => `separator\nQuestion: [Your question here, max ${maxCharsForQuestion} characters]\nAnswer: [True/False] ${timeAndPointsPrompt}`, }; diff --git a/packages/api/src/functions/tests/generatePromptForType.test.ts b/packages/api/src/functions/tests/generatePromptForType.test.ts index a6b6bf3f..c5b84ca7 100644 --- a/packages/api/src/functions/tests/generatePromptForType.test.ts +++ b/packages/api/src/functions/tests/generatePromptForType.test.ts @@ -8,12 +8,12 @@ describe("generatePromptForType", () => { it("should generate prompt for multipleChoice with default number of choices", () => { const result = generatePromptForType(message, "multipleChoice"); expect(result).toEqual( - `Create a multiple choice question (maximum of 100 characters) about: "${message}" with 4 choices. Each choice must not exceed 68 characters and there must be only 1 correct answer. Format as: + `Create a multiple choice question (maximum of 100 characters) about: "${message}" with 4 choices. Each choice must not exceed 50 characters and there must be only 1 correct answer. Format as: Question: [Your question here] -Option 1: [Choice 1] -Option 2: [Choice 2] -Option 3: [Choice 3] -Option 4: [Choice 4] +Option 1: [Choice 1, must not exceed 50 characters] +Option 2: [Choice 2, must not exceed 50 characters] +Option 3: [Choice 3, must not exceed 50 characters] +Option 4: [Choice 4, must not exceed 50 characters] Correct Answer: Option [Correct option number] ${timeAndPointsPrompt}`, ); @@ -22,7 +22,7 @@ ${timeAndPointsPrompt}`, it("should generate prompt for identification", () => { const result = generatePromptForType(message, "identification"); expect(result).toEqual( - `Create an identification question (maximum of 100 characters) based on: "${message}". The answer must not exceed 68 characters. Format as: + `Create an identification question (maximum of 100 characters) based on: "${message}". The answer should be concise and straight to the point and must not include unnesessary words or phrases, and must not exceed 50 characters. Format as: Question: [Your question here] Answer: [Your answer here] ${timeAndPointsPrompt}`, @@ -32,7 +32,7 @@ ${timeAndPointsPrompt}`, it("should generate prompt for trueOrFalse", () => { const result = generatePromptForType(message, "trueOrFalse"); expect(result).toEqual( - `Based on the information "${message}", generate a true or false question (maximum of 100 characters). The answer must not exceed 68 characters. Format as: + `Based on the information "${message}", generate a true or false question (maximum of 100 characters). The answer must not exceed 50 characters. Format as: Question: [Your question here] Answer: [True/False] ${timeAndPointsPrompt}`, @@ -42,12 +42,12 @@ ${timeAndPointsPrompt}`, it("should generate prompt for multiselect with default number of choices", () => { const result = generatePromptForType(message, "multiselect"); expect(result).toEqual( - `Create a multiselect question (maximum of 100 characters) about: "${message}" with 4 choices. The choices must not exceed 68 characters and there must be atleast 1 correct answer. Multiple answers can be correct. Format as: + `Create a multiselect question (maximum of 100 characters) about: "${message}" with 4 choices. The choices must not exceed 50 characters and there must be atleast 1 correct answer. Multiple answers can be correct. Format as: Question: [Your question here] -Option 1: [Choice 1] -Option 2: [Choice 2] -Option 3: [Choice 3] -Option 4: [Choice 4] +Option 1: [Choice 1, must not exceed 50 characters] +Option 2: [Choice 2, must not exceed 50 characters] +Option 3: [Choice 3, must not exceed 50 characters] +Option 4: [Choice 4, must not exceed 50 characters] All Correct Answers: Options [Correct option numbers separated by commas, e.g., 1,3] ${timeAndPointsPrompt}`, ); @@ -64,9 +64,9 @@ ${timeAndPointsPrompt}`, expect(result).toEqual( `Create a multiple choice question (maximum of 80 characters) about: "${message}" with 3 choices. Each choice must not exceed 50 characters and there must be only 1 correct answer. Format as: Question: [Your question here] -Option 1: [Choice 1] -Option 2: [Choice 2] -Option 3: [Choice 3] +Option 1: [Choice 1, must not exceed 50 characters] +Option 2: [Choice 2, must not exceed 50 characters] +Option 3: [Choice 3, must not exceed 50 characters] Correct Answer: Option [Correct option number] ${timeAndPointsPrompt}`, ); @@ -75,7 +75,7 @@ ${timeAndPointsPrompt}`, it("should generate prompt for identification with custom max characters", () => { const result = generatePromptForType(message, "identification", 90, 60); expect(result).toEqual( - `Create an identification question (maximum of 90 characters) based on: "${message}". The answer must not exceed 60 characters. Format as: + `Create an identification question (maximum of 90 characters) based on: "${message}". The answer should be concise and straight to the point and must not include unnesessary words or phrases, and must not exceed 60 characters. Format as: Question: [Your question here] Answer: [Your answer here] ${timeAndPointsPrompt}`, diff --git a/packages/api/src/functions/tests/randomQuestionHandlers.test.ts b/packages/api/src/functions/tests/randomQuestionHandlers.test.ts index fcb515f7..adfa24f1 100644 --- a/packages/api/src/functions/tests/randomQuestionHandlers.test.ts +++ b/packages/api/src/functions/tests/randomQuestionHandlers.test.ts @@ -10,10 +10,10 @@ import { generateChoicesPrompt, timeAndPointsPrompt } from "../gptHandlers"; describe("questionFormatGenerators", () => { it("It should generate format for multiple choice question/s", () => { const mcqFormat = questionFormatGenerators["multipleChoice"]; - const output = `separator\nQuestion: [Your question here, max 100 characters, and each choice below must not exceed 68 characters] - ${generateChoicesPrompt( - 4, - )}\nCorrect Answer: Option [Correct option number and only 1 correct answer] ${timeAndPointsPrompt}`; + const output = `separator\nQuestion: [Your question here, max 100 characters] +${generateChoicesPrompt( + 4, +)}\nCorrect Answer: Option [Correct option number and only 1 correct answer] ${timeAndPointsPrompt}`; expect(mcqFormat()).toEqual(output); }); @@ -21,10 +21,10 @@ describe("questionFormatGenerators", () => { it("It should generate format for multiselect question/s", () => { const multiselectFormat = questionFormatGenerators["multiselect"]; - const output = `separator\nQuestion: [Your question here, max 100 characters, and each choice below must not exceed 68 characters] - ${generateChoicesPrompt( - 4, - )}\nAll Correct Answers: Options [Correct option numbers separated by commas (e.g., 1,3) and at least one correct answer] ${timeAndPointsPrompt}`; + const output = `separator\nQuestion: [Your question here, max 100 characters] +${generateChoicesPrompt( + 4, +)}\nAll Correct Answers: Options [Correct option numbers separated by commas (e.g., 1,3) and at least one correct answer] ${timeAndPointsPrompt}`; expect(multiselectFormat()).toEqual(output); }); @@ -32,7 +32,7 @@ describe("questionFormatGenerators", () => { it("It should generate format for identification question/s", () => { const identicationFormat = questionFormatGenerators["identification"]; - const output = `separator\nQuestion: [Your question here, max 100 characters]\nAnswer: [Your answer here, max 68 characters] ${timeAndPointsPrompt}`; + const output = `separator\nQuestion: [Your question here, max 100 characters]\nAnswer: [Your answer here, max 50 characters, and the answer should be concise and straight to the point and must not include unnesessary words or phrases] ${timeAndPointsPrompt}`; expect(identicationFormat()).toEqual(output); });