# System prompts for LLM interaction # --- Initial Prompt Components --- 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: 2\n- If the correct option is labeled 'A' in the question: A", "INTEGER": "- If the answer is 5: 5\n- If the answer is 12.75: 12.75\n- If the answer is 0.5: 0.5", "MCQ_MULTIPLE_CORRECT": "- If options labeled 'A' and 'C' are correct: A,C\n- If options labeled '1' and '3' are correct: 1,3\n- If only option 'B' is correct: B\n- If only option '2' is correct: 2", "DEFAULT": "- Example: Your 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 tags. Examples: {example_instruction} - If you are unsure or cannot determine the answer: SKIP It is crucial that your response contains ONLY the tag with the correct option identifier(s), numerical value(s) OR the word SKIP inside. Do not include any other text, explanation, or formatting.""" # --- Reprompt Components --- 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., B or 2)", "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 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 tags. Example for single correct MCQ option 'A': A Example for single correct MCQ option '2': 2 Example for multiple correct MCQ options 'A' and 'C': A,C Example for integer answer: 42 Example for decimal answer: 12.75 If you are unsure or cannot determine the answer: SKIP It is crucial that your response contains ONLY the tag with the correct option identifier(s), numerical value(s) OR the word SKIP inside. Do not include any other text, explanation, or formatting.""" # --- Helper functions to get instructions --- 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"])