diff --git a/server/utils/AiProviders/bedrock/index.js b/server/utils/AiProviders/bedrock/index.js index 2ac112bf..4338e7ca 100644 --- a/server/utils/AiProviders/bedrock/index.js +++ b/server/utils/AiProviders/bedrock/index.js @@ -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, })