Skip to content

OLS-3548 Omit temperature for models that deprecate it - #3000

Open
thoraxe wants to merge 3 commits into
openshift:mainfrom
thoraxe:ols-3548-fix-temperature-deprecated
Open

OLS-3548 Omit temperature for models that deprecate it#3000
thoraxe wants to merge 3 commits into
openshift:mainfrom
thoraxe:ols-3548-fix-temperature-deprecated

Conversation

@thoraxe

@thoraxe thoraxe commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds temperature_supported boolean flag to ModelParameters (defaults to True for backward compatibility)
  • The base LLMProvider strips temperature from LLM params when the model's config sets temperature_supported: false
  • Fixes HTTP 400 errors from models like claude-sonnet-5 that have deprecated the temperature parameter

How to use

In olsconfig.yaml, set temperature_supported: false on any model that rejects temperature:

models:
  - name: anthropic.claude-sonnet-5
    parameters:
      temperature_supported: false

Models without this setting (or with temperature_supported: true) continue to receive temperature as before.

Test plan

  • New unit tests verify temperature is stripped when temperature_supported=False
  • New unit tests verify temperature is still present when temperature_supported=True (default)
  • New unit tests verify caller-supplied temperature is also stripped when not supported
  • All 98 existing LLM provider unit tests pass
  • All 210 config model tests pass
  • mypy type check passes on modified files

Summary by CodeRabbit

  • New Features

    • Added a configuration option to indicate whether a model supports temperature controls.
    • Automatically omit temperature for models that do not support it; supported models retain existing behavior.
  • Documentation

    • Updated the example configuration to show how to disable temperature support for specific models.
  • Tests

    • Added coverage for the new option and temperature handling across configuration scenarios.

@openshift-ci
openshift-ci Bot requested review from onmete and tisnik July 13, 2026 13:23
@openshift-ci

openshift-ci Bot commented Jul 13, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign bparees for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
ols/src/llms/providers/provider.py (1)

382-392: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Simplify _model_supports_temperature by removing the dead getattr/None branch.

ModelConfig.parameters is declared as parameters: ModelParameters = ModelParameters(), so it always carries a value — the getattr fallback and the if params is None guard can never trigger. Direct access is cleaner and preserves full type information for mypy strict mode.

♻️ Proposed refactor
     def _model_supports_temperature(self) -> bool:
         """Check whether the current model supports the temperature parameter."""
         if self.provider_config is None:
             return True
         model_config = self.provider_config.models.get(self.model)
         if model_config is None:
             return True
-        params = getattr(model_config, "parameters", None)
-        if params is None:
-            return True
-        return params.temperature_supported
+        return model_config.parameters.temperature_supported
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ols/src/llms/providers/provider.py` around lines 382 - 392, Update
_model_supports_temperature to access model_config.parameters directly and
return its temperature_supported value, removing the getattr fallback and params
None guard while preserving the existing provider_config and model_config None
handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@ols/src/llms/providers/provider.py`:
- Around line 382-392: Update _model_supports_temperature to access
model_config.parameters directly and return its temperature_supported value,
removing the getattr fallback and params None guard while preserving the
existing provider_config and model_config None handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 30b796f3-9d81-46ad-a570-ee0316ca07bf

📥 Commits

Reviewing files that changed from the base of the PR and between 6578cfb and 61d9a97.

📒 Files selected for processing (4)
  • examples/olsconfig.yaml
  • ols/app/models/config.py
  • ols/src/llms/providers/provider.py
  • tests/unit/llms/providers/test_bedrock.py

@thoraxe

thoraxe commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the CodeRabbit nitpick — removed the dead getattr/None guard in _model_supports_temperature. ModelConfig.parameters is declared with a default ModelParameters(), so it can never be None. Simplified to access model_config.parameters.temperature_supported directly.

All 22 bedrock provider tests pass.

@xrajesh

xrajesh commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code


- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@openshift openshift deleted a comment from coderabbitai Bot Jul 23, 2026
@xrajesh

xrajesh commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Code review

