testing thinking
This commit is contained in:
parent
3148979440
commit
97382fde4b
@ -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 '<details type="reasoning" done="false">\n<summary>Thinking…</summary>\n'
|
||||
if not thinking_block:
|
||||
thinking_block = delta["reasoningContent"]["contentBlockIndex"]
|
||||
yield '<thinking>\n'
|
||||
#print(f"Reasoning content: {delta['reasoningContent']}")
|
||||
yield delta["reasoningContent"]["text"]
|
||||
|
||||
|
||||
if "contentBlockStop" in delta and delta["contentBlockDelta"]["contentBlockIndex"] == thinking_block:
|
||||
yield '</thinking>\n\n'
|
||||
|
||||
# Handle regular response text
|
||||
if "text" in delta:
|
||||
yield delta["text"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user