-
Notifications
You must be signed in to change notification settings - Fork 270
feat: support redactedContent in reasoningContent streamed events #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
8858f9d
4a19f45
530e2ce
3af994e
3310114
caaa451
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,18 @@ def handle_content_block_delta( | |
**kwargs, | ||
) | ||
|
||
elif "redactedContent" in delta_content["reasoningContent"]: | ||
if "redactedContent" not in state: | ||
state["redactedContent"] = b"" | ||
|
||
state["redactedContent"] += delta_content["reasoningContent"]["redactedContent"] | ||
callback_handler( | ||
redactedContent=delta_content["reasoningContent"]["redactedContent"], | ||
delta=delta_content, | ||
reasoning=True, | ||
**kwargs, | ||
) | ||
|
||
return state | ||
|
||
|
||
|
@@ -207,6 +219,9 @@ def handle_content_block_stop(state: Dict[str, Any]) -> Dict[str, Any]: | |
} | ||
) | ||
state["reasoningText"] = "" | ||
elif "redactedContent" in state and state["redactedContent"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a line like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
content.append({"reasoningContent": {"redactedContent": state["redactedContent"]}}) | ||
state["redactedContent"] = b"" | ||
|
||
return state | ||
|
||
|
@@ -279,6 +294,7 @@ def process_stream( | |
"current_tool_use": {}, | ||
"reasoningText": "", | ||
"signature": "", | ||
"redactedContent": b"", | ||
} | ||
state["content"] = state["message"]["content"] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,20 @@ def test_handle_content_block_start(chunk: ContentBlockStartEvent, exp_tool_use) | |
{"signature": "val"}, | ||
{"reasoning_signature": "val", "reasoning": True}, | ||
), | ||
# Reasoning - redactedContent - New | ||
( | ||
{"delta": {"reasoningContent": {"redactedContent": b"encrypted"}}}, | ||
{}, | ||
{"redactedContent": b"encrypted"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit: encoded might be better terminology than encrypted. The value is a base64 encoded binary blob There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. Fixed it. |
||
{"redactedContent": b"encrypted", "reasoning": True}, | ||
), | ||
# Reasoning - redactedContent - Existing | ||
( | ||
{"delta": {"reasoningContent": {"redactedContent": b"data"}}}, | ||
{"redactedContent": b"encrypted_"}, | ||
{"redactedContent": b"encrypted_data"}, | ||
{"redactedContent": b"data", "reasoning": True}, | ||
), | ||
# Reasoning - Empty | ||
( | ||
{"delta": {"reasoningContent": {}}}, | ||
|
@@ -230,6 +244,23 @@ def callback_handler(**kwargs): | |
"signature": "123", | ||
}, | ||
), | ||
# redactedContent | ||
( | ||
{ | ||
"content": [], | ||
"current_tool_use": {}, | ||
"text": "", | ||
"reasoningText": "", | ||
"redactedContent": b"encrypted_data", | ||
}, | ||
{ | ||
"content": [{"reasoningContent": {"redactedContent": b"encrypted_data"}}], | ||
"current_tool_use": {}, | ||
"text": "", | ||
"reasoningText": "", | ||
"redactedContent": b"", | ||
}, | ||
), | ||
# Empty | ||
( | ||
{ | ||
|
@@ -355,6 +386,36 @@ def test_extract_usage_metrics(): | |
{"calls": 1}, | ||
[{"role": "user", "content": [{"text": "REDACTED"}]}], | ||
), | ||
( | ||
[ | ||
{"messageStart": {"role": "assistant"}}, | ||
{ | ||
"contentBlockStart": {"start": {}}, | ||
}, | ||
{ | ||
"contentBlockDelta": {"delta": {"reasoningContent": {"redactedContent": b"encrypted_data"}}}, | ||
}, | ||
{"contentBlockStop": {}}, | ||
{ | ||
"messageStop": {"stopReason": "end_turn"}, | ||
}, | ||
{ | ||
"metadata": { | ||
"usage": {"inputTokens": 1, "outputTokens": 1, "totalTokens": 1}, | ||
"metrics": {"latencyMs": 1}, | ||
} | ||
}, | ||
], | ||
"end_turn", | ||
{ | ||
"role": "assistant", | ||
"content": [{"reasoningContent": {"redactedContent": b"encrypted_data"}}], | ||
}, | ||
{"inputTokens": 1, "outputTokens": 1, "totalTokens": 1}, | ||
{"latencyMs": 1}, | ||
{"calls": 1}, | ||
[{"role": "user", "content": [{"text": "Some input!"}]}], | ||
), | ||
], | ||
) | ||
def test_process_stream( | ||
|
Uh oh!
There was an error while loading. Please reload this page.