New custom level tests.

This commit is contained in:
Cristiano Ferreira
2024-09-02 15:28:41 +01:00
parent cf7a966141
commit 9df4889517
3 changed files with 430 additions and 13 deletions

View File

@@ -659,3 +659,19 @@ academic_subjects = [
"Ecology",
"International Business"
]
grammar_types = [
"parts of speech",
"parts of speech - Nouns",
"parts of speech - Pronouns",
"parts of speech - Verbs",
"parts of speech - Adverbs",
"parts of speech - Adjectives",
"parts of speech - Conjunctions",
"parts of speech - Prepositions",
"parts of speech - Interjections",
"sentence structure",
"types of sentences",
"tenses",
"active voice and passive voice"
]

View File

@@ -1443,18 +1443,29 @@ def parse_conversation(conversation_data):
return "\n".join(readable_text)
def gen_multiple_choice_blank_space_utas(quantity: int, start_id: int, all_exams=None):
def gen_multiple_choice_blank_space_utas(quantity: int, start_id: int, topic=None, all_exams=None):
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."
quantity) + (" multiple choice blank space questions of 4 options for an english level exam, some easy "
"questions, some intermediate questions and some advanced questions. Make sure every question "
"only has 1 correct answer.")
if topic is None:
gen_multiple_choice_for_text = gen_multiple_choice_for_text + ("Ensure that the questions cover a range of "
"topics such as verb tense, subject-verb "
"agreement, pronoun usage, sentence structure, "
"and punctuation.")
else:
gen_multiple_choice_for_text = gen_multiple_choice_for_text + ("Ensure that the questions are fill the blanks "
"and cover the grammar "
"topic of '" + topic + "' and the prompts "
"are varied.")
messages = [
{
"role": "system",
"content": (
'You are a helpful assistant designed to output JSON on this format: {"questions": [{"id": "9", "options": '
'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"}], '
@@ -1473,7 +1484,7 @@ def gen_multiple_choice_blank_space_utas(quantity: int, start_id: int, all_exams
GEN_QUESTION_TEMPERATURE)
if len(question["questions"]) != quantity:
return gen_multiple_choice_blank_space_utas(quantity, start_id)
return gen_multiple_choice_blank_space_utas(quantity, start_id, topic, all_exams)
else:
if all_exams is not None:
seen_keys = set()
@@ -2089,3 +2100,309 @@ def gen_listening_section_4(topic, difficulty, req_exercises, number_of_exercise
"text": monologue,
"difficulty": difficulty
}
def gen_transformation_exercise(quantity, start_id, difficulty, topic=None):
json_format = {
"exercises": [
{
"id": 1,
"first": "first sentence",
"second": "second sentence",
"solutions": ["first_missing_word", "second_missing_word"]
}
]
}
messages = [
{
"role": "system",
"content": 'You are a helpful assistant designed to output JSON on this format: ' + str(json_format)
},
{
"role": "user",
"content": ("Create " + str(quantity) + " transformation exercises of " + difficulty + " where the student "
"has to complete the "
"second sentences' 2 blank spaces so that it has the same meaning "
"as the first. Each blank space must correspond to a single word.")
},
{
"role": "user",
"content": 'The id starts at ' + str(start_id) + '.'
}
]
if topic is not None:
messages.append({
"role": "user",
"content": 'Focus the exercises on the grammar subject of ' + topic + '.'
})
token_count = count_total_tokens(messages)
response = make_openai_call(GPT_4_O, messages, token_count, GEN_FIELDS, GEN_QUESTION_TEMPERATURE)
response["prompt"] = "Complete the second sentence so that it has the same meaning as the first."
response["difficulty"] = difficulty
response["topic"] = topic
return response
def gen_gap_filling_exercise(quantity, start_id, difficulty, topic=None):
json_format = {
"exercises": [
{
"id": 1,
"question": "sentence with a blank space to fill",
"solutions": ["option 1", "option 2"]
}
]
}
messages = [
{
"role": "system",
"content": 'You are a helpful assistant designed to output JSON on this format: ' + str(json_format)
},
{
"role": "user",
"content": ("Create " + str(quantity) + " gap filling exercises of " + difficulty + " where the student "
"has to complete the "
"sentence's blank space (signaled as {{id}}) so that it makes sense. "
"The blank space must correspond to a single word.")
},
{
"role": "user",
"content": 'The id starts at ' + str(start_id) + '.'
}
]
if topic is not None:
messages.append({
"role": "user",
"content": 'Focus the exercises on the grammar subject of ' + topic + '.'
})
token_count = count_total_tokens(messages)
response = make_openai_call(GPT_4_O, messages, token_count, GEN_FIELDS, GEN_QUESTION_TEMPERATURE)
response["prompt"] = "Complete the sentence."
response["difficulty"] = difficulty
response["topic"] = topic
return response
def gen_grammar_matching_exercise(quantity, start_id, difficulty, topic=None):
json_format = {
"matching_pairs": [
{
"left": "word/sentence on left",
"right": "word/sentence on right",
}
]
}
messages = [
{
"role": "system",
"content": 'You are a helpful assistant designed to output JSON on this format: ' + str(json_format)
},
{
"role": "user",
"content": ("Create " + str(quantity) + " grammar related matching exercises "
"of " + difficulty + " where the student has to match the "
"words/sentences on the left with "
"words/sentences on the right.")
}
]
if topic is not None:
messages.append({
"role": "user",
"content": 'Focus the exercises on the grammar subject of ' + topic + '.'
})
token_count = count_total_tokens(messages)
response = make_openai_call(GPT_4_O, messages, token_count, GEN_FIELDS, GEN_QUESTION_TEMPERATURE)
return {
"allowRepetition": False,
"options": build_options_grammar_matching(response["matching_pairs"]),
"prompt": "Match the words/sentences on the left with the ones on the right.",
"sentences": build_sentences_grammar_matching(response["matching_pairs"], start_id),
"type": "matchSentences",
"difficulty": difficulty,
"topic": topic
}
def gen_cloze_exercise(quantity, start_id, difficulty, topic=None):
json_format = {
"text": "the text {{1}} blank spaces {{2}} it",
"solutions": [
{
"id": 1,
"solution": [
"with"
]
},
{
"id": 2,
"word": [
"on"
]
}
]
}
messages = [
{
"role": "system",
"content": 'You are a helpful assistant designed to output JSON on this format: ' + str(json_format)
},
{
"role": "user",
"content": ("Generate a text for a cloze exercise with " + str(quantity) + " blank spaces to fill of " + difficulty + " where the student "
"has to complete the "
"blank spaces (signaled as {{id}}) on the text so that it makes sense. "
"Each blank space must correspond to a single word.")
},
{
"role": "user",
"content": 'The id starts at ' + str(start_id) + '.'
}
]
if topic is not None:
messages.append({
"role": "user",
"content": 'Focus the exercises on the grammar subject of ' + topic + '.'
})
token_count = count_total_tokens(messages)
response = make_openai_call(GPT_4_O, messages, token_count, GEN_FIELDS, GEN_QUESTION_TEMPERATURE)
response["prompt"] = "Complete the text by adding a word to each gap."
response["difficulty"] = difficulty
response["topic"] = topic
response["maxWords"] = 1
return response
def gen_true_false_exercise(quantity: int, start_id, difficulty, topic=None):
json_format = {
"questions": [
{
"id": 1,
"prompt": "statement_1",
"solution": "true/false"
},
{
"id": 2,
"prompt": "statement_2",
"solution": "true/false"
}
]
}
messages = [
{
"role": "system",
"content": 'You are a helpful assistant designed to output JSON on this format: ' + str(json_format)
},
{
"role": "user",
"content": (
'Generate ' + str(
quantity) + ' ' + difficulty + ' difficulty grammar related statements for a true or false exercise.')
},
{
"role": "user",
"content": 'The id starts at ' + str(start_id) + '.'
}
]
if topic is not None:
messages.append({
"role": "user",
"content": 'Focus the exercises on the grammar subject of ' + topic + '.'
})
token_count = count_total_tokens(messages)
response = make_openai_call(GPT_4_O, messages, token_count, GEN_FIELDS, GEN_QUESTION_TEMPERATURE)
response["prompt"] = "Decide if the statements are true or false."
response["difficulty"] = difficulty
response["topic"] = topic
return response
def gen_error_correction_exercise(quantity: int, start_id, difficulty, topic=None):
json_format = {
"questions": [
{
"id": 1,
"prompt": "sentence with errors",
"solution": "corrected sentence"
},
{
"id": 2,
"prompt": "sentence with errors",
"solution": "corrected sentence"
}
]
}
messages = [
{
"role": "system",
"content": 'You are a helpful assistant designed to output JSON on this format: ' + str(json_format)
},
{
"role": "user",
"content": (
'Generate ' + str(
quantity) + ' ' + difficulty + ' difficulty grammatically incorrect sentences for an exercise where '
'the user has to fix the sentence.')
},
{
"role": "user",
"content": 'The id starts at ' + str(start_id) + '.'
}
]
if topic is not None:
messages.append({
"role": "user",
"content": 'Focus the exercises on the grammar subject of ' + topic + '.'
})
token_count = count_total_tokens(messages)
response = make_openai_call(GPT_4_O, messages, token_count, GEN_FIELDS, GEN_QUESTION_TEMPERATURE)
response["prompt"] = "Find the mistakes in the sentence and correct them."
response["difficulty"] = difficulty
response["topic"] = topic
return response
def build_options_grammar_matching(pairs):
options = []
letters = iter(string.ascii_uppercase)
for pair in pairs:
options.append({
"id": next(letters),
"sentence": pair["left"]
})
return options
def build_sentences_grammar_matching(pairs, start_id):
sentences = []
letters = iter(string.ascii_uppercase)
for pair in pairs:
sentences.append({
"solution": next(letters),
"sentence": pair["right"]
})
random.shuffle(sentences)
for i, sentence in enumerate(sentences, start=start_id):
sentence["id"] = i
return sentences