|
|
|
|
|
|
|
|
|
ANSWER_FORMAT_INSTRUCTIONS = { |
|
"MCQ_SINGLE_CORRECT": "determine the single correct option identifier (e.g., 1, 2, A, B) as it appears in the question.", |
|
"INTEGER": "determine the single numerical answer. This can be an integer or a decimal value. Provide the number as accurately as possible.", |
|
"MCQ_MULTIPLE_CORRECT": "determine all correct option identifier(s) (e.g., 1, 2, A, B) as they appear in the question. If multiple options are correct, list their identifiers separated by commas.", |
|
"DEFAULT": "determine the correct answer based on the question's format." |
|
} |
|
|
|
EXAMPLE_INSTRUCTIONS = { |
|
"MCQ_SINGLE_CORRECT": "- If the correct option is labeled '2' in the question: <answer>2</answer>\n- If the correct option is labeled 'A' in the question: <answer>A</answer>", |
|
"INTEGER": "- If the answer is 5: <answer>5</answer>\n- If the answer is 12.75: <answer>12.75</answer>\n- If the answer is 0.5: <answer>0.5</answer>", |
|
"MCQ_MULTIPLE_CORRECT": "- If options labeled 'A' and 'C' are correct: <answer>A,C</answer>\n- If options labeled '1' and '3' are correct: <answer>1,3</answer>\n- If only option 'B' is correct: <answer>B</answer>\n- If only option '2' is correct: <answer>2</answer>", |
|
"DEFAULT": "- Example: <answer>Your Answer</answer>" |
|
} |
|
|
|
INITIAL_PROMPT_TEMPLATE = """You are an expert at analyzing exam questions from the {exam_name} {exam_year} exam ({question_type}) and extracting the correct answer option(s)/value. |
|
This exam uses specific marking schemes, so accuracy and correct formatting are crucial. |
|
|
|
Please think step-by-step to solve the problem. |
|
Examine the provided image of the question carefully. |
|
1. Analyze the question and the provided options (if any). |
|
2. Reason through the problem to {answer_format_instruction} |
|
3. Format your final answer by enclosing ONLY the determined identifier(s) or numerical value(s) within <answer> tags. |
|
|
|
Examples: |
|
{example_instruction} |
|
- If you are unsure or cannot determine the answer: <answer>SKIP</answer> |
|
|
|
It is crucial that your response contains ONLY the <answer> tag with the correct option identifier(s), numerical value(s) OR the word SKIP inside. Do not include any other text, explanation, or formatting.""" |
|
|
|
|
|
|
|
|
|
SPECIFIC_INSTRUCTIONS_REPROMPT = { |
|
"MCQ_SINGLE_CORRECT": "provide ONLY the single correct option identifier (e.g., 1, A) as it appears in the question", |
|
"INTEGER": "provide ONLY the single numerical answer (integer or decimal)", |
|
"MCQ_MULTIPLE_CORRECT": "provide ALL correct option identifier(s) (e.g., A,C or 1,3) as they appear in the question, separated by commas if multiple. If only one is correct, provide just that one (e.g., <answer>B</answer> or <answer>2</answer>)", |
|
"DEFAULT": "provide the answer according to the question format" |
|
} |
|
|
|
REPROMPT_PROMPT_TEMPLATE = """You previously provided the following response to an exam question: |
|
--- PREVIOUS RESPONSE START --- |
|
{previous_raw_response} |
|
--- PREVIOUS RESPONSE END --- |
|
|
|
Your previous response did not correctly format the final answer within <answer> tags, or it did not match the expected format for a '{question_type}' question. |
|
|
|
Please re-examine your previous reasoning and {specific_instructions}, enclosed in <answer> tags. |
|
|
|
Example for single correct MCQ option 'A': <answer>A</answer> |
|
Example for single correct MCQ option '2': <answer>2</answer> |
|
Example for multiple correct MCQ options 'A' and 'C': <answer>A,C</answer> |
|
Example for integer answer: <answer>42</answer> |
|
Example for decimal answer: <answer>12.75</answer> |
|
If you are unsure or cannot determine the answer: <answer>SKIP</answer> |
|
|
|
It is crucial that your response contains ONLY the <answer> tag with the correct option identifier(s), numerical value(s) OR the word SKIP inside. Do not include any other text, explanation, or formatting.""" |
|
|
|
|
|
|
|
def get_answer_format_instruction(question_type: str) -> str: |
|
return ANSWER_FORMAT_INSTRUCTIONS.get(question_type, ANSWER_FORMAT_INSTRUCTIONS["DEFAULT"]) |
|
|
|
def get_example_instruction(question_type: str) -> str: |
|
return EXAMPLE_INSTRUCTIONS.get(question_type, EXAMPLE_INSTRUCTIONS["DEFAULT"]) |
|
|
|
def get_specific_instructions_reprompt(question_type: str) -> str: |
|
return SPECIFIC_INSTRUCTIONS_REPROMPT.get(question_type, SPECIFIC_INSTRUCTIONS_REPROMPT["DEFAULT"]) |
|
|