": { "message": "InvokeModelWithResponseStream: operation error Bedrock Runtime:...
🚨 错误信息
{
"error": {
"message": "InvokeModelWithResponseStream: operation error Bedrock Runtime: InvokeModelWithResponseStream, https response error StatusCode: 400, RequestID: 2a8585e0-bbc4-42e5-9da6-a7c4dc33d789, ValidationException: `temperature` and `top_p` cannot both be specified for this model. Please use only one. (request id: 20251123093404748958779Ji8HQgSg) (request id: 20251123093401431850524ZwGXhG4m) (request id: 20251123093332406922867Km14e3Tt)",
"type": "rix_api_error",
"param": "",
"code": null
}
}
🤖 AI解决方案
报错分析报告
1. 错误翻译
原文:`temperature` and `top_p` cannot both be specified for this model. Please use only one.
译文:该模型不能同时指定 `temperature` 和 `top_p` 参数。请只使用其中一个。
2. 原因分析
根本原因:在使用 Bedrock Runtime 服务调用模型时,同时设置了temperature 和 top_p 这两个冲突的采样参数。
错误位置:在调用 InvokeModelWithResponseStream 方法的请求参数配置中。
3. 解决方案
// ✅ 正确的参数配置方式(二选一)
// 方案1:使用 temperature 参数
const params = {
modelId: "your-model-id",
body: JSON.stringify({
prompt: "你的提示词",
temperature: 0.7, // 只使用 temperature
max_tokens: 100
})
};
// 方案2:使用 top_p 参数
const params = {
modelId: "your-model-id",
body: JSON.stringify({
prompt: "你的提示词",
top_p: 0.9, // 只使用 top_p
max_tokens: 100
})
};
4. ️ 预防措施
- 参数选择策略: -
- 参数验证:在发送请求前添加参数检查逻辑,确保不会同时提交冲突的参数配置。
temperature:控制输出的随机性(0=确定性,1=高度随机)
- top_p:基于概率质量的核采样(通常0.9的效果较好)
- 根据具体需求选择最适合的参数
---
提醒:不同模型可能有不同的参数限制,建议查阅对应模型的官方文档了解具体参数要求。