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
|
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime/client/converse_stream.html
|
||||||
streaming_response = self.bedrock_runtime.converse_stream(**payload)
|
streaming_response = self.bedrock_runtime.converse_stream(**payload)
|
||||||
print(f"{streaming_response} for {payload}")
|
print(f"{streaming_response} for {payload}")
|
||||||
thinking_start = False
|
thinking_block = ''
|
||||||
for chunk in streaming_response["stream"]:
|
for chunk in streaming_response["stream"]:
|
||||||
print(chunk)
|
print(chunk)
|
||||||
if "contentBlockDelta" in chunk:
|
if "contentBlockDelta" in chunk:
|
||||||
@ -185,12 +185,15 @@ class Pipeline:
|
|||||||
|
|
||||||
# Handle reasoning content (Chain of Thought)
|
# Handle reasoning content (Chain of Thought)
|
||||||
if "reasoningContent" in delta and "text" in delta["reasoningContent"]:
|
if "reasoningContent" in delta and "text" in delta["reasoningContent"]:
|
||||||
if not thinking_start:
|
if not thinking_block:
|
||||||
thinking_start = True
|
thinking_block = delta["reasoningContent"]["contentBlockIndex"]
|
||||||
yield '<details type="reasoning" done="false">\n<summary>Thinking…</summary>\n'
|
yield '<thinking>\n'
|
||||||
#print(f"Reasoning content: {delta['reasoningContent']}")
|
#print(f"Reasoning content: {delta['reasoningContent']}")
|
||||||
yield delta["reasoningContent"]["text"]
|
yield delta["reasoningContent"]["text"]
|
||||||
|
|
||||||
|
if "contentBlockStop" in delta and delta["contentBlockDelta"]["contentBlockIndex"] == thinking_block:
|
||||||
|
yield '</thinking>\n\n'
|
||||||
|
|
||||||
# Handle regular response text
|
# Handle regular response text
|
||||||
if "text" in delta:
|
if "text" in delta:
|
||||||
yield delta["text"]
|
yield delta["text"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user