"""ab_compare.py, M5: send the SAME input through TWO prompts and see the difference.

This is the heart of prompt engineering: change the instructions, not the code, and
watch the output change. Here we compare a vague prompt against an engineered one.

Run (venv active, key in .env, from this folder):
    python ab_compare.py
"""

import os
from dotenv import load_dotenv
import anthropic

load_dotenv()
client = anthropic.Anthropic()
MODEL = "claude-opus-4-8"        # swap to "claude-haiku-4-5" for cheaper experiments

# The blunt message we want rewritten (same input for both prompts).
BLUNT = "need the report today. you're late again."

# Prompt A, vague. The model has to guess what "nicer" means.
NAIVE_SYSTEM = "Make this message nicer."

# Prompt B, engineered: a clear role, explicit constraints, and a defined output.
ENGINEERED_SYSTEM = (
    "You are a thoughtful colleague. Rewrite the user's blunt message as a warm, "
    "professional email that keeps all the facts, stays concise (2-4 sentences), and "
    "removes any blame. Output only the rewritten message, no preamble."
)


def ask(system, text):
    """Send one message under a given system prompt; return the reply text."""
    response = client.messages.create(
        model=MODEL,
        max_tokens=400,
        system=system,
        messages=[{"role": "user", "content": text}],
    )
    return response.content[0].text


print("INPUT:", BLUNT)
print("\n=== A · vague prompt ===")
print(ask(NAIVE_SYSTEM, BLUNT))
print("\n=== B · engineered prompt ===")
print(ask(ENGINEERED_SYSTEM, BLUNT))
print("\nSame model, same input, only the prompt changed. That's prompt engineering.")
