Need a trivia game to ask varied questions instead of repeating itself? Temperature is one setting that changes how predictably a language model chooses its next token. At each step, the model assigns probabilities to possible tokens. A higher temperature flattens that distribution, giving less likely choices a better chance; a lower temperature favors the most likely choices more strongly. OpenAI accepts values from 0 to 2. section 9.6.1
Temperature affects variability, not factual accuracy or guaranteed uniqueness. For repeated trivia questions, combine it with a prompt that requests a unique question, includes a changing seed, and lists questions already asked. Another setting, top_p, limits the pool of candidate tokens by cumulative probability. section 9.6.1 section 9.6.2
import time
from llm import Llm
...
class Game:
def __init__(self, llm_api_key):
...
self.max_questions = 5
self.questions = []
def ask_llm_for_question(self):
seed = int(time.time())
sys_msg = QUESTION_PROMPT['system']
usr_msg = (
QUESTION_PROMPT['user']
.replace('{already_asked}', '\n'.join(self.questions))
.replace('{seed}', str(seed))
)
return self.llm.ask(usr_msg, sys_msg, temperature=0.7, top_p=0.9)
...
def obtain_question(self):
self.curr_question = self.ask_llm_for_question()
self.questions.append(self.curr_question)
self.status = 'ASK_QUESTION'
return self.curr_question
...
def proceed_to_next_question(self):
self.status = 'GET_QUESTION'
...
The question-generation call uses temperature=0.7 and top_p=0.9 alongside a time-based seed and a record of earlier questions. section 9.6.2
In a Python wrapper, temperature can be an optional argument forwarded to OpenAI’s chat completion call. Check model support before exposing the setting: reasoning models such as gpt-5-mini do not allow explicit temperature or top_p configuration, and gpt-5.1 disallows it when reasoning mode is on. Also watch for a small wrapper bug: the shown `if temperature` check would omit an explicitly supplied value of 0. section 9.6.2
















