Chapter 6
The Creativity Dial — Temperature
Randomness vs. determinism
Back in Chapter 2’s exercise, I asked you to reload the page with [ai_course_ch2] on it twice in a row, and pointed out the wording wasn’t identical both times. I said that wasn’t a bug. This chapter is why.
One quick note before we get into it, since it applies to this chapter and several after it. Some of what follows behaves differently, or not at all, depending on which specific AI model your connected provider defaults to, reasoning models in particular tend to ignore several of these settings. Where that’s a known issue, the chapter says so directly. There’s a proper way to request a specific model, using_model_preference(), covered fully in Chapter 19, but if you get stuck before then, ->using_model_preference( 'model-id' ) chained onto any builder in this module is a safe early preview, just enough to route around a problem model.
What temperature actually controls
At each point while generating text, the model is choosing its next word from a range of statistically likely options. Left alone, it doesn’t always pick the single most probable one, there’s some randomness built in on purpose, which is why the same prompt doesn’t produce the same sentence twice. Temperature is the setting that controls how much randomness gets used.
A low temperature, close to 0, pushes the model toward its most likely, safest word choices every time. Run the same prompt five times at a low temperature and you’ll get five very similar answers. A high temperature, closer to 1, lets it wander further from the obvious choice, which produces more varied, more surprising wording, and also raises the odds of it saying something a little strange or drifting off the point.
Neither setting is “better.” A support bot answering “what’s your refund policy” needs the low end, consistent, predictable, boring in a good way. A tool generating five different tagline options for a client to choose from needs the high end, that’s the whole point of asking for variety.
Seeing it side by side
Create chapter-06-temperature.php inside includes:
<?php
/**
* Chapter 6: The Creativity Dial, Temperature
* Usage: add [ai_course_ch6] to any page or post to see the output.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // No direct access.
}
function ai_course_ch6_temperature() {
$prompt = 'Write a one-sentence product description for a stainless steel water bottle.';
$focused = wp_ai_client_prompt( $prompt )
->using_temperature( 0.1 )
->generate_text();
if ( is_wp_error( $focused ) ) {
return 'Could not generate the first example: ' . esc_html( $focused->get_error_message() );
}
$creative = wp_ai_client_prompt( $prompt )
->using_temperature( 0.9 )
->generate_text();
if ( is_wp_error( $creative ) ) {
return 'Could not generate the second example: ' . esc_html( $creative->get_error_message() );
}
$output = '<p><strong>Temperature 0.1:</strong><br>' . wp_kses_post( $focused ) . '</p>';
$output .= '<p><strong>Temperature 0.9:</strong><br>' . wp_kses_post( $creative ) . '</p>';
return $output;
}
add_shortcode( 'ai_course_ch6', 'ai_course_ch6_temperature' );
Add [ai_course_ch6] to a page and load it. Then reload the page a few more times without changing anything. Watch what happens to each line separately: the 0.1 version barely changes wording from one reload to the next, close to identical every time. The 0.9 version gives you a genuinely different sentence almost every reload, same prompt, same product, same model.
Warning, if you’re on OpenAI: if both lines come back identical, at both 0.1 and 0.9, with no variation at all, this is likely the cause.
OpenAI’s reasoning models (the GPT-5 family, o1, o3) don’t support temperature. Depending on the model and its reasoning settings, the parameter either gets rejected outright or silently ignored, and the model always samples the same way regardless of what you set.
The AI Provider for OpenAI connector doesn’t currently expose a model picker in its settings, just an API key field, so there’s no UI option to switch away from whatever model it defaults to.
Two practical workarounds for this chapter (and the next one on top-p and top-k, which has the same restriction): switch to a different connected provider, Anthropic or Gemini’s standard models both support temperature normally, or wait for Chapter 19, which covers using_model_preference(), a code-level way to request a specific model regardless of what the connector defaults to.
This isn’t a bug in your code, it’s a real, documented limitation of certain models, not the AI Client.
using_temperature() takes a number, usually somewhere between 0 and 1 (some providers allow going up to 2, worth checking your specific provider’s docs if you’re pushing past 1 and getting odd results). If you don’t set it at all, which is what every example before this chapter did, the provider uses its own default, typically somewhere in the middle.
Picking a number isn’t guesswork
A rough starting point: anything asking for a fact, a summary, a technical answer, or data extraction wants something low, 0.1 to 0.3. Anything asking for marketing copy, brainstorming, or creative variety wants something higher, 0.7 to 1. Most real use cases fall clearly into one camp or the other once you ask “do I want this answer to be the same every time, or do I want it to surprise me a little.”
Try it yourself
Take a prompt you’d actually use, a product description generator is a good one if you don’t already have your own, and test it at three temperatures: 0.2, 0.5, and 0.9. Read all three outputs and decide which one you’d actually ship. There’s rarely one objectively correct temperature, it depends on whether consistency or variety matters more for that specific feature, and this exercise is about training your own judgment for that call rather than memorizing a number.