领先一步
VMware 提供培训和认证,助您加速进步。
了解更多Amazon Bedrock Nova 模型代表了新一代的基础模型,支持从文本和图像理解到视频到文本分析的广泛用例。
通过Spring AI Bedrock Converse API 集成,开发人员可以无缝连接到这些先进的 Nova 模型,并以最少的精力构建复杂的对话式应用程序。
这篇博文介绍了 Amazon Nova 模型的主要功能,演示了它们与 Spring AI 的 Bedrock Converse API 的集成,并提供了文本、图像、视频、文档处理和函数调用的实际示例。
Amazon Nova 提供三个级别的模型——Nova Pro、Nova Lite 和 Nova Micro——以满足不同的性能和成本要求。
| 规格 | Nova Pro | Nova Lite | Nova Micro |
|---|---|---|---|
| 模态 | 文本、图像、视频转文本 | 文本、图像、视频转文本 | 文本 |
| 模型 ID | amazon.nova-pro-v1:0 | amazon.nova-lite-v1:0 | amazon.nova-micro-v1:0 |
| 最大令牌 | 300K | 300K | 128K |
Nova Pro 和 Lite 支持多模态功能,包括文本、图像和视频输入,而 Nova Micro 则针对文本交互进行了优化,成本更低。
AWS 配置:您需要
Spring AI 依赖项:将 Spring AI Bedrock Converse starter 添加到您的 Spring Boot 项目中
Maven:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bedrock-converse-spring-boot-starter</artifactId>
</dependency>
Gradle:
dependencies {
implementation 'org.springframework.ai:spring-ai-bedrock-converse-spring-boot-starter'
}
应用程序配置:为 Amazon Bedrock 配置 application.properties
spring.ai.bedrock.aws.region=us-east-1
spring.ai.bedrock.aws.access-key=${AWS_ACCESS_KEY_ID}
spring.ai.bedrock.aws.secret-key=${AWS_SECRET_ACCESS_KEY}
spring.ai.bedrock.aws.session-token=${AWS_SESSION_TOKEN}
spring.ai.bedrock.converse.chat.options.model=amazon.nova-pro-v1:0
spring.ai.bedrock.converse.chat.options.temperature=0.8
spring.ai.bedrock.converse.chat.options.max-tokens=1000
有关更多详细信息,请参阅 Chat Properties 文档。
基于文本的聊天补全非常简单。
String response = ChatClient.create(chatModel)
.prompt("Tell me a joke about AI.")
.call()
.content();
Nova Pro 和 Lite 支持多模态输入,可处理文本和视觉数据。Spring AI 提供了一个可移植的 Multimodal API,支持 Bedrock Nova 模型。
Nova Pro 和 Lite 支持多种 图像模态。这些模型可以分析图像,回答有关图像的问题,对图像进行分类,并根据提供的指令生成摘要。它们支持 image/jpeg、image/png、image/gif 和 image/webp 格式的 base64 编码图像。
将用户文本与图像结合的示例
String response = ChatClient.create(chatModel)
.prompt()
.user(u -> u.text("Explain what do you see on this picture?")
.media(Media.Format.IMAGE_PNG, new ClassPathResource("/test.png")))
.call()
.content();
此代码处理 test.png 图像:
以及文本消息 “请解释一下你在这张图片上看到了什么?”,并生成类似以下的响应:
图片显示了一个装有几种水果的线筐的特写视图……
Amazon Nova Pro/Lite 模型支持在负载中处理单个 视频模态,可以是以 base64 格式提供,也可以是通过 Amazon S3 URI 提供。
支持的视频格式包括 video/x-matros、video/quicktime、video/mp4、video/webm、video/x-flv、video/mpeg、video/x-ms-wmv 和 image/3gpp。
将用户文本与视频结合的示例
String response = ChatClient.create(chatModel)
.prompt()
.user(u -> u.text("Explain what do you see in this video?")
.media(Media.Format.VIDEO_MP4, new ClassPathResource("/test.video.mp4")))
.call()
.content();
此代码处理 test.video.mp4 视频
以及文本消息 “请解释一下你在这段视频中看到了什么?”,并生成类似以下的响应:
视频显示一群小鸡挤在一起……
Nova Pro/Lite 支持两种 文档模态。
将用户文本与媒体文档结合的示例
String response = ChatClient.create(chatModel)
.prompt()
.user(u -> u.text(
"You are a very professional document summarization specialist. Please summarize the given document.")
.media(Media.Format.DOC_PDF, new ClassPathResource("/spring-ai-reference-overview.pdf")))
.call()
.content();
此代码处理 spring-ai-reference-overview.pdf 文档:
以及文本消息,并生成类似以下的响应:
介绍
- Spring AI 旨在简化具有人工智能 (AI) 功能的应用程序的开发,目标是避免不必要的复杂性……
Nova 模型支持 工具/函数调用,用于与外部工具集成。
@Bean
@Description("Get the weather in a location. Return temperature in Celsius or Fahrenheit.")
public Function<WeatherRequest, WeatherResponse> weatherFunction() {
return new MockWeatherService();
}
String response = ChatClient.create(this.chatModel)
.prompt("What's the weather like in Boston?")
.function("weatherFunction") // bean name
.inputType(WeatherRequest.class)
.call()
.content();
VMware Tanzu Platform 10 通过 VMware Tanzu AI Server 集成了 Amazon Bedrock Nova 模型,该服务器由 Spring AI 提供支持。此集成提供了:
有关使用 Tanzu AI Server 部署 AI 应用程序的更多信息,请访问 VMware Tanzu AI 文档。
Spring AI 通过 Converse API 与 Amazon Bedrock Nova 模型集成,为构建高级会话应用程序提供了强大的功能。Nova Pro 和 Lite 为跨文本、图像、视频和文档开发多模态体验提供了全面的工具。函数调用通过启用与外部工具和服务的交互,进一步扩展了这些功能。
立即开始使用 Nova 模型和 Spring AI 构建高级 AI 应用程序!