Skip to content

Commit 3e771ec

Browse files
ja-botmoonbox3
andauthored
Python: Add missing index in Bedrock FunctionCallContent instantiation (#12203)
### Motivation and Context The current implementation of `BedrockChatCompletion` does not correctly initialize `FunctionCallContent` instances when using the Converse Stream API, as the index is not set. As a result, when adding two consecutive `FunctionCallContent` instances that belong to different function calls, the `__add__` method does not raise a `ContentAdditionException` exception, and the parameters are incorrectly merged. ### Description This PR ensures proper initialization of the index in `FunctionCallContent` instances by using the `contentBlockIndex` value returned by the Converse Stream API in both delta and start content block messages. This prevents parameters from different function calls from being merged. See: - https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ContentBlockDeltaEvent.html - https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ContentBlockStartEvent.html Closes #12202 ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 Co-authored-by: Javier Cruz <me@javiercruz.com> Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
1 parent 53e080e commit 3e771ec

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

python/semantic_kernel/connectors/ai/bedrock/services/bedrock_chat_completion.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def _parse_content_block_start_event(self, event: dict[str, Any]) -> StreamingCh
321321
FunctionCallContent(
322322
id=event["contentBlockStart"]["start"]["toolUse"]["toolUseId"],
323323
name=event["contentBlockStart"]["start"]["toolUse"]["name"],
324+
index=event["contentBlockStart"]["contentBlockIndex"],
324325
)
325326
)
326327

@@ -350,6 +351,7 @@ def _parse_content_block_delta_event(
350351
else FunctionCallContent(
351352
arguments=event["contentBlockDelta"]["delta"]["toolUse"]["input"],
352353
inner_content=event,
354+
index=event["contentBlockDelta"]["contentBlockIndex"],
353355
)
354356
]
355357

0 commit comments

Comments
 (0)