From 2ed5f90d8f5d8e8f6fa380368c8a45bd59058075 Mon Sep 17 00:00:00 2001 From: Vigilans Date: Tue, 21 Apr 2026 22:36:06 +0800 Subject: [PATCH] style: run black formatter --- .../responses_adapters/streaming_iterator.py | 20 +++++++------- .../responses_adapters/transformation.py | 22 +++++++++++----- .../responses_adapters/utils.py | 26 ++++++++++--------- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/streaming_iterator.py b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/streaming_iterator.py index 7392c79919d..edcd712d98d 100644 --- a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/streaming_iterator.py +++ b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/streaming_iterator.py @@ -332,8 +332,12 @@ class AnthropicResponsesStreamWrapper: usage_delta["cache_read_input_tokens"] = cache_read_tokens if self._web_tool_uses: usage_delta["server_tool_use"] = { - "web_search_requests": sum(c["name"] == "web_search" for c in self._web_tool_uses), - "web_fetch_requests": sum(c["name"] == "web_fetch" for c in self._web_tool_uses), + "web_search_requests": sum( + c["name"] == "web_search" for c in self._web_tool_uses + ), + "web_fetch_requests": sum( + c["name"] == "web_fetch" for c in self._web_tool_uses + ), } self._chunk_queue.append( @@ -369,9 +373,7 @@ class AnthropicResponsesStreamWrapper: }, } ) - self._chunk_queue.append( - {"type": "content_block_stop", "index": block_idx} - ) + self._chunk_queue.append({"type": "content_block_stop", "index": block_idx}) def _emit_web_search_results(self, annotations: list) -> list: """Emit web_search_tool_result blocks and return citations for text emission.""" @@ -387,9 +389,7 @@ class AnthropicResponsesStreamWrapper: "content_block": block, } ) - self._chunk_queue.append( - {"type": "content_block_stop", "index": block_idx} - ) + self._chunk_queue.append({"type": "content_block_stop", "index": block_idx}) return citations def _emit_cited_text_blocks(self, text: str, citations: list) -> None: @@ -418,9 +418,7 @@ class AnthropicResponsesStreamWrapper: "delta": {"type": "citations_delta", "citation": cit}, } ) - self._chunk_queue.append( - {"type": "content_block_stop", "index": block_idx} - ) + self._chunk_queue.append({"type": "content_block_stop", "index": block_idx}) def __aiter__(self) -> "AnthropicResponsesStreamWrapper": return self diff --git a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py index a442de87581..6ba310b87db 100644 --- a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py +++ b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py @@ -464,7 +464,9 @@ class LiteLLMAnthropicToResponsesAPIAdapter: ) content.extend(blocks) content.extend( - build_text_blocks_with_citations(getattr(part, "text", ""), citations) + build_text_blocks_with_citations( + getattr(part, "text", ""), citations + ) ) break @@ -501,12 +503,16 @@ class LiteLLMAnthropicToResponsesAPIAdapter: elif item_type == "message" and web_tool_uses: for part in item.get("content", []): if isinstance(part, dict) and part.get("type") == "output_text": - blocks, citations = build_web_search_results_from_annotations( - web_tool_uses, part.get("annotations") or [] + blocks, citations = ( + build_web_search_results_from_annotations( + web_tool_uses, part.get("annotations") or [] + ) ) content.extend(blocks) content.extend( - build_text_blocks_with_citations(part.get("text", ""), citations) + build_text_blocks_with_citations( + part.get("text", ""), citations + ) ) break elif item_type == "message": @@ -548,8 +554,12 @@ class LiteLLMAnthropicToResponsesAPIAdapter: if web_tool_uses: anthropic_usage["server_tool_use"] = { # type: ignore[typeddict-unknown-key] - "web_search_requests": sum(c["name"] == "web_search" for c in web_tool_uses), - "web_fetch_requests": sum(c["name"] == "web_fetch" for c in web_tool_uses), + "web_search_requests": sum( + c["name"] == "web_search" for c in web_tool_uses + ), + "web_fetch_requests": sum( + c["name"] == "web_fetch" for c in web_tool_uses + ), } return AnthropicMessagesResponse( diff --git a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/utils.py b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/utils.py index da40247d2ca..8839fce0d33 100644 --- a/litellm/llms/anthropic/experimental_pass_through/responses_adapters/utils.py +++ b/litellm/llms/anthropic/experimental_pass_through/responses_adapters/utils.py @@ -64,12 +64,18 @@ def build_web_search_results_from_annotations( start = ann.get("start_index", 0) or 0 end = ann.get("end_index", 0) or 0 - citations.append((start, end, { - "type": "web_search_result_location", - "url": url, - "title": title, - "cited_text": title, - })) + citations.append( + ( + start, + end, + { + "type": "web_search_result_location", + "url": url, + "title": title, + "cited_text": title, + }, + ) + ) if url and url not in seen_urls: seen_urls[url] = { @@ -105,9 +111,7 @@ def build_text_blocks_with_citations( text[start:end] is the cited range; everything else is uncited. """ if not citations: - return [ - AnthropicResponseContentBlockText(type="text", text=text).model_dump() - ] + return [AnthropicResponseContentBlockText(type="text", text=text).model_dump()] blocks: List[Dict[str, Any]] = [] pos = 0 @@ -129,9 +133,7 @@ def build_text_blocks_with_citations( if pos < len(text): blocks.append( - AnthropicResponseContentBlockText( - type="text", text=text[pos:] - ).model_dump() + AnthropicResponseContentBlockText(type="text", text=text[pos:]).model_dump() ) return blocks