AWS Bedrock 对象结构
将 AWS Bedrock 集成到您的应用程序中,使您能够无缝利用托管在 AWS 上的多种 AI 模型。本节详细介绍了如何根据您的需求配置 AWS Bedrock endpoint。
示例配置
注意: AWS Bedrock endpoint 支持所有 Shared Endpoint Settings,包括
streamRate、titleModel、titleMethod、titlePrompt、titlePromptTemplate和titleEndpoint。下方显示的设置是 Bedrock 特有的,或具有 Bedrock 特有的默认值。
titleModel
键:
| Key | Type | Description | Example |
|---|---|---|---|
| titleModel | String | 指定用于生成对话标题的 Model。 | Recommended: anthropic.claude-3-haiku-20240307-v1:0. Set to "current_model" to use the same model as the chat. |
默认值: 未指定
示例:
streamRate
键:
| Key | Type | Description | Example |
|---|---|---|---|
| streamRate | Number | 设置每个新 token 的处理速率(以毫秒为单位)。 | This can help stabilize processing of concurrent requests and provide smoother frontend stream rendering. |
默认值: 未指定
示例:
availableRegions
键:
| Key | Type | Description | Example |
|---|---|---|---|
| availableRegions | Array | 指定您希望在 Bedrock 中使用的 AWS 区域。 | If provided, users will see a dropdown to select the region. If not selected, the default region is used. |
默认值: 未指定
示例:
models
键:
| Key | Type | Description | Example |
|---|---|---|---|
| models | Array of Strings | 指定可用于 Bedrock endpoint 的自定义模型 ID。 | When provided, these models appear in the model selector for Bedrock. |
默认: 未指定(使用默认的 Bedrock 模型列表)
示例:
inferenceProfiles
键:
| Key | Type | Description | Example |
|---|---|---|---|
| inferenceProfiles | Object (Record) | 将模型 ID 映射到用于跨区域推理的推理配置文件 ARN。键为模型 ID,值为推理配置文件 ARN 或环境变量引用。 | When a selected model matches a key, the corresponding ARN is used as the application inference profile. |
默认值: 未指定
示例:
注意:
- 推理配置 (Inference profiles) 支持跨区域推理,允许你将请求路由到不同 AWS 区域的模型。
- 值支持使用
${ENV_VAR}语法进行环境变量插值。 - 键中的模型 ID 必须与用户在 UI 中选择的模型相匹配
- 与
models字段配合使用,以在模型选择器中启用跨区域模型 ID。 - 有关创建和管理推理配置文件的完整指南,请参阅 AWS Bedrock Inference Profiles
组合示例:
guardrailConfig
键:
| Key | Type | Description | Example |
|---|---|---|---|
| guardrailConfig | Object | 用于过滤和审核模型输入与输出的 AWS Bedrock Guardrails 配置。 | Optional. When configured, all Bedrock requests will be validated against the specified guardrail. |
子键:
| Key | Type | Description | Example |
|---|---|---|---|
| guardrailIdentifier | String | 要应用的护栏的唯一标识符。 | Required when using guardrails. |
| guardrailVersion | String | 要使用的 guardrail 版本。 | Required when using guardrails. |
| trace | String | 控制用于调试的 guardrail 追踪输出。选项:"enabled"、"enabled_full" 或 "disabled"。 | Optional. Default: "disabled" |
| streamProcessingMode | String | 控制 guardrail 流处理模式。选项:"sync" 或 "async"。 | Optional. Default: "sync" |
示例:
注意:
- Guardrails 有助于通过过滤有害内容、PII 和其他敏感信息来确保负责任的 AI 使用。
guardrailIdentifier可以在 AWS Bedrock 控制台的 Guardrails 下找到- 在开发过程中将
trace设置为"enabled"或"enabled_full",以查看触发了哪些护栏策略。 - 将
streamProcessingMode设置为"async"以更快地流式传输响应(代价是安全护栏可能会在扫描完成前放行不当内容) - 在生产环境中,请将
trace设置为"disabled"以减小响应负载大小。
注意事项
- AWS Bedrock 身份验证通过环境变量进行配置。你可以使用
BEDROCK_AWS_PROFILE、AWS SDK 默认凭证提供程序链、用于 Bedrock API 密钥的BEDROCK_AWS_BEARER_TOKEN,或 Bedrock 特定的静态凭证。详情请参阅 AWS Bedrock 设置指南。
这篇指南怎么样?