A trivia game needs fresh questions, but an LLM may give similar answers to similar prompts. Top-p filtering is one way to adjust how predictable its responses are. The model writes one token at a time, assigning probabilities to possible next tokens. The top_p setting, from 0 to 1, limits selection using a cutoff based on their cumulative probability. section 9.6.1 section 9.6.2
Top_p and temperature both affect response variability, but they do different jobs: top_p limits the token options considered, while temperature changes the shape of their probability distribution. Neither setting by itself promises a unique question. section 9.6.1 section 9.6.2
Make room for different trivia questions
A question-generating call uses temperature=0.7 and top_p=0.9. It also supplies a changing seed and a list of questions already asked. The sampling settings adjust variability; the prompt gives the model more specific reasons to produce a different question. section 9.6.2
from openai import OpenAI
class Llm:
...
def ask(self, user_message, sys_message=None, schema=None,
temperature=None, top_p=None):
messages = self.construct_messages(user_message, sys_message)
llm_args = {'model': 'gpt-5.1', 'messages': messages}
if temperature:
llm_args['temperature'] = temperature
if top_p:
llm_args['top_p'] = top_p
if schema:
completion = self.client.beta.chat.completions.parse(
response_format=schema,
**llm_args
)
return completion.choices[0].message.parsed
else:
completion = self.client.chat.completions.create(**llm_args)
return completion.choices[0].message.content
The Python wrapper accepts an optional top_p argument and passes it to the OpenAI call when supplied, so callers can choose a setting for each request. section 9.6.2
Check model support before exposing the setting. OpenAI reasoning models such as gpt-5-mini do not support explicitly configured top_p; gpt-5.1 also disallows it when reasoning mode is enabled. Keep the wider reliability problem separate: changing sampling cannot guarantee that a generated question is factual. section 9.6.2 section 9.6.1











