Added missing fillBlanks mc variant that was in UTAS to custom level

This commit is contained in:
Carlos Mesquita
2024-09-06 09:36:24 +01:00
parent a2cfa335d7
commit a931c5ec2e
2 changed files with 69 additions and 0 deletions

9
app.py
View File

@@ -1317,6 +1317,7 @@ class CustomLevelExerciseTypes(Enum):
MULTIPLE_CHOICE_4 = "multiple_choice_4"
MULTIPLE_CHOICE_BLANK_SPACE = "multiple_choice_blank_space"
MULTIPLE_CHOICE_UNDERLINED = "multiple_choice_underlined"
FILL_BLANKS_MC = "fill_blanks_mc"
BLANK_SPACE_TEXT = "blank_space_text"
READING_PASSAGE_UTAS = "reading_passage_utas"
WRITING_LETTER = "writing_letter"
@@ -1414,6 +1415,14 @@ def get_custom_level():
exercise_id = exercise_id + qty
exercise_qty = exercise_qty - qty
elif exercise_type == CustomLevelExerciseTypes.FILL_BLANKS_MC.value:
response["exercises"]["exercise_" + str(i)] = gen_fill_blanks_mc_utas(
exercise_qty, exercise_id, exercise_text_size
)
response["exercises"]["exercise_" + str(i)]["type"] = "fillBlanks"
response["exercises"]["exercise_" + str(i)]["variant"] = "mc"
exercise_id = exercise_id + exercise_qty
elif exercise_type == CustomLevelExerciseTypes.BLANK_SPACE_TEXT.value:
response["exercises"]["exercise_" + str(i)] = gen_blank_space_text_utas(exercise_qty, exercise_id,
exercise_text_size)

View File

@@ -1563,6 +1563,66 @@ def gen_multiple_choice_underlined_utas(quantity: int, start_id: int, all_exams=
return response
def gen_fill_blanks_mc_utas(quantity: int, start_id: int, size: int, topic=random.choice(mti_topics)):
json_format = {
"question": {
"solutions": [
{
"id": "<question id>",
"solution": "<the option that holds the solution>"
}
],
"words": [
{
"id": "<question id>",
"options": {
"A": "<a option>",
"B": "<b option>",
"C": "<c option>",
"D": "<d option>"
}
}
],
"text": "text"
}
}
messages = [
{
"role": "system",
"content": 'You are a helpful assistant designed to output JSON on this format: ' + str(json_format)
},
{
"role": "user",
"content": (
f'Generate a text of at least {size} words about the topic {topic}. Make sure the text is structured '
'in paragraphs formatted with newlines (\\n\\n) to delimit them.'
)
},
{
"role": "user",
"content": (
f'From the generated text choose {quantity} words (cannot be sequential words) to replace '
'once with {{id}} where id starts on ' + str(start_id) + ' and is incremented for each word. '
'For each word choose 4 options, 1 correct and the other ones false. Make sure that only 1 is the '
'correct one amongst the 4 options and put the solution on the solutions array. '
'The ids must be ordered throughout the text and the words must be replaced only once. Put the '
'removed words and respective ids on the words array of the json in the correct order. You can\'t '
'reference multiple times the same id across the text, if for example one of the chosen words is '
'"word1" then word1 must be placed in the text with an id once, if word1 is referenced other '
'times in the text then replace with the actual text of word.'
)
}
]
token_count = count_total_tokens(messages)
question = make_openai_call(GPT_4_O, messages, token_count,
["question"],
GEN_QUESTION_TEMPERATURE)
return question["question"]
def gen_blank_space_text_utas(quantity: int, start_id: int, size: int, topic=random.choice(mti_topics)):
json_format = {
"question": {