Update reading fill the blanks.

This commit is contained in:
Cristiano Ferreira
2024-07-18 19:07:38 +01:00
parent e7d84b9704
commit 358f240d16
2 changed files with 105 additions and 18 deletions

View File

@@ -173,7 +173,6 @@ topics = [
"Space Exploration",
"Artificial Intelligence",
"Climate Change",
"World Religions",
"The Human Brain",
"Renewable Energy",
"Cultural Diversity",

View File

@@ -22,7 +22,7 @@ def gen_reading_passage_1(topic, req_exercises, difficulty):
number_of_exercises_q = divide_number_into_parts(TOTAL_READING_PASSAGE_1_EXERCISES, len(req_exercises))
passage = generate_reading_passage(QuestionType.READING_PASSAGE_1, topic)
passage = generate_reading_passage_1_text(topic)
if passage == "":
return gen_reading_passage_1(topic, req_exercises, difficulty)
start_id = 1
@@ -45,7 +45,7 @@ def gen_reading_passage_2(topic, req_exercises, difficulty):
number_of_exercises_q = divide_number_into_parts(TOTAL_READING_PASSAGE_2_EXERCISES, len(req_exercises))
passage = generate_reading_passage(QuestionType.READING_PASSAGE_2, topic)
passage = generate_reading_passage_2_text(topic)
if passage == "":
return gen_reading_passage_2(topic, req_exercises, difficulty)
start_id = 14
@@ -68,7 +68,7 @@ def gen_reading_passage_3(topic, req_exercises, difficulty):
number_of_exercises_q = divide_number_into_parts(TOTAL_READING_PASSAGE_3_EXERCISES, len(req_exercises))
passage = generate_reading_passage(QuestionType.READING_PASSAGE_3, topic)
passage = generate_reading_passage_3_text(topic)
if passage == "":
return gen_reading_passage_3(topic, req_exercises, difficulty)
start_id = 27
@@ -145,7 +145,12 @@ def add_random_words_and_shuffle(word_array, num_random_words):
random.shuffle(combined_array)
return combined_array
result = []
for i, word in enumerate(combined_array):
letter = chr(65 + i) # chr(65) is 'A'
result.append({"letter": letter, "word": word})
return result
def fillblanks_build_solutions_array(words, start_id):
@@ -260,7 +265,8 @@ def get_perfect_answer(question: str, size: int):
token_count = count_total_tokens(messages)
return make_openai_call(GPT_4_O, messages, token_count, GEN_TEXT_FIELDS, GEN_QUESTION_TEMPERATURE)
def generate_reading_passage(type: QuestionType, topic: str):
def generate_reading_passage_1_text(topic: str):
messages = [
{
"role": "system",
@@ -271,7 +277,7 @@ def generate_reading_passage(type: QuestionType, topic: str):
{
"role": "user",
"content": (
'Generate an extensive text for IELTS ' + type.value + ', of at least 1500 words, on the topic '
'Generate an extensive text for IELTS Reading Passage 1, of at least 800 words, on the topic '
'of "' + topic + '". The passage should offer '
'a substantial amount of information, '
'analysis, or narrative relevant to the chosen '
@@ -282,7 +288,75 @@ def generate_reading_passage(type: QuestionType, topic: str):
'Make sure that the generated text does not '
'contain forbidden subjects in muslim countries.')
}
},
{
"role": "system",
"content": ('The generated text should be fairly easy to understand.')
},
]
token_count = count_total_tokens(messages)
return make_openai_call(GPT_4_O, messages, token_count, GEN_TEXT_FIELDS, GEN_QUESTION_TEMPERATURE)
def generate_reading_passage_2_text(topic: str):
messages = [
{
"role": "system",
"content": (
'You are a helpful assistant designed to output JSON on this format: '
'{"title": "title of the text", "text": "generated text"}')
},
{
"role": "user",
"content": (
'Generate an extensive text for IELTS Reading Passage 2, of at least 800 words, on the topic '
'of "' + topic + '". The passage should offer '
'a substantial amount of information, '
'analysis, or narrative relevant to the chosen '
'subject matter. This text passage aims to '
'serve as the primary reading section of an '
'IELTS test, providing an in-depth and '
'comprehensive exploration of the topic. '
'Make sure that the generated text does not '
'contain forbidden subjects in muslim countries.')
},
{
"role": "system",
"content": ('The generated text should be fairly hard to understand.')
},
]
token_count = count_total_tokens(messages)
return make_openai_call(GPT_4_O, messages, token_count, GEN_TEXT_FIELDS, GEN_QUESTION_TEMPERATURE)
def generate_reading_passage_3_text(topic: str):
messages = [
{
"role": "system",
"content": (
'You are a helpful assistant designed to output JSON on this format: '
'{"title": "title of the text", "text": "generated text"}')
},
{
"role": "user",
"content": (
'Generate an extensive text for IELTS Reading Passage 3, of at least 800 words, on the topic '
'of "' + topic + '". The passage should offer '
'a substantial amount of information, '
'analysis, or narrative relevant to the chosen '
'subject matter. This text passage aims to '
'serve as the primary reading section of an '
'IELTS test, providing an in-depth and '
'comprehensive exploration of the topic. '
'Make sure that the generated text does not '
'contain forbidden subjects in muslim countries.')
},
{
"role": "system",
"content": ('The generated text should be very hard to understand and include different points, theories, '
'subtle differences of opinions from people over the specified topic .')
},
]
token_count = count_total_tokens(messages)
return make_openai_call(GPT_4_O, messages, token_count, GEN_TEXT_FIELDS, GEN_QUESTION_TEMPERATURE)
@@ -595,18 +669,12 @@ def gen_summary_fill_blanks_exercise(text: str, quantity: int, start_id, difficu
"role": "system",
"content": (
'You are a helpful assistant designed to output JSON on this format: '
'{ "summary": "summary", "words": ["word_1", "word_2"] }')
'{ "summary": "summary" }')
},
{
"role": "user",
"content": ('Summarize this text: "'+ text + '"')
},
{
"role": "user",
"content": ('Select ' + str(quantity) + ' ' + difficulty + ' difficulty words, it must be words and not '
'expressions, from the summary.')
}
]
token_count = count_total_tokens(messages)
@@ -615,14 +683,34 @@ def gen_summary_fill_blanks_exercise(text: str, quantity: int, start_id, difficu
["summary"],
GEN_QUESTION_TEMPERATURE)
messages = [
{
"role": "system",
"content": (
'You are a helpful assistant designed to output JSON on this format: '
'{"words": ["word_1", "word_2"] }')
},
{
"role": "user",
"content": ('Select ' + str(quantity) + ' ' + difficulty + ' difficulty words, it must be words and not '
'expressions, from this:\n' + response["summary"])
}
]
token_count = count_total_tokens(messages)
words_response = make_openai_call(GPT_4_O, messages, token_count,
["summary"],
GEN_QUESTION_TEMPERATURE)
response["words"] = words_response["words"]
replaced_summary = replace_first_occurrences_with_placeholders(response["summary"], response["words"], start_id)
options_words = add_random_words_and_shuffle(response["words"], 5)
options_words = add_random_words_and_shuffle(response["words"], 1)
solutions = fillblanks_build_solutions_array(response["words"], start_id)
return {
"allowRepetition": True,
"id": str(uuid.uuid4()),
"prompt": "Complete the summary below. Click a blank to select the corresponding word(s) for it.\\nThere are "
"prompt": "Complete the summary below. Write the letter of the corresponding word(s) for it.\\nThere are "
"more words than spaces so you will not use them all. You may use any of the words more than once.",
"solutions": solutions,
"text": replaced_summary,
@@ -1334,7 +1422,7 @@ def gen_blank_space_text_utas(quantity: int, start_id: int, size: int, topic=ran
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_1_text(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 {