BishanSingh246/test
0
1import re2from langchain.prompts import PromptTemplate3 4 5def clean_pdf_text(text: str) -> str:6 """Cleans text extracted from a PDF file."""7 # TODO: Remove References/Bibliography section.8 return remove_citations(text)9 10 11def remove_citations(text: str) -> str:12 """Removes in-text citations from a string."""13 # (Author, Year)14 text = re.sub(r'\([A-Za-z0-9,.\s]+\s\d{4}\)', '', text)15 # [1], [2], [3-5], [3, 33, 49, 51]16 text = re.sub(r'\[[0-9,-]+(,\s[0-9,-]+)*\]', '', text)17 return text18 19 20template = """You are a teacher grading a quiz. 21You are given a question, the student's answer, and the true answer, and are asked to score the student answer as either CORRECT or INCORRECT.22Example Format:23QUESTION: question here24STUDENT ANSWER: student's answer here25TRUE ANSWER: true answer here26GRADE: CORRECT or INCORRECT here27Grade the student answers based ONLY on their factual accuracy. Ignore differences in punctuation and phrasing between the student answer and true answer. It is OK if the student answer contains more information than the true answer, as long as it does not contain any conflicting statements. Begin! 28QUESTION: {query}29STUDENT ANSWER: {result}30TRUE ANSWER: {answer}31GRADE:32And explain why the STUDENT ANSWER is correct or incorrect.33"""34 35GRADE_ANSWER_PROMPT = PromptTemplate(input_variables=["query", "result", "answer"], template=template)36 37template = """You are a teacher grading a quiz. 38You are given a question, the student's answer, and the true answer, and are asked to score the student answer as either CORRECT or INCORRECT.39You are also asked to identify potential sources of bias in the question and in the true answer.40Example Format:41QUESTION: question here42STUDENT ANSWER: student's answer here43TRUE ANSWER: true answer here44GRADE: CORRECT or INCORRECT here45Grade the student answers based ONLY on their factual accuracy. Ignore differences in punctuation and phrasing between the student answer and true answer. It is OK if the student answer contains more information than the true answer, as long as it does not contain any conflicting statements. Begin! 46QUESTION: {query}47STUDENT ANSWER: {result}48TRUE ANSWER: {answer}49GRADE:50And explain why the STUDENT ANSWER is correct or incorrect, identify potential sources of bias in the QUESTION, and identify potential sources of bias in the TRUE ANSWER.51"""52 53GRADE_ANSWER_PROMPT_BIAS_CHECK = PromptTemplate(input_variables=["query", "result", "answer"], template=template)54 55template = """You are assessing a submitted student answer to a question relative to the true answer based on the provided criteria: 56 57 ***58 QUESTION: {query}59 ***60 STUDENT ANSWER: {result}61 ***62 TRUE ANSWER: {answer}63 ***64 Criteria: 65 relevance: Is the submission referring to a real quote from the text?"66 conciseness: Is the answer concise and to the point?"67 correct: Is the answer correct?"68 ***69 Does the submission meet the criterion? First, write out in a step by step manner your reasoning about the criterion to be sure that your conclusion is correct. Avoid simply stating the correct answers at the outset. Then print the "CORRECT" or "INCORRECT" (without quotes or punctuation) on its own line corresponding to the correct answer.70 Reasoning:71"""72 73GRADE_ANSWER_PROMPT_OPENAI = PromptTemplate(input_variables=["query", "result", "answer"], template=template)74 75template = """You are a teacher grading a quiz. 76You are given a question, the student's answer, and the true answer, and are asked to score the student answer as either CORRECT or INCORRECT.77Example Format:78QUESTION: question here79STUDENT ANSWER: student's answer here80TRUE ANSWER: true answer here81GRADE: CORRECT or INCORRECT here82Grade the student answers based ONLY on their factual accuracy. Ignore differences in punctuation and phrasing between the student answer and true answer. It is OK if the student answer contains more information than the true answer, as long as it does not contain any conflicting statements. Begin! 83QUESTION: {query}84STUDENT ANSWER: {result}85TRUE ANSWER: {answer}86GRADE:"""87 88GRADE_ANSWER_PROMPT_FAST = PromptTemplate(input_variables=["query", "result", "answer"], template=template)89 90template = """ 91 Given the question: \n92 {query}93 Decide if the following retrieved context is relevant: \n94 {result}95 Answer in the following format: \n96 "Context is relevant: True or False." \n 97 And explain why it supports or does not support the correct answer: {answer}"""98 99GRADE_DOCS_PROMPT = PromptTemplate(input_variables=["query", "result", "answer"], template=template)100 101template = """ 102 Given the question: \n103 {query}104 Decide if the following retrieved context is relevant to the {answer}: \n105 {result}106 Answer in the following format: \n107 "Context is relevant: True or False." \n """108 109GRADE_DOCS_PROMPT_FAST = PromptTemplate(input_variables=["query", "result", "answer"], template=template)