Add difficulty settings for generation
This commit is contained in:
68
app.py
68
app.py
@@ -52,6 +52,7 @@ def get_listening_section_1_question():
|
||||
# Extract parameters from the URL query string
|
||||
topic = request.args.get('topic', default=random.choice(two_people_scenarios))
|
||||
req_exercises = request.args.getlist('exercises')
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
|
||||
if (len(req_exercises) == 0):
|
||||
req_exercises = random.sample(LISTENING_EXERCISE_TYPES, 1)
|
||||
@@ -65,10 +66,11 @@ def get_listening_section_1_question():
|
||||
start_id = 1
|
||||
exercises = generate_listening_conversation_exercises(unprocessed_conversation, req_exercises,
|
||||
number_of_exercises_q,
|
||||
start_id)
|
||||
start_id, difficulty)
|
||||
return {
|
||||
"exercises": exercises,
|
||||
"text": processed_conversation
|
||||
"text": processed_conversation,
|
||||
"difficulty": difficulty
|
||||
}
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -82,6 +84,7 @@ def get_listening_section_2_question():
|
||||
# Extract parameters from the URL query string
|
||||
topic = request.args.get('topic', default=random.choice(social_monologue_contexts))
|
||||
req_exercises = request.args.getlist('exercises')
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
|
||||
if (len(req_exercises) == 0):
|
||||
req_exercises = random.sample(LISTENING_EXERCISE_TYPES, 2)
|
||||
@@ -92,10 +95,11 @@ def get_listening_section_2_question():
|
||||
|
||||
app.logger.info("Generated monologue: " + str(monologue))
|
||||
start_id = 11
|
||||
exercises = generate_listening_monologue_exercises(monologue, req_exercises, number_of_exercises_q, start_id)
|
||||
exercises = generate_listening_monologue_exercises(monologue, req_exercises, number_of_exercises_q, start_id, difficulty)
|
||||
return {
|
||||
"exercises": exercises,
|
||||
"text": monologue
|
||||
"text": monologue,
|
||||
"difficulty": difficulty
|
||||
}
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -109,6 +113,7 @@ def get_listening_section_3_question():
|
||||
# Extract parameters from the URL query string
|
||||
topic = request.args.get('topic', default=random.choice(four_people_scenarios))
|
||||
req_exercises = request.args.getlist('exercises')
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
|
||||
if (len(req_exercises) == 0):
|
||||
req_exercises = random.sample(LISTENING_EXERCISE_TYPES, 1)
|
||||
@@ -122,10 +127,11 @@ def get_listening_section_3_question():
|
||||
start_id = 21
|
||||
exercises = generate_listening_conversation_exercises(unprocessed_conversation, req_exercises,
|
||||
number_of_exercises_q,
|
||||
start_id)
|
||||
start_id, difficulty)
|
||||
return {
|
||||
"exercises": exercises,
|
||||
"text": processed_conversation
|
||||
"text": processed_conversation,
|
||||
"difficulty": difficulty
|
||||
}
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -139,6 +145,7 @@ def get_listening_section_4_question():
|
||||
# Extract parameters from the URL query string
|
||||
topic = request.args.get('topic', default=random.choice(academic_subjects))
|
||||
req_exercises = request.args.getlist('exercises')
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
|
||||
if (len(req_exercises) == 0):
|
||||
req_exercises = random.sample(LISTENING_EXERCISE_TYPES, 2)
|
||||
@@ -149,10 +156,11 @@ def get_listening_section_4_question():
|
||||
|
||||
app.logger.info("Generated monologue: " + str(monologue))
|
||||
start_id = 31
|
||||
exercises = generate_listening_monologue_exercises(monologue, req_exercises, number_of_exercises_q, start_id)
|
||||
exercises = generate_listening_monologue_exercises(monologue, req_exercises, number_of_exercises_q, start_id, difficulty)
|
||||
return {
|
||||
"exercises": exercises,
|
||||
"text": monologue
|
||||
"text": monologue,
|
||||
"difficulty": difficulty
|
||||
}
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -165,7 +173,9 @@ def save_listening():
|
||||
data = request.get_json()
|
||||
parts = data.get('parts')
|
||||
minTimer = data.get('minTimer', LISTENING_MIN_TIMER_DEFAULT)
|
||||
difficulty = data.get('difficulty', random.choice(difficulties))
|
||||
template = getListeningTemplate()
|
||||
template['difficulty'] = difficulty
|
||||
id = str(uuid.uuid4())
|
||||
for i, part in enumerate(parts, start=0):
|
||||
part_template = getListeningPartTemplate()
|
||||
@@ -240,16 +250,18 @@ def grade_writing_task_1():
|
||||
@app.route('/writing_task1_general', methods=['GET'])
|
||||
@jwt_required()
|
||||
def get_writing_task_1_general_question():
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
try:
|
||||
gen_wt1_question = "Craft a prompt for an IELTS Writing Task 1 General Training exercise that instructs the " \
|
||||
"student to compose a letter. The prompt should present a specific scenario or situation, " \
|
||||
"requiring the student to provide information, advice, or instructions within the letter. " \
|
||||
"Make sure that the generated prompt does not contain forbidden subjects in muslim countries."
|
||||
"Make sure that the generated prompt is of " + difficulty + " difficulty and does not contain forbidden subjects in muslim countries."
|
||||
token_count = count_tokens(gen_wt1_question)["n_tokens"]
|
||||
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, gen_wt1_question, token_count, None,
|
||||
GEN_QUESTION_TEMPERATURE)
|
||||
return {
|
||||
"question": response.strip()
|
||||
"question": response.strip(),
|
||||
"difficulty": difficulty
|
||||
}
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -296,8 +308,9 @@ def grade_writing_task_2():
|
||||
@app.route('/writing_task2_general', methods=['GET'])
|
||||
@jwt_required()
|
||||
def get_writing_task_2_general_question():
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
try:
|
||||
gen_wt2_question = "Craft a comprehensive question for IELTS Writing Task 2 General Training that directs the candidate " \
|
||||
gen_wt2_question = "Craft a comprehensive question of " + difficulty + " difficulty for IELTS Writing Task 2 General Training that directs the candidate " \
|
||||
"to delve into an in-depth analysis of contrasting perspectives on a specific topic. The candidate " \
|
||||
"should be asked to discuss the strengths and weaknesses of both viewpoints, provide evidence or " \
|
||||
"examples, and present a well-rounded argument before concluding with their personal opinion on the " \
|
||||
@@ -306,7 +319,8 @@ def get_writing_task_2_general_question():
|
||||
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, gen_wt2_question, token_count, None,
|
||||
GEN_QUESTION_TEMPERATURE)
|
||||
return {
|
||||
"question": response.strip()
|
||||
"question": response.strip(),
|
||||
"difficulty": difficulty
|
||||
}
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -388,8 +402,9 @@ def grade_speaking_task_1():
|
||||
@app.route('/speaking_task_1', methods=['GET'])
|
||||
@jwt_required()
|
||||
def get_speaking_task_1_question():
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
try:
|
||||
gen_sp1_question = "Craft a thought-provoking question for IELTS Speaking Part 1 that encourages candidates to delve deeply " \
|
||||
gen_sp1_question = "Craft a thought-provoking question of " + difficulty + " difficulty for IELTS Speaking Part 1 that encourages candidates to delve deeply " \
|
||||
"into personal experiences, preferences, or insights on diverse topics. Instruct the candidate to offer " \
|
||||
"not only detailed descriptions but also provide nuanced explanations, examples, or anecdotes to enrich " \
|
||||
"their response. Make sure that the generated question does not contain forbidden subjects in muslim countries." \
|
||||
@@ -398,6 +413,7 @@ def get_speaking_task_1_question():
|
||||
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, gen_sp1_question, token_count, GEN_FIELDS,
|
||||
GEN_QUESTION_TEMPERATURE)
|
||||
response["type"] = 1
|
||||
response["difficulty"] = difficulty
|
||||
return response
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -459,8 +475,9 @@ def grade_speaking_task_2():
|
||||
@app.route('/speaking_task_2', methods=['GET'])
|
||||
@jwt_required()
|
||||
def get_speaking_task_2_question():
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
try:
|
||||
gen_sp2_question = "Create a question for IELTS Speaking Part 2 that encourages candidates to narrate a personal experience " \
|
||||
gen_sp2_question = "Create a question of " + difficulty + " difficulty for IELTS Speaking Part 2 that encourages candidates to narrate a personal experience " \
|
||||
"or story related to a randomly selected topic. Include 3 prompts that guide the candidate to describe " \
|
||||
"specific aspects of the experience, such as details about the situation, their actions, and the " \
|
||||
"reasons it left a lasting impression. Make sure that the generated question does not contain forbidden subjects in muslim countries." \
|
||||
@@ -470,6 +487,7 @@ def get_speaking_task_2_question():
|
||||
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, gen_sp2_question, token_count, GEN_FIELDS,
|
||||
GEN_QUESTION_TEMPERATURE)
|
||||
response["type"] = 2
|
||||
response["difficulty"] = difficulty
|
||||
return response
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -478,8 +496,9 @@ def get_speaking_task_2_question():
|
||||
@app.route('/speaking_task_3', methods=['GET'])
|
||||
@jwt_required()
|
||||
def get_speaking_task_3_question():
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
try:
|
||||
gen_sp3_question = "Formulate a set of 3 questions for IELTS Speaking Part 3 that encourage candidates to engage in a " \
|
||||
gen_sp3_question = "Formulate a set of 3 questions of " + difficulty + " difficulty for IELTS Speaking Part 3 that encourage candidates to engage in a " \
|
||||
"meaningful discussion on a particular topic. Provide inquiries, ensuring " \
|
||||
"they explore various aspects, perspectives, and implications related to the topic. " \
|
||||
"Make sure that the generated question does not contain forbidden subjects in muslim countries." \
|
||||
@@ -492,6 +511,7 @@ def get_speaking_task_3_question():
|
||||
response["questions"] = [re.sub(r"^\d+\.\s*", "", question) if re.match(r"^\d+\.", question) else question for
|
||||
question in response["questions"]]
|
||||
response["type"] = 3
|
||||
response["difficulty"] = difficulty
|
||||
return response
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -669,6 +689,7 @@ def get_reading_passage_1_question():
|
||||
# Extract parameters from the URL query string
|
||||
topic = request.args.get('topic', default=random.choice(topics))
|
||||
req_exercises = request.args.getlist('exercises')
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
|
||||
if (len(req_exercises) == 0):
|
||||
req_exercises = random.sample(READING_EXERCISE_TYPES, 2)
|
||||
@@ -678,13 +699,14 @@ def get_reading_passage_1_question():
|
||||
passage = generate_reading_passage(QuestionType.READING_PASSAGE_1, topic)
|
||||
app.logger.info("Generated passage: " + str(passage))
|
||||
start_id = 1
|
||||
exercises = generate_reading_exercises(passage["text"], req_exercises, number_of_exercises_q, start_id)
|
||||
exercises = generate_reading_exercises(passage["text"], req_exercises, number_of_exercises_q, start_id, difficulty)
|
||||
return {
|
||||
"exercises": exercises,
|
||||
"text": {
|
||||
"content": passage["text"],
|
||||
"title": passage["title"]
|
||||
}
|
||||
},
|
||||
"difficulty": difficulty
|
||||
}
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -697,6 +719,7 @@ def get_reading_passage_2_question():
|
||||
# Extract parameters from the URL query string
|
||||
topic = request.args.get('topic', default=random.choice(topics))
|
||||
req_exercises = request.args.getlist('exercises')
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
|
||||
if (len(req_exercises) == 0):
|
||||
req_exercises = random.sample(READING_EXERCISE_TYPES, 2)
|
||||
@@ -706,13 +729,14 @@ def get_reading_passage_2_question():
|
||||
passage = generate_reading_passage(QuestionType.READING_PASSAGE_2, topic)
|
||||
app.logger.info("Generated passage: " + str(passage))
|
||||
start_id = 14
|
||||
exercises = generate_reading_exercises(passage["text"], req_exercises, number_of_exercises_q, start_id)
|
||||
exercises = generate_reading_exercises(passage["text"], req_exercises, number_of_exercises_q, start_id, difficulty)
|
||||
return {
|
||||
"exercises": exercises,
|
||||
"text": {
|
||||
"content": passage["text"],
|
||||
"title": passage["title"]
|
||||
}
|
||||
},
|
||||
"difficulty": difficulty
|
||||
}
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
@@ -725,6 +749,7 @@ def get_reading_passage_3_question():
|
||||
# Extract parameters from the URL query string
|
||||
topic = request.args.get('topic', default=random.choice(topics))
|
||||
req_exercises = request.args.getlist('exercises')
|
||||
difficulty = request.args.get("difficulty", default=random.choice(difficulties))
|
||||
|
||||
if (len(req_exercises) == 0):
|
||||
req_exercises = random.sample(READING_EXERCISE_TYPES, 2)
|
||||
@@ -734,13 +759,14 @@ def get_reading_passage_3_question():
|
||||
passage = generate_reading_passage(QuestionType.READING_PASSAGE_3, topic)
|
||||
app.logger.info("Generated passage: " + str(passage))
|
||||
start_id = 27
|
||||
exercises = generate_reading_exercises(passage["text"], req_exercises, number_of_exercises_q, start_id)
|
||||
exercises = generate_reading_exercises(passage["text"], req_exercises, number_of_exercises_q, start_id, difficulty)
|
||||
return {
|
||||
"exercises": exercises,
|
||||
"text": {
|
||||
"content": passage["text"],
|
||||
"title": passage["title"]
|
||||
}
|
||||
},
|
||||
"difficulty": difficulty
|
||||
}
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
Reference in New Issue
Block a user