

# 调用 Amazon Nova 理解模型
<a name="invoke"></a>

**注意**  
本文档适用于 Amazon Nova 版本 1。有关如何向 Amazon Nova 2 发送请求的信息，请访问[核心推理](https://docs.aws.amazon.com/nova/latest/nova2-userguide/core-inference.html)。

Amazon Nova 多模态理解模型可用于通过 Invoke API（[InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html)、[InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html)）和 Converse API（[Converse](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html) 和 [ConverseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html)）进行推理。要创建对话应用程序，请参阅 [Carry out a conversation with the converse API operations](https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html)。这两种 API 方法（Invoke 和 Converse）都遵循非常相似的请求模式，详见下文

Invoke API 和 Converse API 之间的主要区别如下：
+ Converse 不支持像 topK 这样的推理参数，这些参数需要在 `additionalModelRequestFields` 中传递，而在 Invoke API 中，它可以直接在推理参数中传递。
+ 文档支持仅限于 Converse API，Invoke API 不支持。
+ Invoke API 和 Converse API 构造的回复解析格式不同。
+ `ConverseStream` 和 `InvokeModelWithStreaming` 之间的回复流不同。

要调用 Amazon Nova 模型，您必须在计划使用这些模型的每个区域[申请访问 Amazon Bedrock 基础模型](https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html#getting-started-model-access)。

**Topics**
+ [Messages API 概述](#messages-api-overview)
+ [使用系统提示](#utilizing-system-prompt)
+ [使用 Converse API](using-converse-api.md)
+ [使用 Invoke API](using-invoke-api.md)
+ [完整的请求架构](complete-request-schema.md)

## Messages API 概述
<a name="messages-api-overview"></a>

Amazon Nova 理解模型使用 Messages API，它支持提交包含文本、图像、视频和文档的输入消息的结构化列表。然后，模型在对话中生成下一条消息。Messages API 支持单一查询和无状态多轮对话，允许创建聊天机器人和虚拟助手应用程序。API 管理用户和 Amazon Nova 模型（助手）之间的对话交流。

Amazon Nova 模型经过训练，可在交替的用户和助手对话回合中进行操作。创建新消息时，您可以使用消息参数指定之前的对话回合。模型随后在对话中生成接下来的消息。

每条输入消息都必须是一个包含角色和内容的对象。用户可以使用用户角色指定一条消息，也可以包含多条同时具有用户和助手角色的消息。第一条消息必须始终使用用户角色。如果采用预填充来自 Amazon Nova 的回复的技术（通过包含一条具有助手角色的最终消息），则模型将继续根据所提供的内容进行回复。这种方法仍会产生以助手角色生成的回复。

以下是单个用户消息：

```
[{
  "role": "user",
  "content": [{"text":"Hello, Nova"}]
}]
```

 以下是多个对话回合示例：

```
[
  {"role": "user", "content": [{"text": "Hello there."}]},
  {"role": "assistant", "content": [{"text": "Hi, I'm Chatbot trained to answer your questions. How can I help you?"}]},
  {"role": "user", "content": [{"text": "Can you explain LLMs in plain English?"}]}
]
```

以下是部分填充的 Amazon Nova 回复示例：

```
[
  {"role": "user", "content": [{"text":"Please describe yourself using only JSON"}]},
  {"role": "assistant", "content": [{"text":"Here is my JSON description:\n{"}]}
]
```

有关创建 Amazon Nova 模型提示的信息，请参阅 [文本理解提示最佳实践](prompting-text-understanding.md)。

## 使用系统提示
<a name="utilizing-system-prompt"></a>

您可以在请求中包含系统提示。系统提示允许您为 Amazon Nova 提供上下文和说明，例如指定特定的目标或角色。在 `system` 字段中指定系统提示，如以下示例所示：

```
[
   {"text": "You are an expert SaS analyst......"}
]
```

有关如何包含系统提示的示例，请参阅以下各节：
+ [使用 Converse API](https://docs.aws.amazon.com/nova/latest/userguide/using-converse-api.html)
+ [使用 Invoke API](https://docs.aws.amazon.com/nova/latest/userguide/using-invoke-api.html)
+ [完整的请求架构](https://docs.aws.amazon.com/nova/latest/userguide/complete-request-schema.html)