fix: omit temperature param for Bedrock Claude Opus 4.7 (#5472)

* addconditionally pass temperature based on aws bedrock model id

* move to config

---------

Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
This commit is contained in:
Marcello Fitton
2026-04-21 14:39:42 -07:00
committed by GitHub
parent faf2dd998e
commit 38206a14b3

View File

@@ -35,6 +35,15 @@ class AWSBedrockLLM {
// Add other models here if identified
];
/**
* List of Bedrock models observed to not support the `temperature` inference parameter.
* @type {string[]}
*/
noTemperatureModels = [
"anthropic.claude-opus-4-7",
// Add other models here if identified
];
/**
* Initializes the AWS Bedrock LLM connector.
* @param {object | null} [embedder=null] - An optional embedder instance. Defaults to NativeEmbedder.
@@ -103,6 +112,21 @@ class AWSBedrockLLM {
return createBedrockCredentials(this.authMethod);
}
/**
* Gets the temperature configuration for the AWS Bedrock LLM.
* @param {number} temperature - The temperature to use.
* @returns {{temperature: number}} The temperature configuration object with the temperature value as a float.
*/
temperatureConfig(temperature = this.defaultTemp) {
if (typeof temperature !== "number") return {};
// So model names prefix `us.` and may not be exact matches - so we check with includes to see if the model
// substring matches any of the models in the noTemperatureModels array.
if (this.noTemperatureModels.some((model) => this.model.includes(model)))
return {};
return { temperature: parseFloat(temperature) };
}
/**
* Gets the configured AWS authentication method ('iam' or 'sessionToken').
* Defaults to 'iam' if the environment variable is invalid.
@@ -408,7 +432,7 @@ class AWSBedrockLLM {
messages: history,
inferenceConfig: {
maxTokens: maxTokensToSend,
temperature: temperature ?? this.defaultTemp,
...this.temperatureConfig(temperature),
},
system: systemBlock,
})
@@ -483,7 +507,7 @@ class AWSBedrockLLM {
messages: history,
inferenceConfig: {
maxTokens: maxTokensToSend,
temperature: temperature ?? this.defaultTemp,
...this.temperatureConfig(temperature),
},
system: systemBlock,
})