Add exercises for utas level.

This commit is contained in:
Cristiano Ferreira
2024-06-13 18:24:42 +01:00
parent 7633822916
commit 1d110d5fa9
3 changed files with 101 additions and 45 deletions

View File

@@ -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,
seen_keys)
return {
"id": str(uuid.uuid4()),
"prompt": "Select the appropriate option.",
"questions": fix_exercise_ids(question, start_id)["questions"],
"type": "multipleChoice",
}
return fix_exercise_ids(question, start_id)
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:
return gen_multiple_choice_level(quantity, start_id)
else:
return {
"id": str(uuid.uuid4()),
"prompt": "Select the appropriate option.",
"questions": fix_exercise_ids(question, start_id)["questions"],
"type": "multipleChoice",
}
return fix_exercise_ids(question, start_id)["questions"]
def gen_blank_space_text_utas(quantity: int, start_id: int, size: int, topic=random.choice(mti_topics)):
json_format = {
@@ -1277,37 +1267,24 @@ def gen_blank_space_text_utas(quantity: int, start_id: int, size: int, topic=ran
["question"],
GEN_QUESTION_TEMPERATURE)
return {
"id": str(uuid.uuid4()),
"prompt": "Select the appropriate option.",
"questions": question["question"],
"type": "blankSpace"
}
return question["question"]
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)
exercises = gen_reading_exercises_utas(passage["text"], start_id, sa_quantity, mc_quantity)
if contains_empty_dict(exercises):
return gen_reading_passage_utas(start_id, sa_quantity, mc_quantity, topic)
short_answer = gen_short_answer_utas(passage["text"], start_id, sa_quantity)
mc_exercises = gen_text_multiple_choice_utas(passage["text"], start_id+sa_quantity, mc_quantity)
return {
"exercises": exercises,
"exercises": {
"shortAnswer":short_answer,
"multipleChoice": mc_exercises,
},
"text": {
"content": passage["text"],
"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):
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)
return make_openai_call(GPT_4_O, messages, token_count,
["questions"],
GEN_QUESTION_TEMPERATURE)
GEN_QUESTION_TEMPERATURE)["questions"]
def gen_text_multiple_choice_utas(text: str, start_id: int, mc_quantity: int):
json_format = {
"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:
return gen_multiple_choice_level(mc_quantity, start_id)
else:
return {
"id": str(uuid.uuid4()),
"prompt": "Select the appropriate option.",
"questions": fix_exercise_ids(question, start_id)["questions"],
"type": "multipleChoice",
}
return fix_exercise_ids(question, start_id)["questions"]