Skip to content

Commit 7da727a

Browse files
feat(types): replace List[str] with SequenceNotStr in params
1 parent 3e3c7a7 commit 7da727a

40 files changed

+183
-147
lines changed

src/openai/_utils/_transform.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
lru_cache,
1717
is_mapping,
1818
is_iterable,
19+
is_sequence,
1920
)
2021
from .._files import is_base64_file_input
2122
from ._typing import (
@@ -24,6 +25,7 @@
2425
extract_type_arg,
2526
is_iterable_type,
2627
is_required_type,
28+
is_sequence_type,
2729
is_annotated_type,
2830
strip_annotated_type,
2931
)
@@ -184,6 +186,8 @@ def _transform_recursive(
184186
(is_list_type(stripped_type) and is_list(data))
185187
# Iterable[T]
186188
or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
189+
# Sequence[T]
190+
or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
187191
):
188192
# dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
189193
# intended as an iterable, so we don't transform it.
@@ -346,6 +350,8 @@ async def _async_transform_recursive(
346350
(is_list_type(stripped_type) and is_list(data))
347351
# Iterable[T]
348352
or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
353+
# Sequence[T]
354+
or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
349355
):
350356
# dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
351357
# intended as an iterable, so we don't transform it.

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
MessagesWithStreamingResponse,
2020
AsyncMessagesWithStreamingResponse,
2121
)
22-
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
22+
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr
2323
from ...._utils import required_args, maybe_transform, async_maybe_transform
2424
from ...._compat import cached_property
2525
from ...._resource import SyncAPIResource, AsyncAPIResource
@@ -260,7 +260,7 @@ def create(
260260
safety_identifier: str | NotGiven = NOT_GIVEN,
261261
seed: Optional[int] | NotGiven = NOT_GIVEN,
262262
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | NotGiven = NOT_GIVEN,
263-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
263+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
264264
store: Optional[bool] | NotGiven = NOT_GIVEN,
265265
stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
266266
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
@@ -549,7 +549,7 @@ def create(
549549
safety_identifier: str | NotGiven = NOT_GIVEN,
550550
seed: Optional[int] | NotGiven = NOT_GIVEN,
551551
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | NotGiven = NOT_GIVEN,
552-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
552+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
553553
store: Optional[bool] | NotGiven = NOT_GIVEN,
554554
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
555555
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -837,7 +837,7 @@ def create(
837837
safety_identifier: str | NotGiven = NOT_GIVEN,
838838
seed: Optional[int] | NotGiven = NOT_GIVEN,
839839
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | NotGiven = NOT_GIVEN,
840-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
840+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
841841
store: Optional[bool] | NotGiven = NOT_GIVEN,
842842
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
843843
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -1124,7 +1124,7 @@ def create(
11241124
safety_identifier: str | NotGiven = NOT_GIVEN,
11251125
seed: Optional[int] | NotGiven = NOT_GIVEN,
11261126
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | NotGiven = NOT_GIVEN,
1127-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
1127+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
11281128
store: Optional[bool] | NotGiven = NOT_GIVEN,
11291129
stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
11301130
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
@@ -1696,7 +1696,7 @@ async def create(
16961696
safety_identifier: str | NotGiven = NOT_GIVEN,
16971697
seed: Optional[int] | NotGiven = NOT_GIVEN,
16981698
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | NotGiven = NOT_GIVEN,
1699-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
1699+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
17001700
store: Optional[bool] | NotGiven = NOT_GIVEN,
17011701
stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
17021702
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
@@ -1985,7 +1985,7 @@ async def create(
19851985
safety_identifier: str | NotGiven = NOT_GIVEN,
19861986
seed: Optional[int] | NotGiven = NOT_GIVEN,
19871987
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | NotGiven = NOT_GIVEN,
1988-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
1988+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
19891989
store: Optional[bool] | NotGiven = NOT_GIVEN,
19901990
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
19911991
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -2273,7 +2273,7 @@ async def create(
22732273
safety_identifier: str | NotGiven = NOT_GIVEN,
22742274
seed: Optional[int] | NotGiven = NOT_GIVEN,
22752275
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | NotGiven = NOT_GIVEN,
2276-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
2276+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
22772277
store: Optional[bool] | NotGiven = NOT_GIVEN,
22782278
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
22792279
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -2560,7 +2560,7 @@ async def create(
25602560
safety_identifier: str | NotGiven = NOT_GIVEN,
25612561
seed: Optional[int] | NotGiven = NOT_GIVEN,
25622562
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | NotGiven = NOT_GIVEN,
2563-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
2563+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
25642564
store: Optional[bool] | NotGiven = NOT_GIVEN,
25652565
stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
25662566
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,

src/openai/resources/completions.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, List, Union, Iterable, Optional
5+
from typing import Dict, Union, Iterable, Optional
66
from typing_extensions import Literal, overload
77

88
import httpx
99

1010
from .. import _legacy_response
1111
from ..types import completion_create_params
12-
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
12+
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr
1313
from .._utils import required_args, maybe_transform, async_maybe_transform
1414
from .._compat import cached_property
1515
from .._resource import SyncAPIResource, AsyncAPIResource
@@ -49,7 +49,7 @@ def create(
4949
self,
5050
*,
5151
model: Union[str, Literal["gpt-3.5-turbo-instruct", "davinci-002", "babbage-002"]],
52-
prompt: Union[str, List[str], Iterable[int], Iterable[Iterable[int]], None],
52+
prompt: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]], None],
5353
best_of: Optional[int] | NotGiven = NOT_GIVEN,
5454
echo: Optional[bool] | NotGiven = NOT_GIVEN,
5555
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -59,7 +59,7 @@ def create(
5959
n: Optional[int] | NotGiven = NOT_GIVEN,
6060
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
6161
seed: Optional[int] | NotGiven = NOT_GIVEN,
62-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
62+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
6363
stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
6464
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
6565
suffix: Optional[str] | NotGiven = NOT_GIVEN,
@@ -204,7 +204,7 @@ def create(
204204
self,
205205
*,
206206
model: Union[str, Literal["gpt-3.5-turbo-instruct", "davinci-002", "babbage-002"]],
207-
prompt: Union[str, List[str], Iterable[int], Iterable[Iterable[int]], None],
207+
prompt: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]], None],
208208
stream: Literal[True],
209209
best_of: Optional[int] | NotGiven = NOT_GIVEN,
210210
echo: Optional[bool] | NotGiven = NOT_GIVEN,
@@ -215,7 +215,7 @@ def create(
215215
n: Optional[int] | NotGiven = NOT_GIVEN,
216216
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
217217
seed: Optional[int] | NotGiven = NOT_GIVEN,
218-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
218+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
219219
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
220220
suffix: Optional[str] | NotGiven = NOT_GIVEN,
221221
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -359,7 +359,7 @@ def create(
359359
self,
360360
*,
361361
model: Union[str, Literal["gpt-3.5-turbo-instruct", "davinci-002", "babbage-002"]],
362-
prompt: Union[str, List[str], Iterable[int], Iterable[Iterable[int]], None],
362+
prompt: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]], None],
363363
stream: bool,
364364
best_of: Optional[int] | NotGiven = NOT_GIVEN,
365365
echo: Optional[bool] | NotGiven = NOT_GIVEN,
@@ -370,7 +370,7 @@ def create(
370370
n: Optional[int] | NotGiven = NOT_GIVEN,
371371
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
372372
seed: Optional[int] | NotGiven = NOT_GIVEN,
373-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
373+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
374374
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
375375
suffix: Optional[str] | NotGiven = NOT_GIVEN,
376376
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -514,7 +514,7 @@ def create(
514514
self,
515515
*,
516516
model: Union[str, Literal["gpt-3.5-turbo-instruct", "davinci-002", "babbage-002"]],
517-
prompt: Union[str, List[str], Iterable[int], Iterable[Iterable[int]], None],
517+
prompt: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]], None],
518518
best_of: Optional[int] | NotGiven = NOT_GIVEN,
519519
echo: Optional[bool] | NotGiven = NOT_GIVEN,
520520
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -524,7 +524,7 @@ def create(
524524
n: Optional[int] | NotGiven = NOT_GIVEN,
525525
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
526526
seed: Optional[int] | NotGiven = NOT_GIVEN,
527-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
527+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
528528
stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
529529
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
530530
suffix: Optional[str] | NotGiven = NOT_GIVEN,
@@ -599,7 +599,7 @@ async def create(
599599
self,
600600
*,
601601
model: Union[str, Literal["gpt-3.5-turbo-instruct", "davinci-002", "babbage-002"]],
602-
prompt: Union[str, List[str], Iterable[int], Iterable[Iterable[int]], None],
602+
prompt: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]], None],
603603
best_of: Optional[int] | NotGiven = NOT_GIVEN,
604604
echo: Optional[bool] | NotGiven = NOT_GIVEN,
605605
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -609,7 +609,7 @@ async def create(
609609
n: Optional[int] | NotGiven = NOT_GIVEN,
610610
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
611611
seed: Optional[int] | NotGiven = NOT_GIVEN,
612-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
612+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
613613
stream: Optional[Literal[False]] | NotGiven = NOT_GIVEN,
614614
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
615615
suffix: Optional[str] | NotGiven = NOT_GIVEN,
@@ -754,7 +754,7 @@ async def create(
754754
self,
755755
*,
756756
model: Union[str, Literal["gpt-3.5-turbo-instruct", "davinci-002", "babbage-002"]],
757-
prompt: Union[str, List[str], Iterable[int], Iterable[Iterable[int]], None],
757+
prompt: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]], None],
758758
stream: Literal[True],
759759
best_of: Optional[int] | NotGiven = NOT_GIVEN,
760760
echo: Optional[bool] | NotGiven = NOT_GIVEN,
@@ -765,7 +765,7 @@ async def create(
765765
n: Optional[int] | NotGiven = NOT_GIVEN,
766766
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
767767
seed: Optional[int] | NotGiven = NOT_GIVEN,
768-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
768+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
769769
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
770770
suffix: Optional[str] | NotGiven = NOT_GIVEN,
771771
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -909,7 +909,7 @@ async def create(
909909
self,
910910
*,
911911
model: Union[str, Literal["gpt-3.5-turbo-instruct", "davinci-002", "babbage-002"]],
912-
prompt: Union[str, List[str], Iterable[int], Iterable[Iterable[int]], None],
912+
prompt: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]], None],
913913
stream: bool,
914914
best_of: Optional[int] | NotGiven = NOT_GIVEN,
915915
echo: Optional[bool] | NotGiven = NOT_GIVEN,
@@ -920,7 +920,7 @@ async def create(
920920
n: Optional[int] | NotGiven = NOT_GIVEN,
921921
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
922922
seed: Optional[int] | NotGiven = NOT_GIVEN,
923-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
923+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
924924
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
925925
suffix: Optional[str] | NotGiven = NOT_GIVEN,
926926
temperature: Optional[float] | NotGiven = NOT_GIVEN,
@@ -1064,7 +1064,7 @@ async def create(
10641064
self,
10651065
*,
10661066
model: Union[str, Literal["gpt-3.5-turbo-instruct", "davinci-002", "babbage-002"]],
1067-
prompt: Union[str, List[str], Iterable[int], Iterable[Iterable[int]], None],
1067+
prompt: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]], None],
10681068
best_of: Optional[int] | NotGiven = NOT_GIVEN,
10691069
echo: Optional[bool] | NotGiven = NOT_GIVEN,
10701070
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
@@ -1074,7 +1074,7 @@ async def create(
10741074
n: Optional[int] | NotGiven = NOT_GIVEN,
10751075
presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
10761076
seed: Optional[int] | NotGiven = NOT_GIVEN,
1077-
stop: Union[Optional[str], List[str], None] | NotGiven = NOT_GIVEN,
1077+
stop: Union[Optional[str], SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
10781078
stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
10791079
stream_options: Optional[ChatCompletionStreamOptionsParam] | NotGiven = NOT_GIVEN,
10801080
suffix: Optional[str] | NotGiven = NOT_GIVEN,

src/openai/resources/containers/containers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
from __future__ import annotations
44

5-
from typing import List
65
from typing_extensions import Literal
76

87
import httpx
98

109
from ... import _legacy_response
1110
from ...types import container_list_params, container_create_params
12-
from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
11+
from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven, SequenceNotStr
1312
from ..._utils import maybe_transform, async_maybe_transform
1413
from ..._compat import cached_property
1514
from ..._resource import SyncAPIResource, AsyncAPIResource
@@ -60,7 +59,7 @@ def create(
6059
*,
6160
name: str,
6261
expires_after: container_create_params.ExpiresAfter | NotGiven = NOT_GIVEN,
63-
file_ids: List[str] | NotGiven = NOT_GIVEN,
62+
file_ids: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
6463
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
6564
# The extra values given here take precedence over values defined on the client or passed to this method.
6665
extra_headers: Headers | None = None,
@@ -256,7 +255,7 @@ async def create(
256255
*,
257256
name: str,
258257
expires_after: container_create_params.ExpiresAfter | NotGiven = NOT_GIVEN,
259-
file_ids: List[str] | NotGiven = NOT_GIVEN,
258+
file_ids: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
260259
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
261260
# The extra values given here take precedence over values defined on the client or passed to this method.
262261
extra_headers: Headers | None = None,

src/openai/resources/embeddings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import array
66
import base64
7-
from typing import List, Union, Iterable, cast
7+
from typing import Union, Iterable, cast
88
from typing_extensions import Literal
99

1010
import httpx
1111

1212
from .. import _legacy_response
1313
from ..types import embedding_create_params
14-
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
14+
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr
1515
from .._utils import is_given, maybe_transform
1616
from .._compat import cached_property
1717
from .._extras import numpy as np, has_numpy
@@ -47,7 +47,7 @@ def with_streaming_response(self) -> EmbeddingsWithStreamingResponse:
4747
def create(
4848
self,
4949
*,
50-
input: Union[str, List[str], Iterable[int], Iterable[Iterable[int]]],
50+
input: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]]],
5151
model: Union[str, EmbeddingModel],
5252
dimensions: int | NotGiven = NOT_GIVEN,
5353
encoding_format: Literal["float", "base64"] | NotGiven = NOT_GIVEN,
@@ -166,7 +166,7 @@ def with_streaming_response(self) -> AsyncEmbeddingsWithStreamingResponse:
166166
async def create(
167167
self,
168168
*,
169-
input: Union[str, List[str], Iterable[int], Iterable[Iterable[int]]],
169+
input: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]]],
170170
model: Union[str, EmbeddingModel],
171171
dimensions: int | NotGiven = NOT_GIVEN,
172172
encoding_format: Literal["float", "base64"] | NotGiven = NOT_GIVEN,

0 commit comments

Comments
 (0)