-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add Claude adaptive thinking effort support for Bedrock Converse #22
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: issue-17
Are you sure you want to change the base?
Changes from all commits
17309cf
f3ab376
093225d
746b469
d2aaaab
143532f
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 |
|---|---|---|
|
|
@@ -6,19 +6,21 @@ | |
|
|
||
| import json | ||
| import logging | ||
| from typing import Any | ||
| from typing import Any, Literal | ||
|
|
||
| import boto3 | ||
|
|
||
| from wags_llm.client.base import InvokeJsonResponse, LLMJsonClient | ||
| from wags_llm.client.exceptions import ( | ||
| LLMEmptyResponseError, | ||
| LLMInvalidEffortError, | ||
| LLMInvocationError, | ||
| LLMJsonDecodeError, | ||
| LLMResponseFormatError, | ||
| ) | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
| _VALID_EFFORT_LEVELS = ("high", "medium", "low") | ||
|
|
||
|
|
||
| class BedrockClaudeJsonClient(LLMJsonClient): | ||
|
|
@@ -31,6 +33,7 @@ def __init__( | |
| profile_name: str, | ||
| max_tokens: int = 300, | ||
| temperature: float = 0.0, | ||
| effort: Literal["high", "medium", "low"] | None = None, | ||
| ) -> None: | ||
| """Initialize the Bedrock Claude client. | ||
|
|
||
|
|
@@ -39,18 +42,26 @@ def __init__( | |
| :param profile_name: AWS profile name. | ||
| :param max_tokens: Maximum number of tokens to request from the model. | ||
| :param temperature: Sampling temperature. | ||
| :param effort: Optional adaptive thinking effort level for supported Claude models using Bedrock Converse: "high", "medium", "low", or None to use the model default. | ||
| :raise LLMInvalidEffortError: If effort is not "high", "medium", "low", or None. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, this was a claude-specific parameter. I think the custom error should live in this module. If I'm wrong, then we can leave it where its at |
||
| """ | ||
| if effort is not None and effort not in _VALID_EFFORT_LEVELS: | ||
| msg = f"Invalid effort '{effort}'; must be one of 'high', 'medium', 'low', or None." | ||
| raise LLMInvalidEffortError(msg) | ||
|
|
||
| _logger.debug( | ||
| "BedrockClaudeJsonClient config: model_id='%s', region_name='%s', profile_name='%s', max_tokens=%i, temperature=%f", | ||
| "BedrockClaudeJsonClient config: model_id='%s', region_name='%s', profile_name='%s', max_tokens=%i, temperature=%f, effort=%s", | ||
| model_id, | ||
| region_name, | ||
| profile_name, | ||
| max_tokens, | ||
| temperature, | ||
| effort, | ||
| ) | ||
| self.model_id = model_id | ||
| self.max_tokens = max_tokens | ||
| self.temperature = temperature | ||
| self.effort = effort | ||
|
|
||
| session = boto3.Session(profile_name=profile_name) | ||
| self._client = session.client("bedrock-runtime", region_name=region_name) | ||
|
|
@@ -98,6 +109,12 @@ def invoke_json( | |
| }, | ||
| } | ||
|
|
||
| adaptive_thinking_params: dict[str, Any] = {"thinking": {"type": "adaptive"}} | ||
| if self.effort: | ||
| adaptive_thinking_params["output_config"] = {"effort": self.effort} | ||
|
|
||
| converse_params["additionalModelRequestFields"] = adaptive_thinking_params | ||
|
|
||
|
Comment on lines
+112
to
+117
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should |
||
| if json_schema: | ||
| converse_params["outputConfig"] = { | ||
| "textFormat": { | ||
|
|
||
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.
Can we use an enum here?