diff --git a/app.py b/app.py index 684a422..d257497 100644 --- a/app.py +++ b/app.py @@ -397,10 +397,10 @@ def get_writing_task_2_general_question(): { "role": "user", "content": ( - 'Craft a comprehensive question of ' + difficulty + 'difficulty like the ones for IELTS Writing Task 2 General Training that directs the candidate ' - 'to delve into an in-depth analysis of contrasting perspectives on the topic of "' + 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 subject.') + 'Craft a comprehensive question of ' + difficulty + 'difficulty like the ones for IELTS Writing Task 2 General Training that directs the candidate ' + 'to delve into an in-depth analysis of contrasting perspectives on the topic of "' + 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 subject.') } ] token_count = count_total_tokens(messages) @@ -435,15 +435,35 @@ def grade_speaking_task_1(): answer = speech_to_text(sound_file_name) logging.info("POST - speaking_task_1 - " + str(request_id) + " - Transcripted answer: " + answer) + json_format = { + "comment": "extensive comment about answer quality", + "overall": 0.0, + "task_response": { + "Fluency and Coherence": { + "grade": 0.0, + "comment": "extensive comment about fluency and coherence" + }, + "Lexical Resource": { + "grade": 0.0, + "comment": "extensive comment about lexical resource" + }, + "Grammatical Range and Accuracy": { + "grade": 0.0, + "comment": "extensive comment about grammatical range and accuracy" + }, + "Pronunciation": { + "grade": 0.0, + "comment": "extensive comment about pronunciation on the transcribed answer" + } + } + } + if has_x_words(answer, 20): messages = [ { "role": "system", "content": ( - 'You are a helpful assistant designed to output JSON on this format: ' - '{"comment": "comment about answer quality", "overall": 0.0, ' - '"task_response": {"Fluency and Coherence": 0.0, "Lexical Resource": 0.0, ' - '"Grammatical Range and Accuracy": 0.0, "Pronunciation": 0.0}}') + 'You are a helpful assistant designed to output JSON on this format: ' + str(json_format)) }, { "role": "user", @@ -453,6 +473,10 @@ def grade_speaking_task_1(): 'assign a score of 0 if the response fails to address the question. Additionally, provide ' 'detailed commentary highlighting both strengths and weaknesses in the response.' '\n Question: "' + question + '" \n Answer: "' + answer + '"') + }, + { + "role": "user", + "content": 'Address the student as "you"' } ] token_count = count_total_tokens(messages) @@ -579,15 +603,35 @@ def grade_speaking_task_2(): answer = speech_to_text(sound_file_name) logging.info("POST - speaking_task_2 - " + str(request_id) + " - Transcripted answer: " + answer) + json_format = { + "comment": "extensive comment about answer quality", + "overall": 0.0, + "task_response": { + "Fluency and Coherence": { + "grade": 0.0, + "comment": "extensive comment about fluency and coherence" + }, + "Lexical Resource": { + "grade": 0.0, + "comment": "extensive comment about lexical resource" + }, + "Grammatical Range and Accuracy": { + "grade": 0.0, + "comment": "extensive comment about grammatical range and accuracy" + }, + "Pronunciation": { + "grade": 0.0, + "comment": "extensive comment about pronunciation on the transcribed answer" + } + } + } + if has_x_words(answer, 20): messages = [ { "role": "system", "content": ( - 'You are a helpful assistant designed to output JSON on this format: ' - '{"comment": "comment about answer quality", "overall": 0.0, ' - '"task_response": {"Fluency and Coherence": 0.0, "Lexical Resource": 0.0, ' - '"Grammatical Range and Accuracy": 0.0, "Pronunciation": 0.0}}') + 'You are a helpful assistant designed to output JSON on this format: ' + str(json_format)) }, { "role": "user", @@ -597,13 +641,17 @@ def grade_speaking_task_2(): 'assign a score of 0 if the response fails to address the question. Additionally, provide ' 'detailed commentary highlighting both strengths and weaknesses in the response.' '\n Question: "' + question + '" \n Answer: "' + answer + '"') + }, + { + "role": "user", + "content": 'Address the student as "you"' } ] token_count = count_total_tokens(messages) logging.info("POST - speaking_task_2 - " + str(request_id) + " - Requesting grading of the answer.") - response = make_openai_call(GPT_3_5_TURBO, messages, token_count,["comment"], - GRADING_TEMPERATURE) + response = make_openai_call(GPT_3_5_TURBO, messages, token_count, ["comment"], + GRADING_TEMPERATURE) logging.info("POST - speaking_task_2 - " + str(request_id) + " - Answer graded: " + str(response)) perfect_answer_messages = [ @@ -800,15 +848,34 @@ def grade_speaking_task_3(): token_count, ["answer"], GEN_QUESTION_TEMPERATURE)) + json_format = { + "comment": "extensive comment about answer quality", + "overall": 0.0, + "task_response": { + "Fluency and Coherence": { + "grade": 0.0, + "comment": "extensive comment about fluency and coherence" + }, + "Lexical Resource": { + "grade": 0.0, + "comment": "extensive comment about lexical resource" + }, + "Grammatical Range and Accuracy": { + "grade": 0.0, + "comment": "extensive comment about grammatical range and accuracy" + }, + "Pronunciation": { + "grade": 0.0, + "comment": "extensive comment about pronunciation on the transcribed answer" + } + } + } messages = [ { "role": "system", "content": ( - 'You are a helpful assistant designed to output JSON on this format: ' - '{"comment": "comment about answer quality", "overall": 0.0, ' - '"task_response": {"Fluency and Coherence": 0.0, "Lexical Resource": 0.0, ' - '"Grammatical Range and Accuracy": 0.0, "Pronunciation": 0.0}}') + 'You are a helpful assistant designed to output JSON on this format: ' + str(json_format)) } ] message = ( @@ -833,6 +900,11 @@ def grade_speaking_task_3(): "content": message }) + messages.append({ + "role": "user", + "content": 'Address the student as "you"' + }) + token_count = count_total_tokens(messages) logging.info("POST - speaking_task_3 - " + str(request_id) + " - Requesting grading of the answers.")