Choosing Parameters for Your Use Case
Recommended settings for factual Q&A, creative writing, code, and chat.
The Parameter Decision Framework
Choosing sampling parameters is not guesswork — it follows a logic based on your task requirements. Two key dimensions determine the right configuration:
- Output accuracy: how important is it that the output is correct and predictable?
- Output diversity: how important is it that outputs vary and explore?
High accuracy → low temperature. High diversity → high temperature. Most tasks sit somewhere between these extremes.
Factual Q&A: Accuracy is Everything
For factual question answering, there is typically one correct answer. Any randomness increases the chance of a wrong answer. Use:
- temperature = 0: greedy decoding, fully deterministic
- top_p = 1.0: leave unrestricted; at temperature=0, top-p has no effect
This ensures the model always picks its most confident answer, which is the most likely to be correct.
import openai
client = openai.OpenAI(api_key='sk-...')
# Factual Q&A configuration
def factual_qa(question):
resp = client.chat.completions.create(
model='gpt-4o',
messages=[
{'role': 'system', 'content': 'Answer factual questions concisely and accurately.'},
{'role': 'user', 'content': question}
],
temperature=0,
top_p=1.0
)
return resp.choices[0].message.content
answer = factual_qa('What is the boiling point of water at sea level?')
print(answer) # Always: '100 degrees Celsius (212 degrees Fahrenheit).'All lessons in this course
- What Is Temperature in LLMs?
- Top-p Nucleus Sampling
- Top-k Sampling
- Choosing Parameters for Your Use Case