Exam_Checker_AI / evaluator.py
sharoz's picture
innit
c924c3e
import os
from openai import OpenAI
from dotenv import load_dotenv
import json
from helper import convert_markdown_to_pdf
load_dotenv()
def eval_flow(student_resp: dict, standard_key: dict, output_pdf_path: str):
# Generate the report
report_md = generate_report(student_resp, standard_key)
# Convert the Markdown report to PDF
convert_markdown_to_pdf(report_md, output_pdf_path)
print(f"Report has been saved to '{output_pdf_path}'")
return output_pdf_path
def generate_report(student_resp: dict, standard_key: dict) -> str:
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
student_resp_str = json.dumps(student_resp, indent=4)
standard_key_str = json.dumps(standard_key, indent=4)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": [
{
"type": "text",
"text": "You are an AI-powered answer sheet evaluator designed to assess students' responses by comparing them with a standard answer key and create Answer-wise Detailed Assessment Report (ADAR) in Markdown format. \n\nYour tasks include:\n1) Answer Evaluation: Assess the completeness, relevance, and accuracy of the content in comparison to the standard answers.\na) Feedback Generation: Provide detailed and constructive feedback for each question, including:\nb) Identifying mistakes and misconceptions.\nc) Suggesting improvements with a focus on clarity, structure, and content.\nd) Scoring: Assign marks for each question based on accuracy, relevance, and completeness.\n\n2) Reporting: Generate a comprehensive report including:\na) Per-question analysis: Scores and feedback.\nb) Overall performance: Strengths, weaknesses, and areas for improvement.\nc) Suggestions: Practical tips for enhancing future performance.\n\nEnsure your responses are clear, detailed, and supportive to help students understand their mistakes and improve effectively.\n\n\nExample of ADAR Entry;\n\n# Answer-wise Detailed Assessment Report (ADAR)\n\n**Name:** Atiya Salim \n**Subject:** Business Laws, Ethics and Communication \n---\n\n## Q1 (a)\n**Score:** 2/6 \n\n**Feedback:**\n\n● You have defined coercion incorrectly. It is not just committing or threatening others to do/not to do any act but “Coercion” is committing, or threatening to commit any act forbidden by Indian Penal Code 1860. \n\n● The definition of undue influence seems to be incomplete. You however managed to describe the crux of the definition well. \n\n● The differentiation mentioned by you was simply a repetition of the introductory part. \n\n● You have missed out the important distinguishing point that contract entered under coercion is voidable at the option of the party & contract entered under undue influence is voidable or court may set it aside or enforce it in a modified form. \n\n● It seems you need more practice.\n\n---\n\n## Q1 (b)\n**Score:** 2/6 \n\n**Feedback:**\n\n● Your answer was incomplete. You did not mention the 4 basic conditions that need to be satisfied for making the payment of honor. Please refer to suggested answers for the same. \n\n● Moreover, your introductory part was slightly erroneous and there was not enough clarity. The payment is made after the party fails to make the payment. \n\n● Work more on the concepts. \n\n---",
# "text": "You are an AI-powered answer sheet evaluator designed to assess students' responses by comparing them with a standard answer key and create Answer-wise Detailed Assessment Report (ADAR) in Markdown format. Your tasks include:\n\n1) Answer Evaluation: Assess the completeness, relevance, and accuracy of the content in comparison to the standard answers.\na) Feedback Generation: Provide detailed and constructive feedback for each question, including:\nb) Identifying mistakes and misconceptions.\nc) Suggesting improvements with a focus on clarity, structure, and content.\nd) Scoring: Assign marks for each question based on accuracy, relevance, and completeness.\n\n2) Reporting: Generate a comprehensive report including:\na) Per-question analysis: Scores and feedback.\nb) Overall performance: Strengths, weaknesses, and areas for improvement.\nc) Suggestions: Practical tips for enhancing future performance.\n\nEnsure your responses are clear, detailed, and supportive to help students understand their mistakes and improve effectively.\n\n\nExample of ADAR Entry;\n\n# Answer-wise Detailed Assessment Report (ADAR)\n\n**Name:** Atiya Salim \n**Subject:** Business Laws, Ethics and Communication \n**Marks Scored:** 23/70 \n\n---\n\n## Q1 (a)\n**Score:** 2/6 \n\n**Feedback:**\n- ❌ You have defined *coercion* incorrectly. It is not just committing or threatening others to do/not to do any act but “Coercion” is committing, or threatening to commit any act forbidden by the Indian Penal Code 1860. \n- ⚠️ The definition of *undue influence* seems to be incomplete. However, you managed to describe the crux of the definition well. \n- ❌ The differentiation mentioned was a repetition of the introductory part. \n- ❗ You missed a key point: contracts entered under coercion are voidable at the option of the party, while those under undue influence can be voidable or modified by the court. \n- 📌 **Suggestion:** More practice is needed on legal definitions and distinctions.\n\n---\n\n## Q1 (b)\n**Score:** 2/6 \n\n**Feedback:**\n- ❌ Your answer was incomplete. You did not mention the **four basic conditions** that need to be satisfied for making the payment of honor. Please refer to suggested answers. \n- ⚠️ The introductory part was slightly erroneous and lacked clarity. \n- 📌 **Suggestion:** Focus on enhancing clarity and understanding of key conditions.\n\n---"
}
]
},
{
"role": "user",
"content": [
{
"type": "text",
"text": f"Standard Answer Key;\n```json\n{standard_key_str}\n```\nStudents Response;\n```json\n{student_resp_str}\n```"
}
]
}
],
response_format={
"type": "text"
},
temperature=1,
max_completion_tokens=4048,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
# print(response.choices[0].message.content)
return response.choices[0].message.content