Add perfect answer to writing grading

This commit is contained in:
cristiano.ferreira
2023-11-30 17:38:44 +00:00
parent 22de63c346
commit 171d72109e

32
app.py
View File

@@ -183,13 +183,19 @@ def grade_writing_task_1():
try: try:
data = request.get_json() data = request.get_json()
question = data.get('question') question = data.get('question')
context = data.get('context')
answer = data.get('answer') answer = data.get('answer')
if has_words(answer): if has_words(answer):
messages = get_grading_messages(QuestionType.WRITING_TASK_1, question, answer, context) message = (
token_count = reduce(lambda count, item: count + count_tokens(item)['n_tokens'], "Grade this Writing Task 1 answer according to ielts grading system and provide an example of a perfect "
map(lambda x: x["content"], filter(lambda x: "content" in x, messages)), 0) "answer and an elaborated comment where you deep dive into what is wrong and right about the answer."
response = make_openai_call(GPT_3_5_TURBO, messages, token_count, GRADING_FIELDS, GRADING_TEMPERATURE) "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 return response
else: else:
return { return {
@@ -231,10 +237,17 @@ def grade_writing_task_2():
question = data.get('question') question = data.get('question')
answer = data.get('answer') answer = data.get('answer')
if has_words(answer): if has_words(answer):
messages = get_grading_messages(QuestionType.WRITING_TASK_2, question, answer) message = (
token_count = reduce(lambda count, item: count + count_tokens(item)['n_tokens'], "Grade this Writing Task 2 answer according to ielts grading system and provide an example of a perfect "
map(lambda x: x["content"], filter(lambda x: "content" in x, messages)), 0) "answer and an elaborated comment where you deep dive into what is wrong and right about the answer."
response = make_openai_call(GPT_3_5_TURBO, messages, token_count, GRADING_FIELDS, GRADING_TEMPERATURE) "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 return response
else: else:
return { return {
@@ -597,6 +610,7 @@ def get_reading_passage_3_question():
except Exception as e: except Exception as e:
return str(e) return str(e)
@app.route('/reading', methods=['POST']) @app.route('/reading', methods=['POST'])
@jwt_required() @jwt_required()
def save_reading_passage(): def save_reading_passage():