Focused generation
Generate stable, focused answers or code with less variation.
AI & ML · Const
Temperature controls sampling randomness in a completion. Values from 0 to 2 trade determinism for variety: lower is more focused, higher is more random.
Temperature controls randomness during sampling. Lower values make output more focused and deterministic, while higher values increase variation; it accepts values from 0 to 2.
temperature: number | null| Name | Type | Description |
|---|---|---|
temperature | number or null | Sampling temperature, from 0 to 2. Higher values increase randomness; lower values make output more focused and deterministic. |
The generated completion, including its text and associated metadata.
from openai import OpenAI
client = OpenAI()
response = client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt="Write a haiku about winter.",
temperature=0.2,
max_tokens=30,
)
print(response.choices[0].text)This runnable Python example requests a focused completion by setting temperature to 0.2.
Generate stable, focused answers or code with less variation.
Increase creative variation in prose or brainstorming output.
Tune output randomness while leaving top_p unchanged.
top_pmax_tokensmodelprompt