Adding bullet points to grading_summary endpoint

This commit is contained in:
Pedro Fonseca
2024-03-24 23:21:38 +00:00
parent 3aa33f10b4
commit 94c2b5a052
2 changed files with 34 additions and 5 deletions

View File

@@ -40,6 +40,10 @@ tools = [{
"type": "string",
"description": "A small paragraph text with suggestions on how to possibly get a better grade than the one obtained.",
},
"bullet_points": {
"type": "string",
"description": "Text with four bullet points to improve the english speaking ability. Only include text for the bullet points separated by a paragraph. ",
},
},
"required": ["evaluation", "suggestions"],
},
@@ -214,9 +218,11 @@ def calculate_grading_summary(body):
for section in extracted_sections:
openai_response_dict = calculate_section_grade_summary(section)
ret = ret + [{'code': section['code'], 'name': section['name'], 'grade': section['grade'],
'evaluation': openai_response_dict['evaluation'],
'suggestions': openai_response_dict['suggestions']}]
'suggestions': openai_response_dict['suggestions'],
'bullet_points': parse_bullet_points(openai_response_dict['bullet_points'], section['grade'])}]
return {'sections': ret}
@@ -236,7 +242,8 @@ def calculate_section_grade_summary(section):
"content": "Don't offer suggestions in the evaluation comment. Only in the suggestions section."},
{"role": "user",
"content": "Your evaluation comment on the grade should enunciate the grade, be insightful, be speculative, be one paragraph long. "},
{"role": "user", "content": "Please save the evaluation comment and suggestions generated."}
{"role": "user", "content": "Please save the evaluation comment and suggestions generated."},
{"role": "user", "content": "Offer bullet points to improve the english speaking ability."},
]
if section['code'] == "level":
@@ -266,7 +273,7 @@ def parse_openai_response(response):
response['choices'][0]['message']['tool_calls'][0]['function']['arguments']:
return json.loads(response['choices'][0]['message']['tool_calls'][0]['function']['arguments'])
else:
return {'evaluation': "", 'suggestions': ""}
return {'evaluation': "", 'suggestions': "", 'bullet_points': []}
def extract_existing_sections_from_body(my_dict, keys_to_extract):
@@ -276,6 +283,21 @@ def extract_existing_sections_from_body(my_dict, keys_to_extract):
my_dict['sections']))
def parse_bullet_points(bullet_points_str, grade):
max_grade_for_suggestions = 9
if isinstance(bullet_points_str, str) and grade < max_grade_for_suggestions:
# Split the string by '\n'
lines = bullet_points_str.split('\n')
# Remove '-' and trim whitespace from each line
cleaned_lines = [line.replace('-', '').strip() for line in lines]
# Add '.' to lines that don't end with it
return [line + '.' if line and not line.endswith('.') else line for line in cleaned_lines]
else:
return []
def get_fixed_text(text):
message = ('Fix the errors in the given text and put it in a JSON. Do not complete the answer, only replace what '
'is wrong. Sample JSON: {"fixed_text": "fixed test with no '
@@ -284,6 +306,7 @@ def get_fixed_text(text):
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count, ["fixed_text"], 0.2)
return response["fixed_text"]
def get_speaking_corrections(text):
message = ('Fix the errors in the provided transcription and put it in a JSON. Do not complete the answer, only '
'replace what is wrong. Sample JSON: {"fixed_text": "fixed '