

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 了解 Amazon Bedrock 中的智能提示路由
<a name="prompt-routing"></a>

Amazon Bedrock 智能提示路由提供了单个无服务器端点，可在同一模型系列内的不同基础模型之间高效路由请求。它可以针对每个请求动态预测每个模型的响应质量，然后将请求路由到响应质量最好的模型。这有助于优化响应质量和成本。

**Topics**
+ [智能提示路由支持的区域和模型](#prompt-routing-support)
+ [优势](#prompt-routing-benefits)
+ [默认和配置的提示路由器](#prompt-routing-types)
+ [注意事项和限制](#prompt-routing-limitations)
+ [提示路由器标准和备用模型](#prompt-router-criteria)
+ [智能提示路由的工作方式](#prompt-routing-works)
+ [如何使用智能提示路由](#prompt-routing-use)

## 智能提示路由支持的区域和模型
<a name="prompt-routing-support"></a>

智能提示路由可用于不同类型的模型。以下列表描述了对不同类型的 Amazon Bedrock 型号的支持：
+ **单区域模型支持**-列出支持向一个区域中的基础模型发送推理请求的区域。 AWS 有关 Amazon Bedrock 上可用型号的完整列表，请参阅[Amazon Bedrock 中支持的根基模型](models-supported.md)。
+ **跨区域推理配置文件支持**-列出支持使用跨区域推理配置文件的区域，跨区域推理配置文件支持向地理区域内多个 AWS 区域的基础模型发送推理请求。推理配置文件在模型 ID 前有一个前缀，表示其地理区域（例如`us.`，`apac`）。有关 Amazon Bedrock 中可用推理配置文件的更多信息，请参阅。[支持推理配置文件的区域和模型](inference-profiles-support.md)

下表显示了支持智能提示路由的模型：


| Provider | 模型 | 模型 ID | 支持单区域模型 | 跨区域推理配置文件支持 | 
| --- | --- | --- | --- | --- | 
| Amazon | Nova Lite | 亚马逊。 nova-lite-v1:0 |  us-east-1 us-gov-west-1  |  ap-northeast-1 ap-northeast-2 ap-south-1 ap-southeast-2 eu-central-1 eu-west-1 eu-west-3 us-east-1 us-east-2 us-west-2  | 
| Amazon | Nova Pro | 亚马逊。 nova-pro-v1:0 |  us-east-1 us-gov-west-1  |  ap-northeast-1 ap-northeast-2 ap-south-1 ap-southeast-2 eu-central-1 eu-west-1 eu-west-3 us-east-1 us-east-2 us-west-2  | 
| Anthropic | Claude 3 Haiku | anthropic.claude-3-haiku-20240307-v1:0 |  ap-northeast-1 ap-northeast-2 ap-south-1 ap-southeast-2 eu-central-1 eu-west-1 eu-west-3 us-east-1 us-gov-west-1 us-west-2  |  ap-northeast-1 ap-northeast-2 ap-south-1 ap-southeast-2 eu-central-1 eu-west-1 eu-west-3 us-east-1 us-east-2 us-gov-east-1 us-west-2  | 
| Anthropic | Claude 3.5 Haiku | anthropic.claude-3-5-haiku-20241022-v1:0 |  us-west-2  |  us-east-1 us-east-2 us-west-2  | 
| Anthropic | Claude 3.5 Sonnet | anthropic.claude-3-5-sonnet-20240620-v1:0 |  ap-northeast-1 ap-northeast-2 eu-central-1 us-east-1 us-gov-west-1 us-west-2  |  ap-northeast-1 ap-northeast-2 ap-south-1 ap-southeast-2 eu-central-1 eu-west-1 eu-west-3 us-east-1 us-east-2 us-gov-east-1 us-west-2  | 
| Anthropic | Claude 3.5 Sonnet v2 | anthropic.claude-3-5-sonnet-20241022-v2:0 |  ap-southeast-2 us-west-2  |  ap-northeast-1 ap-south-1 ap-southeast-2 eu-west-3 us-east-1 us-east-2 us-west-2  | 
| Meta | Llama 3.1 70B Instruct | meta.llama3-1-70 1:0 b-instruct-v |  us-west-2  |  us-east-1 us-east-2 us-west-2  | 
| Meta | Llama 3.1 8B Instruct | meta.llama3-1-8 1:0 b-instruct-v |  us-west-2  |  us-east-1 us-east-2 us-west-2  | 
| Meta | Llama 3.2 11B Instruct | meta.llama3-2-11 1:0 b-instruct-v | 不适用 |  us-east-1 us-east-2 us-west-2  | 
| Meta | Llama 3.2 90B Instruct | meta.llama3-2-90 1:0 b-instruct-v | 不适用 |  us-east-1 us-east-2 us-west-2  | 
| Meta | Llama 3.3 70B Instruct | meta.llama3-3-70 1:0 b-instruct-v |  us-east-2  |  us-east-1 us-east-2 us-west-2  | 

## 优势
<a name="prompt-routing-benefits"></a>
+ **优化的响应质量和成本：**将提示路由到不同的基础模型，以最低的成本实现最佳响应质量。
+ **简化的管理：**无需复杂的编排逻辑。
+ **具有前瞻性：**在新模型推出后将其纳入。

## 默认和配置的提示路由器
<a name="prompt-routing-types"></a>

使用智能提示路由时，可以使用 Amazon Bedrock 提供的默认提示路由器，也可以配置自己的提示路由器。

默认提示路由器是 Amazon Bedrock 提供的预先配置的路由系统。这些路由器具有预定义的设置，专为与特定的基础模型 out-of-the-box配合使用而设计。它们提供了一种简单的 ready-to-use解决方案，无需配置任何路由设置。在开始使用智能提示路由时，建议您尝试使用 Amazon Bedrock 提供的默认路由器。在预览版阶段，您可以选择使用 Anthropic 和 Meta 系列中的精选模型。

配置的提示路由器使您能够根据特定需求和偏好定义自己的路由配置。当您需要更好地掌控路由请求的方式以及要使用的模型时，它们更适合。配置的路由器可以根据响应质量指标和使用案例进行优化。在试用默认路由器后，您可以配置适合自己应用程序的专属路由器，在演练场中评测响应质量，然后在响应满足要求的情况下将其用于生产应用程序。

## 注意事项和限制
<a name="prompt-routing-limitations"></a>

以下是 Amazon Bedrock 中的智能提示路由的考虑因素和限制。
+ 智能提示路由仅针对英文提示进行了优化。
+ 智能提示路由无法根据特定于应用程序的性能数据调整路由决策或响应。
+ 智能提示路由并非总是能为独有或特殊的使用案例提供最佳路由。路由的有效性取决于初始训练数据。

## 提示路由器标准和备用模型
<a name="prompt-router-criteria"></a>

在配置提示路由器时，您可以指定路由标准，该标准用于根据响应质量差异来决定选择哪种模型用于处理请求。使用此标准来确定备用模型的响应应与其他模型的响应相近的程度。

### 备用模型
<a name="prompt-router-criteria-fallback"></a>

选择适合您的请求的备用模型。该模型用作可靠的基准。然后，您可以选择其他模型，通过与备用模型相比来提高准确率或降低成本。备用模型充当锚点，而路由标准根据响应质量差异确定何时切换到另一个模型。

### 响应质量差异
<a name="prompt-router-criteria-respquality"></a>

响应质量差异用于衡量备用模型与其他模型的响应之间的差异。值较小表示响应相似。值较高表示备用模型与其他模型之间的响应存在显著差异。

例如，10% 的响应质量差异意味着，假设备用模型 Claude Haiku3 的响应质量为 10%，那么仅当另一个模型（比如 Claude Sonnet3）的响应质量比 Claude Haiku3 的响应高 10% 时，路由器才会切换到后一个模型。

## 智能提示路由的工作方式
<a name="prompt-routing-works"></a>

1. 

**模型选择和路由器配置**

   选择要用于应用程序的模型系列。如果您使用的是默认提示路由器，则可以从 Anthropic 或 Meta 系列的模型中进行选择。如果您使用的是配置的提示路由器，则可以从其他模型中进行选择并配置路由标准。有关更多信息，请参阅 [如何使用智能提示路由](#prompt-routing-use)。

1. 

**传入请求分析**

   对于每个传入请求，系统都会分析提示以了解其内容和上下文。

1. 

**响应质量预测**

   Amazon Bedrock 会根据提示，预测所选系列中每个指定模型的响应质量。如果您配置了提示路由器，该路由器会将路由标准（即响应质量差异）纳入考量，如果未满足标准，它会将请求路由到您的指定备用模型。

1. 

**模型选择和请求转发**

   根据响应质量预测，Amazon Bedrock 可针对特定请求，动态选择可提供最佳响应质量和成本组合的模型。该请求随后会被转发到所选模型进行处理。

1. 

**响应处理**

   系统会检索来自所选模型的响应并将其返回给用户。该响应包含有关用于处理请求的模型的信息。

## 如何使用智能提示路由
<a name="prompt-routing-use"></a>

要开始使用智能提示路由，请使用 Amazon Bedrock 控制台或 AWS SDK。 AWS CLI

**注意**  
为了充分利用智能提示路由，您应该定期检查性能来利用新模型。要优化您的使用，请监控可用的性能和成本指标。

后续章节将介绍如何从控制台和 CLI 使用此功能。配置提示路由器后，Amazon Bedrock 将执行[智能提示路由的工作方式](#prompt-routing-works)中所述的步骤，从所选路由器中的一个模型生成响应。

------
#### [ console ]

要从 AWS 管理控制台使用智能提示路由，请执行以下操作：

1. 转到 Amazon Bedrock 控制台中的[提示路由器](https://console.aws.amazon.com/bedrock/home?region=us-east-1#/prompt-routers)中心。使用您的 AWS 凭证登录控制台。

1. 选择要使用的模型系列。如果您是首次使用该功能，则可以使用默认提示路由器进行实验。在预览版阶段，您可以从 Anthropic 或 Meta 系列中的模型进行选择。然后，您可以打开演练场并通过提示进行实验。
**注意**  
您必须在同一个系列中选择两个模型。

1. 在对默认路由器进行实验之后，您就可以配置自己的路由器了。您必须为路由器提供一个唯一名称，并可以选择提供描述。

1. 定义将提示路由到不同模型的路由规则。指定用于路由的模型、路由标准以及在未满足路由标准时要使用的备用模型。

1. 您现在可以打开演练场，尝试不同的提示来监控提示路由器的性能。通过分析系统如何路由提示以及每个模型的性能，您可以根据需要调整路由标准和模型，以优化性能和成本。

------
#### [ API ]

要通过 AWS CLI使用智能提示路由，请执行以下操作：

1. 在实验了默认提示路由器之后，您可以使用 [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreatePromptRouter.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreatePromptRouter.html) API 或 [https://docs.aws.amazon.com/cli/latest/reference/bedrock/create-prompt-router.html](https://docs.aws.amazon.com/cli/latest/reference/bedrock/create-prompt-router.html) CLI 命令创建能够处理智能提示路由的路由器。

   以下命令显示了创建提示路由器的示例，其中：
   + *<router-name>*是您的路由器的唯一名称。
   + *<region>*是您要创建路由器 AWS 区域 的地方。
   + *<modelA>*以及*<modelB>*可供选择的路由模型。例如 `anthropic.claude-3-5-sonnet-20240620-v1:0`。

   ```
   aws bedrock create-prompt-router \
       --prompt-router-name <router-name> \
       --models '[{"modelArn": "arn:aws:bedrock:<region>::foundation-model/<modelA>"}]' \ 
       --fallback-model '[{"modelArn": "arn:aws:bedrock:<region>::foundation-model/<modelB>"}]' \ 
       --routing-criteria '{"responseQualityDifference": 0.5}'
   ```

1. 使用 AWS CLI将您的提示发送到智能提示路由器。路由器将预测每个模型的响应质量，然后将请求路由到响应质量最好的模型。

1. 查看对您的请求的响应。它将包含有关所用模型和路由标准的信息。

1. 在使用提示路由器时，您还可以使用以下额外的 API 操作：
   + [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_GetPromptRouter.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_GetPromptRouter.html)
   + [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_ListPromptRouters.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_ListPromptRouters.html)
   + [https://docs.aws.amazon.com/bedrock/latest/APIReference/API_DeletePromptRouter.html](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_DeletePromptRouter.html)

------