Skip to content
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

Fix streaming functionality with Bedrock guardrails (#176) #177

Conversation

ardf
Copy link
Contributor

@ardf ardf commented Sep 2, 2024

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.

Copy link
Collaborator

@3coins 3coins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ardf
Thanks for submitting the fix. Looks good!

@3coins 3coins merged commit adcfc34 into langchain-ai:main Oct 9, 2024
12 checks passed
@3coins
Copy link
Collaborator

3coins commented Oct 9, 2024

@ardf
Can you also backport this fix to v0.1 branch. Thanks for your contribution.

ardf added a commit to ardf/langchain-aws that referenced this pull request Oct 10, 2024
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.
@ardf
Copy link
Contributor Author

ardf commented Oct 10, 2024

@3coins Please check #231

3coins pushed a commit that referenced this pull request Oct 11, 2024
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants