From 97382fde4bdabee5377aa4ba7bfebb0f37fded2d Mon Sep 17 00:00:00 2001 From: jknapp Date: Sun, 16 Mar 2025 20:12:48 -0700 Subject: [PATCH] testing thinking --- claude_sonnet-3-7-bedrock.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/claude_sonnet-3-7-bedrock.py b/claude_sonnet-3-7-bedrock.py index 534d9a5..8538763 100644 --- a/claude_sonnet-3-7-bedrock.py +++ b/claude_sonnet-3-7-bedrock.py @@ -177,7 +177,7 @@ class Pipeline: # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime/client/converse_stream.html streaming_response = self.bedrock_runtime.converse_stream(**payload) print(f"{streaming_response} for {payload}") - thinking_start = False + thinking_block = '' for chunk in streaming_response["stream"]: print(chunk) if "contentBlockDelta" in chunk: @@ -185,12 +185,15 @@ class Pipeline: # Handle reasoning content (Chain of Thought) if "reasoningContent" in delta and "text" in delta["reasoningContent"]: - if not thinking_start: - thinking_start = True - yield '
\nThinking…\n' + if not thinking_block: + thinking_block = delta["reasoningContent"]["contentBlockIndex"] + yield '\n' #print(f"Reasoning content: {delta['reasoningContent']}") yield delta["reasoningContent"]["text"] - + + if "contentBlockStop" in delta and delta["contentBlockDelta"]["contentBlockIndex"] == thinking_block: + yield '\n\n' + # Handle regular response text if "text" in delta: yield delta["text"]