Found 2 issues:

  1. Parameter override precedence violated - Temperature stripping is applied AFTER developer config overrides in _override_params, contradicting the documented precedence order that states "config params overrides everything" (line 371-375). If a user sets dev_config.llm_params.temperature, it will still be stripped if the model doesn't support temperature, violating the documented contract.

if config.dev_config.llm_params:
logger.debug(
"overriding LLM params with debug options %s",
config.dev_config.llm_params,
)
updated_params = {**updated_params, **config.dev_config.llm_params}
if not self._model_supports_temperature():
updated_params.pop("temperature", None)

  1. Commits should be squashed - PR contains 2 commits that are not independent (second commit removes dead code from first). CLAUDE.md requires one logical commit per PR unless changes are explicitly independent.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@xrajesh

xrajesh commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Additional note (lower priority): The new temperature_supported field in ModelParameters should have test coverage in tests/unit/app/models/test_config.py to verify the default value and explicit setting behavior, following the pattern established for other ModelParameters fields like reasoning_effort, reasoning_summary, and verbosity. The provider-level tests are good but model-level validation is missing.

@xrajesh

xrajesh commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

But @thoraxe - we will need the operator changes to go along with this change right - the user will have to configure this in the CR.

Add a temperature_supported model parameter (default: true) that lets
operators flag models which reject the temperature kwarg. When false,
the provider strips temperature from params and logs a warning —
even if dev_config overrides set it, since the model will error either
way.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@thoraxe

thoraxe commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

No operator changes are needed — temperature_supported is just another field in ModelParameters alongside reasoning_effort, reasoning_summary, and verbosity. The operator already passes model parameters through to the service config, so no CR schema change is required. The default is true, so existing deployments are unaffected.

This is purely a bug fix: models that reject temperature were getting it sent anyway. A user could configure it, but that's already possible through the existing parameters passthrough.

@thoraxe
thoraxe force-pushed the ols-3548-fix-temperature-deprecated branch from fee421e to efc23a8 Compare July 24, 2026 15:10
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0be0bc4e-d0b0-4616-bde5-c0a64635c3d5

📥 Commits

Reviewing files that changed from the base of the PR and between a5d88d7 and 80b9f27.

📒 Files selected for processing (2)
  • ols/src/llms/providers/provider.py
  • tests/unit/llms/providers/test_bedrock.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • ols/src/llms/providers/provider.py

📝 Walkthrough

Walkthrough

Adds a temperature_supported model parameter and updates provider overrides to remove temperature for models that do not support it, with configuration and AWS Bedrock test coverage.

Changes

Temperature capability configuration

Layer / File(s) Summary
Configuration definition and documentation
ols/app/models/config.py, examples/olsconfig.yaml, tests/unit/app/models/test_config.py
Adds the temperature_supported boolean field to ModelParameters with a default of true. Provides a YAML configuration example showing how to disable temperature for models that reject it. Tests verify the default value and explicit true and false values.
Provider enforcement and tests
ols/src/llms/providers/provider.py, tests/unit/llms/providers/test_bedrock.py
The provider checks the model's temperature_supported configuration, removes temperature from parameters and API calls when unsupported, and logs the removal. Bedrock tests cover unsupported models, supported models, caller-supplied temperature, and temperature overrides from dev_config.llm_params.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Provider
  participant ModelConfig
  Caller->>Provider: call with temperature parameter
  Provider->>ModelConfig: check temperature_supported
  alt temperature_supported = true
    Provider->>Provider: keep temperature in params
  else temperature_supported = false
    Provider->>Provider: remove temperature from params
    Provider->>Provider: log warning
  end
  Provider->>Caller: return result
Loading

Suggested reviewers: tisnik, onmete

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: omitting temperature for models that do not support it.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unit/llms/providers/test_bedrock.py (1)

354-386: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover developer-config overrides as well.

This test covers caller-supplied temperature, but ols/src/llms/providers/provider.py also merges config.dev_config.llm_params before stripping unsupported parameters. Add a regression case setting developer-config temperature with temperature_supported=False and assert it is omitted.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/llms/providers/test_bedrock.py` around lines 354 - 386, Add a
regression test alongside test_temperature_stripped_even_when_caller_passes_it
that sets config.dev_config.llm_params temperature while temperature_supported
is False, then constructs and loads Bedrock and asserts temperature is absent
from both bedrock.params and ChatBedrockConverse call_kwargs. Reuse the existing
provider setup and patching pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/olsconfig.yaml`:
- Line 16: Update the OLS configuration example around temperature_supported so
it is not grouped with the reasoning-only parameters guidance. Provide a
separate example or revise the surrounding comment to clarify that
temperature_supported is a general model capability flag and may be needed for
non-reasoning models that reject temperature.

