Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes image type, adds document type for ChatBedrockConverse (#143)
## Description This PR fixes the image type supported by Bedrock Anthropic and other models. It also adds a new type for supporting documents. ### Image sample code ```python from langchain_core.messages import HumanMessage from langchain_aws import ChatBedrock llm = ChatBedrock( model_id="anthropic.claude-3-sonnet-20240229-v1:0", beta_use_converse_api=True ) # Convert image to bytes image_path = "images/random-image.jpg" image_bytes = None with open(image_path, "rb") as f: image_bytes = f.read() messages = [ HumanMessage( content=[ { "type": "image", "image": { "format": "jpeg", "source": { "bytes": image_bytes } } }, "What is this image about?" ] ) ] llm.invoke(messages) ``` ### Document sample code ```python from langchain_core.messages import HumanMessage from langchain_aws import ChatBedrock llm = ChatBedrock( model_id="anthropic.claude-3-sonnet-20240229-v1:0", beta_use_converse_api=True ) # Convert document to bytes doc_path = "documents/random-doc.pdf" doc_bytes = None with open(doc_path, "rb") as f: doc_bytes = f.read() messages = [ HumanMessage( content=[ { "type": "document", "document": { "format": "pdf", "name": "random-doc", "source": { "bytes": doc_bytes } } }, "What is this document about?" ] ) ] llm.invoke(messages) ``` Related to #75 Fixes #132
- Loading branch information