Start on level exam for utas.

This commit is contained in:
Cristiano Ferreira
2024-06-10 19:30:41 +01:00
parent 4ff3b02a1d
commit 9bc06d8340
2 changed files with 62 additions and 3 deletions

View File

@@ -1036,7 +1036,7 @@ def gen_multiple_choice_level(quantity: int, start_id=1):
["questions"],
GEN_QUESTION_TEMPERATURE)
if len(question["questions"]) != 25:
if len(question["questions"]) != quantity:
return gen_multiple_choice_level(quantity, start_id)
else:
all_exams = get_all("level")
@@ -1063,12 +1063,11 @@ def replace_exercise_if_exists(all_exams, current_exercise, current_exam, seen_k
seen_keys.add(key)
for exam in all_exams:
exam_dict = exam.to_dict()
if any(
exercise["prompt"] == current_exercise["prompt"] and
any(exercise["options"][0]["text"] == current_option["text"] for current_option in
current_exercise["options"])
for exercise in exam_dict.get("exercises", [])[0]["questions"]
for exercise in exam.get("questions", [])
):
return replace_exercise_if_exists(all_exams, generate_single_mc_level_question(), current_exam, seen_keys)
return current_exercise, seen_keys
@@ -1109,3 +1108,48 @@ def parse_conversation(conversation_data):
readable_text.append(f"{name}: {text}")
return "\n".join(readable_text)
def gen_multiple_choice_blank_space_utas(quantity: int, start_id: int, all_exams):
gen_multiple_choice_for_text = "Generate " + str(
quantity) + " multiple choice blank space questions of 4 options for an english level exam, some easy questions, some intermediate " \
"questions and some advanced questions. Ensure that the questions cover a range of topics such as " \
"verb tense, subject-verb agreement, pronoun usage, sentence structure, and punctuation. Make sure " \
"every question only has 1 correct answer."
messages = [
{
"role": "system",
"content": (
'You are a helpful assistant designed to output JSON on this format: {"questions": [{"id": "9", "options": '
'[{"id": "A", "text": '
'"And"}, {"id": "B", "text": "Cat"}, {"id": "C", "text": '
'"Happy"}, {"id": "D", "text": "Jump"}], '
'"prompt": "Which of the following is a conjunction?", '
'"solution": "A", "variant": "text"}]}')
},
{
"role": "user",
"content": gen_multiple_choice_for_text
}
]
token_count = count_total_tokens(messages)
question = make_openai_call(GPT_4_O, messages, token_count,
["questions"],
GEN_QUESTION_TEMPERATURE)
if len(question["questions"]) != quantity:
return gen_multiple_choice_level(quantity, start_id)
else:
seen_keys = set()
for i in range(len(question["questions"])):
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",
}