CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-dev-langchain4j--langchain4j-bedrock

AWS Bedrock integration for LangChain4j enabling Java applications to interact with various LLM providers through a unified interface

Overview
Eval results
Files

multimodal.mddocs/guides/

Multi-modal: Images and Documents

Process images and documents with multi-modal models.

Supported Models

  • Claude 3.x series (all variants)
  • Amazon Nova Pro

Image Processing

From URL

import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.data.message.ImageContent;
import dev.langchain4j.data.message.TextContent;

UserMessage message = UserMessage.from(
    TextContent.from("What's in this image?"),
    ImageContent.from("https://example.com/image.jpg")
);

ChatResponse response = model.chat(ChatRequest.builder()
    .messages(message)
    .build());

From Base64

String base64Image = "iVBORw0KGgoAAAANSUhEUgAAAAUA...";
UserMessage message = UserMessage.from(
    TextContent.from("Describe this diagram"),
    ImageContent.from(base64Image, "image/png")
);

ChatResponse response = model.chat(ChatRequest.builder()
    .messages(message)
    .build());

From File

import dev.langchain4j.data.image.Image;

Image image = Image.from("/path/to/image.png");
UserMessage message = UserMessage.from(
    TextContent.from("Analyze this chart"),
    ImageContent.from(image)
);

ChatResponse response = model.chat(ChatRequest.builder()
    .messages(message)
    .build());

Document Processing

import dev.langchain4j.data.message.DocumentContent;
import dev.langchain4j.data.document.Document;

Document pdfDoc = Document.from("/path/to/document.pdf");
UserMessage message = UserMessage.from(
    TextContent.from("Summarize this document"),
    DocumentContent.from(pdfDoc)
);

ChatResponse response = model.chat(ChatRequest.builder()
    .messages(message)
    .build());

Multiple Images

UserMessage message = UserMessage.from(
    TextContent.from("Compare these images"),
    ImageContent.from("https://example.com/image1.jpg"),
    ImageContent.from("https://example.com/image2.jpg")
);

ChatResponse response = model.chat(ChatRequest.builder()
    .messages(message)
    .build());

Supported Image Formats

  • JPEG (image/jpeg)
  • PNG (image/png)
  • GIF (image/gif)
  • WebP (image/webp)

Limitations

  • Model support: Not all Bedrock models support multi-modal inputs
  • Image size: Typically 5MB limit (varies by model)
  • Image count: Some models restrict number of images per request
  • Document types: PDF support varies by model

Example: Image Analysis

BedrockChatModel model = BedrockChatModel.builder()
    .region(Region.US_EAST_1)
    .modelId("anthropic.claude-3-5-sonnet-20241022-v2:0")
    .build();

// Analyze product image
Image productImage = Image.from("/path/to/product.jpg");
UserMessage message = UserMessage.from(
    TextContent.from("Describe this product and suggest marketing copy"),
    ImageContent.from(productImage)
);

ChatResponse response = model.chat(ChatRequest.builder()
    .messages(message)
    .build());

System.out.println(response.aiMessage().text());

Related:

  • Chat Models API
  • Model Reference

Install with Tessl CLI

npx tessl i tessl/maven-dev-langchain4j--langchain4j-bedrock

docs

index.md

README.md

tile.json