-
Notifications
You must be signed in to change notification settings - Fork 74
Fix Anthropic temperature for newer Claude models #2490
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
692bc54
Throw an error if remove inference was requested but not possible
johnjosephhorton 65a5475
Merge branch 'main' of github.com:expectedparrot/edsl
johnjosephhorton 6783aac
Merge branch 'main' of github.com:expectedparrot/edsl
johnjosephhorton f1a5ef8
Merge branch 'main' of github.com:expectedparrot/edsl
johnjosephhorton 5bce224
Fix Anthropic temperature for newer models
johnjosephhorton c17941f
Update lockfile
onmyraedar 289851d
Small fixes
onmyraedar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ _build/* | |
| .DS_Store | ||
| .coverage | ||
| .edsl_cache | ||
| .edsl_objects/ | ||
| .env | ||
| .ipynb_checkpoints/ | ||
| .mypy_cache | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import asyncio | ||
|
|
||
| from edsl.inference_services.services.anthropic_service import AnthropicService | ||
|
|
||
|
|
||
| def test_requires_temperature_one_for_models_after_opus_46(): | ||
| assert AnthropicService._requires_temperature_one( | ||
| "claude-sonnet-4-6-20260217" | ||
| ) | ||
| assert AnthropicService._requires_temperature_one("claude-opus-4-7-20260416") | ||
| assert AnthropicService._requires_temperature_one("claude-opus-4-7") | ||
| assert not AnthropicService._requires_temperature_one("claude-opus-4-6-20260205") | ||
| assert not AnthropicService._requires_temperature_one("claude-opus-4-5-20251124") | ||
| assert not AnthropicService._requires_temperature_one("claude-3-5-sonnet-20241022") | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def test_anthropic_request_uses_temperature_one_for_affected_models(monkeypatch): | ||
| captured_kwargs = {} | ||
|
|
||
| class DummyResponse: | ||
| def model_dump(self): | ||
| return {"content": [{"type": "text", "text": "ok"}]} | ||
|
|
||
| class DummyMessages: | ||
| async def create(self, **kwargs): | ||
| captured_kwargs.update(kwargs) | ||
| return DummyResponse() | ||
|
|
||
| class DummyAnthropicClient: | ||
| def __init__(self, api_key): | ||
| self.messages = DummyMessages() | ||
|
|
||
| monkeypatch.setattr( | ||
| "edsl.inference_services.services.anthropic_service.AsyncAnthropic", | ||
| DummyAnthropicClient, | ||
| ) | ||
|
|
||
| model_class = AnthropicService.create_model("claude-sonnet-4-6-20260217") | ||
| model = model_class(temperature=0.2, skip_api_key_check=True) | ||
|
|
||
| asyncio.run(model.async_execute_model_call("hello")) | ||
|
|
||
| assert captured_kwargs["temperature"] == 1.0 | ||
| assert model.temperature == 0.2 | ||
| assert model.parameters["temperature"] == 0.2 | ||
|
|
||
|
|
||
| def test_anthropic_request_preserves_temperature_for_legacy_models(monkeypatch): | ||
| captured_kwargs = {} | ||
|
|
||
| class DummyResponse: | ||
| def model_dump(self): | ||
| return {"content": [{"type": "text", "text": "ok"}]} | ||
|
|
||
| class DummyMessages: | ||
| async def create(self, **kwargs): | ||
| captured_kwargs.update(kwargs) | ||
| return DummyResponse() | ||
|
|
||
| class DummyAnthropicClient: | ||
| def __init__(self, api_key): | ||
| self.messages = DummyMessages() | ||
|
|
||
| monkeypatch.setattr( | ||
| "edsl.inference_services.services.anthropic_service.AsyncAnthropic", | ||
| DummyAnthropicClient, | ||
| ) | ||
|
|
||
| model_class = AnthropicService.create_model("claude-opus-4-5-20251124") | ||
| model = model_class(temperature=0.2, skip_api_key_check=True) | ||
|
|
||
| asyncio.run(model.async_execute_model_call("hello")) | ||
|
|
||
| assert captured_kwargs["temperature"] == 0.2 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.