fix(llms): send max_completion_tokens for the GPT-5 family across providers (#5547)
This commit is contained in:
@@ -76,9 +76,12 @@ class AzureOpenAIStructuredLLM(LLMBase):
|
||||
"model": self.config.model,
|
||||
"messages": messages,
|
||||
"temperature": self.config.temperature,
|
||||
"max_tokens": self.config.max_tokens,
|
||||
"top_p": self.config.top_p,
|
||||
}
|
||||
if self._uses_max_completion_tokens(self.config.model):
|
||||
params["max_completion_tokens"] = self.config.max_tokens
|
||||
else:
|
||||
params["max_tokens"] = self.config.max_tokens
|
||||
if response_format:
|
||||
params["response_format"] = response_format
|
||||
if tools:
|
||||
|
||||
+25
-1
@@ -79,6 +79,25 @@ class LLMBase(ABC):
|
||||
|
||||
return False
|
||||
|
||||
def _uses_max_completion_tokens(self, model: str) -> bool:
|
||||
"""
|
||||
Check if the model expects ``max_completion_tokens`` instead of ``max_tokens``.
|
||||
|
||||
The whole GPT-5 family (gpt-5.4-mini, gpt-5.4-nano, gpt-5.5, ...) rejects the
|
||||
legacy ``max_tokens`` parameter on the Chat Completions API and requires
|
||||
``max_completion_tokens``. Older models (gpt-4.x, gpt-3.5, etc.) still accept
|
||||
``max_tokens``.
|
||||
|
||||
Args:
|
||||
model: The model name to check
|
||||
|
||||
Returns:
|
||||
bool: True if the model requires ``max_completion_tokens``
|
||||
"""
|
||||
# Strip provider prefixes (e.g. "openai/gpt-5.4-mini" -> "gpt-5.4-mini")
|
||||
base_model = (model or "").lower().rsplit("/", 1)[-1]
|
||||
return base_model.startswith("gpt-5")
|
||||
|
||||
def _get_supported_params(self, **kwargs) -> Dict:
|
||||
"""
|
||||
Get parameters that are supported by the current model.
|
||||
@@ -141,10 +160,15 @@ class LLMBase(ABC):
|
||||
"""
|
||||
params = {
|
||||
"temperature": self.config.temperature,
|
||||
"max_tokens": self.config.max_tokens,
|
||||
"top_p": self.config.top_p,
|
||||
}
|
||||
|
||||
model = getattr(self.config, "model", "")
|
||||
if self._uses_max_completion_tokens(model):
|
||||
params["max_completion_tokens"] = self.config.max_tokens
|
||||
else:
|
||||
params["max_tokens"] = self.config.max_tokens
|
||||
|
||||
# Add provider-specific parameters from kwargs
|
||||
params.update(kwargs)
|
||||
|
||||
|
||||
@@ -74,9 +74,12 @@ class LiteLLM(LLMBase):
|
||||
"model": self.config.model,
|
||||
"messages": messages,
|
||||
"temperature": self.config.temperature,
|
||||
"max_tokens": self.config.max_tokens,
|
||||
"top_p": self.config.top_p,
|
||||
}
|
||||
if self._uses_max_completion_tokens(self.config.model):
|
||||
params["max_completion_tokens"] = self.config.max_tokens
|
||||
else:
|
||||
params["max_tokens"] = self.config.max_tokens
|
||||
if response_format:
|
||||
params["response_format"] = response_format
|
||||
if tools: # TODO: Remove tools if no issues found with new memory addition logic
|
||||
|
||||
Reference in New Issue
Block a user