mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(anthropic): satisfy strict lint and update tests pinned to the dropped served model
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
847172d311
commit
07d4936428
4 changed files with 13 additions and 19 deletions
|
|
@ -1069,7 +1069,8 @@ class ModelResponseIterator:
|
|||
"""
|
||||
message_start_block: Final = MessageStartBlock(**chunk)
|
||||
start_message: Final = message_start_block["message"]
|
||||
self.served_model = start_message["model"] if "model" in start_message else None
|
||||
if "model" in start_message:
|
||||
self.served_model = start_message["model"]
|
||||
if "usage" in message_start_block["message"]:
|
||||
usage = self._handle_usage(anthropic_usage_chunk=message_start_block["message"]["usage"])
|
||||
elif type_chunk == "error":
|
||||
|
|
|
|||
|
|
@ -2756,9 +2756,7 @@ def _served_model_stream_chunks(model: str | None) -> list[dict]:
|
|||
def test_message_start_model_is_carried_on_stream_chunks():
|
||||
iterator: Final = ModelResponseIterator(None, sync_stream=True)
|
||||
|
||||
parsed: Final = [
|
||||
iterator.chunk_parser(chunk) for chunk in _served_model_stream_chunks("claude-served-1")
|
||||
]
|
||||
parsed: Final = [iterator.chunk_parser(chunk) for chunk in _served_model_stream_chunks("claude-served-1")]
|
||||
|
||||
assert all(chunk.model == "claude-served-1" for chunk in parsed)
|
||||
|
||||
|
|
@ -2766,9 +2764,7 @@ def test_message_start_model_is_carried_on_stream_chunks():
|
|||
def test_message_start_without_model_leaves_chunk_model_unset():
|
||||
iterator: Final = ModelResponseIterator(None, sync_stream=True)
|
||||
|
||||
parsed: Final = [
|
||||
iterator.chunk_parser(chunk) for chunk in _served_model_stream_chunks(None)
|
||||
]
|
||||
parsed: Final = [iterator.chunk_parser(chunk) for chunk in _served_model_stream_chunks(None)]
|
||||
|
||||
assert all(chunk.model is None for chunk in parsed)
|
||||
|
||||
|
|
@ -2777,9 +2773,7 @@ def test_served_model_reaches_assembled_stream_through_custom_stream_wrapper():
|
|||
from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper
|
||||
|
||||
served_model: Final = "claude-served-1"
|
||||
sse_lines: Final = [
|
||||
f"data: {json.dumps(chunk)}\n".encode() for chunk in _served_model_stream_chunks(served_model)
|
||||
]
|
||||
sse_lines: Final = [f"data: {json.dumps(chunk)}\n".encode() for chunk in _served_model_stream_chunks(served_model)]
|
||||
iterator: Final = ModelResponseIterator(iter(sse_lines), sync_stream=True)
|
||||
wrapper: Final = CustomStreamWrapper(
|
||||
completion_stream=iter(iterator),
|
||||
|
|
@ -2793,7 +2787,5 @@ def test_served_model_reaches_assembled_stream_through_custom_stream_wrapper():
|
|||
assert len(chunks) > 1
|
||||
for chunk in chunks[1:]:
|
||||
assert chunk._hidden_params["provider_response_model"] == served_model
|
||||
assembled: Final = litellm.stream_chunk_builder(
|
||||
chunks=list(chunks), messages=[{"role": "user", "content": "hi"}]
|
||||
)
|
||||
assembled: Final = litellm.stream_chunk_builder(chunks=list(chunks), messages=[{"role": "user", "content": "hi"}])
|
||||
assert assembled._hidden_params["provider_response_model"] == served_model
|
||||
|
|
|
|||
|
|
@ -1291,8 +1291,9 @@ class TestToolPermissionGuardrailAnthropicMessages:
|
|||
async def test_rewrite_mode_keeps_the_stream_identity_it_had_before_the_shared_helper(self):
|
||||
"""Well-formed SSE must round-trip exactly as it did before the helpers were shared.
|
||||
|
||||
The shared module can stamp the upstream message id and model onto the assembled response
|
||||
for callers that ask for it; this path never did, and a client reads those bytes.
|
||||
The shared module can stamp the upstream message id onto the assembled response for
|
||||
callers that ask for it; this path never did, and a client reads those bytes. The model,
|
||||
though, is now the upstream's, matching what the untouched passthrough shows clients.
|
||||
"""
|
||||
with patch.object(self.rewriting, "should_run_guardrail", return_value=True):
|
||||
out = await self._drain(self.rewriting, self._sse_chunks("Read"))
|
||||
|
|
@ -1304,7 +1305,7 @@ class TestToolPermissionGuardrailAnthropicMessages:
|
|||
if line.startswith("data: ") and json.loads(line[6:]).get("type") == "message_start"
|
||||
)["message"]
|
||||
assert message_start["id"].startswith("chatcmpl-"), "the rewritten stream must not adopt the upstream message id"
|
||||
assert message_start["model"] == "unknown-model", "the rewritten stream must not adopt the upstream model"
|
||||
assert message_start["model"] == "claude-sonnet-4-5", "the rewritten stream reports the model the upstream served"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_message_start_without_a_dict_message_fails_closed(self):
|
||||
|
|
|
|||
|
|
@ -2541,7 +2541,7 @@ class TestRecordPartialUsageForFailure:
|
|||
function_id="test-partial-usage-failure",
|
||||
)
|
||||
|
||||
def _interrupted_chunks(self):
|
||||
def _interrupted_chunks(self, *, model: str = "claude-sonnet-5"):
|
||||
return [
|
||||
self._sse(
|
||||
"message_start",
|
||||
|
|
@ -2551,7 +2551,7 @@ class TestRecordPartialUsageForFailure:
|
|||
"id": "msg_abc",
|
||||
"type": "message",
|
||||
"role": "assistant",
|
||||
"model": "claude-sonnet-5",
|
||||
"model": model,
|
||||
"content": [],
|
||||
"stop_reason": None,
|
||||
"stop_sequence": None,
|
||||
|
|
@ -2588,7 +2588,7 @@ class TestRecordPartialUsageForFailure:
|
|||
AnthropicPassthroughLoggingHandler.record_partial_usage_for_failure(
|
||||
litellm_logging_obj=logging_obj,
|
||||
request_body={"model": "claude-unpriced-test-model", "stream": True},
|
||||
all_chunks=self._interrupted_chunks(),
|
||||
all_chunks=self._interrupted_chunks(model="claude-unpriced-test-model"),
|
||||
)
|
||||
|
||||
usage = logging_obj.model_call_details["combined_usage_object"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue