fix: allow omitting temperature for models that reject it (e.g. Opus 4.7+) - #2109
Conversation
…4.7+)
Anthropic Opus 4.7/4.8 reject the `temperature` parameter ("temperature is
deprecated for this model"), and LiteLLM's drop_params can't strip it (the
deprecation isn't in its static param metadata). Holmes always sent temperature
(TEMPERATURE default 1e-8), so these models 400'd.
Make TEMPERATURE omittable: an empty string / "none" / "null" yields None, and
completion() already skips the param when it's None — so no temperature is sent.
Verified against Opus 4.6/4.7/4.8 via a LiteLLM gateway.
Signed-off-by: Yakir Shriker <yakirshr@gmail.com>
WalkthroughA new ChangesTemperature optional parsing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
✅ Deploy Preview for holmes-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
holmes/common/env_vars.py (1)
68-77: ⚡ Quick winConsider adding error handling for invalid float values.
If
TEMPERATUREis set to an invalid numeric string (e.g.,"abc"), thefloat(raw)call will raise aValueErrorat startup. While this fails fast and is easy to debug, wrapping it in a try-except with a more descriptive error message could improve the developer experience.🛡️ Proposed error handling enhancement
def _load_temperature() -> Optional[float]: # Set TEMPERATURE to an empty string / "none" / "null" to send NO temperature at # all. Required for models that reject the parameter (e.g. Anthropic Opus 4.7+: # "temperature is deprecated for this model"); LiteLLM's drop_params can't strip # it because the deprecation isn't in its static param metadata, so it must be # omitted at the source. raw = os.environ.get("TEMPERATURE", "0.00000001").strip() if raw.lower() in ("", "none", "null"): return None - return float(raw) + try: + return float(raw) + except ValueError as e: + raise ValueError(f"Invalid TEMPERATURE value '{raw}': must be a number, 'none', 'null', or empty") from e🤖 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 `@holmes/common/env_vars.py` around lines 68 - 77, The _load_temperature function should guard against invalid numeric strings from the TEMPERATURE env var: wrap the float(raw) conversion in a try/except ValueError and raise a new ValueError (or use process logging then re-raise) with a clear message that includes the invalid raw value and that TEMPERATURE must be a float or one of "", "none", "null"; update the function _load_temperature to perform this validation around the float(raw) call and surface a descriptive error instead of the raw ValueError.
🤖 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 `@holmes/common/env_vars.py`:
- Around line 68-77: The _load_temperature function should guard against invalid
numeric strings from the TEMPERATURE env var: wrap the float(raw) conversion in
a try/except ValueError and raise a new ValueError (or use process logging then
re-raise) with a clear message that includes the invalid raw value and that
TEMPERATURE must be a float or one of "", "none", "null"; update the function
_load_temperature to perform this validation around the float(raw) call and
surface a descriptive error instead of the raw ValueError.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 56e822ff-84f0-4619-a32e-788346e1d7d3
📒 Files selected for processing (2)
holmes/common/env_vars.pytests/common/test_temperature_env.py
Problem
Anthropic Opus 4.7 / 4.8 reject the
temperatureparameter:HolmesGPT always sends
temperature(tool_calling_llm.py→completion(..., temperature=TEMPERATURE), default1e-8), so these models 400 on every call.drop_params=Truedoesn't help — the deprecation is an Anthropic runtime behavior, not in LiteLLM's static param metadata (verified with litellm up to 1.86.2), so it isn't stripped.Fix
Make
TEMPERATUREomittable: an empty string /none/nullyieldsNone, andcompletion()already skips the param when it'sNone— so notemperatureis sent. Models that accepttemperatureare unaffected (default unchanged).TEMPERATURE=none # send no temperature paramVerification
tests/common/test_temperature_env.py).TEMPERATURE=none, Opus 4.6 / 4.7 / 4.8 all complete successfully; without it, 4.7/4.8 return the 400 above.Signed-off-by: Yakir Shriker yakirshr@gmail.com
Summary by CodeRabbit
New Features
Tests