LlamaIndex Multi-Modal LLM Integration: AWS Bedrock
AWS Bedrock is a fully managed service that offers a choice of high-performing foundation models from leading AI companies through a single API, along with a broad set of capabilities you need to build generative AI applications with security, privacy, and responsible AI.
Installation
pip install llama-index-multi-modal-llms-bedrock
Usage
Here's how to use the AWS Bedrock multi-modal integration:
Basic Usage
from llama_index.multi_modal_llms.bedrock import BedrockMultiModal
from llama_index.core import SimpleDirectoryReader
from llama_index.core.schema import ImageDocument
# Initialize the model (credentials can be provided through environment variables)
llm = BedrockMultiModal(
model="anthropic.claude-3-haiku-20240307-v1:0", # or other Bedrock multi-modal models
temperature=0.0,
max_tokens=300,
region_name="eu-central-1", # make sure to use the region where the model access is granted
)
# Method 1: Load images using SimpleDirectoryReader
image_documents = SimpleDirectoryReader(
input_files=["path/to/image.jpg"]
).load_data()
# Method 2: Create image documents directly
image_doc = ImageDocument(
image_path="/path/to/image.jpg", # Local file path
# OR
image="base64_encoded_image_string", # Base64 encoded image
)
# Get a completion with both text and image
response = llm.complete(
prompt="Describe this image in detail:",
image_documents=image_documents, # or [image_doc]
)
print(response.text)
AWS Authentication
You can authenticate with AWS Bedrock in several ways:
- Environment variables:
export AWS_ACCESS_KEY_ID=your_access_key
export AWS_SECRET_ACCESS_KEY=your_secret_key
export AWS_REGION=us-east-1 # optional
- Explicit credentials:
llm = BedrockMultiModal(
model="anthropic.claude-3-haiku-20240307-v1:0",
aws_access_key_id="your_access_key",
aws_secret_access_key="your_secret_key",
region_name="eu-central-1",
)
- AWS CLI configuration:
aws configure
- IAM role-based authentication (when running on AWS services like EC2, Lambda, etc.)
Supported Models
Currently supported multi-modal models in AWS Bedrock:
anthropic.claude-3-sonnet-20240229-v1:0anthropic.claude-3-haiku-20240307-v1:0anthropic.claude-3-opus-20240229-v1:0anthropic.claude-3-5-sonnet-20240620-v1:0anthropic.claude-3-5-sonnet-20241022-v2:0anthropic.claude-3-5-haiku-20241022-v1:0
Advanced Usage
# Using multiple images
image_docs = SimpleDirectoryReader(
input_files=["image1.jpg", "image2.jpg"]
).load_data()
response = llm.complete(
prompt="Compare these two images:", image_documents=image_docs
)
# Custom parameters
llm = BedrockMultiModal(
model="anthropic.claude-3-haiku-20240307-v1:0",
temperature=0.0,
max_tokens=300,
timeout=60.0, # API timeout in seconds
max_retries=10, # Maximum number of API retries
additional_kwargs={
# Add other model-specific parameters
},
)
# Response includes token counts
print(f"Input tokens: {response.additional_kwargs['input_tokens']}")
print(f"Output tokens: {response.additional_kwargs['output_tokens']}")
Development
To install development dependencies:
pip install -e ".[dev]"
To run tests:
pytest tests/
License
This project is licensed under the MIT License.
Metadata
Release files for llama-index-multi-modal-llms-bedrock 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llama_index_multi_modal_llms_bedrock-0.2.1.tar.gz | 7.0 kB | Without provenance | Details for llama_index_multi_modal_llms_bedrock-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llama_index_multi_modal_llms_bedrock-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for llama_index_multi_modal_llms_bedrock-0.2.1-py3-none-any.whl |
Total release size: 15.1 kB
Release files / llama_index_multi_modal_llms_bedrock-0.2.1.tar.gz
| Download URL | llama_index_multi_modal_llms_bedrock-0.2.1.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a4522ae47797e45d4515c423d74a8d4c73c31518f22bcb1f05abf006738dae5
|
|
BLAKE2b-256 checksum How to use checksums |
a8bf22ef726a21a2de23a097eaf240c0246129d025eb30538c0286c8cee3f05b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Release files / llama_index_multi_modal_llms_bedrock-0.2.1-py3-none-any.whl
| Download URL | llama_index_multi_modal_llms_bedrock-0.2.1-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f824d06c8bcd0b64e9fb712fbab2c383d9e561eaf7638573ff24b5571ebc480f
|
|
BLAKE2b-256 checksum How to use checksums |
b98a38c644913a2f98de0c69da2b1f7e8b4dabd7d56af41ccf0d2f7c957a8ad9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Security for llama-index-multi-modal-llms-bedrock 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.