-
Notifications
You must be signed in to change notification settings - Fork 27
fix(llm): exclude sampling params for reasoning models #1822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
29fc0f5
f52e448
4e64102
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -327,12 +327,17 @@ class Country(BaseModel): | |
| ) | ||
| endpoint = Endpoint("/" + endpoint) | ||
|
|
||
| request_body = { | ||
| is_reasoning_model = model.lower().startswith(("o1", "o3", "o4")) | ||
|
|
||
| request_body: dict[str, Any] = { | ||
| "messages": messages, | ||
| "max_tokens": max_tokens, | ||
| "temperature": temperature, | ||
| } | ||
|
|
||
| # Reasoning models (o1, o3, o4) don't support temperature | ||
| if not is_reasoning_model: | ||
| request_body["temperature"] = temperature | ||
|
|
||
| # Handle response_format - convert BaseModel to schema if needed | ||
| if response_format: | ||
| if isinstance(response_format, type) and issubclass( | ||
|
|
@@ -548,17 +553,22 @@ class Country(BaseModel): | |
| ) | ||
| endpoint = Endpoint("/" + endpoint) | ||
|
|
||
| # Build request body - Claude models don't support some OpenAI-specific parameters | ||
| is_claude_model = "claude" in model.lower() | ||
| # Build request body - some models don't support certain parameters | ||
| model_lower = model.lower() | ||
| is_claude_model = "claude" in model_lower | ||
| is_reasoning_model = model_lower.startswith(("o1", "o3", "o4")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using model name is unreliable sadly. But I think this is a best effort we can live with. |
||
|
|
||
| request_body = { | ||
| request_body: dict[str, Any] = { | ||
| "messages": converted_messages, | ||
| "max_tokens": max_tokens, | ||
| "temperature": temperature, | ||
| } | ||
|
|
||
| # Only add OpenAI-specific parameters for non-Claude models | ||
| if not is_claude_model: | ||
| # Reasoning models (o1, o3, o4) don't support temperature and sampling parameters | ||
| if not is_reasoning_model: | ||
| request_body["temperature"] = temperature | ||
|
|
||
| # Only add OpenAI-specific parameters for non-Claude and non-reasoning models | ||
| if not is_claude_model and not is_reasoning_model: | ||
| request_body["n"] = n | ||
| request_body["frequency_penalty"] = frequency_penalty | ||
| request_body["presence_penalty"] = presence_penalty | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2 — correctness: OpenAI's o1/o3/o4 reasoning models also reject
max_tokens(400: "Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.") — the same class of error this PR fixes fortemperature/n/frequency_penalty/presence_penalty/top_p. Bothchat_completionsmethods still send"max_tokens": max_tokensunconditionally for reasoning models (also at_llm_gateway_service.py:563inUiPathLlmChatService).If the LLM Gateway forwards this field to OpenAI unchanged on the passthrough endpoint, SRE-625200 may not be fully closed — reasoning-model calls could still 400, just on a different field. Worth confirming whether the gateway already translates
max_tokens→max_completion_tokensserver-side for o-series models; if not, this needs the same treatment as the other params.(Codex recheck: agree — flagged the same gateway-translation uncertainty as a risk callout.)