---

Nitpick comments:
In `@tests/unit/llms/providers/test_bedrock.py`:
- Around line 354-386: Add a regression test alongside
test_temperature_stripped_even_when_caller_passes_it that sets
config.dev_config.llm_params temperature while temperature_supported is False,
then constructs and loads Bedrock and asserts temperature is absent from both
bedrock.params and ChatBedrockConverse call_kwargs. Reuse the existing provider
setup and patching pattern.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 31419fed-1f7a-4df5-b540-188d29c4b57a

📥 Commits

Reviewing files that changed from the base of the PR and between f04f142 and efc23a8.

📒 Files selected for processing (5)
  • examples/olsconfig.yaml
  • ols/app/models/config.py
  • ols/src/llms/providers/provider.py
  • tests/unit/app/models/test_config.py
  • tests/unit/llms/providers/test_bedrock.py

Comment thread examples/olsconfig.yaml Outdated
- Move temperature_supported out of the reasoning-only example block in
  olsconfig.yaml and into a dedicated Bedrock section comment. The flag
  applies to any model that rejects temperature, not only reasoning models,
  so grouping it with reasoning_effort/reasoning_summary was misleading.

- Add test_temperature_stripped_when_set_via_dev_config to test_bedrock.py
  to cover the case where config.dev_config.llm_params sets temperature but
  temperature_supported=False. Previously only caller-supplied and default
  temperature stripping were covered.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/unit/llms/providers/test_bedrock.py`:
- Around line 393-422: Update test_temperature_stripped_when_set_via_dev_config
to use pytest monkeypatching (or a try/finally cleanup) when overriding
config.dev_config.llm_params, ensuring the original value is restored
automatically even if setup or assertions fail. Remove the manual reset that can
discard a pre-existing developer configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f9780235-cd2d-4878-a838-f76b9c67c811

📥 Commits

Reviewing files that changed from the base of the PR and between efc23a8 and a5d88d7.

📒 Files selected for processing (2)
  • examples/olsconfig.yaml
  • tests/unit/llms/providers/test_bedrock.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/olsconfig.yaml

Comment thread tests/unit/llms/providers/test_bedrock.py Outdated
@thoraxe

thoraxe commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

/retest

…rder

Replace direct global mutation of config.dev_config.llm_params with
pytest monkeypatch so the fixture is always restored after the test,
even on assertion failure.

Add an inline comment to _override_params explaining why temperature
stripping is applied after dev_config merging: it is a hard physical
capability check, not a precedence decision.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@thoraxe

thoraxe commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Re: xrajesh's concern about temperature stripping overriding dev_config precedence

The behavior is intentional and not a bug — here's the reasoning:

dev_config does win over defaults and call-site params (the merge order is preserved). But temperature stripping that happens afterward is not a precedence decision — it is a physical capability enforcement. If the model's API does not accept a temperature argument, sending one will cause an API error regardless of which layer configured it. The strip has to happen last, after the final merged param set is known, because only at that point do we know all sources have had their say.

The analogy: dev_config can override anything about how the model is called, but it cannot override what the model's API physically accepts. That is a constraint imposed by the model vendor, not by our config system.

To make this intent clear to future readers, I added an inline comment in _override_params (commit 80b9f27f) explaining exactly this. The CodeRabbit monkeypatch fix for test_temperature_stripped_when_set_via_dev_config is included in the same commit — the manual reset at the end of that test has been removed, so test isolation is now guaranteed even on assertion failure.

All 23 bedrock tests pass.

@thoraxe

thoraxe commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@thoraxe

thoraxe commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@openshift-ci

openshift-ci Bot commented Aug 5, 2026

Copy link
Copy Markdown

@thoraxe: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-ols-cluster 80b9f27 link true /test e2e-ols-cluster

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants