Skip to content

Commit 96c7502

Browse files
cpsievertclaude
andauthored
feat: add reasoning parameter to ChatAzureOpenAI() (#260)
* fix: add reasoning parameter to ChatAzureOpenAI for reasoning model detection Azure OpenAI uses custom deployment IDs instead of model names, so the existing `is_reasoning_model()` check (which looks for "o" or "gpt-5" prefixes) doesn't work. This adds a `reasoning` parameter to `ChatAzureOpenAI()` that users can set to enable reasoning features for their o-series deployments. Changes: - Add `_is_reasoning_model` attribute to `OpenAIProvider` - Use `self._is_reasoning_model` instead of `is_reasoning_model(self.model)` in `_chat_perform_args()` to determine whether to include reasoning content - Add `reasoning` parameter to `ChatAzureOpenAI()` matching `ChatOpenAI()` - Fix type annotations to use `ResponsesSubmitInputArgs` and `Response` (since Azure uses the responses API, not completions) Fixes #242 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: also detect reasoning models by deployment_id pattern When deployment_id matches known reasoning model patterns (o*, gpt-5*), automatically enable reasoning features. This maintains backward compatibility with existing tests while still allowing explicit override via the reasoning parameter for custom deployment names. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Include encrypted content if reasoning is specified This way, for Azure, an empty dictionary will lead to encrypted content being included * Update changelog --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 83333c2 commit 96c7502

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
* `tool_web_fetch()` is supported by Claude (requires beta header) and Google.
2121
* New content types `ContentToolRequestSearch`, `ContentToolResponseSearch`, `ContentToolRequestFetch`, and `ContentToolResponseFetch` capture web tool interactions.
2222
* `ChatOpenAI()` and `ChatAzureOpenAI()` gain a new `service_tier` parameter to request a specific service tier (e.g., `"flex"` for slower/cheaper or `"priority"` for faster/more expensive). (#204)
23+
* `ChatAzureOpenAI()` gains a `reasoning` parameter. (#260)
2324
* `Chat` and `Turn` now have a `_repr_markdown_` method and an overall improved `repr()` experience. (#245)
2425
* `ChatAuto()` now accepts `"claude"` as an alias for `"anthropic"`, reflecting Anthropic's rebranding of developer tools under the Claude name. (#239)
2526

@@ -40,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4041
* Fixed MCP tools not working with `ChatGoogle()`. (#257)
4142
* Tool functions parameters that are `typing.Annotated` with a `pydantic.Field` (e.g., `def add(x: Annotated[int, Field(description="First number")])`) are now handled correctly. (#251)
4243

44+
4345
## [0.14.0] - 2025-12-09
4446

4547
### New features

chatlas/_provider_openai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def _chat_perform_args(
279279

280280
# Request reasoning content for reasoning models
281281
include = []
282-
if is_reasoning_model(self.model):
282+
if "reasoning" in kwargs_full or is_reasoning_model(self.model):
283283
include.append("reasoning.encrypted_content")
284284

285285
if "log_probs" in kwargs_full:

chatlas/_provider_openai_azure.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
from ._utils import MISSING, MISSING_TYPE, is_testing, split_http_client_kwargs
1212

1313
if TYPE_CHECKING:
14-
from .types.openai import ChatAzureClientArgs, SubmitInputArgs
14+
from openai.types.responses import Response
15+
from openai.types.shared.reasoning_effort import ReasoningEffort
16+
from openai.types.shared_params.reasoning import Reasoning
17+
18+
from .types.openai import (
19+
ChatAzureClientArgs,
20+
ResponsesSubmitInputArgs,
21+
SubmitInputArgs,
22+
)
1523

1624

1725
def ChatAzureOpenAI(
@@ -21,11 +29,12 @@ def ChatAzureOpenAI(
2129
api_version: str,
2230
api_key: Optional[str] = None,
2331
system_prompt: Optional[str] = None,
32+
reasoning: "Optional[ReasoningEffort | Reasoning]" = None,
2433
service_tier: Optional[
2534
Literal["auto", "default", "flex", "scale", "priority"]
2635
] = None,
2736
kwargs: Optional["ChatAzureClientArgs"] = None,
28-
) -> Chat["SubmitInputArgs", ChatCompletion]:
37+
) -> "Chat[ResponsesSubmitInputArgs, Response]":
2938
"""
3039
Chat with a model hosted on Azure OpenAI.
3140

@@ -65,6 +74,11 @@ def ChatAzureOpenAI(
6574
variable.
6675
system_prompt
6776
A system prompt to set the behavior of the assistant.
77+
reasoning
78+
The reasoning effort (e.g., `"low"`, `"medium"`, `"high"`) for
79+
reasoning-capable models like the o and gpt-5 series. To use the default
80+
reasoning settings in a way that will work for multi-turn conversations,
81+
set this to an empty dictionary `{}`.
6882
service_tier
6983
Request a specific service tier. Options:
7084
- `"auto"` (default): uses the service tier configured in Project settings.
@@ -81,7 +95,13 @@ def ChatAzureOpenAI(
8195
A Chat object.
8296
"""
8397

84-
kwargs_chat: "SubmitInputArgs" = {}
98+
kwargs_chat: "ResponsesSubmitInputArgs" = {}
99+
100+
if reasoning is not None:
101+
if isinstance(reasoning, str):
102+
reasoning = {"effort": reasoning, "summary": "auto"}
103+
kwargs_chat["reasoning"] = reasoning
104+
85105
if service_tier is not None:
86106
kwargs_chat["service_tier"] = service_tier
87107

0 commit comments

Comments
 (0)