boto / boto3

AWS SDK for Python
https://aws.amazon.com/sdk-for-python/
Apache License 2.0
9.07k stars 1.87k forks source link

Claude 3.5 V2 Sonnet doesn't support file attachments on the API, works in playground #4341

Open bdavj opened 1 week ago

bdavj commented 1 week ago

Describe the bug

Using a 2.5mb PDF, and a 300kb image, same result with both.

On the playground, both upload OK and can converse effectively around the documents.

On the API, I get the following response:

botocore.exceptions.EventStreamError: An error occurred (validationException) when calling the ConverseStream operation: The model returned the following errors: Input is too long for requested model.

This is using ChatBedrock, and the message section formatted as either: {"image": {"format": get_file_format(file_obj), "source": {"base64": base64.b64encode(binary_data).decode('utf-8')}}} or

{
                            "document": {
                                "name": sanitize_filename(file_obj.name),
                                "format": get_file_format(file_obj),
                                "source": {
                                    "base64": base64.b64encode(binary_data).decode('utf-8')
                                },
                            }
                        }

This has also been tried using the raw binary data as bytes in the source.

Regression Issue

Expected Behavior

To be able to converse as per the playground on enclosing an image / document

Current Behavior

botocore.exceptions.EventStreamError: An error occurred (validationException) when calling the ConverseStream operation: The model returned the following errors: Input is too long for requested model.

Reproduction Steps

### Possible Solution _No response_ ### Additional Information/Context _No response_ ### SDK version used 1.35.57 ### Environment details (OS name and version, etc.) Mac OS Sonoma, Python 3.12.5
tim-finnigan commented 1 week ago

Thanks for reaching out. Here is the converse_stream documentation for reference. The command is calling the Bedrock ConverseStream API, and it looks like the issue here is with the API validation. I'm not sure why the behavior isn't consistent with the console.

Can you provide a complete code snippet for reproducing the issue? You mentioned using ChatBedrock, so I'm also wondering if the issue could be with the third-party integration. If you want to share debug logs as well (with any sensitive info redacted) by adding boto3.set_stream_logger('') to your script then that could also help provide more insight here.