register
def register(
name:str, label:str, note:str, dflt:str, check:NoneType=None
)->str:Add the prompt name with a plain label, a note on what it changes, its dflt text and an optional check. Return dflt.
Each prompt of the tutor has two parts. The variable parts (the concept, the thread, the JSON shape) stay in code. The instruction text is in this registry. Each prompt has a name, a plain label, a note on what it changes, and its default text from code. The Settings page shows each prompt, and you can change its text there. The tutor reads each prompt when it calls the model. Thus a change works on the next question, with no restart.
Import the tools that this module uses. The settings come from settings only when a prompt is read, so the import stays light.
register adds a prompt to PROMPTS and returns its default text. A check can refuse a bad text: it raises ValueError with a plain message.
Add the prompt name with a plain label, a note on what it changes, its dflt text and an optional check. Return dflt.
lines gives the lines of a text that are not empty. need_lines makes a check that refuses a text without exactly n such lines.
A check that refuses a text that does not have n lines that are not empty.
The lines of text that are not empty, without spaces at the ends.
prompt gives the saved text of a prompt, else its default. set_prompt saves a text in the settings, under the prompts key. An empty text, or a text that is the same as the default, removes the saved text. Then the default is in use again, also when a new version changes the default.
Save the text of the prompt name. An empty text uses the default. A text that fails the check raises ValueError. Return the text in use.
The text of the prompt name now: the saved text, else the default.
A small prompt with a check of 2 lines. Its default is in use at first.
A saved text is in use at once, and the settings keep it under prompts.
A text that fails the check is refused with a plain message, and the saved text stays.
An empty text, or only spaces, removes the saved text, so the default is in use again. A text that is the same as the default is not kept.
An unknown name is an error. Then the test prompt goes away.