diff --git a/app.py b/app.py index b0896eb..bb1b5bd 100644 --- a/app.py +++ b/app.py @@ -183,13 +183,19 @@ def grade_writing_task_1(): try: data = request.get_json() question = data.get('question') - context = data.get('context') answer = data.get('answer') if has_words(answer): - messages = get_grading_messages(QuestionType.WRITING_TASK_1, question, answer, context) - token_count = reduce(lambda count, item: count + count_tokens(item)['n_tokens'], - map(lambda x: x["content"], filter(lambda x: "content" in x, messages)), 0) - response = make_openai_call(GPT_3_5_TURBO, messages, token_count, GRADING_FIELDS, GRADING_TEMPERATURE) + message = ( + "Grade this Writing Task 1 answer according to ielts grading system and provide an example of a perfect " + "answer and an elaborated comment where you deep dive into what is wrong and right about the answer." + "Provide your answer on the following json format: {'perfect_answer': 'example perfect answer', 'comment': 'comment about answer quality', 'overall': 7.0, " + "'task_response': {'Task Achievement': 0.0, 'Coherence and Cohesion': 0.0, 'Lexical Resource': 0.0, " + "'Grammatical Range and Accuracy': 0.0}}\n The question was '" + question + "' " + "and the answer was '" + answer + "'") + token_count = count_tokens(message)["n_tokens"] + response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count, + ["comment"], + GEN_QUESTION_TEMPERATURE) return response else: return { @@ -231,10 +237,17 @@ def grade_writing_task_2(): question = data.get('question') answer = data.get('answer') if has_words(answer): - messages = get_grading_messages(QuestionType.WRITING_TASK_2, question, answer) - token_count = reduce(lambda count, item: count + count_tokens(item)['n_tokens'], - map(lambda x: x["content"], filter(lambda x: "content" in x, messages)), 0) - response = make_openai_call(GPT_3_5_TURBO, messages, token_count, GRADING_FIELDS, GRADING_TEMPERATURE) + message = ( + "Grade this Writing Task 2 answer according to ielts grading system and provide an example of a perfect " + "answer and an elaborated comment where you deep dive into what is wrong and right about the answer." + "Provide your answer on the following json format: {'perfect_answer': 'example perfect answer', 'comment': 'comment about answer quality', 'overall': 7.0, " + "'task_response': {'Task Achievement': 0.0, 'Coherence and Cohesion': 0.0, 'Lexical Resource': 0.0, " + "'Grammatical Range and Accuracy': 0.0}}\n The question was '" + question + "' " + "and the answer was '" + answer + "'") + token_count = count_tokens(message)["n_tokens"] + response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count, + ["comment"], + GEN_QUESTION_TEMPERATURE) return response else: return { @@ -597,6 +610,7 @@ def get_reading_passage_3_question(): except Exception as e: return str(e) + @app.route('/reading', methods=['POST']) @jwt_required() def save_reading_passage():