edulinq / quizgen

MIT License
4 stars 0 forks source link

Template Question Generation #26

Open eriq-augustine opened 6 months ago

eriq-augustine commented 6 months ago

Create a way to populate a group using a template. We should be able to use standard Jinja templates.

To populate the pool of values for the template variables, we can use two methods:

Once we have a list of objects, questions can be generated and then sampled the same as any question.

eriq-augustine commented 6 months ago

Here are some more thoughts I have had on this.

It would be useful to allow for variables anywhere in a question's config, not just prompt and answers.

I want to keep the templates simple, so we may not even use a library. I don't want loops or control structures, just replacements. Or maybe not, maybe just use Jinja templates.

I see three "modes", and we can implement all three:

  1. Replacements (list of objects) are specified in the JSON.
  2. Code is called that produces the replacements (JSON list of objects).
  3. Code is called that produces an entire question JSON object.

For the methods that call code, we should just call an executable that should output JSON on stdout. I don't want direct code in the JSON, don't want to deal with loading libraries, and don't want to have to code in support for multiple languages. So, stdout it is.

In the first mode, I see a procedure like:

There will be an issue if the initial doc is not valid JSON (and therefore cannot be parsed). We could say that replacements need to be in strings (and therefore will be valid). Cannot add elements like this (which is fine, could be done in full generation version). Cannot template non-string values (fine if we parse/type-check all values). Could hack in new keys (injection-style) (unless we escape strings)