From 1591f8d9fbee4d4e9e725f827e458698a637c05b Mon Sep 17 00:00:00 2001 From: Cristiano Ferreira Date: Wed, 17 Jan 2024 16:37:59 +0000 Subject: [PATCH] Improve speaking corrections to return fixed_text. --- app.py | 6 +++--- helper/openai_interface.py | 12 ++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app.py b/app.py index b807b57..4486e20 100644 --- a/app.py +++ b/app.py @@ -347,7 +347,7 @@ def grade_speaking_task_1(): None, GEN_QUESTION_TEMPERATURE) response['transcript'] = answer - response['corrections'] = get_speaking_corrections(answer) + response['fixed_text'] = get_speaking_corrections(answer) return response else: return { @@ -415,7 +415,7 @@ def grade_speaking_task_2(): None, GEN_QUESTION_TEMPERATURE) response['transcript'] = answer - response['corrections'] = get_speaking_corrections(answer) + response['fixed_text'] = get_speaking_corrections(answer) return response else: return { @@ -532,7 +532,7 @@ def grade_speaking_task_3(): for i, answer in enumerate(text_answers, start=1): response['transcript_' + str(i)] = answer - response['corrections_' + str(i)] = get_speaking_corrections(answer) + response['fixed_text_' + str(i)] = get_speaking_corrections(answer) return response except Exception as e: return str(e), 400 diff --git a/helper/openai_interface.py b/helper/openai_interface.py index dbf0273..af2d343 100644 --- a/helper/openai_interface.py +++ b/helper/openai_interface.py @@ -257,12 +257,8 @@ def get_fixed_text(text): return response["fixed_text"] def get_speaking_corrections(text): - message = ('Given the provided transcription, identify and extract any inaccuracies, including incorrect words and ' - 'expressions. Put them in the json with the correct words and expressions that should be on the transcription ' - 'instead. Sample JSON: {"corrections":[{"wrong": "wrong_word", "correct": "correct_word"}] ' - '\n The text: "' + text + '"') + message = ('Fix the errors in the provided transcription and put it in a JSON. Sample JSON: {"fixed_text": "fixed ' + 'transcription with no misspelling errors"}] \n The text: "' + text + '"') token_count = count_tokens(message)["n_tokens"] - response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count, ["corrections"], 0.2) - # Filter out items with the same value for misspelled and correction - filtered_data = [item for item in response["corrections"] if item['wrong'] != item['correct']] - return filtered_data + response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count, ["fixed_text"], 0.2) + return response["fixed_text"]