mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-08-27 19:29:56 -04:00
a094b7f807
Eval chain is currently very sensitive to differences in phrasing, punctuation, and tangential information. This prompt has worked better for me on my examples. More general q: Do we have any framework for evaluating default prompt changes? Could maybe start doing some regression testing?
63 lines
2.8 KiB
Python
63 lines
2.8 KiB
Python
# flake8: noqa
|
|
from langchain.prompts import PromptTemplate
|
|
|
|
template = """You are a teacher grading a quiz.
|
|
You 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.
|
|
|
|
Example Format:
|
|
QUESTION: question here
|
|
STUDENT ANSWER: student's answer here
|
|
TRUE ANSWER: true answer here
|
|
GRADE: CORRECT or INCORRECT here
|
|
|
|
Grade 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!
|
|
|
|
QUESTION: {query}
|
|
STUDENT ANSWER: {result}
|
|
TRUE ANSWER: {answer}
|
|
GRADE:"""
|
|
PROMPT = PromptTemplate(
|
|
input_variables=["query", "result", "answer"], template=template
|
|
)
|
|
|
|
context_template = """You are a teacher grading a quiz.
|
|
You are given a question, the context the question is about, and the student's answer. You are asked to score the student's answer as either CORRECT or INCORRECT, based on the context.
|
|
|
|
Example Format:
|
|
QUESTION: question here
|
|
CONTEXT: context the question is about here
|
|
STUDENT ANSWER: student's answer here
|
|
GRADE: CORRECT or INCORRECT here
|
|
|
|
Grade 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!
|
|
|
|
QUESTION: {query}
|
|
CONTEXT: {context}
|
|
STUDENT ANSWER: {result}
|
|
GRADE:"""
|
|
CONTEXT_PROMPT = PromptTemplate(
|
|
input_variables=["query", "context", "result"], template=context_template
|
|
)
|
|
|
|
|
|
cot_template = """You are a teacher grading a quiz.
|
|
You are given a question, the context the question is about, and the student's answer. You are asked to score the student's answer as either CORRECT or INCORRECT, based on the context.
|
|
Write out in a step by step manner your reasoning to be sure that your conclusion is correct. Avoid simply stating the correct answer at the outset.
|
|
|
|
Example Format:
|
|
QUESTION: question here
|
|
CONTEXT: context the question is about here
|
|
STUDENT ANSWER: student's answer here
|
|
EXPLANATION: step by step reasoning here
|
|
GRADE: CORRECT or INCORRECT here
|
|
|
|
Grade 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!
|
|
|
|
QUESTION: {query}
|
|
CONTEXT: {context}
|
|
STUDENT ANSWER: {result}
|
|
EXPLANATION:"""
|
|
COT_PROMPT = PromptTemplate(
|
|
input_variables=["query", "context", "result"], template=cot_template
|
|
)
|