"""Lab 01 - Your first Foundry model call.

Objective 2.1 - Deploy a model and interact with it.

Proves: project endpoint, Entra auth, and model deployment all work.
Run:  az login  &&  python 01_first_call.py
"""
from _common import banner, get_clients, require

MODEL = require("MODEL_DEPLOYMENT")

banner("Lab 01 - First call to a Foundry model")

_, openai = get_clients()

# The Responses API. `input` is the user prompt.
response = openai.responses.create(
    model=MODEL,
    input="What is the size of France in square miles? Answer in one sentence.",
)
print("\nPlain call:\n ", response.output_text)

# `instructions` IS the system message in the Responses API.
# There is no messages=[{"role": "system", ...}] array any more.
response = openai.responses.create(
    model=MODEL,
    instructions="You are a terse geography tutor. Never exceed 20 words.",
    input="Why is the Rhine economically important?",
    temperature=0.3,
    max_output_tokens=100,
)
print("\nWith a system message:\n ", response.output_text)

# Temperature 0 = deterministic. Run this twice; expect identical output.
for attempt in (1, 2):
    r = openai.responses.create(
        model=MODEL,
        instructions="Reply with exactly one word.",
        input="Classify the sentiment: 'The train was late again.'",
        temperature=0,
    )
    print(f"\nDeterminism check {attempt}: {r.output_text.strip()}")

print("\nRecall for the exam:")
print("  - model=      takes the DEPLOYMENT name, not the model name")
print("  - instructions= is the system message")
print("  - max_output_tokens caps the COMPLETION, not the prompt")
print("  - temperature 0 for classification and extraction work")
