Using Document Chat with the Amazon Bedrock Converse API
Learn the basics of using Amazon Bedrock Converse API document chat to directly pass PDF, text, HTML, and other file formats directly to Amazon Bedrock.
Jason Stehle
Amazon Employee
Published Jun 25, 2024
In a previous article, I provided a quick tutorial on the Amazon Bedrock Converse API. In this article, I will walk through a simple document chat example to illustrate how it works.
The Converse API provides a consistent way to access large language models (LLMs) on Amazon Bedrock. It supports turn-based messages between the user and the generative AI model. It also provides convenient structures for supporting image and document data types.
Document chat is a capability that allows the developer to send a document directly to Amazon Bedrock without needing to first extract the text of the document. I recommend using document chat with the following formats:
- PDF
- HTML
- Word (.docx, .doc)
- Markdown (.md)
- Text (.txt)
Note that you will likely have the most success using document chat with flowing text formats. For example, don't expect embedded images in a PDF to be included along with the text, or tabular information to come through cleanly.
You can find the documentation for the DocumentBlock’s supported file types here.
You’ll want to have the latest AWS SDK and Amazon Bedrock model access configured before proceeding:
- Set up the Boto3 AWS SDK and Python: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html
- Select an AWS region that supports the Anthropic Claude 3 Sonnet model. I'm using us-west-2 (Oregon). You can check the documentation for model support by region.
- Configure Amazon Bedrock model access for your account and region. Example here: https://catalog.workshops.aws/building-with-amazon-bedrock/en-US/prerequisites/bedrock-setup
- If you don’t have your own local integrated development environment, you can try AWS Cloud9. Setup instructions here: https://catalog.workshops.aws/building-with-amazon-bedrock/en-US/prerequisites/cloud9-setup
- Large language models are non-deterministic. You should expect different results than those shown in this article.
- If you run this code from your own AWS account, you will be charged for the tokens consumed.
- I generally subscribe to a “Minimum Viable Prompt” philosophy. You may need to write more detailed prompts for your use case.
- Not every model supports all of the capabilities of the Converse API, so it’s important to review the supported model features in the official documentation.
NOTE: The code below requires a local PDF-format file named “amazon-leadership-principles-070621-us.pdf”. You can download this file from the Amazon Leadership Principles page, or alter the code to use a document of your choosing. See the Converse API DocumentBlock documentation for the list of supported document formats.
This will generate a response similar to the following:
Based on the leadership principles outlined in the document, I believe the most important one for an intern to adopt at the start of their career is "Learn and Be Curious".
Here's why I think this principle is particularly crucial for someone just starting out:
- As an intern or someone new to the workforce, there is a vast amount to learn - about the company, the industry, professional skills, and more. Having a mindset of continuous learning and curiosity will allow the intern to soak up as much knowledge and experience as possible during this formative stage.
- The principle states "Leaders are never done learning and always seek to improve themselves." This growth mindset is invaluable early in one's career when the potential for development is immense.
- Being curious about "new possibilities and acting to explore them" as mentioned in the principle can open doors to new opportunities, projects, and career paths that the intern may not have initially considered.
- Many of the other principles like "Customer Obsession", "Invent and Simplify", and "Think Big" require a foundation of learning, curiosity, and always seeking to improve oneself.
While all the leadership principles are important, embracing a mindset of continuous learning and curiosity can set an intern up for success by allowing them to rapidly acquire new skills, adapt to new situations, and uncover new avenues for growth and development in their early career stage.
I hope this gave you a good sense of how Amazon Bedrock Converse API's new document chat capability can help simplify handling documents with Amazon Bedrock!
- Not every model supports every capability of the Converse API, so it’s important to review the supported model features in the official documentation.
- You can find more generative AI hands-on activities at the Building with Amazon Bedrock workshop guide.
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.