Skip to content

Commit 8d2ce62

Browse files
committed
apply linter
1 parent f9366e5 commit 8d2ce62

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/patches/_botocore_patches.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ def patched_process_anthropic_claude_chunk(self, chunk):
344344
return
345345

346346
if message_type == "message_start":
347-
# {'type': 'message_start', 'message': {'id': 'id', 'type': 'message', 'role': 'assistant', 'model': 'claude-2.0', 'content': [], 'stop_reason': None, 'stop_sequence': None, 'usage': {'input_tokens': 18, 'output_tokens': 1}}}
347+
# {'type': 'message_start', 'message': {'id': 'id', 'type': 'message', 'role': 'assistant',
348+
# 'model': 'claude-2.0', 'content': [], 'stop_reason': None, 'stop_sequence': None,
349+
# 'usage': {'input_tokens': 18, 'output_tokens': 1}}}
348350
if chunk.get("message", {}).get("role") == "assistant":
349351
self._record_message = True
350352
message = chunk["message"]
@@ -356,7 +358,8 @@ def patched_process_anthropic_claude_chunk(self, chunk):
356358

357359
if message_type == "content_block_start":
358360
# {'type': 'content_block_start', 'index': 0, 'content_block': {'type': 'text', 'text': ''}}
359-
# {'type': 'content_block_start', 'index': 1, 'content_block': {'type': 'tool_use', 'id': 'id', 'name': 'func_name', 'input': {}}}
361+
# {'type': 'content_block_start', 'index': 1, 'content_block':
362+
# {'type': 'tool_use', 'id': 'id', 'name': 'func_name', 'input': {}}}
360363
if self._record_message:
361364
block = chunk.get("content_block", {})
362365
if block.get("type") == "text":
@@ -380,9 +383,7 @@ def patched_process_anthropic_claude_chunk(self, chunk):
380383
# {'type': 'content_block_stop', 'index': 0}
381384
if self._tool_json_input_buf:
382385
try:
383-
self._content_block["input"] = json.loads(
384-
self._tool_json_input_buf
385-
)
386+
self._content_block["input"] = json.loads(self._tool_json_input_buf)
386387
except json.JSONDecodeError:
387388
self._content_block["input"] = self._tool_json_input_buf
388389
self._message["content"].append(self._content_block)
@@ -391,18 +392,16 @@ def patched_process_anthropic_claude_chunk(self, chunk):
391392
return
392393

393394
if message_type == "message_delta":
394-
# {'type': 'message_delta', 'delta': {'stop_reason': 'end_turn', 'stop_sequence': None}, 'usage': {'output_tokens': 123}}
395-
if (
396-
stop_reason := chunk.get("delta", {}).get("stop_reason")
397-
) is not None:
395+
# {'type': 'message_delta', 'delta': {'stop_reason': 'end_turn', 'stop_sequence': None},
396+
# 'usage': {'output_tokens': 123}}
397+
if (stop_reason := chunk.get("delta", {}).get("stop_reason")) is not None:
398398
self._response["stopReason"] = stop_reason
399399
return
400400

401401
if message_type == "message_stop":
402-
# {'type': 'message_stop', 'amazon-bedrock-invocationMetrics': {'inputTokenCount': 18, 'outputTokenCount': 123, 'invocationLatency': 5250, 'firstByteLatency': 290}}
403-
if invocation_metrics := chunk.get(
404-
"amazon-bedrock-invocationMetrics"
405-
):
402+
# {'type': 'message_stop', 'amazon-bedrock-invocationMetrics':
403+
# {'inputTokenCount': 18, 'outputTokenCount': 123, 'invocationLatency': 5250, 'firstByteLatency': 290}}
404+
if invocation_metrics := chunk.get("amazon-bedrock-invocationMetrics"):
406405
self._process_invocation_metrics(invocation_metrics)
407406

408407
if self._record_message:
@@ -415,7 +414,9 @@ def patched_process_anthropic_claude_chunk(self, chunk):
415414

416415
bedrock_utils.ConverseStreamWrapper.__init__ = patched_init
417416
bedrock_utils.ConverseStreamWrapper._process_event = patched_process_event
418-
bedrock_utils.InvokeModelWithResponseStreamWrapper._process_anthropic_claude_chunk = patched_process_anthropic_claude_chunk
417+
bedrock_utils.InvokeModelWithResponseStreamWrapper._process_anthropic_claude_chunk = (
418+
patched_process_anthropic_claude_chunk
419+
)
419420
bedrock_utils.extract_tool_calls = patched_extract_tool_calls
420421

421422
# END The OpenTelemetry Authors code

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/patches/test_instrumentation_patch.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ def _test_unpatched_botocore_instrumentation(self):
228228
self._test_unpatched_process_anthropic_claude_chunk(None, None)
229229
self._test_unpatched_process_anthropic_claude_chunk({}, {})
230230

231-
232231
def _test_unpatched_gevent_instrumentation(self):
233232
self.assertFalse(gevent.monkey.is_module_patched("os"), "gevent os module has been patched")
234233
self.assertFalse(gevent.monkey.is_module_patched("thread"), "gevent thread module has been patched")
@@ -690,13 +689,19 @@ def _test_patched_extract_tool_calls(self):
690689
result = bedrock_utils.extract_tool_calls(message_with_string_content, True)
691690
self.assertIsNone(result)
692691

693-
def _test_patched_process_anthropic_claude_chunk(self, input_value: Dict[str, str], expected_output: Dict[str, str]):
692+
def _test_patched_process_anthropic_claude_chunk(
693+
self, input_value: Dict[str, str], expected_output: Dict[str, str]
694+
):
694695
self._test_process_anthropic_claude_chunk(input_value, expected_output, False)
695696

696-
def _test_unpatched_process_anthropic_claude_chunk(self, input_value: Dict[str, str], expected_output: Dict[str, str]):
697+
def _test_unpatched_process_anthropic_claude_chunk(
698+
self, input_value: Dict[str, str], expected_output: Dict[str, str]
699+
):
697700
self._test_process_anthropic_claude_chunk(input_value, expected_output, True)
698701

699-
def _test_process_anthropic_claude_chunk(self, input_value: Dict[str, str], expected_output: Dict[str, str], expect_exception: bool):
702+
def _test_process_anthropic_claude_chunk(
703+
self, input_value: Dict[str, str], expected_output: Dict[str, str], expect_exception: bool
704+
):
700705
"""Test that _process_anthropic_claude_chunk handles various tool_use input formats."""
701706
wrapper = bedrock_utils.InvokeModelWithResponseStreamWrapper(
702707
stream=MagicMock(),
@@ -735,9 +740,7 @@ def _test_process_anthropic_claude_chunk(self, input_value: Dict[str, str], expe
735740

736741
# Simulate content_block_stop
737742
try:
738-
wrapper._process_anthropic_claude_chunk(
739-
{"type": "content_block_stop", "index": 0}
740-
)
743+
wrapper._process_anthropic_claude_chunk({"type": "content_block_stop", "index": 0})
741744
except TypeError:
742745
if expect_exception:
743746
return

0 commit comments

Comments
 (0)