Improve speaking corrections to return fixed_text.
This commit is contained in:
6
app.py
6
app.py
@@ -347,7 +347,7 @@ def grade_speaking_task_1():
|
|||||||
None,
|
None,
|
||||||
GEN_QUESTION_TEMPERATURE)
|
GEN_QUESTION_TEMPERATURE)
|
||||||
response['transcript'] = answer
|
response['transcript'] = answer
|
||||||
response['corrections'] = get_speaking_corrections(answer)
|
response['fixed_text'] = get_speaking_corrections(answer)
|
||||||
return response
|
return response
|
||||||
else:
|
else:
|
||||||
return {
|
return {
|
||||||
@@ -415,7 +415,7 @@ def grade_speaking_task_2():
|
|||||||
None,
|
None,
|
||||||
GEN_QUESTION_TEMPERATURE)
|
GEN_QUESTION_TEMPERATURE)
|
||||||
response['transcript'] = answer
|
response['transcript'] = answer
|
||||||
response['corrections'] = get_speaking_corrections(answer)
|
response['fixed_text'] = get_speaking_corrections(answer)
|
||||||
return response
|
return response
|
||||||
else:
|
else:
|
||||||
return {
|
return {
|
||||||
@@ -532,7 +532,7 @@ def grade_speaking_task_3():
|
|||||||
|
|
||||||
for i, answer in enumerate(text_answers, start=1):
|
for i, answer in enumerate(text_answers, start=1):
|
||||||
response['transcript_' + str(i)] = answer
|
response['transcript_' + str(i)] = answer
|
||||||
response['corrections_' + str(i)] = get_speaking_corrections(answer)
|
response['fixed_text_' + str(i)] = get_speaking_corrections(answer)
|
||||||
return response
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return str(e), 400
|
return str(e), 400
|
||||||
|
|||||||
@@ -257,12 +257,8 @@ def get_fixed_text(text):
|
|||||||
return response["fixed_text"]
|
return response["fixed_text"]
|
||||||
|
|
||||||
def get_speaking_corrections(text):
|
def get_speaking_corrections(text):
|
||||||
message = ('Given the provided transcription, identify and extract any inaccuracies, including incorrect words and '
|
message = ('Fix the errors in the provided transcription and put it in a JSON. Sample JSON: {"fixed_text": "fixed '
|
||||||
'expressions. Put them in the json with the correct words and expressions that should be on the transcription '
|
'transcription with no misspelling errors"}] \n The text: "' + text + '"')
|
||||||
'instead. Sample JSON: {"corrections":[{"wrong": "wrong_word", "correct": "correct_word"}] '
|
|
||||||
'\n The text: "' + text + '"')
|
|
||||||
token_count = count_tokens(message)["n_tokens"]
|
token_count = count_tokens(message)["n_tokens"]
|
||||||
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count, ["corrections"], 0.2)
|
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count, ["fixed_text"], 0.2)
|
||||||
# Filter out items with the same value for misspelled and correction
|
return response["fixed_text"]
|
||||||
filtered_data = [item for item in response["corrections"] if item['wrong'] != item['correct']]
|
|
||||||
return filtered_data
|
|
||||||
|
|||||||
Reference in New Issue
Block a user