Skip to content

Commit 8d3bf88

Browse files
fix(types): rename chat completion tool
1 parent d3900c1 commit 8d3bf88

File tree

8 files changed

+37
-38
lines changed

8 files changed

+37
-38
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 111
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-d7e255da603b878e7e823135520211ce6a9e02890c9d549bbf3953a877ee5ef3.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-56d3a72a5caa187aebcf9de169a6a28a9dc3f70a79d7467a03a9e22595936066.yml
33
openapi_spec_hash: 3eb8d86c06f0bb5e1190983e5acfc9ba
4-
config_hash: 2e7cf948f94e24f94c7d12ba2de2734a
4+
config_hash: 7e18239879286d68a48ac5487a649aa6

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ from openai.types.chat import (
7979
ChatCompletionStreamOptions,
8080
ChatCompletionSystemMessageParam,
8181
ChatCompletionTokenLogprob,
82-
ChatCompletionTool,
82+
ChatCompletionToolUnion,
8383
ChatCompletionToolChoiceOption,
8484
ChatCompletionToolMessageParam,
8585
ChatCompletionUserMessageParam,

src/openai/lib/_parsing/_completions.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
ChatCompletionMessage,
2222
ParsedFunctionToolCall,
2323
ParsedChatCompletionMessage,
24+
ChatCompletionToolUnionParam,
2425
ChatCompletionFunctionToolParam,
2526
completion_create_params,
2627
)
2728
from ..._exceptions import LengthFinishReasonError, ContentFilterFinishReasonError
2829
from ...types.shared_params import FunctionDefinition
2930
from ...types.chat.completion_create_params import ResponseFormat as ResponseFormatParam
30-
from ...types.chat.chat_completion_tool_param import ChatCompletionToolParam
3131
from ...types.chat.chat_completion_message_function_tool_call import Function
3232

