@@ -453,17 +453,17 @@ def _stream(
453
453
has_tool_use = True
454
454
455
455
# Fix stopReason for streaming responses that contain tool use
456
- if "messageStop" in chunk and has_tool_use :
457
- message_stop = chunk [ "messageStop" ]
458
- if message_stop . get ( "stopReason" ) == "end_turn" :
459
- # Create corrected chunk with tool_use stopReason
460
- modified_chunk = chunk . copy ()
461
- modified_chunk [ "messageStop" ] = message_stop . copy ()
462
- modified_chunk [ "messageStop" ][ "stopReason" ] = "tool_use"
463
- logger . info ( "Override stop reason from end_turn to tool_use" )
464
- callback ( modified_chunk )
465
- else :
466
- callback (chunk )
456
+ if (
457
+ has_tool_use
458
+ and "messageStop" in chunk
459
+ and ( message_stop := chunk [ "messageStop" ]). get ( "stopReason" ) == "end_turn"
460
+ ):
461
+ # Create corrected chunk with tool_use stopReason
462
+ modified_chunk = chunk . copy ()
463
+ modified_chunk [ "messageStop" ] = message_stop . copy ( )
464
+ modified_chunk [ "messageStop" ][ "stopReason" ] = "tool_use"
465
+ logger . warning ( "Override stop reason from end_turn to tool_use" )
466
+ callback (modified_chunk )
467
467
else :
468
468
callback (chunk )
469
469
@@ -607,7 +607,7 @@ def _convert_non_streaming_to_streaming(self, response: dict[str, Any]) -> Itera
607
607
message_content = response ["output" ]["message" ]["content" ]
608
608
if any ("toolUse" in content for content in message_content ):
609
609
current_stop_reason = "tool_use"
610
- logger .info ("Override stop reason from end_turn to tool_use" )
610
+ logger .warning ("Override stop reason from end_turn to tool_use" )
611
611
612
612
yield {
613
613
"messageStop" : {
0 commit comments