AWS Bedrock integration for LangChain4j enabling Java applications to interact with various LLM providers through a unified interface
Process images and documents with multi-modal models.
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());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());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());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());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());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: