Minor speaking improvements.

This commit is contained in:
Cristiano Ferreira
2024-08-05 21:57:42 +01:00
parent b795a3fb79
commit 470f4cc83b

103
app.py
View File

@@ -314,6 +314,11 @@ def grade_writing_task_1():
'Additionally, provide a detailed commentary highlighting both strengths and ' 'Additionally, provide a detailed commentary highlighting both strengths and '
'weaknesses in the response. ' 'weaknesses in the response. '
'\n Question: "' + question + '" \n Answer: "' + answer + '"') '\n Question: "' + question + '" \n Answer: "' + answer + '"')
},
{
"role": "user",
"content": ('Refer to the parts of the letter as: "Greeting Opener", "bullet 1", "bullet 2", '
'"bullet 3", "closer (restate the purpose of the letter)", "closing greeting"')
} }
] ]
token_count = count_total_tokens(messages) token_count = count_total_tokens(messages)
@@ -713,7 +718,8 @@ def get_speaking_task_1_question():
"first_topic": "topic 1", "first_topic": "topic 1",
"second_topic": "topic 2", "second_topic": "topic 2",
"questions": [ "questions": [
"Introductory question, should start with a greeting and introduce a question about the first topic, starting the topic with 'Let's talk about x' and then the question.", "Introductory question about the first topic, starting the topic with 'Let's talk about x' and then the "
"question.",
"Follow up question about the first topic", "Follow up question about the first topic",
"Follow up question about the first topic", "Follow up question about the first topic",
"Question about second topic", "Question about second topic",
@@ -731,21 +737,25 @@ def get_speaking_task_1_question():
{ {
"role": "user", "role": "user",
"content": ( "content": (
'Craft 5 simple questions of easy difficulty for IELTS Speaking Part 1 ' 'Craft 5 simple and single questions of easy difficulty for IELTS Speaking Part 1 '
'that encourages candidates to delve deeply into ' 'that encourages candidates to delve deeply into '
'personal experiences, preferences, or insights on the topic ' 'personal experiences, preferences, or insights on the topic '
'of "' + first_topic + '" and the topic of "' + second_topic + '". Instruct the candidate ' 'of "' + first_topic + '" and the topic of "' + second_topic + '". '
'to offer not only detailed ' 'Make sure that the generated '
'descriptions but also provide ' 'question'
'nuanced explanations, examples, ' 'does not contain forbidden '
'or anecdotes to enrich their response. ' 'subjects in'
'Make sure that the generated question '
'does not contain forbidden subjects in '
'muslim countries.') 'muslim countries.')
}, },
{ {
"role": "user", "role": "user",
"content": 'The questions should lead to the usage of 4 verb tenses (present perfect, present, past and future).' "content": 'The questions should lead to the usage of 4 verb tenses (present perfect, present, '
'past and future).'
},
{
"role": "user",
"content": 'They must be 1 single question each and not be double-barreled questions.'
} }
] ]
token_count = count_total_tokens(messages) token_count = count_total_tokens(messages)
@@ -785,7 +795,8 @@ def grade_speaking_task_2():
"task_response": { "task_response": {
"Fluency and Coherence": { "Fluency and Coherence": {
"grade": 0.0, "grade": 0.0,
"comment": "extensive comment about fluency and coherence, use examples to justify the grade awarded." "comment": "extensive comment about fluency and coherence, use examples to justify the grade "
"awarded."
}, },
"Lexical Resource": { "Lexical Resource": {
"grade": 0.0, "grade": 0.0,
@@ -793,11 +804,13 @@ def grade_speaking_task_2():
}, },
"Grammatical Range and Accuracy": { "Grammatical Range and Accuracy": {
"grade": 0.0, "grade": 0.0,
"comment": "extensive comment about grammatical range and accuracy, use examples to justify the grade awarded." "comment": "extensive comment about grammatical range and accuracy, use examples to justify the "
"grade awarded."
}, },
"Pronunciation": { "Pronunciation": {
"grade": 0.0, "grade": 0.0,
"comment": "extensive comment about pronunciation on the transcribed answer, use examples to justify the grade awarded." "comment": "extensive comment about pronunciation on the transcribed answer, use examples to "
"justify the grade awarded."
} }
} }
} }
@@ -974,11 +987,16 @@ def get_speaking_task_3_question():
{ {
"role": "user", "role": "user",
"content": ( "content": (
'Formulate a set of 5 questions of hard difficulty for IELTS Speaking Part 3 that encourage candidates to engage in a ' 'Formulate a set of 5 single questions of hard difficulty for IELTS Speaking Part 3 that encourage candidates to engage in a '
'meaningful discussion on the topic of "' + topic + '". Provide inquiries, ensuring ' 'meaningful discussion on the topic of "' + topic + '". Provide inquiries, ensuring '
'they explore various aspects, perspectives, and implications related to the topic.' '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.') 'Make sure that the generated question does not contain forbidden subjects in muslim countries.')
},
{
"role": "user",
"content": 'They must be 1 single question each and not be double-barreled questions.'
} }
] ]
token_count = count_total_tokens(messages) token_count = count_total_tokens(messages)
@@ -1203,7 +1221,7 @@ def save_speaking():
def generate_video_1(): def generate_video_1():
try: try:
data = request.get_json() data = request.get_json()
sp3_questions = [] sp1_questions = []
avatar = data.get("avatar", random.choice(list(AvatarEnum)).value) avatar = data.get("avatar", random.choice(list(AvatarEnum)).value)
request_id = str(uuid.uuid4()) request_id = str(uuid.uuid4())
@@ -1211,8 +1229,24 @@ def generate_video_1():
"Use this id to track the logs: " + str(request_id) + " - Request data: " + str( "Use this id to track the logs: " + str(request_id) + " - Request data: " + str(
request.get_json())) request.get_json()))
id_to_name = {
"5912afa7c77c47d3883af3d874047aaf": "MATTHEW",
"9e58d96a383e4568a7f1e49df549e0e4": "VERA",
"d2cdd9c0379a4d06ae2afb6e5039bd0c": "EDWARD",
"045cb5dcd00042b3a1e4f3bc1c12176b": "TANYA",
"1ae1e5396cc444bfad332155fdb7a934": "KAYLA",
"0ee6aa7cc1084063a630ae514fccaa31": "JEROME",
"5772cff935844516ad7eeff21f839e43": "TYLER",
}
standard_questions = [
"Hello my name is " + id_to_name.get(avatar) + ", what is yours?",
"Do you work or do you study?"
]
questions = standard_questions + data["questions"]
logging.info("POST - generate_video_1 - " + str(request_id) + " - Creating videos for speaking part 1.") logging.info("POST - generate_video_1 - " + str(request_id) + " - Creating videos for speaking part 1.")
for question in data["questions"]: for question in questions:
logging.info("POST - generate_video_1 - " + str(request_id) + " - Creating video for question: " + question) logging.info("POST - generate_video_1 - " + str(request_id) + " - Creating video for question: " + question)
result = create_video(question, avatar) result = create_video(question, avatar)
logging.info("POST - generate_video_1 - " + str(request_id) + " - Video created: " + result) logging.info("POST - generate_video_1 - " + str(request_id) + " - Video created: " + result)
@@ -1231,13 +1265,13 @@ def generate_video_1():
"video_path": firebase_file_path, "video_path": firebase_file_path,
"video_url": url "video_url": url
} }
sp3_questions.append(video) sp1_questions.append(video)
else: else:
logging.error("POST - generate_video_1 - " + str( logging.error("POST - generate_video_1 - " + str(
request_id) + " - Failed to create video for part 1 question: " + question) request_id) + " - Failed to create video for part 1 question: " + question)
response = { response = {
"prompts": sp3_questions, "prompts": sp1_questions,
"first_title": data["first_topic"], "first_title": data["first_topic"],
"second_title": data["second_topic"], "second_title": data["second_topic"],
"type": "interactiveSpeaking", "type": "interactiveSpeaking",
@@ -1607,6 +1641,39 @@ def get_custom_level():
return response return response
@app.route('/grade_short_answers', methods=['POST'])
@jwt_required()
def grade_short_answers():
data = request.get_json()
json_format = {
"exercises": [
{
"id": 1,
"correct": True,
"correct_answer": " correct answer if wrong"
}
]
}
try:
messages = [
{
"role": "system",
"content": (
'You are a helpful assistant designed to output JSON on this format: ' + str(json_format))
},
{
"role": "user",
"content": 'Grade these answers according to the text content and write a correct answer if they are wrong. Text, questions and answers:\n ' + str(data)
}
]
token_count = count_total_tokens(messages)
response = make_openai_call(GPT_4_O, messages, token_count, GEN_FIELDS, GEN_QUESTION_TEMPERATURE)
return response
except Exception as e:
return str(e)
@app.route('/fetch_tips', methods=['POST']) @app.route('/fetch_tips', methods=['POST'])
@jwt_required() @jwt_required()