From 2adb7d1847602042379b18d818b23aa053ddd53e Mon Sep 17 00:00:00 2001 From: Cristiano Ferreira Date: Tue, 25 Jun 2024 20:49:27 +0100 Subject: [PATCH 1/3] Listening part 1. --- app.py | 5 +++-- helper/constants.py | 2 ++ helper/exercises.py | 20 ++++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index a2a2fe2..0072408 100644 --- a/app.py +++ b/app.py @@ -53,7 +53,7 @@ def get_listening_section_1_question(): difficulty = request.args.get("difficulty", default=random.choice(difficulties)) if (len(req_exercises) == 0): - req_exercises = random.sample(LISTENING_EXERCISE_TYPES, 1) + req_exercises = random.sample(LISTENING_1_EXERCISE_TYPES, 1) number_of_exercises_q = divide_number_into_parts(TOTAL_LISTENING_SECTION_1_EXERCISES, len(req_exercises)) @@ -62,7 +62,8 @@ def get_listening_section_1_question(): app.logger.info("Generated conversation: " + str(processed_conversation)) start_id = 1 - exercises = generate_listening_conversation_exercises(parse_conversation(processed_conversation), req_exercises, + exercises = generate_listening_conversation_exercises(parse_conversation(processed_conversation), + req_exercises, number_of_exercises_q, start_id, difficulty) return { diff --git a/helper/constants.py b/helper/constants.py index c5f924c..3074171 100644 --- a/helper/constants.py +++ b/helper/constants.py @@ -19,6 +19,8 @@ GEN_TEXT_FIELDS = ['title'] LISTENING_GEN_FIELDS = ['transcript', 'exercise'] READING_EXERCISE_TYPES = ['fillBlanks', 'writeBlanks', 'trueFalse', 'paragraphMatch'] LISTENING_EXERCISE_TYPES = ['multipleChoice', 'writeBlanksQuestions', 'writeBlanksFill', 'writeBlanksForm'] +LISTENING_1_EXERCISE_TYPES = ['multipleChoice', 'writeBlanksQuestions', 'writeBlanksFill', 'writeBlanksFill', + 'writeBlanksForm', 'writeBlanksForm', 'writeBlanksForm', 'writeBlanksForm'] TOTAL_READING_PASSAGE_1_EXERCISES = 13 TOTAL_READING_PASSAGE_2_EXERCISES = 13 diff --git a/helper/exercises.py b/helper/exercises.py index 1d05bee..5b954e4 100644 --- a/helper/exercises.py +++ b/helper/exercises.py @@ -283,6 +283,16 @@ def generate_listening_1_conversation(topic: str): 'Make sure that the generated conversation does not contain forbidden subjects in ' 'muslim countries.') + }, + { + "role": "user", + "content": 'Try to have misleading discourse (refer multiple dates, multiple colors and etc).' + + }, + { + "role": "user", + "content": 'Try to have spelling of names (cities, people, etc)' + } ] token_count = count_total_tokens(messages) @@ -951,13 +961,19 @@ def gen_write_blanks_form_exercise_listening_conversation(text: str, quantity: i "role": "system", "content": ( 'You are a helpful assistant designed to output JSON on this format: ' - '{"form": ["key: value", "key2: value"]}') + '{"form": ["key": "value", "key2": "value"]}') }, { "role": "user", "content": ( 'Generate a form with ' + str( - quantity) + ' ' + difficulty + ' difficulty key-value pairs about this conversation:\n"' + text + '"') + quantity) + ' entries with information about this conversation:\n"' + text + '"') + + }, + { + "role": "user", + "content": 'It must be a form and not questions. ' + 'Example: {"form": ["Color of car": "blue", "Brand of car": "toyota"]}' } ] From 9a696bbeb5d6baf24dfe62ce1c81f86a635a751e Mon Sep 17 00:00:00 2001 From: Cristiano Ferreira Date: Thu, 27 Jun 2024 21:29:22 +0100 Subject: [PATCH 2/3] Listening part 2. --- app.py | 2 +- helper/constants.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 0072408..92edd15 100644 --- a/app.py +++ b/app.py @@ -86,7 +86,7 @@ def get_listening_section_2_question(): difficulty = request.args.get("difficulty", default=random.choice(difficulties)) if (len(req_exercises) == 0): - req_exercises = random.sample(LISTENING_EXERCISE_TYPES, 2) + req_exercises = random.sample(LISTENING_2_EXERCISE_TYPES, 2) number_of_exercises_q = divide_number_into_parts(TOTAL_LISTENING_SECTION_2_EXERCISES, len(req_exercises)) diff --git a/helper/constants.py b/helper/constants.py index 3074171..24c6281 100644 --- a/helper/constants.py +++ b/helper/constants.py @@ -21,6 +21,7 @@ READING_EXERCISE_TYPES = ['fillBlanks', 'writeBlanks', 'trueFalse', 'paragraphMa LISTENING_EXERCISE_TYPES = ['multipleChoice', 'writeBlanksQuestions', 'writeBlanksFill', 'writeBlanksForm'] LISTENING_1_EXERCISE_TYPES = ['multipleChoice', 'writeBlanksQuestions', 'writeBlanksFill', 'writeBlanksFill', 'writeBlanksForm', 'writeBlanksForm', 'writeBlanksForm', 'writeBlanksForm'] +LISTENING_2_EXERCISE_TYPES = ['multipleChoice', 'writeBlanksQuestions'] TOTAL_READING_PASSAGE_1_EXERCISES = 13 TOTAL_READING_PASSAGE_2_EXERCISES = 13 From a3cd1cdf590e8d129824a95e03065a2b1c1b6876 Mon Sep 17 00:00:00 2001 From: Cristiano Ferreira Date: Thu, 27 Jun 2024 22:03:59 +0100 Subject: [PATCH 3/3] Listening part 3 and 4. --- app.py | 2 +- helper/constants.py | 2 ++ helper/exercises.py | 17 +++++++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 92edd15..e0afe36 100644 --- a/app.py +++ b/app.py @@ -116,7 +116,7 @@ def get_listening_section_3_question(): difficulty = request.args.get("difficulty", default=random.choice(difficulties)) if (len(req_exercises) == 0): - req_exercises = random.sample(LISTENING_EXERCISE_TYPES, 1) + req_exercises = random.sample(LISTENING_3_EXERCISE_TYPES, 1) number_of_exercises_q = divide_number_into_parts(TOTAL_LISTENING_SECTION_3_EXERCISES, len(req_exercises)) diff --git a/helper/constants.py b/helper/constants.py index 24c6281..67df516 100644 --- a/helper/constants.py +++ b/helper/constants.py @@ -22,6 +22,8 @@ LISTENING_EXERCISE_TYPES = ['multipleChoice', 'writeBlanksQuestions', 'writeBlan LISTENING_1_EXERCISE_TYPES = ['multipleChoice', 'writeBlanksQuestions', 'writeBlanksFill', 'writeBlanksFill', 'writeBlanksForm', 'writeBlanksForm', 'writeBlanksForm', 'writeBlanksForm'] LISTENING_2_EXERCISE_TYPES = ['multipleChoice', 'writeBlanksQuestions'] +LISTENING_3_EXERCISE_TYPES = ['multipleChoice3Options', 'writeBlanksQuestions'] +LISTENING_4_EXERCISE_TYPES = ['multipleChoice', 'writeBlanksQuestions', 'writeBlanksFill', 'writeBlanksForm'] TOTAL_READING_PASSAGE_1_EXERCISES = 13 TOTAL_READING_PASSAGE_2_EXERCISES = 13 diff --git a/helper/exercises.py b/helper/exercises.py index 5b954e4..8c12869 100644 --- a/helper/exercises.py +++ b/helper/exercises.py @@ -410,7 +410,7 @@ def generate_listening_4_monologue(topic: str): { "role": "user", "content": ( - 'Generate a comprehensive monologue on the academic subject ' + 'Generate a comprehensive and complex monologue on the academic subject ' 'of: "' + topic + '". Make sure that the generated monologue does not contain forbidden subjects in ' 'muslim countries.') @@ -477,7 +477,12 @@ def generate_listening_conversation_exercises(conversation: str, req_exercises: if req_exercise == "multipleChoice": question = gen_multiple_choice_exercise_listening_conversation(conversation, number_of_exercises, start_id, - difficulty) + difficulty, 4) + exercises.append(question) + print("Added multiple choice: " + str(question)) + elif req_exercise == "multipleChoice3Options": + question = gen_multiple_choice_exercise_listening_conversation(conversation, number_of_exercises, start_id, + difficulty, 3) exercises.append(question) print("Added multiple choice: " + str(question)) elif req_exercise == "writeBlanksQuestions": @@ -733,7 +738,7 @@ def assign_letters_to_paragraphs(paragraphs): return result -def gen_multiple_choice_exercise_listening_conversation(text: str, quantity: int, start_id, difficulty): +def gen_multiple_choice_exercise_listening_conversation(text: str, quantity: int, start_id, difficulty, n_options=4): messages = [ { "role": "system", @@ -747,7 +752,7 @@ def gen_multiple_choice_exercise_listening_conversation(text: str, quantity: int { "role": "user", "content": ( - 'Generate ' + str(quantity) + ' ' + difficulty + ' difficulty multiple choice questions of 4 options ' + 'Generate ' + str(quantity) + ' ' + difficulty + ' difficulty multiple choice questions of ' + str(n_options) + ' options ' 'of for this conversation:\n"' + text + '"') } @@ -763,7 +768,7 @@ def gen_multiple_choice_exercise_listening_conversation(text: str, quantity: int } -def gen_multiple_choice_exercise_listening_monologue(text: str, quantity: int, start_id, difficulty): +def gen_multiple_choice_exercise_listening_monologue(text: str, quantity: int, start_id, difficulty, n_options=4): messages = [ { "role": "system", @@ -778,7 +783,7 @@ def gen_multiple_choice_exercise_listening_monologue(text: str, quantity: int, s "role": "user", "content": ( 'Generate ' + str( - quantity) + ' ' + difficulty + ' difficulty multiple choice questions of 4 options ' + quantity) + ' ' + difficulty + ' difficulty multiple choice questions of ' + str(n_options) + ' options ' 'of for this monologue:\n"' + text + '"') }