INNER CODE UNIT · Python
extract_instruction
KodCode-AI/kodcode · pipeline/step1.3_process_and_sanitize.py:60
def extract_instruction(message_content):
"""
Extracts the instruction from the assistant's message content.
Removes any leading "Question X" or similar prefixes.
"""
instruction = message_content.strip()
# Remove leading "Question X" where X is a number (e.g., "Question 4:", "### Question 4:", etc.)
# Remove various forms of "Question" prefixes
instruction = re.sub(r'^\[?Question\s*\d*\]?:?\s*', '', instruction, flags=re.IGNORECASE)
instruction = re.sub(r'^#+\s*\[?Question\s*\d*\]?:?\s*', '', instruction, flags=re.IGNORECASE)
instruction = re.sub(r'^\[?Question\s*\d*\]?:.*?$', '', instruction, flags=re.IGNORECASE | re.MULTILINE)
instruction = re.sub(r'^#+\s*New\s+Question:?\s*', '', instruction, flags=re.IGNORECASE)
instruction = re.sub(r'^\*\*Question\s*\d*:?\*\*\s*', '', instruction, flags=re.IGNORECASE)
instruction = re.sub(r'^\*\*Question:?\*\*\s*', '', instruction, flags=re.IGNORECASE)
instruction = re.sub(r'^\[?Question\s*\d+\]?:?\s*', '', instruction, flags=re.IGNORECASE)
instruction = re.sub(r'^#+\s*\[?Question\s*\d+\]?:?\s*', '', instruction, flags=re.IGNORECASE)
instruction = re.sub(r'^\[?Question\s*\d+\]?:.*?$', '', instruction, flags=re.IGNORECASE | re.MULTILINE)