Add default for topic on custom level and random reorder for multiple choice options.

This commit is contained in:
Cristiano Ferreira
2024-07-26 15:59:11 +01:00
parent 88ba9ab561
commit 19f204d74d
2 changed files with 34 additions and 5 deletions

View File

@@ -1368,7 +1368,9 @@ def gen_multiple_choice_blank_space_utas(quantity: int, start_id: int, all_exams
question["questions"][i], seen_keys = replace_exercise_if_exists_utas(all_exams, question["questions"][i],
question,
seen_keys)
return fix_exercise_ids(question, start_id)
response = fix_exercise_ids(question, start_id)
response["questions"] = randomize_mc_options_order(response["questions"])
return response
def gen_multiple_choice_underlined_utas(quantity: int, start_id: int):
@@ -1437,7 +1439,9 @@ def gen_multiple_choice_underlined_utas(quantity: int, start_id: int):
if len(question["questions"]) != quantity:
return gen_multiple_choice_level(quantity, start_id)
else:
return fix_exercise_ids(question, start_id)
response = fix_exercise_ids(question, start_id)
response["questions"] = randomize_mc_options_order(response["questions"])
return response
def gen_blank_space_text_utas(quantity: int, start_id: int, size: int, topic=random.choice(mti_topics)):
@@ -1590,7 +1594,9 @@ def gen_text_multiple_choice_utas(text: str, start_id: int, mc_quantity: int):
if len(question["questions"]) != mc_quantity:
return gen_multiple_choice_level(mc_quantity, start_id)
else:
return fix_exercise_ids(question, start_id)["questions"]
response = fix_exercise_ids(question, start_id)
response["questions"] = randomize_mc_options_order(response["questions"])
return response
def generate_level_mc(start_id: int, quantity: int):
@@ -1644,4 +1650,26 @@ def generate_level_mc(start_id: int, quantity: int):
question = make_openai_call(GPT_4_O, messages, token_count, ["questions"],
GEN_QUESTION_TEMPERATURE)
return fix_exercise_ids(question, start_id)
response = fix_exercise_ids(question, start_id)
response["questions"] = randomize_mc_options_order(response["questions"])
return response
def randomize_mc_options_order(questions):
option_ids = ['A', 'B', 'C', 'D']
for question in questions:
# Store the original solution text
original_solution_text = next(
option['text'] for option in question['options'] if option['id'] == question['solution'])
# Shuffle the options
random.shuffle(question['options'])
# Update the option ids and find the new solution id
for idx, option in enumerate(question['options']):
option['id'] = option_ids[idx]
if option['text'] == original_solution_text:
question['solution'] = option['id']
return questions