llama-index multi-modal llms bedrock integration
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llama_index_multi_modal_llms_bedrock-0.2.0.tar.gz.
File metadata
- Download URL: llama_index_multi_modal_llms_bedrock-0.2.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3710721c6daae58f79e4eef82f088813093b040dd47f6af45aae995516616003
|
|
| MD5 |
9c5e5d4e228cc2dec37a23d6ca153ecf
|
|
| BLAKE2b-256 |
71967983bf65389911173b957d7fe64e88a985d185bcb630aefbc00ef8f117f3
|
File details
Details for the file llama_index_multi_modal_llms_bedrock-0.2.0-py3-none-any.whl.
File metadata
- Download URL: llama_index_multi_modal_llms_bedrock-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61b40bf74de3e0cfb33ee54adab613a3d6ddefa150991d8ea3a316a6d515007d
|
|
| MD5 |
d31f639cd9f34b4aea12ac530b715e4f
|
|
| BLAKE2b-256 |
8864364c32c57c5bd80a8094eb1e528f2da2851a5b11105e7b04ab96ebffc6d8
|