Add exercises for utas level.
This commit is contained in:
94
app.py
94
app.py
@@ -1013,14 +1013,100 @@ def get_level_exam():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return str(e)
|
return str(e)
|
||||||
|
|
||||||
@app.route('/level_utas', method=['GET'])
|
@app.route('/level_utas', methods=['GET'])
|
||||||
@jwt_required()
|
@jwt_required()
|
||||||
def get_level_utas():
|
def get_level_utas():
|
||||||
try:
|
try:
|
||||||
number_of_exercises = 45
|
# Formats
|
||||||
mc_exercises = gen_multiple_choice_level(number_of_exercises)
|
mc = {
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prompt": "Choose the correct word or group of words that completes the sentences.",
|
||||||
|
"questions": None,
|
||||||
|
"type": "multipleChoice",
|
||||||
|
"part": 1
|
||||||
|
}
|
||||||
|
|
||||||
|
umc = {
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prompt": "Choose the underlined word or group of words that is not correct.",
|
||||||
|
"questions": None,
|
||||||
|
"type": "multipleChoice",
|
||||||
|
"part": 2
|
||||||
|
}
|
||||||
|
|
||||||
|
bs_1 = {
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prompt": "Read the text and write the correct word for each space.",
|
||||||
|
"questions": None,
|
||||||
|
"type": "blankSpaceText",
|
||||||
|
"part": 3
|
||||||
|
}
|
||||||
|
|
||||||
|
bs_2 = {
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prompt": "Read the text and write the correct word for each space.",
|
||||||
|
"questions": None,
|
||||||
|
"type": "blankSpaceText",
|
||||||
|
"part": 4
|
||||||
|
}
|
||||||
|
|
||||||
|
reading = {
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prompt": "Read the text and answer the questions below.",
|
||||||
|
"questions": None,
|
||||||
|
"type": "readingExercises",
|
||||||
|
"part": 5
|
||||||
|
}
|
||||||
|
|
||||||
|
all_mc_questions = []
|
||||||
|
|
||||||
|
# PART 1
|
||||||
|
mc_exercises1 = gen_multiple_choice_blank_space_utas(15, 1, all_mc_questions)
|
||||||
|
print(json.dumps(mc_exercises1, indent=4))
|
||||||
|
all_mc_questions.append(mc_exercises1)
|
||||||
|
|
||||||
|
# PART 2
|
||||||
|
mc_exercises2 = gen_multiple_choice_blank_space_utas(15, 16, all_mc_questions)
|
||||||
|
print(json.dumps(mc_exercises2, indent=4))
|
||||||
|
all_mc_questions.append(mc_exercises2)
|
||||||
|
|
||||||
|
# PART 3
|
||||||
|
mc_exercises3 = gen_multiple_choice_blank_space_utas(15, 31, all_mc_questions)
|
||||||
|
print(json.dumps(mc_exercises3, indent=4))
|
||||||
|
all_mc_questions.append(mc_exercises3)
|
||||||
|
|
||||||
|
mc_exercises = mc_exercises1['questions'] + mc_exercises2['questions'] + mc_exercises3['questions']
|
||||||
|
print(json.dumps(mc_exercises, indent=4))
|
||||||
|
mc["questions"] = mc_exercises
|
||||||
|
|
||||||
|
# Underlined mc
|
||||||
|
underlined_mc = gen_multiple_choice_underlined_utas(15, 46)
|
||||||
|
print(json.dumps(underlined_mc, indent=4))
|
||||||
|
umc["questions"] = underlined_mc
|
||||||
|
|
||||||
|
# Blank Space text 1
|
||||||
|
blank_space_text_1 = gen_blank_space_text_utas(12, 61, 250)
|
||||||
|
print(json.dumps(blank_space_text_1, indent=4))
|
||||||
|
bs_1["questions"] = blank_space_text_1
|
||||||
|
|
||||||
|
# Blank Space text 2
|
||||||
|
blank_space_text_2 = gen_blank_space_text_utas(14, 73, 350)
|
||||||
|
print(json.dumps(blank_space_text_2, indent=4))
|
||||||
|
bs_2["questions"] = blank_space_text_2
|
||||||
|
|
||||||
|
# Reading text
|
||||||
|
reading_text = gen_reading_passage_utas(87, 10, 4)
|
||||||
|
print(json.dumps(reading_text, indent=4))
|
||||||
|
reading["questions"] = reading_text
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"exercises": [mc_exercises],
|
"exercises": {
|
||||||
|
"blankSpaceMultipleChoice": mc,
|
||||||
|
"underlinedMultipleChoice": umc,
|
||||||
|
"blankSpaceText1": bs_1,
|
||||||
|
"blankSpaceText2": bs_2,
|
||||||
|
"readingExercises": reading,
|
||||||
|
},
|
||||||
"isDiagnostic": False,
|
"isDiagnostic": False,
|
||||||
"minTimer": 25,
|
"minTimer": 25,
|
||||||
"module": "level"
|
"module": "level"
|
||||||
|
|||||||
@@ -141,7 +141,6 @@ mti_topics = [
|
|||||||
"Poverty Alleviation",
|
"Poverty Alleviation",
|
||||||
"Cybersecurity and Privacy",
|
"Cybersecurity and Privacy",
|
||||||
"Human Rights",
|
"Human Rights",
|
||||||
"Social Justice",
|
|
||||||
"Food and Agriculture",
|
"Food and Agriculture",
|
||||||
"Cyberbullying and Online Safety",
|
"Cyberbullying and Online Safety",
|
||||||
"Linguistic Diversity",
|
"Linguistic Diversity",
|
||||||
@@ -232,7 +231,6 @@ topics = [
|
|||||||
"Meditation Practices",
|
"Meditation Practices",
|
||||||
"Literary Symbolism",
|
"Literary Symbolism",
|
||||||
"Marine Conservation",
|
"Marine Conservation",
|
||||||
"Social Justice Movements",
|
|
||||||
"Sustainable Tourism",
|
"Sustainable Tourism",
|
||||||
"Ancient Philosophy",
|
"Ancient Philosophy",
|
||||||
"Cold War Era",
|
"Cold War Era",
|
||||||
|
|||||||
@@ -1147,12 +1147,7 @@ def gen_multiple_choice_blank_space_utas(quantity: int, start_id: int, all_exams
|
|||||||
question["questions"][i], seen_keys = replace_exercise_if_exists(all_exams, question["questions"][i],
|
question["questions"][i], seen_keys = replace_exercise_if_exists(all_exams, question["questions"][i],
|
||||||
question,
|
question,
|
||||||
seen_keys)
|
seen_keys)
|
||||||
return {
|
return fix_exercise_ids(question, start_id)
|
||||||
"id": str(uuid.uuid4()),
|
|
||||||
"prompt": "Select the appropriate option.",
|
|
||||||
"questions": fix_exercise_ids(question, start_id)["questions"],
|
|
||||||
"type": "multipleChoice",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def gen_multiple_choice_underlined_utas(quantity: int, start_id: int):
|
def gen_multiple_choice_underlined_utas(quantity: int, start_id: int):
|
||||||
@@ -1220,12 +1215,7 @@ def gen_multiple_choice_underlined_utas(quantity: int, start_id: int):
|
|||||||
if len(question["questions"]) != quantity:
|
if len(question["questions"]) != quantity:
|
||||||
return gen_multiple_choice_level(quantity, start_id)
|
return gen_multiple_choice_level(quantity, start_id)
|
||||||
else:
|
else:
|
||||||
return {
|
return fix_exercise_ids(question, start_id)["questions"]
|
||||||
"id": str(uuid.uuid4()),
|
|
||||||
"prompt": "Select the appropriate option.",
|
|
||||||
"questions": fix_exercise_ids(question, start_id)["questions"],
|
|
||||||
"type": "multipleChoice",
|
|
||||||
}
|
|
||||||
|
|
||||||
def gen_blank_space_text_utas(quantity: int, start_id: int, size: int, topic=random.choice(mti_topics)):
|
def gen_blank_space_text_utas(quantity: int, start_id: int, size: int, topic=random.choice(mti_topics)):
|
||||||
json_format = {
|
json_format = {
|
||||||
@@ -1277,37 +1267,24 @@ def gen_blank_space_text_utas(quantity: int, start_id: int, size: int, topic=ran
|
|||||||
["question"],
|
["question"],
|
||||||
GEN_QUESTION_TEMPERATURE)
|
GEN_QUESTION_TEMPERATURE)
|
||||||
|
|
||||||
return {
|
return question["question"]
|
||||||
"id": str(uuid.uuid4()),
|
|
||||||
"prompt": "Select the appropriate option.",
|
|
||||||
"questions": question["question"],
|
|
||||||
"type": "blankSpace"
|
|
||||||
}
|
|
||||||
|
|
||||||
def gen_reading_passage_utas(start_id, sa_quantity: int, mc_quantity: int, topic=random.choice(mti_topics)):
|
def gen_reading_passage_utas(start_id, sa_quantity: int, mc_quantity: int, topic=random.choice(mti_topics)):
|
||||||
|
|
||||||
passage = generate_reading_passage(QuestionType.READING_PASSAGE_1, topic)
|
passage = generate_reading_passage(QuestionType.READING_PASSAGE_1, topic)
|
||||||
exercises = gen_reading_exercises_utas(passage["text"], start_id, sa_quantity, mc_quantity)
|
short_answer = gen_short_answer_utas(passage["text"], start_id, sa_quantity)
|
||||||
if contains_empty_dict(exercises):
|
mc_exercises = gen_text_multiple_choice_utas(passage["text"], start_id+sa_quantity, mc_quantity)
|
||||||
return gen_reading_passage_utas(start_id, sa_quantity, mc_quantity, topic)
|
|
||||||
return {
|
return {
|
||||||
"exercises": exercises,
|
"exercises": {
|
||||||
|
"shortAnswer":short_answer,
|
||||||
|
"multipleChoice": mc_exercises,
|
||||||
|
},
|
||||||
"text": {
|
"text": {
|
||||||
"content": passage["text"],
|
"content": passage["text"],
|
||||||
"title": passage["title"]
|
"title": passage["title"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def gen_reading_exercises_utas(passage: str, start_id: int, sa_quantity: int, mc_quantity: int):
|
|
||||||
exercises = []
|
|
||||||
|
|
||||||
sa_questions = gen_short_answer_utas(passage, start_id, sa_quantity)
|
|
||||||
exercises.append(sa_questions)
|
|
||||||
mc_questions = gen_text_multiple_choice_utas(passage, start_id+sa_quantity, mc_quantity)
|
|
||||||
exercises.append(mc_questions)
|
|
||||||
|
|
||||||
return exercises
|
|
||||||
|
|
||||||
def gen_short_answer_utas(text: str, start_id: int, sa_quantity: int):
|
def gen_short_answer_utas(text: str, start_id: int, sa_quantity: int):
|
||||||
json_format = {"questions": [{"id": 1, "question": "question", "possible_answers": ["answer_1", "answer_2"]}]}
|
json_format = {"questions": [{"id": 1, "question": "question", "possible_answers": ["answer_1", "answer_2"]}]}
|
||||||
|
|
||||||
@@ -1331,7 +1308,7 @@ def gen_short_answer_utas(text: str, start_id: int, sa_quantity: int):
|
|||||||
token_count = count_total_tokens(messages)
|
token_count = count_total_tokens(messages)
|
||||||
return make_openai_call(GPT_4_O, messages, token_count,
|
return make_openai_call(GPT_4_O, messages, token_count,
|
||||||
["questions"],
|
["questions"],
|
||||||
GEN_QUESTION_TEMPERATURE)
|
GEN_QUESTION_TEMPERATURE)["questions"]
|
||||||
def gen_text_multiple_choice_utas(text: str, start_id: int, mc_quantity: int):
|
def gen_text_multiple_choice_utas(text: str, start_id: int, mc_quantity: int):
|
||||||
json_format = {
|
json_format = {
|
||||||
"questions": [
|
"questions": [
|
||||||
@@ -1385,9 +1362,4 @@ def gen_text_multiple_choice_utas(text: str, start_id: int, mc_quantity: int):
|
|||||||
if len(question["questions"]) != mc_quantity:
|
if len(question["questions"]) != mc_quantity:
|
||||||
return gen_multiple_choice_level(mc_quantity, start_id)
|
return gen_multiple_choice_level(mc_quantity, start_id)
|
||||||
else:
|
else:
|
||||||
return {
|
return fix_exercise_ids(question, start_id)["questions"]
|
||||||
"id": str(uuid.uuid4()),
|
|
||||||
"prompt": "Select the appropriate option.",
|
|
||||||
"questions": fix_exercise_ids(question, start_id)["questions"],
|
|
||||||
"type": "multipleChoice",
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user