-
Notifications
You must be signed in to change notification settings - Fork 864
fix(kosong): support adaptive thinking for Opus 4.7+ models #1911
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 |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
|
|
||
| import copy | ||
| import json | ||
| import re | ||
| from collections.abc import AsyncIterator, Mapping, Sequence | ||
| from typing import TYPE_CHECKING, Any, Literal, Self, TypedDict, Unpack, cast | ||
|
|
||
|
|
@@ -237,7 +238,13 @@ async def generate( | |
| def _use_adaptive_thinking(self) -> bool: | ||
| """Whether to use adaptive thinking (Opus 4.6+) instead of budget-based thinking.""" | ||
| model = self._model.lower() | ||
| return "opus-4.6" in model or "opus-4-6" in model | ||
| if "opus" not in model: | ||
| return False | ||
| match = re.search(r"opus[.-]?(\d+)[.-](\d{1,3})(?!\d)", model) | ||
| if match: | ||
| major, minor = int(match.group(1)), int(match.group(2)) | ||
| return (major, minor) >= (4, 6) | ||
| return False | ||
|
|
||
| def with_thinking(self, effort: "ThinkingEffort") -> Self: | ||
| thinking_config: ThinkingConfigParam | ||
|
|
@@ -248,7 +255,7 @@ def with_thinking(self, effort: "ThinkingEffort") -> Self: | |
| case "off": | ||
| thinking_config = {"type": "disabled"} | ||
| case _: | ||
| thinking_config = {"type": "adaptive"} # type: ignore[typeddict-item] | ||
| thinking_config = {"type": "adaptive", "display": "summarized"} # type: ignore[typeddict-item] | ||
|
Contributor
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. 🟡 Test snapshot not updated after adding The code now produces Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| new = self.with_generation_kwargs(thinking=thinking_config) | ||
| # Remove the now-unnecessary interleaved-thinking beta header. | ||
| if ( | ||
|
|
||
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 updated model parsing logic is intended to support additional Opus naming variants (e.g.,
claude-opus-4-7,claude-opus-4.7,aws/claude-opus-4-6) and future minor versions, but the existing snapshot tests only coverclaude-opus-4-6-.... Add automated coverage for at least one 4.7 model name and one dotted form (4.7) to prevent regressions in_use_adaptive_thinking()behavior.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.
Agree that test coverage would be valuable. Will leave that to the maintainers to decide on the preferred test structure for this project.