mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-26 04:34:13 +00:00
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) <noreply@anthropic.com>
This commit is contained in:
parent
11c84f21a6
commit
7dc8c9409c
@ -223,6 +223,21 @@ class OpenAICompatProvider(LLMProvider):
|
|||||||
# Build kwargs
|
# 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(
|
def _build_kwargs(
|
||||||
self,
|
self,
|
||||||
messages: list[dict[str, Any]],
|
messages: list[dict[str, Any]],
|
||||||
@ -247,9 +262,13 @@ class OpenAICompatProvider(LLMProvider):
|
|||||||
kwargs: dict[str, Any] = {
|
kwargs: dict[str, Any] = {
|
||||||
"model": model_name,
|
"model": model_name,
|
||||||
"messages": self._sanitize_messages(self._sanitize_empty_content(messages)),
|
"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):
|
if spec and getattr(spec, "supports_max_completion_tokens", False):
|
||||||
kwargs["max_completion_tokens"] = max(1, max_tokens)
|
kwargs["max_completion_tokens"] = max(1, max_tokens)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -200,6 +200,7 @@ PROVIDERS: tuple[ProviderSpec, ...] = (
|
|||||||
env_key="OPENAI_API_KEY",
|
env_key="OPENAI_API_KEY",
|
||||||
display_name="OpenAI",
|
display_name="OpenAI",
|
||||||
backend="openai_compat",
|
backend="openai_compat",
|
||||||
|
supports_max_completion_tokens=True,
|
||||||
),
|
),
|
||||||
# OpenAI Codex: OAuth-based, dedicated provider
|
# OpenAI Codex: OAuth-based, dedicated provider
|
||||||
ProviderSpec(
|
ProviderSpec(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user