Session 5· 01· 10 min
Plain Response Baseline
What you'll learn
- ▸Make a standard chat.completions.create() call
- ▸See the raw text response with no JSON or tool constraints
- ▸Establish the baseline every later exercise improves on
Before you start
You should have Session1 working. Switch to the Session5 folder, create a new .venv, install requirements.txt, and copy your .env over. Every Session 5 script reads OPENAI_API_KEY from .env.
What you will build
A tiny script that asks the model a question and prints the plain-text answer. No JSON, no tools, no structure. This is the "before" picture — every later exercise tightens the output format.
The pattern for every Session 5 script
load_dotenv
.env → env vars
OpenAI()
client
chat.completions.create
API call
print content
plain text
Chat Completions vs Responses
A note on the endpoint
Session 1 used client.responses.create(). Session 5 uses the older client.chat.completions.create() for everything in Phases 1 and 2. Both work; Chat Completions has broader tool/schema support today. You will see responses.parse() again in Phase 3.
The code
01_plain_response_basics.py
client = OpenAI(api_key=api_key) ①
response = client.chat.completions.create( ②
model=model,
messages=[
{"role": "system",
"content": "You are a beginner-friendly teacher."}, ③
{"role": "user",
"content": "Explain LLM in 2 simple lines for beginners."},
],
)
print(response.choices[0].message.content) ④①Same client object as Session 1 — the SDK is unified.
②Chat Completions endpoint: messages in, message out.
③System + user message pattern you already know from Session 1.
④Response shape is different from Session 1: response.choices[0].message.content (a list of candidates, take the first, read its message content).
Run it
$ python 01_plain_response_basics.py
Knowledge check
Knowledge Check
Why is this lesson called "baseline"?
Code Check
What is the path to the generated text in a Chat Completions response?
Recap — what you just learned
- ✓Session 5 uses chat.completions.create() — the older, tool-capable endpoint
- ✓Response text is at response.choices[0].message.content
- ✓This plain-text baseline is what we improve on in every later lesson