Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode:...
错误信息
InvokeModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestID: fb0a7357-06c6-4419-bb35-dbf7a6d57470, ValidationException: `temperature` and `top_p` cannot both be specified for this model. Please use only one. (request id: 20251214234009962908297dZgs70P3) (request id: 20251214234001204205887uMGO5Ida) (request id: 202512142340011576813578izL94AT) (request id: 20251214233918902681701vaR6bedC)
AI 解决方案
报错分析
1. 错误翻译
原文:`temperature` and `top_p` cannot both be specified for this model. Please use only one.
译文:此模型不能同时指定 `temperature` 和 `top_p` 参数,请仅使用其中一个。
2. 原因分析
根本原因:你在调用 AWS Bedrock 的模型时,同时提供了
temperature 和 top_p 这两个文本生成参数。然而,该特定模型的设计限制要求这两个参数只能使用其中一个,不能同时设置。具体位置:这发生在调用 InvokeModelWithResponseStream 方法时,请求体中的模型调用参数配置部分。
3. 解决方案
根据你使用的模型和API结构,修改你的调用参数。选择方案一或方案二。
方案一:使用 temperature(推荐用于更可控、可复现的随机性)
// 请求体示例 (假设使用 Claude 模型)
{
"modelId": "anthropic.claude-3-haiku-20240307-v1:0",
"contentType": "application/json",
"accept": "application/json",
"body": "{\"anthropic_version\":\"bedrock-2023-05-31\",\"max_tokens\":1024,\"temperature\":0.7,\"messages\":[...]}"
// 注意:移除了 "top_p" 字段,只保留 "temperature"
}
方案二:使用 top_p(推荐用于更高质量、聚焦的词汇选择)
// 请求体示例 (假设使用 Claude 模型)
{
"modelId": "anthropic.claude-3-haiku-20240307-v1:0",
"contentType": "application/json",
"accept": "application/json",
"body": "{\"anthropic_version\":\"bedrock-2023-05-31\",\"max_tokens\":1024,\"top_p\":0.9,\"messages\":[...]}"
// 注意:移除了 "temperature" 字段,只保留 "top_p"
}
4. ️ 预防措施
请检查您的模型调用代码,确保
temperature 和 top_p 参数没有同时出现在请求体中。