Prefer base64 img/video bytes in Bedrock endpoints#21
Draft
Conversation
Support base64-pre-encoded image and video bytes in payloads for Bedrock endpoints (by decoding before passing to boto3). Issue a warning when raw bytes are passed because although this works fine for invocation, it prevents saving experiment results (per #20)
d669d7b to
396a57d
Compare
Collaborator
|
Thanks for the PR! i'm reluctant to add this complexity at the connector level, when the issue is really about the json serialization, and considering that most SDK (boto3, OpenAI, Anthropic) seem to prefer handing the serialization of objects themselves. This would also address the bytes/string issue for all other file objects: audio, docs, etc. Here's what I have in mind class BytesEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, bytes):
return b64encode(obj).decode("utf-8")
return super().default(obj)
def bytes_decoder(dct):
if "bytes" in dct:
return {"bytes": b64decode(dct["bytes"])}
return dct |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available: #20
Description of changes:
Align Bedrock input payloads to the Converse API spec (rather than boto3 Python SDK behavior) to un-block saving image understanding use-case load tests to file without changing current serialization setup:
bytesin payloads for Bedrock endpoints (by decoding before passing to boto3 which will re-encode again).Not done yet:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.