test(bedrock): pin stream-path cap omission; document truthiness edge
Self-review follow-up: cover call_converse_stream's max_tokens=None path (same builder, previously unpinned) and document why the shim reads the caller cap with truthiness rather than 'is None' (parity with the Anthropic shim's reading).
This commit is contained in:
@@ -2218,6 +2218,9 @@ class _BedrockCompletionsAdapter:
|
||||
# allowed output, matching the no-cap-by-default policy every
|
||||
# other aux wire already follows (#10809: vision descriptions
|
||||
# stayed capped at the shim's old hardcoded 4096 on Bedrock).
|
||||
# Truthiness (not `is None`) is deliberate — it matches the
|
||||
# sibling Anthropic shim's reading of max_tokens above, so a
|
||||
# nonsense explicit 0 is treated as "no cap" on both wires.
|
||||
max_tokens=int(max_tokens) if max_tokens else None,
|
||||
temperature=kwargs.get("temperature"),
|
||||
top_p=kwargs.get("top_p"),
|
||||
|
||||
@@ -423,6 +423,27 @@ class TestBuildConverseKwargs:
|
||||
)
|
||||
assert "inferenceConfig" not in kwargs
|
||||
|
||||
def test_call_converse_stream_omits_cap_for_none(self):
|
||||
"""The streaming entry point funnels through the same builder — pin
|
||||
that max_tokens=None omits the cap there too."""
|
||||
from unittest.mock import MagicMock, patch as mock_patch
|
||||
from agent.bedrock_adapter import call_converse_stream
|
||||
boto3_client = MagicMock()
|
||||
boto3_client.converse_stream.return_value = {"stream": []}
|
||||
with mock_patch(
|
||||
"agent.bedrock_adapter._get_bedrock_runtime_client",
|
||||
return_value=boto3_client,
|
||||
):
|
||||
call_converse_stream(
|
||||
region="us-east-1",
|
||||
model="test-model",
|
||||
messages=[{"role": "user", "content": "Hi"}],
|
||||
max_tokens=None,
|
||||
temperature=0.2,
|
||||
)
|
||||
wire_kwargs = boto3_client.converse_stream.call_args.kwargs
|
||||
assert "maxTokens" not in wire_kwargs.get("inferenceConfig", {})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user