0Pricing
AI Engineering Academy · Lesson

Controlling Model Behavior with Parameters

Experiment with temperature, max_tokens, and top_p to see how they change output style, length, and creativity, then choose appropriate settings for your use case.

The Core Parameters That Matter

A handful of parameters shape your output the most: temperature, max_tokens, top_p, frequency_penalty, and presence_penalty. Master these five and you control the model.

Temperature: Controlling Randomness

Temperature controls randomness. Near 0, the model picks the safest word and stays consistent — great for facts. Around 0.7-1.0, it gets varied and creative. See the code.

from openai import OpenAI
client = OpenAI()

for temp in [0.0, 0.7, 1.5]:
    response = client.chat.completions.create(
        model='gpt-4o-mini',
        messages=[{'role': 'user', 'content': 'Name a color.'}],
        temperature=temp,
        max_tokens=5
    )
    print(f'Temp {temp}: {response.choices[0].message.content}')
# Temp 0.0: Red       (always most common)
# Temp 0.7: Blue      (varied but sensible)
# Temp 1.5: Vermillion (surprising choices)

All lessons in this course

  1. Setting Up Your Python Environment
  2. The Chat Completions Endpoint
  3. Controlling Model Behavior with Parameters
  4. Error Handling and Rate Limits
← Back to AI Engineering Academy