-
Notifications
You must be signed in to change notification settings - Fork 553
fix: CitationLocation is UnionType, and correctly joining citation chunks when streaming is being used #1341
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
base: main
Are you sure you want to change the base?
Conversation
|
Adding a bit more light for future reviewers. Multi-turn conversations which received CitationContentBlocks do not work. The call fails with The error message is a little ambiguous but the problem is that in a message array looking like the This gives us two options
I do not want to continue with option 1 for forward looking reasons. Right now, citationsContent only contains Option 2 requires that we pass the content back. We can do this by in This implementation will break, or rather not automatically work, when new shapes are added to the GeneratedContent Union. This is acceptable for now. Multi turn tests have been added for both the streaming and non streaming paths. This change also proposes a breaking change to the CitationStreamEvent to remove an unnecessary nesting with the "callback" key. Given that citations were broken for multi-turn. This breaking change seems like it can be made freely. The key decision points here are
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| def __init__(self, delta: ContentBlockDelta, citation: Citation) -> None: | ||
| """Initialize with delta and citation content.""" | ||
| super().__init__({"callback": {"citation": citation, "delta": delta}}) | ||
| super().__init__({"citation": citation, "delta": delta}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note, this is a breaking change as well. However, as noted citations is a broken feature at the moment.
Description
When using a Bedrock model with citations enabled, the returned
CitationLocationobject inside ofCitationis a UNION, which means that currently it must be one ofdocumentChar,documentChunk,documentPage,searchResultLocation, andweb.Changing
_format_request_message_contentwould cause the following error to surface:As
handle_content_block_stopfromstreaming.pyis not formatting the chunks correctly when citations are usedRelated Issues
[BUG] Bedrock Runtime API CitationLocation Tagged Union Structure Error #1323
Documentation PR
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ContentBlockDelta.html
Type of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.