Terminal-Based Question Generator
Creates a barebones OPB markdown question via a series of tui prompts.
Getting started
Install the package via pip:
pip install "problem_bank_scripts[tui]"
Or, install the latest development version from the repository:
pip install "problem_bank_scripts[tui] @ git+https://github.com/open-resources/problem_bank_scripts"
Create a .env file in the directory you will be running the TUI.
In it, fill in the required variables below, and any optional variables you wish to use.
Variable |
Description |
Required? |
|---|---|---|
|
Your Username On GitHub |
Yes |
WRITE_PATH |
The absolute path to the question bank
the question should be created in
when using the
--create-pr option, e.g.,/home/<your-name>/instructor_stats_bank/source/unsorted |
Yes
|
PL_QUESTION_PATH |
The absolute path to your local prairielearn course,
e.g.,
/home/<your-name>/pl-opb-ind100/questions |
Yes
|
|
Your Name |
Yes |
|
Your Initials |
Yes |
|
Allows using the OpenAI API |
If |
TEXTBOOK |
The textbook you’re creating the question from,
e.g.,
openstax-stats-2e |
No
|
Usage
Create a question via:
pbs-cli create-question
# OR
python -m problem_bank_scripts.tui
For more information run pbs-cli create-question --help
To see all available commands, run pbs-cli --help.
Variables
To designate certain values as variables, wrap it in curly braces, and prefix it with the variable name you want as follows:
{<variablename>:<original value>}
Variable Example
To make 12.6 a variable in the sentence
12.6% are age 65 and over., you would write it as:
{percent_senior:12.6}% are age 65 and over.
So for the following input in the TUI:
would result in the following being generated in the generate function:
generate: |
...
percent_senior = round(random.uniform(11.3, 13.9), 1) # 12.6
data2['params']['percent_senior'] = percent_senior
...
and the following in the markdown file generated:
# {{ params.title }}
{{ params.percent_senior }}% are age 65 and over.
...
For string variables, make sure add quotes around the value:
{percent_senior:"12.6"}% are age 65 and over.
Terminal commands
The following commands can be used in the terminal:
Command |
Description |
|---|---|
Ctrl + C |
Exit the program |
Ctrl + D |
Exit the program (same as Ctrl + C, but can be used if Ctrl + C is not working) |
Ctrl + U |
Clears the line for the input you are in. |
Saving results
In case you run into an issue where either you cancel the program before it terminates or it crashes due to an exception being thrown, the data you have already inputted will be saved in a file called saved.json.
You will be given the option to use this file the next time you run
pbs-cli create-question, so that you do not need to re-enter all the data again.
Warning
saved.json is overwritten each time you run the program.
If you want to keep the file for future use, you should create a copy of it.
You can use the --saved-json argument to specify a different file to read from and write to:
pbs-cli create-question --saved-json <path_to_file>
Creating a PR
To automatically have your generated Markdown question committed to Github with
a draft PR created for it, add the --create-pr flag to the command.
Make sure WRITE_PATH in your .env file is set correctly.
gh must be installed and authenticated for this to work.
To install, follow the instructions at on Github.
To authenticate, run
gh auth login, as explained in the Github CLI documentation.
GPT
Warning
OpenStax forbids using their material in LLMs without permission, so do not use the --gpt flag with OpenStax textbooks.
To allow use of GPT add the --gpt flag to the command:
pbs-cli create-question --gpt
This allows for GPT use in generating multiple-choice options and number-input solutions.