-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Convert 'thinking' parameter to 'reasoning_effort' for Claude models #28031
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
Changes from all commits
3c378f4
9f92def
9524892
21be278
ee23705
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -130,6 +130,62 @@ def get_supported_openai_params(self, model: str) -> list: | |||||||||||||||||
|
|
||||||||||||||||||
| return base_params | ||||||||||||||||||
|
|
||||||||||||||||||
| def map_openai_params( | ||||||||||||||||||
| self, | ||||||||||||||||||
| non_default_params: dict, | ||||||||||||||||||
| optional_params: dict, | ||||||||||||||||||
| model: str, | ||||||||||||||||||
| drop_params: bool, | ||||||||||||||||||
| ) -> dict: | ||||||||||||||||||
| """ | ||||||||||||||||||
| Map OpenAI params to GitHub Copilot params. | ||||||||||||||||||
|
|
||||||||||||||||||
| GitHub Copilot uses an OpenAI-compatible API and does not understand the | ||||||||||||||||||
| Anthropic-native ``thinking`` parameter. When Claude Code calls the proxy's | ||||||||||||||||||
| ``/v1/messages`` endpoint with ``thinking`` and the request is routed to a | ||||||||||||||||||
| ``github_copilot/claude-*`` model, ``thinking`` must be converted to | ||||||||||||||||||
| ``reasoning_effort`` before being forwarded to the Copilot API. | ||||||||||||||||||
|
|
||||||||||||||||||
| ``reasoning_effort`` is written directly to ``optional_params`` rather than | ||||||||||||||||||
| deferred to the parent: ``OpenAIConfig.map_openai_params`` dispatches to the | ||||||||||||||||||
| global ``openAIGPTConfig`` whose supported-params list does not include | ||||||||||||||||||
| ``reasoning_effort`` for Claude models, so a deferred write would be dropped. | ||||||||||||||||||
| """ | ||||||||||||||||||
| if "claude" in model.lower(): | ||||||||||||||||||
| thinking = non_default_params.pop("thinking", None) | ||||||||||||||||||
| else: | ||||||||||||||||||
| thinking = None | ||||||||||||||||||
| existing_reasoning_effort = non_default_params.get( | ||||||||||||||||||
| "reasoning_effort" | ||||||||||||||||||
| ) or optional_params.get("reasoning_effort") | ||||||||||||||||||
| if ( | ||||||||||||||||||
| thinking is not None | ||||||||||||||||||
| and isinstance(thinking, dict) | ||||||||||||||||||
| and thinking.get("type") == "enabled" | ||||||||||||||||||
| and existing_reasoning_effort is None | ||||||||||||||||||
| ): | ||||||||||||||||||
| budget_tokens = thinking.get("budget_tokens") or 0 | ||||||||||||||||||
| if budget_tokens >= 10000: | ||||||||||||||||||
| reasoning_effort = "high" | ||||||||||||||||||
| elif budget_tokens >= 5000: | ||||||||||||||||||
| reasoning_effort = "medium" | ||||||||||||||||||
| elif budget_tokens >= 2000: | ||||||||||||||||||
| reasoning_effort = "low" | ||||||||||||||||||
| else: | ||||||||||||||||||
| reasoning_effort = "minimal" | ||||||||||||||||||
|
Comment on lines
+172
to
+175
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.
Suggested change
Author
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. "minimal" is a valid reasoning_effort value, not an invalid one.
|
||||||||||||||||||
| optional_params["reasoning_effort"] = reasoning_effort | ||||||||||||||||||
| elif ( | ||||||||||||||||||
| "claude" in model.lower() | ||||||||||||||||||
| and non_default_params.get("reasoning_effort") is not None | ||||||||||||||||||
| ): | ||||||||||||||||||
| optional_params["reasoning_effort"] = non_default_params.pop( | ||||||||||||||||||
| "reasoning_effort" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| return super().map_openai_params( | ||||||||||||||||||
| non_default_params, optional_params, model, drop_params | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| def _determine_initiator(self, messages: List[AllMessageValues]) -> str: | ||||||||||||||||||
| """ | ||||||||||||||||||
| Determine if request is user or agent initiated based on message roles. | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.