From 9654d9ff644a21f1ec778cfefbbb7fe0ec7f3f8e Mon Sep 17 00:00:00 2001 From: Cristiano Ferreira Date: Mon, 20 May 2024 14:40:09 +0100 Subject: [PATCH] Reformat code. --- app.py | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/app.py b/app.py index 20de726..379f0fa 100644 --- a/app.py +++ b/app.py @@ -260,8 +260,8 @@ def grade_writing_task_1(): ] token_count = count_total_tokens(messages) response = make_openai_call(GPT_3_5_TURBO, messages, token_count, - ["comment"], - GRADING_TEMPERATURE) + ["comment"], + GRADING_TEMPERATURE) response["overall"] = fix_writing_overall(response["overall"], response["task_response"]) response['fixed_text'] = get_fixed_text(answer) return response @@ -295,7 +295,7 @@ def get_writing_task_1_general_question(): ] token_count = count_total_tokens(messages) response = make_openai_call(GPT_3_5_TURBO, messages, token_count, "prompt", - GEN_QUESTION_TEMPERATURE) + GEN_QUESTION_TEMPERATURE) return { "question": response["prompt"].strip(), "difficulty": difficulty, @@ -346,7 +346,8 @@ def grade_writing_task_2(): }, { "role": "user", - "content": ('Evaluate the given Writing Task 2 response based on the IELTS grading system, ensuring a ' + "content": ( + 'Evaluate the given Writing Task 2 response based on the IELTS grading system, ensuring a ' 'strict assessment that penalizes errors. Deduct points for deviations from the task, and ' 'assign a score of 0 if the response fails to address the question. Additionally, provide an ' 'exemplary answer with a minimum of 250 words, along with a detailed commentary highlighting ' @@ -356,13 +357,14 @@ def grade_writing_task_2(): ] token_count = count_total_tokens(messages) response = make_openai_call(GPT_4_O, messages, token_count, ["comment"], - GEN_QUESTION_TEMPERATURE) + GEN_QUESTION_TEMPERATURE) response["overall"] = fix_writing_overall(response["overall"], response["task_response"]) response['fixed_text'] = get_fixed_text(answer) return response except Exception as e: return str(e) + def fix_writing_overall(overall: float, task_response: dict): if overall > max(task_response.values()) or overall < min(task_response.values()): total_sum = sum(task_response.values()) @@ -371,6 +373,7 @@ def fix_writing_overall(overall: float, task_response: dict): return rounded_average return overall + @app.route('/writing_task2_general', methods=['GET']) @jwt_required() def get_writing_task_2_general_question(): @@ -385,7 +388,8 @@ 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 ' + "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.') @@ -427,24 +431,27 @@ def grade_speaking_task_1(): 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}}') + "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}}') }, { "role": "user", - "content": ('Evaluate the given Speaking Part 1 response based on the IELTS grading system, ensuring a ' - 'strict assessment that penalizes errors. Deduct points for deviations from the task, and ' - '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 + '"') + "content": ( + 'Evaluate the given Speaking Part 1 response based on the IELTS grading system, ensuring a ' + 'strict assessment that penalizes errors. Deduct points for deviations from the task, and ' + '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 + '"') } ] token_count = count_total_tokens(messages) + logging.info("POST - speaking_task_1 - " + 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_1 - " + str(request_id) + " - Answer graded: " + str(response)) perfect_answer_messages = [