Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

* The deprecation warning for `temperature`, `top_p` and `top_k` on `ChatAnthropic()` no longer says these parameters have no effect on current models. Anthropic's deprecation page says Claude 4.7 and later models return a 400 error when they are set to a non-default value, and that API version 2026-10-21 removes them for every model; the warning now says so. What is forwarded is unchanged.
* `ChatOllama()` can now be created without a `model`, so `ChatOllama().list_models()` works. Sending a message without a model still raises an error that lists the available models. (#166)
* `ChatGoogle()` now reports `finish_reason == "content_filter"` for Gemini's `IMAGE_SAFETY`, `IMAGE_PROHIBITED_CONTENT`, `IMAGE_RECITATION` and `LANGUAGE` finish reasons, instead of passing the raw Gemini string through, and reports `"tool_use"` (rather than `"success"`) when a turn ends with a tool request, as `ChatOpenAI()` does. (#473)
* The error raised for a tool request with invalid JSON arguments from `ChatOpenAI()` and `ChatOpenAICompletions()` (and the providers built on them) now shows the offending arguments, instead of the literal text `{args}`.
Expand Down
17 changes: 11 additions & 6 deletions chatlas/_provider_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,15 +799,20 @@ def translate_model_params(self, params: StandardModelParams) -> "SubmitInputArg
res: "SubmitInputArgs" = {}

# anthropic>=1.0 removed these sampling parameters from the request
# schema; current models ignore them. Forward them via `extra_body`
# so older models that still honor them keep working.
# schema; Claude 4.7 and later reject non-default values with a 400.
# Forward them via `extra_body` so older models that still honor them
# keep working.
removed = [p for p in ("temperature", "top_p", "top_k") if p in params]
if removed:
warnings.warn(
f"The {', '.join(removed)} sampling parameter(s) no longer have "
"an effect on current Anthropic models. They are forwarded via "
"`extra_body` for older models that still honor them; this "
"forwarding is deprecated and will be removed in a future release.",
f"The {', '.join(removed)} sampling parameter(s) are deprecated by "
"Anthropic: Claude 4.7 and later models return a 400 error when they "
"are set to a non-default value, and API version 2026-10-21 removes "
"them for every model "
"(https://platform.claude.com/docs/en/about-claude/model-deprecations). "
"They are forwarded via `extra_body` for older models that still "
"honor them; this forwarding is deprecated and will be removed in a "
"future release.",
DeprecationWarning,
stacklevel=2,
)
Expand Down
24 changes: 22 additions & 2 deletions tests/test_set_model_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ def test_translate_model_params_anthropic():
"stop_sequences": ["STOP"],
}

with pytest.warns(DeprecationWarning, match="no longer have an effect"):
with pytest.warns(
DeprecationWarning,
match="return a 400 error when they are set to a non-default value",
):
result = provider.translate_model_params(params)

expected = {
Expand Down Expand Up @@ -517,7 +520,10 @@ def test_anthropic_model_params_integration():
)

# Test that provider.translate_model_params converts them correctly
with pytest.warns(DeprecationWarning, match="no longer have an effect"):
with pytest.warns(
DeprecationWarning,
match="return a 400 error when they are set to a non-default value",
):
provider_args = chat.provider.translate_model_params(
chat._standard_model_params
)
Expand Down Expand Up @@ -564,3 +570,17 @@ def test_chat_kwargs_with_model_params():
assert kwargs.get("max_tokens") == 100
assert kwargs.get("frequency_penalty") == 0.1
assert kwargs.get("presence_penalty") == 0.3 # Should override chat.chat_kwargs


def test_anthropic_sampling_warning_cites_the_deprecation_page():
"""The warning says what Anthropic documents: a 400 on Claude 4.7+, removal in 2026-10-21."""
provider = ChatAnthropic().provider

with pytest.warns(DeprecationWarning) as record:
provider.translate_model_params({"temperature": 0.7, "top_k": 50})

message = str(record[0].message)
assert message.startswith("The temperature, top_k sampling parameter(s)")
assert "Claude 4.7 and later" in message
assert "2026-10-21" in message
assert "no longer have an effect" not in message
Loading