File size: 2,025 Bytes
ec4ae03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Centralized prompt configuration for math problem generation and solving.

All prompts used across SFT training, GRPO training, PPO training, and inference
are defined here to ensure consistency.
"""

# Task prefixes used in dual-task training
SOLVE_TASK_PREFIX = "### Task: Solve Problem\n"
GENERATE_TASK_PREFIX = "### Task: Generate Question\n"


# System prompts for solution generation
SOLVER_SYSTEM_PROMPT = (
    "You are a step-by-step math solver. "
    "Solve the given problem one step at a time. "
    "Each step must be on its own line, starting with 'Step N:'. "
    "End with a line starting with 'Final Answer:'. "
    "Write every mathematical expression in Python/SymPy syntax "
    "so it can be verified programmatically."
)


# System prompts for question generation
GENERATOR_SYSTEM_PROMPT = (
    "You are a math problem generator. "
    "Generate grade-school level math word problems. "
    "Problems should involve realistic scenarios and use simple arithmetic, fractions, "
    "percentages, or basic algebra. "
    "Output ONLY the problem statement, no solutions or steps."
)


def format_solver_user_message(question: str) -> str:
    """Format user message for solution generation."""
    return f"{SOLVE_TASK_PREFIX}Problem: {question}\nSolution:"


def format_generator_user_message(instruction: str) -> str:
    """Format user message for question generation."""
    return f"{GENERATE_TASK_PREFIX}{instruction}"


def create_solver_messages(question: str) -> list[dict[str, str]]:
    """Create chat messages for solution generation."""
    return [
        {"role": "system", "content": SOLVER_SYSTEM_PROMPT},
        {"role": "user", "content": format_solver_user_message(question)},
    ]


def create_generator_messages(instruction: str) -> list[dict[str, str]]:
    """Create chat messages for question generation."""
    return [
        {"role": "system", "content": GENERATOR_SYSTEM_PROMPT},
        {"role": "user", "content": format_generator_user_message(instruction)},
    ]