Add default for topic on custom level and random reorder for multiple choice options.
This commit is contained in:
3
app.py
3
app.py
@@ -1,3 +1,4 @@
|
||||
import random
|
||||
import threading
|
||||
from functools import reduce
|
||||
|
||||
@@ -1512,7 +1513,7 @@ def get_custom_level():
|
||||
for i in range(1, nr_exercises + 1, 1):
|
||||
exercise_type = request.args.get('exercise_' + str(i) + '_type')
|
||||
exercise_qty = int(request.args.get('exercise_' + str(i) + '_qty', -1))
|
||||
exercise_topic = request.args.get('exercise_' + str(i) + '_topic')
|
||||
exercise_topic = request.args.get('exercise_' + str(i) + '_topic', random.choice(topics))
|
||||
exercise_text_size = int(request.args.get('exercise_' + str(i) + '_text_size', -1))
|
||||
exercise_sa_qty = int(request.args.get('exercise_' + str(i) + '_sa_qty', -1))
|
||||
exercise_mc_qty = int(request.args.get('exercise_' + str(i) + '_mc_qty', -1))
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user