Skip to content

Commit 1737130

Browse files
author
Maha Lakshmi Soumya Yalavarthi
committed
Fix temperature/top_p parameter conflict in Bedrock client
- Modified BedrockClient to handle temperature/top_p mutual exclusivity - Use top_p only when temperature is 0.0 to avoid ValidationException - Maintains backward compatibility with existing code - Resolves Claude model parameter validation errors
1 parent 3175d5b commit 1737130

File tree

1 file changed

+15
-1
lines changed
  • lib/idp_common_pkg/idp_common/bedrock

1 file changed

+15
-1
lines changed

lib/idp_common_pkg/idp_common/bedrock/client.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,21 @@ def invoke_model(
271271
# Initialize inference config with temperature
272272
inference_config = {"temperature": temperature}
273273

274-
# Skip top_p entirely to avoid conflicts with temperature
274+
# Handle top_p parameter - only use if temperature is 0 or not specified
275+
# Some models don't allow both temperature and top_p to be specified
276+
if top_p is not None and temperature == 0.0:
277+
# Convert top_p to float if it's a string
278+
if isinstance(top_p, str):
279+
try:
280+
top_p = float(top_p)
281+
except ValueError:
282+
logger.warning(f"Failed to convert top_p value '{top_p}' to float. Not using top_p.")
283+
top_p = None
284+
285+
if top_p is not None:
286+
inference_config["topP"] = top_p
287+
# Remove temperature when using top_p to avoid conflicts
288+
del inference_config["temperature"]
275289

276290
# Handle max_tokens parameter
277291
if max_tokens is not None:

0 commit comments

Comments
 (0)