The Examplary platform supports AI-assisted question generation for custom question types.
You can enable this feature by configuring the generation option in your question type's metadata.
The generation field is an object that defines the settings for AI-assisted question generation.
Specify an enabled boolean to turn this feature on or off, and provide any additional instructions for the AI.
new QuestionType({
generation: {
enabled: true,
instructions:
"Requires an `options` setting with an array of strings that will be used as multiple choice options. Also set `possibleAnswers` to an array containing the accepted option values for response processing.",
},
});Validating generated questions
Question types can check the questions the AI generates before they are added to a test. Write a function that receives { question } and returns { valid: boolean, error?: string }, and add it to your question type with addValidator(). It can be async.
import type { Question } from "@examplary/schemas";
export default ({ question }: { question: Question }) => {
const options = question.settings?.options ?? [];
if (options.length < 2) {
return { valid: false, error: "Provide at least two options." };
}
return { valid: true };
};import { QuestionType } from "@examplary/apps";
import validateQuestion from "./validate-question";
const multipleChoice = new QuestionType({
// ...
});
multipleChoice.addValidator(validateQuestion);
export default multipleChoice;When a question is invalid, it isn't added and your error message goes back to the AI, so make it specific. The validator runs on our servers as one of your app's hooks, in the same sandbox. If it fails or returns anything else, the question is accepted as is.