Calculate Grading Summary Logic

This commit is contained in:
Pedro Fonseca
2024-01-06 18:46:29 +00:00
parent f2e8497756
commit ac27239787
2 changed files with 28 additions and 22 deletions

14
app.py
View File

@@ -11,6 +11,7 @@ from helper.heygen_api import create_videos_and_save_to_db
from helper.speech_to_text_helper import *
from helper.token_counter import count_tokens
from helper.openai_interface import make_openai_call, make_openai_instruct_call
from grading_summary.grading_summary import calculate_grading_summary
import os
import re
import logging
@@ -37,6 +38,7 @@ thread_event = threading.Event()
logging.basicConfig(level=logging.DEBUG, # Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
format='%(asctime)s - %(levelname)s - %(message)s')
@app.route('/healthcheck', methods=['GET'])
def healthcheck():
return {"healthy": True}
@@ -511,7 +513,8 @@ def grade_speaking_task_3():
formatted_text += f"**Answer {i}:**\n{entry['answer']}\n\n"
message += formatted_text
message += ("'\n\nProvide your answer on the following json format: {'comment': 'comment about answer quality', "
message += (
"'\n\nProvide your answer on the following json format: {'comment': 'comment about answer quality', "
"'overall': 0.0, 'task_response': {'Fluency and Coherence': 0.0, 'Lexical Resource': 0.0, "
"'Grammatical Range and Accuracy': 0.0, 'Pronunciation': 0.0}}")
@@ -690,5 +693,14 @@ def fetch_answer_tips():
return str(e)
@app.route('/grading_summary', methods=['POST'])
@jwt_required()
def grading_summary():
try:
return calculate_grading_summary(request.get_json())
except Exception as e:
return str(e)
if __name__ == '__main__':
app.run()

View File

@@ -3,7 +3,6 @@ import json
import openai
import os
from dotenv import load_dotenv
from functools import reduce
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
@@ -35,12 +34,7 @@ tools = [{
}]
# Input Format
# {'sections': Array of {'code': key, 'name': name, 'grade': grade}}
# Output
# {'sections': Array of {'code': key, 'name': name, 'grade': grade, 'evaluation': evaluation, 'suggestions': suggestions}}
def grading_summary(body):
def calculate_grading_summary(body):
extracted_sections = extract_existing_sections_from_body(body, section_keys)
ret = []