抢占先机
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 |
最大 token 数 | 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
有关更多详细信息,请参考聊天属性文档。
基于文本的聊天补全非常简单
String response = ChatClient.create(chatModel)
.prompt("Tell me a joke about AI.")
.call()
.content();
Nova Pro 和 Lite 支持多模态输入,支持处理文本和视觉数据。Spring AI 提供了一个可移植的 多模态 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
图像:,以及文本消息
"Explain what do you see on this picture?"
,并生成如下响应:
图像显示了装有几块水果的金属水果篮的特写视图...
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
视频 ,以及文本消息
"Explain what do you see in this video?"
,并生成如下响应:
视频显示了一群小鸡(也称为雏鸡)挤在一起,在某个表面上...
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(由 Spring AI 提供支持)集成了 Amazon Bedrock Nova 模型。此集成提供
有关使用 Tanzu AI Server 部署 AI 应用程序的更多信息,请访问 VMware Tanzu AI 文档。
通过 Converse API 将 Spring AI 与 Amazon Bedrock Nova 模型集成,为构建先进的对话式应用程序提供了强大的功能。Nova Pro 和 Lite 为开发跨文本、图像、视频和文档的多模态体验提供了全面的工具。函数调用通过支持与外部工具和服务交互,进一步扩展了这些功能。
立即开始使用 Nova 模型和 Spring AI 构建先进的 AI 应用程序!