Skip to content

Commit a84825c

Browse files
done
1 parent 3154a78 commit a84825c

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

src/openai/_response.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
AsyncIterator,
1818
cast,
1919
overload,
20+
21+
2022
)
2123
from typing_extensions import Awaitable, ParamSpec, override, get_origin
2224

src/openai/types/responses/response.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
from typing import List, Union, Optional
3+
from typing import List, Union, Optional , Dict, Any
44
from typing_extensions import Literal, TypeAlias
55

66
from .tool import Tool
@@ -30,6 +30,7 @@ class IncompleteDetails(BaseModel):
3030
"""The reason why the response is incomplete."""
3131

3232

33+
<<<<<<< Updated upstream
3334
ToolChoice: TypeAlias = Union[
3435
ToolChoiceOptions, ToolChoiceAllowed, ToolChoiceTypes, ToolChoiceFunction, ToolChoiceMcp, ToolChoiceCustom
3536
]
@@ -38,6 +39,11 @@ class IncompleteDetails(BaseModel):
3839
class Conversation(BaseModel):
3940
id: str
4041
"""The unique ID of the conversation."""
42+
=======
43+
ToolChoice: TypeAlias = Optional[Union[ToolChoiceOptions, ToolChoiceTypes, ToolChoiceFunction, ToolChoiceMcp, Dict[str, Any]]]
44+
45+
46+
>>>>>>> Stashed changes
4147

4248

4349
class Response(BaseModel):

src/openai/types/responses/tool_choice_options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55
__all__ = ["ToolChoiceOptions"]
66

7-
ToolChoiceOptions: TypeAlias = Literal["none", "auto", "required"]
7+
# ToolChoiceOptions: TypeAlias = Literal["none", "auto", "required"]
8+
ToolChoiceOptions: TypeAlias = Literal["none", "auto", "required", "allowed_tools"]
9+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from openai.types.responses import ToolChoiceOptions
2+
3+
def test_tool_choice_valid_values():
4+
"""Test that ToolChoiceOptions accepts valid values."""
5+
valid_values = ["none", "auto", "required", "allowed_tools"]
6+
for value in valid_values:
7+
assert value in ToolChoiceOptions.__args__ # check if Literal includes it
8+
9+
10+
def test_tool_choice_invalid_value():
11+
"""Test that an invalid tool_choice raises an error."""
12+
invalid_value = "invalid_mode"
13+
assert invalid_value not in ToolChoiceOptions.__args__

tests/api_resources/test_responses.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,3 +708,31 @@ async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None:
708708
await async_client.responses.with_raw_response.cancel(
709709
"",
710710
)
711+
712+
713+
714+
715+
716+
import pytest
717+
from openai import OpenAI
718+
719+
def test_tool_choice_object(monkeypatch):
720+
client = OpenAI()
721+
722+
# Mock transport (so we don’t actually call API)
723+
def fake_request(*args, **kwargs):
724+
assert "tool_choice" in kwargs["json"]
725+
assert kwargs["json"]["tool_choice"]["type"] == "code_interpreter"
726+
return {"id": "resp_test", "output": "ok"}
727+
728+
monkeypatch.setattr(client._client, "post", fake_request)
729+
730+
response = client.responses.create(
731+
model="gpt-5",
732+
input="test",
733+
tools=[{"type": "code_interpreter"}],
734+
tool_choice={"type": "code_interpreter"},
735+
)
736+
737+
assert response["output"] == "ok"
738+

0 commit comments

Comments
 (0)