3333
ResponseFormatT = TypeVar(
@@ -41,7 +41,7 @@
4141

4242

4343
def is_strict_chat_completion_tool_param(
44-
tool: ChatCompletionToolParam,
44+
tool: ChatCompletionToolUnionParam,
4545
) -> TypeGuard[ChatCompletionFunctionToolParam]:
4646
"""Check if the given tool is a strict ChatCompletionFunctionToolParam."""
4747
if not tool["type"] == "function":
@@ -53,7 +53,7 @@ def is_strict_chat_completion_tool_param(
5353

5454

5555
def select_strict_chat_completion_tools(
56-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
56+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
5757
) -> Iterable[ChatCompletionFunctionToolParam] | NotGiven:
5858
"""Select only the strict ChatCompletionFunctionToolParams from the given tools."""
5959
if not is_given(tools):
@@ -63,7 +63,7 @@ def select_strict_chat_completion_tools(
6363

6464

6565
def validate_input_tools(
66-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
66+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
6767
) -> Iterable[ChatCompletionFunctionToolParam] | NotGiven:
6868
if not is_given(tools):
6969
return NOT_GIVEN
@@ -86,7 +86,7 @@ def validate_input_tools(
8686
def parse_chat_completion(
8787
*,
8888
response_format: type[ResponseFormatT] | completion_create_params.ResponseFormat | NotGiven,
89-
input_tools: Iterable[ChatCompletionToolParam] | NotGiven,
89+
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven,
9090
chat_completion: ChatCompletion | ParsedChatCompletion[object],
9191
) -> ParsedChatCompletion[ResponseFormatT]:
9292
if is_given(input_tools):
@@ -166,13 +166,13 @@ def parse_chat_completion(
166166

167167

168168
def get_input_tool_by_name(
169-
*, input_tools: list[ChatCompletionToolParam], name: str
169+
*, input_tools: list[ChatCompletionToolUnionParam], name: str
170170
) -> ChatCompletionFunctionToolParam | None:
171171
return next((t for t in input_tools if t["type"] == "function" and t.get("function", {}).get("name") == name), None)
172172

173173

174174
def parse_function_tool_arguments(
175-
*, input_tools: list[ChatCompletionToolParam], function: Function | ParsedFunction
175+
*, input_tools: list[ChatCompletionToolUnionParam], function: Function | ParsedFunction
176176
) -> object | None:
177177
input_tool = get_input_tool_by_name(input_tools=input_tools, name=function.name)
178178
if not input_tool:
@@ -218,7 +218,7 @@ def solve_response_format_t(
218218
def has_parseable_input(
219219
*,
220220
response_format: type | ResponseFormatParam | NotGiven,
221-
input_tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
221+
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
222222
) -> bool:
223223
if has_rich_response_format(response_format):
224224
return True
@@ -246,7 +246,7 @@ def is_response_format_param(response_format: object) -> TypeGuard[ResponseForma
246246
return is_dict(response_format)
247247

248248

249-
def is_parseable_tool(input_tool: ChatCompletionToolParam) -> bool:
249+
def is_parseable_tool(input_tool: ChatCompletionToolUnionParam) -> bool:
250250
if input_tool["type"] != "function":
251251
return False
252252

src/openai/lib/streaming/chat/_completions.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@
3737
parse_function_tool_arguments,
3838
)
3939
from ...._streaming import Stream, AsyncStream
40-
from ....types.chat import ChatCompletionChunk, ParsedChatCompletion
40+
from ....types.chat import ChatCompletionChunk, ParsedChatCompletion, ChatCompletionToolUnionParam
4141
from ...._exceptions import LengthFinishReasonError, ContentFilterFinishReasonError
4242
from ....types.chat.chat_completion import ChoiceLogprobs
4343
from ....types.chat.chat_completion_chunk import Choice as ChoiceChunk
4444
from ....types.chat.completion_create_params import ResponseFormat as ResponseFormatParam
45-
from ....types.chat.chat_completion_tool_param import ChatCompletionToolParam
4645

4746

4847
class ChatCompletionStream(Generic[ResponseFormatT]):
@@ -59,7 +58,7 @@ def __init__(
5958
*,
6059
raw_stream: Stream[ChatCompletionChunk],
6160
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
62-
input_tools: Iterable[ChatCompletionToolParam] | NotGiven,
61+
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven,
6362
) -> None:
6463
self._raw_stream = raw_stream
6564
self._response = raw_stream.response
@@ -140,7 +139,7 @@ def __init__(
140139
api_request: Callable[[], Stream[ChatCompletionChunk]],
141140
*,
142141
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
143-
input_tools: Iterable[ChatCompletionToolParam] | NotGiven,
142+
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven,
144143
) -> None:
145144
self.__stream: ChatCompletionStream[ResponseFormatT] | None = None
146145
self.__api_request = api_request
@@ -182,7 +181,7 @@ def __init__(
182181
*,
183182
raw_stream: AsyncStream[ChatCompletionChunk],
184183
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
185-
input_tools: Iterable[ChatCompletionToolParam] | NotGiven,
184+
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven,
186185
) -> None:
187186
self._raw_stream = raw_stream
188187
self._response = raw_stream.response
@@ -263,7 +262,7 @@ def __init__(
263262
api_request: Awaitable[AsyncStream[ChatCompletionChunk]],
264263
*,
265264
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven,
266-
input_tools: Iterable[ChatCompletionToolParam] | NotGiven,
265+
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven,
267266
) -> None:
268267
self.__stream: AsyncChatCompletionStream[ResponseFormatT] | None = None
269268
self.__api_request = api_request
@@ -315,7 +314,7 @@ class ChatCompletionStreamState(Generic[ResponseFormatT]):
315314
def __init__(
316315
self,
317316
*,
318-
input_tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
317+
input_tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
319318
response_format: type[ResponseFormatT] | ResponseFormatParam | NotGiven = NOT_GIVEN,
320319
) -> None:
321320
self.__current_completion_snapshot: ParsedChatCompletionSnapshot | None = None
@@ -585,7 +584,7 @@ def _build_events(
585584

586585

587586
class ChoiceEventState:
588-
def __init__(self, *, input_tools: list[ChatCompletionToolParam]) -> None:
587+
def __init__(self, *, input_tools: list[ChatCompletionToolUnionParam]) -> None:
589588
self._input_tools = input_tools
590589

591590
self._content_done = False

src/openai/resources/chat/completions/completions.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
from ....types.chat.chat_completion_chunk import ChatCompletionChunk
4848
from ....types.chat.parsed_chat_completion import ParsedChatCompletion
4949
from ....types.chat.chat_completion_deleted import ChatCompletionDeleted
50-
from ....types.chat.chat_completion_tool_param import ChatCompletionToolParam
5150
from ....types.chat.chat_completion_audio_param import ChatCompletionAudioParam
5251
from ....types.chat.chat_completion_message_param import ChatCompletionMessageParam
52+
from ....types.chat.chat_completion_tool_union_param import ChatCompletionToolUnionParam
5353
from ....types.chat.chat_completion_stream_options_param import ChatCompletionStreamOptionsParam
5454
from ....types.chat.chat_completion_prediction_content_param import ChatCompletionPredictionContentParam
5555
from ....types.chat.chat_completion_tool_choice_option_param import ChatCompletionToolChoiceOptionParam
@@ -111,7 +111,7 @@ def parse(
111111
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
112112
temperature: Optional[float] | NotGiven = NOT_GIVEN,
113113
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
114-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
114+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
115115
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
116116
top_p: Optional[float] | NotGiven = NOT_GIVEN,
117117
user: str | NotGiven = NOT_GIVEN,
@@ -266,7 +266,7 @@ def create(
266266
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
267267
temperature: Optional[float] | NotGiven = NOT_GIVEN,
268268
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
269-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
269+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
270270
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
271271
top_p: Optional[float] | NotGiven = NOT_GIVEN,
272272
user: str | NotGiven = NOT_GIVEN,
@@ -555,7 +555,7 @@ def create(
555555
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
556556
temperature: Optional[float] | NotGiven = NOT_GIVEN,
557557
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
558-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
558+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
559559
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
560560
top_p: Optional[float] | NotGiven = NOT_GIVEN,
561561
user: str | NotGiven = NOT_GIVEN,
@@ -844,7 +844,7 @@ def create(
844844
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
845845
temperature: Optional[float] | NotGiven = NOT_GIVEN,
846846
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
847-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
847+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
848848
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
849849
top_p: Optional[float] | NotGiven = NOT_GIVEN,
850850
user: str | NotGiven = NOT_GIVEN,
@@ -1133,7 +1133,7 @@ def create(
11331133
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
11341134
temperature: Optional[float] | NotGiven = NOT_GIVEN,
11351135
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
1136-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
1136+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
11371137
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
11381138
top_p: Optional[float] | NotGiven = NOT_GIVEN,
11391139
user: str | NotGiven = NOT_GIVEN,
@@ -1408,7 +1408,7 @@ def stream(
14081408
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
14091409
temperature: Optional[float] | NotGiven = NOT_GIVEN,
14101410
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
1411-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
1411+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
14121412
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
14131413
top_p: Optional[float] | NotGiven = NOT_GIVEN,
14141414
user: str | NotGiven = NOT_GIVEN,
@@ -1550,7 +1550,7 @@ async def parse(
15501550
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
15511551
temperature: Optional[float] | NotGiven = NOT_GIVEN,
15521552
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
1553-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
1553+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
15541554
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
15551555
top_p: Optional[float] | NotGiven = NOT_GIVEN,
15561556
user: str | NotGiven = NOT_GIVEN,
@@ -1705,7 +1705,7 @@ async def create(
17051705
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
17061706
temperature: Optional[float] | NotGiven = NOT_GIVEN,
17071707
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
1708-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
1708+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
17091709
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
17101710
top_p: Optional[float] | NotGiven = NOT_GIVEN,
17111711
user: str | NotGiven = NOT_GIVEN,
@@ -1994,7 +1994,7 @@ async def create(
19941994
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
19951995
temperature: Optional[float] | NotGiven = NOT_GIVEN,
19961996
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
1997-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
1997+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
19981998
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
19991999
top_p: Optional[float] | NotGiven = NOT_GIVEN,
20002000
user: str | NotGiven = NOT_GIVEN,
@@ -2283,7 +2283,7 @@ async def create(
22832283
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
22842284
temperature: Optional[float] | NotGiven = NOT_GIVEN,
22852285
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
2286-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
2286+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
22872287
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
22882288
top_p: Optional[float] | NotGiven = NOT_GIVEN,
22892289
user: str | NotGiven = NOT_GIVEN,
@@ -2572,7 +2572,7 @@ async def create(
25722572
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
25732573
temperature: Optional[float] | NotGiven = NOT_GIVEN,
25742574
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
2575-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
2575+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
25762576
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
25772577
top_p: Optional[float] | NotGiven = NOT_GIVEN,
25782578
user: str | NotGiven = NOT_GIVEN,
@@ -2847,7 +2847,7 @@ def stream(
28472847
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
28482848
temperature: Optional[float] | NotGiven = NOT_GIVEN,
28492849
tool_choice: ChatCompletionToolChoiceOptionParam | NotGiven = NOT_GIVEN,
2850-
tools: Iterable[ChatCompletionToolParam] | NotGiven = NOT_GIVEN,
2850+
tools: Iterable[ChatCompletionToolUnionParam] | NotGiven = NOT_GIVEN,
28512851
top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
28522852
top_p: Optional[float] | NotGiven = NOT_GIVEN,
28532853
user: str | NotGiven = NOT_GIVEN,

src/openai/types/chat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
ParsedFunction as ParsedFunction,
2222
ParsedFunctionToolCall as ParsedFunctionToolCall,
2323
)
24-
from .chat_completion_tool_param import ChatCompletionToolParam as ChatCompletionToolParam
2524
from .chat_completion_audio_param import ChatCompletionAudioParam as ChatCompletionAudioParam
2625
from .chat_completion_function_tool import ChatCompletionFunctionTool as ChatCompletionFunctionTool
2726
from .chat_completion_message_param import ChatCompletionMessageParam as ChatCompletionMessageParam
2827
from .chat_completion_store_message import ChatCompletionStoreMessage as ChatCompletionStoreMessage
2928
from .chat_completion_token_logprob import ChatCompletionTokenLogprob as ChatCompletionTokenLogprob
3029
from .chat_completion_reasoning_effort import ChatCompletionReasoningEffort as ChatCompletionReasoningEffort
30+
from .chat_completion_tool_union_param import ChatCompletionToolUnionParam as ChatCompletionToolUnionParam
3131
from .chat_completion_content_part_text import ChatCompletionContentPartText as ChatCompletionContentPartText
3232
from .chat_completion_custom_tool_param import ChatCompletionCustomToolParam as ChatCompletionCustomToolParam
3333
from .chat_completion_message_tool_call import ChatCompletionMessageToolCall as ChatCompletionMessageToolCall

src/openai/types/chat/chat_completion_tool_param.py renamed to src/openai/types/chat/chat_completion_tool_union_param.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
from .chat_completion_custom_tool_param import ChatCompletionCustomToolParam
99
from .chat_completion_function_tool_param import ChatCompletionFunctionToolParam
1010

11-
__all__ = ["ChatCompletionToolParam"]
11+
__all__ = ["ChatCompletionToolUnionParam"]
1212

13-
ChatCompletionToolParam: TypeAlias = Union[ChatCompletionFunctionToolParam, ChatCompletionCustomToolParam]
13+
ChatCompletionToolUnionParam: TypeAlias = Union[ChatCompletionFunctionToolParam, ChatCompletionCustomToolParam]

src/openai/types/chat/completion_create_params.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from ..shared.chat_model import ChatModel
99
from ..shared_params.metadata import Metadata
1010
from ..shared.reasoning_effort import ReasoningEffort
11-
from .chat_completion_tool_param import ChatCompletionToolParam
1211
from .chat_completion_audio_param import ChatCompletionAudioParam
1312
from .chat_completion_message_param import ChatCompletionMessageParam
13+
from .chat_completion_tool_union_param import ChatCompletionToolUnionParam
1414
from ..shared_params.function_parameters import FunctionParameters
1515
from ..shared_params.response_format_text import ResponseFormatText
1616
from .chat_completion_stream_options_param import ChatCompletionStreamOptionsParam
@@ -284,7 +284,7 @@ class CompletionCreateParamsBase(TypedDict, total=False):
284284
are present.
285285
"""
286286

287-
tools: Iterable[ChatCompletionToolParam]
287+
tools: Iterable[ChatCompletionToolUnionParam]
288288
"""A list of tools the model may call.
289289
290290
You can provide either

0 commit comments

Comments
 (0)