-
Notifications
You must be signed in to change notification settings - Fork 103
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
ChatBedrock doesn't support streaming when Bedrock guardrails are applied #176
Comments
I am also seeing this issue. In addition - ChatBedrock still does not support Guardrails configurations, which are necessary to properly do prompt attack filtering via input tagging and to filter responses asynchronously. |
Well, AFAIK, it does support bedrock guardrails, however streaming has to be disabled for the same. The problem occurs when streaming is enabled. I've migrated to ChatBedrockConverse for my project, which will eventually replace ChatBedrock class. |
Does ChatBedrockConverse fix it? |
Yes, I'm able to stream the response using ChatBedrockConverse with guardrails configured. |
Thank you. |
is ChatBedrockConverse a drop in replacement for ChatBedrock? |
This PR addresses an issue where the streaming functionality in ChatBedrock breaks when Bedrock guardrails are applied. The problem was caused by a KeyError in the `_stream_response_to_generation_chunk` method when trying to access the 'stop_sequence' key, which may not always be present in the response structure when guardrails are active. ## Changes - Modified the `_stream_response_to_generation_chunk` method in `llms/bedrock.py` to use the `get()` method when accessing dictionary keys that may not always be present. ## Testing - Tested the streaming functionality with and without Bedrock guardrails applied. - Verified that the streaming works correctly in both scenarios without raising KeyErrors.
Fixed by #177 |
langchain-ai#177) This PR addresses an issue where the streaming functionality in ChatBedrock breaks when Bedrock guardrails are applied. The problem was caused by a KeyError in the `_stream_response_to_generation_chunk` method when trying to access the 'stop_sequence' key, which may not always be present in the response structure when guardrails are active. ## Changes - Modified the `_stream_response_to_generation_chunk` method in `llms/bedrock.py` to use the `get()` method when accessing dictionary keys that may not always be present. ## Testing - Tested the streaming functionality with and without Bedrock guardrails applied. - Verified that the streaming works correctly in both scenarios without raising KeyErrors.
…ardrails (#176) (#231) This PR addresses an issue where the streaming functionality in ChatBedrock breaks when Bedrock guardrails are applied. The problem was caused by a KeyError in the `_stream_response_to_generation_chunk` method when trying to access the 'stop_sequence' key, which may not always be present in the response structure when guardrails are active. ## Changes - Modified the `_stream_response_to_generation_chunk` method in `llms/bedrock.py` to use the `get()` method when accessing dictionary keys that may not always be present. ## Testing - Tested the streaming functionality with and without Bedrock guardrails applied. - Verified that the streaming works correctly in both scenarios without raising KeyErrors.
Description
When using ChatBedrock with streaming enabled and Bedrock guardrails applied, the streaming functionality breaks. This appears to be due to differences in the response structure when guardrails are active.
Steps to Reproduce
Current Behavior
The streaming functionality fails with a KeyError, specifically:
This occurs in the
_stream_response_to_generation_chunk
method of thellms\bedrock.py
file.Expected Behavior
The streaming functionality should work correctly regardless of whether guardrails are applied or not.
Additional Context
Environment
Possible Solution
The
_stream_response_to_generation_chunk
method inbedrock.py
should be updated to handle cases where the response structure differs when guardrails are applied. This may involve checking for the existence of certain keys before accessing them, or handling different response structures based on whether guardrails are active.The text was updated successfully, but these errors were encountered: