Repository navigation
Fix P2P simulator defaults and Sonnet 5 thinking #57
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,98 @@ | ||
| import json | ||
| from datetime import UTC, datetime | ||
|
|
||
| import anthropic | ||
| import httpx | ||
| import pytest | ||
|
|
||
| from chi_bench.core.models import P2PSessionRecord, PayerPeerToPeerRequest | ||
| from chi_bench.services.p2p import P2PService | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("benchmark_side", ["payer", "provider"]) | ||
| @pytest.mark.parametrize( | ||
| ("model_env", "expected_model"), | ||
| [ | ||
| (None, "claude-sonnet-5"), | ||
| ("", "claude-sonnet-5"), | ||
| ("sonnet", "claude-sonnet-5"), | ||
| ("claude-sonnet-5", "claude-sonnet-5"), | ||
| ("haiku", "claude-haiku-4-5-20251001"), | ||
| ], | ||
| ) | ||
| def test_p2p_simulator_returns_text(monkeypatch, benchmark_side, model_env, expected_model): | ||
| if model_env is None: | ||
| monkeypatch.delenv("CHI_BENCH_P2P_SIMULATOR_MODEL", raising=False) | ||
| else: | ||
| monkeypatch.setenv("CHI_BENCH_P2P_SIMULATOR_MODEL", model_env) | ||
|
|
||
| requests = [] | ||
|
|
||
| def respond(request): | ||
| payload = json.loads(request.content) | ||
| requests.append(payload) | ||
| if payload["model"] == "claude-sonnet-4-20250514": | ||
| return httpx.Response( | ||
| 404, | ||
| json={ | ||
| "type": "error", | ||
| "error": { | ||
| "type": "not_found_error", | ||
| "message": "model: claude-sonnet-4-20250514", | ||
| }, | ||
| }, | ||
| ) | ||
| content = [{"type": "text", "text": " Let's review the evidence. "}] | ||
| if payload["model"] == "claude-sonnet-5" and payload.get("thinking") != { | ||
| "type": "disabled" | ||
| }: | ||
| content.insert(0, {"type": "thinking", "thinking": "Review", "signature": "test"}) | ||
| return httpx.Response( | ||
| 200, | ||
| json={ | ||
| "id": "msg_p2p", | ||
| "type": "message", | ||
| "role": "assistant", | ||
| "model": payload["model"], | ||
| "content": content, | ||
| "stop_reason": "end_turn", | ||
| "stop_sequence": None, | ||
| "usage": {"input_tokens": 10, "output_tokens": 8}, | ||
| }, | ||
| ) | ||
|
|
||
| now = datetime(2026, 10, 7, tzinfo=UTC) | ||
| p2p_request = PayerPeerToPeerRequest( | ||
| id="p2p-1", case_id="case-1", created_at=now, updated_at=now | ||
| ) | ||
| session = P2PSessionRecord( | ||
| id="session-1", | ||
| request_id=p2p_request.id, | ||
| case_id=p2p_request.case_id, | ||
| benchmark_side=benchmark_side, | ||
| created_at=now, | ||
| updated_at=now, | ||
| ) | ||
| service = P2PService(ctx=None) | ||
| monkeypatch.setattr(service, "_build_provider_context", lambda request: "You are the provider.") | ||
| monkeypatch.setattr(service, "_build_payer_context", lambda request: "You are the payer.") | ||
| with anthropic.Anthropic( | ||
| api_key="test-key", http_client=httpx.Client(transport=httpx.MockTransport(respond)) | ||
| ) as client: | ||
| monkeypatch.setattr(anthropic, "Anthropic", lambda: client) | ||
| reply, revealed_fact_id = service._generate_counterpart_reply( | ||
| session=session, | ||
| request=p2p_request, | ||
| contract={}, | ||
| message="Can we review the evidence?", | ||
| agent_turn_index=1, | ||
| ) | ||
|
|
||
| assert reply == "Let's review the evidence." | ||
| assert revealed_fact_id is None | ||
| assert len(requests) == 1 | ||
| assert requests[0]["model"] == expected_model | ||
| if expected_model == "claude-sonnet-5": | ||
| assert requests[0]["thinking"] == {"type": "disabled"} | ||
| else: | ||
| assert "thinking" not in requests[0] |
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.