From 7dc8c9409cb5e839e49232676687a03b021903cc Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sat, 4 Apr 2026 07:05:46 +0000 Subject: [PATCH] feat(providers): add GPT-5 model family support for OpenAI provider Enable GPT-5 models (gpt-5, gpt-5.4, gpt-5.4-mini, etc.) to work correctly with the OpenAI-compatible provider by: - Setting `supports_max_completion_tokens=True` on the OpenAI provider spec so `max_completion_tokens` is sent instead of the deprecated `max_tokens` parameter that GPT-5 rejects. - Adding `_supports_temperature()` to conditionally omit the `temperature` parameter for reasoning models (o1/o3/o4) and when `reasoning_effort` is active, matching the existing Azure provider behaviour. Both changes are backward-compatible: older GPT-4 models continue to work as before since `max_completion_tokens` is accepted by all recent OpenAI models and temperature is only omitted when reasoning is active. Co-Authored-By: Claude Opus 4.6 (1M context) --- nanobot/providers/openai_compat_provider.py | 21 ++++++++++++++++++++- nanobot/providers/registry.py | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/nanobot/providers/openai_compat_provider.py b/nanobot/providers/openai_compat_provider.py index 132f05a28..3702d2745 100644 --- a/nanobot/providers/openai_compat_provider.py +++ b/nanobot/providers/openai_compat_provider.py @@ -223,6 +223,21 @@ class OpenAICompatProvider(LLMProvider): # Build kwargs # ------------------------------------------------------------------ + @staticmethod + def _supports_temperature( + model_name: str, + reasoning_effort: str | None = None, + ) -> bool: + """Return True when the model accepts a temperature parameter. + + GPT-5 family and reasoning models (o1/o3/o4) reject temperature + when reasoning_effort is set to anything other than ``"none"``. + """ + if reasoning_effort and reasoning_effort.lower() != "none": + return False + name = model_name.lower() + return not any(token in name for token in ("o1", "o3", "o4")) + def _build_kwargs( self, messages: list[dict[str, Any]], @@ -247,9 +262,13 @@ class OpenAICompatProvider(LLMProvider): kwargs: dict[str, Any] = { "model": model_name, "messages": self._sanitize_messages(self._sanitize_empty_content(messages)), - "temperature": temperature, } + # GPT-5 and reasoning models (o1/o3/o4) reject temperature when + # reasoning_effort is active. Only include it when safe. + if self._supports_temperature(model_name, reasoning_effort): + kwargs["temperature"] = temperature + if spec and getattr(spec, "supports_max_completion_tokens", False): kwargs["max_completion_tokens"] = max(1, max_tokens) else: diff --git a/nanobot/providers/registry.py b/nanobot/providers/registry.py index 75b82c1ec..69d04782a 100644 --- a/nanobot/providers/registry.py +++ b/nanobot/providers/registry.py @@ -200,6 +200,7 @@ PROVIDERS: tuple[ProviderSpec, ...] = ( env_key="OPENAI_API_KEY", display_name="OpenAI", backend="openai_compat", + supports_max_completion_tokens=True, ), # OpenAI Codex: OAuth-based, dedicated provider ProviderSpec(