-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Python: Fix BedrockChatClient sending invalid toolChoice "none" to Bedrock API #4535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||||||
| # Copyright (c) Microsoft. All rights reserved. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # type: ignore | ||||||||||||||||||||||||
| # Because the Bedrock client does not have typing, we are ignoring type issues in this module. | ||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import asyncio | ||||||||||||||||||||||||
|
|
@@ -288,14 +289,16 @@ class MyOptions(BedrockChatOptions, total=False): | |||||||||||||||||||||||
| env_file_path=env_file_path, | ||||||||||||||||||||||||
| env_file_encoding=env_file_encoding, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| if not settings.get("region"): | ||||||||||||||||||||||||
| settings["region"] = DEFAULT_REGION | ||||||||||||||||||||||||
| region = settings.get("region") or DEFAULT_REGION | ||||||||||||||||||||||||
| chat_model_id = settings.get("chat_model_id") | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if client is None: | ||||||||||||||||||||||||
| if client: | ||||||||||||||||||||||||
| self._bedrock_client = client | ||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||
| session = boto3_session or self._create_session(settings) | ||||||||||||||||||||||||
|
Comment on lines
+295
to
298
|
||||||||||||||||||||||||
| if client: | |
| self._bedrock_client = client | |
| else: | |
| session = boto3_session or self._create_session(settings) | |
| if client is not None: | |
| self._bedrock_client = client | |
| else: | |
| if boto3_session is not None: | |
| session = boto3_session | |
| else: | |
| session = self._create_session(settings) |
Copilot
AI
Mar 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the streaming path, parsed_response.finish_reason is already normalized by _process_converse_response (via _map_finish_reason). Mapping it again with _map_finish_reason turns values like "stop" into None, so streamed ChatResponseUpdate.finish_reason will be incorrect/missing. Use parsed_response.finish_reason directly (or capture the raw Bedrock completion reason before mapping).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The header
# type: ignoredoes not disable type checking for the module in mypy/pyright (mypy uses# mypy: ignore-errors, pyright uses# pyright: ignore). As written, this comment is misleading and may not achieve the intended suppression; consider removing it or switching to the correct per-tool directive / targeted ignores.