formatter: skip temperature override for reasoning models
GPT-5 and the o-series reject temperature=0 with a 400 BadRequestError — only the default (1) is supported for reasoning models. Add an _is_reasoning_model helper and pass temperature only when the model name does not start with gpt-5/o1/o3/o4. Determinism on reasoning models is a property of the architecture, not a parameter. Discovered on the first real LLM run against the seed exemplars.
This commit is contained in:
+20
-5
@@ -88,6 +88,17 @@ def build_user_message(messy_entry: str) -> str:
|
||||
)
|
||||
|
||||
|
||||
def _is_reasoning_model(model: str) -> bool:
|
||||
"""Reasoning-model families (GPT-5, o-series) don't accept temperature overrides.
|
||||
|
||||
OpenAI rejects ``temperature=0`` on these with a 400 BadRequestError;
|
||||
only the default (1) is supported. Determinism on reasoning models is a
|
||||
property of the architecture, not a parameter.
|
||||
"""
|
||||
prefixes = ("gpt-5", "o1", "o3", "o4")
|
||||
return any(model.startswith(p) for p in prefixes)
|
||||
|
||||
|
||||
def _openai_caller(system: str, user: str) -> str:
|
||||
"""Default caller — hits the real OpenAI API.
|
||||
|
||||
@@ -99,14 +110,18 @@ def _openai_caller(system: str, user: str) -> str:
|
||||
from openai import OpenAI # imported lazily so unit tests do not need the network
|
||||
|
||||
client = OpenAI()
|
||||
response = client.chat.completions.create(
|
||||
model=MODEL,
|
||||
temperature=0,
|
||||
messages=[
|
||||
kwargs: dict = {
|
||||
"model": MODEL,
|
||||
"messages": [
|
||||
{"role": "system", "content": system},
|
||||
{"role": "user", "content": user},
|
||||
],
|
||||
)
|
||||
}
|
||||
# Non-reasoning models still benefit from temperature=0; reasoning models
|
||||
# reject it.
|
||||
if not _is_reasoning_model(MODEL):
|
||||
kwargs["temperature"] = 0
|
||||
response = client.chat.completions.create(**kwargs)
|
||||
return response.choices[0].message.content or ""
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user