Skip to content

Commit 6b398c9

Browse files
committed
fix: better bedrock message handler close langgenius#10976
Signed-off-by: yihong0618 <[email protected]>
1 parent 1cb5a12 commit 6b398c9

File tree

1 file changed

+10
-0
lines changed
  • api/core/model_runtime/model_providers/bedrock/llm

1 file changed

+10
-0
lines changed

api/core/model_runtime/model_providers/bedrock/llm/llm.py

+10
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ def _generate_with_converse(
194194
if model_info["support_tool_use"] and tools:
195195
parameters["toolConfig"] = self._convert_converse_tool_config(tools=tools)
196196
try:
197+
# for issue #10976
198+
# add placeholder for conversation because that bedrock-runtime doesn't support two users
199+
# FIXME: when bedrock-runtime support two users, we should remove this placeholder
200+
conversations_list = parameters["messages"]
201+
# if two roles next to each other, insert a placeholder('role': 'assistant') for conversation
202+
for i in range(len(conversations_list) - 1):
203+
if conversations_list[i]["role"] == "user" and conversations_list[i + 1]["role"] == "user":
204+
# insert a placeholder for assistant and it can not be empty string
205+
conversations_list.insert(i + 1, {"role": "assistant", "content": [{"text": "placeholder"}]})
206+
197207
if stream:
198208
response = bedrock_client.converse_stream(**parameters)
199209
return self._handle_converse_stream_response(

0 commit comments

Comments
 (0)