Skip to content

Commit 1ccd9b6

Browse files
feat: extract chat models to a named enum (#1322)
1 parent 0c489f1 commit 1ccd9b6

File tree

5 files changed

+45
-218
lines changed

5 files changed

+45
-218
lines changed

api.md

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Methods:
1818

1919
# Chat
2020

21+
Types:
22+
23+
```python
24+
from openai.types import ChatModel
25+
```
26+
2127
## Completions
2228

2329
Types:

src/openai/resources/chat/completions.py

+9-192
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import httpx
99

1010
from ... import _legacy_response
11+
from ...types import ChatModel
1112
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
1213
from ..._utils import (
1314
required_args,
@@ -47,30 +48,7 @@ def create(
4748
self,
4849
*,
4950
messages: Iterable[ChatCompletionMessageParam],
50-
model: Union[
51-
str,
52-
Literal[
53-
"gpt-4-turbo",
54-
"gpt-4-turbo-2024-04-09",
55-
"gpt-4-0125-preview",
56-
"gpt-4-turbo-preview",
57-
"gpt-4-1106-preview",
58-
"gpt-4-vision-preview",
59-
"gpt-4",
60-
"gpt-4-0314",
61-
"gpt-4-0613",
62-
"gpt-4-32k",
63-
"gpt-4-32k-0314",
64-
"gpt-4-32k-0613",
65-
"gpt-3.5-turbo",
66-
"gpt-3.5-turbo-16k",
67-
"gpt-3.5-turbo-0301",
68-
"gpt-3.5-turbo-0613",
69-
"gpt-3.5-turbo-1106",
70-
"gpt-3.5-turbo-0125",
71-
"gpt-3.5-turbo-16k-0613",
72-
],
73-
],
51+
model: Union[str, ChatModel],
7452
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
7553
function_call: completion_create_params.FunctionCall | NotGiven = NOT_GIVEN,
7654
functions: Iterable[completion_create_params.Function] | NotGiven = NOT_GIVEN,
@@ -238,30 +216,7 @@ def create(
238216
self,
239217
*,
240218
messages: Iterable[ChatCompletionMessageParam],
241-
model: Union[
242-
str,
243-
Literal[
244-
"gpt-4-turbo",
245-
"gpt-4-turbo-2024-04-09",
246-
"gpt-4-0125-preview",
247-
"gpt-4-turbo-preview",
248-
"gpt-4-1106-preview",
249-
"gpt-4-vision-preview",
250-
"gpt-4",
251-
"gpt-4-0314",
252-
"gpt-4-0613",
253-
"gpt-4-32k",
254-
"gpt-4-32k-0314",
255-
"gpt-4-32k-0613",
256-
"gpt-3.5-turbo",
257-
"gpt-3.5-turbo-16k",
258-
"gpt-3.5-turbo-0301",
259-
"gpt-3.5-turbo-0613",
260-
"gpt-3.5-turbo-1106",
261-
"gpt-3.5-turbo-0125",
262-
"gpt-3.5-turbo-16k-0613",
263-
],
264-
],
219+
model: Union[str, ChatModel],
265220
stream: Literal[True],
266221
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
267222
function_call: completion_create_params.FunctionCall | NotGiven = NOT_GIVEN,
@@ -429,30 +384,7 @@ def create(
429384
self,
430385
*,
431386
messages: Iterable[ChatCompletionMessageParam],
432-
model: Union[
433-
str,
434-
Literal[
435-
"gpt-4-turbo",
436-
"gpt-4-turbo-2024-04-09",
437-
"gpt-4-0125-preview",
438-
"gpt-4-turbo-preview",
439-
"gpt-4-1106-preview",
440-
"gpt-4-vision-preview",
441-
"gpt-4",
442-
"gpt-4-0314",
443-
"gpt-4-0613",
444-
"gpt-4-32k",
445-
"gpt-4-32k-0314",
446-
"gpt-4-32k-0613",
447-
"gpt-3.5-turbo",
448-
"gpt-3.5-turbo-16k",
449-
"gpt-3.5-turbo-0301",
450-
"gpt-3.5-turbo-0613",
451-
"gpt-3.5-turbo-1106",
452-
"gpt-3.5-turbo-0125",
453-
"gpt-3.5-turbo-16k-0613",
454-
],
455-
],
387+
model: Union[str, ChatModel],
456388
stream: bool,
457389
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
458390
function_call: completion_create_params.FunctionCall | NotGiven = NOT_GIVEN,
@@ -620,30 +552,7 @@ def create(
620552
self,
621553
*,
622554
messages: Iterable[ChatCompletionMessageParam],
623-
model: Union[
624-
str,
625-
Literal[
626-
"gpt-4-turbo",
627-
"gpt-4-turbo-2024-04-09",
628-
"gpt-4-0125-preview",
629-
"gpt-4-turbo-preview",
630-
"gpt-4-1106-preview",
631-
"gpt-4-vision-preview",
632-
"gpt-4",
633-
"gpt-4-0314",
634-
"gpt-4-0613",
635-
"gpt-4-32k",
636-
"gpt-4-32k-0314",
637-
"gpt-4-32k-0613",
638-
"gpt-3.5-turbo",
639-
"gpt-3.5-turbo-16k",
640-
"gpt-3.5-turbo-0301",
641-
"gpt-3.5-turbo-0613",
642-
"gpt-3.5-turbo-1106",
643-
"gpt-3.5-turbo-0125",
644-
"gpt-3.5-turbo-16k-0613",
645-
],
646-
],
555+
model: Union[str, ChatModel],
647556
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
648557
function_call: completion_create_params.FunctionCall | NotGiven = NOT_GIVEN,
649558
functions: Iterable[completion_create_params.Function] | NotGiven = NOT_GIVEN,
@@ -719,30 +628,7 @@ async def create(
719628
self,
720629
*,
721630
messages: Iterable[ChatCompletionMessageParam],
722-
model: Union[
723-
str,
724-
Literal[
725-
"gpt-4-turbo",
726-
"gpt-4-turbo-2024-04-09",
727-
"gpt-4-0125-preview",
728-
"gpt-4-turbo-preview",
729-
"gpt-4-1106-preview",
730-
"gpt-4-vision-preview",
731-
"gpt-4",
732-
"gpt-4-0314",
733-
"gpt-4-0613",
734-
"gpt-4-32k",
735-
"gpt-4-32k-0314",
736-
"gpt-4-32k-0613",
737-
"gpt-3.5-turbo",
738-
"gpt-3.5-turbo-16k",
739-
"gpt-3.5-turbo-0301",
740-
"gpt-3.5-turbo-0613",
741-
"gpt-3.5-turbo-1106",
742-
"gpt-3.5-turbo-0125",
743-
"gpt-3.5-turbo-16k-0613",
744-
],
745-
],
631+
model: Union[str, ChatModel],
746632
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
747633
function_call: completion_create_params.FunctionCall | NotGiven = NOT_GIVEN,
748634
functions: Iterable[completion_create_params.Function] | NotGiven = NOT_GIVEN,
@@ -910,30 +796,7 @@ async def create(
910796
self,
911797
*,
912798
messages: Iterable[ChatCompletionMessageParam],
913-
model: Union[
914-
str,
915-
Literal[
916-
"gpt-4-turbo",
917-
"gpt-4-turbo-2024-04-09",
918-
"gpt-4-0125-preview",
919-
"gpt-4-turbo-preview",
920-
"gpt-4-1106-preview",
921-
"gpt-4-vision-preview",
922-
"gpt-4",
923-
"gpt-4-0314",
924-
"gpt-4-0613",
925-
"gpt-4-32k",
926-
"gpt-4-32k-0314",
927-
"gpt-4-32k-0613",
928-
"gpt-3.5-turbo",
929-
"gpt-3.5-turbo-16k",
930-
"gpt-3.5-turbo-0301",
931-
"gpt-3.5-turbo-0613",
932-
"gpt-3.5-turbo-1106",
933-
"gpt-3.5-turbo-0125",
934-
"gpt-3.5-turbo-16k-0613",
935-
],
936-
],
799+
model: Union[str, ChatModel],
937800
stream: Literal[True],
938801
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
939802
function_call: completion_create_params.FunctionCall | NotGiven = NOT_GIVEN,
@@ -1101,30 +964,7 @@ async def create(
1101964
self,
1102965
*,
1103966
messages: Iterable[ChatCompletionMessageParam],
1104-
model: Union[
1105-
str,
1106-
Literal[
1107-
"gpt-4-turbo",
1108-
"gpt-4-turbo-2024-04-09",
1109-
"gpt-4-0125-preview",
1110-
"gpt-4-turbo-preview",
1111-
"gpt-4-1106-preview",
1112-
"gpt-4-vision-preview",
1113-
"gpt-4",
1114-
"gpt-4-0314",
1115-
"gpt-4-0613",
1116-
"gpt-4-32k",
1117-
"gpt-4-32k-0314",
1118-
"gpt-4-32k-0613",
1119-
"gpt-3.5-turbo",
1120-
"gpt-3.5-turbo-16k",
1121-
"gpt-3.5-turbo-0301",
1122-
"gpt-3.5-turbo-0613",
1123-
"gpt-3.5-turbo-1106",
1124-
"gpt-3.5-turbo-0125",
1125-
"gpt-3.5-turbo-16k-0613",
1126-
],
1127-
],
967+
model: Union[str, ChatModel],
1128968
stream: bool,
1129969
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
1130970
function_call: completion_create_params.FunctionCall | NotGiven = NOT_GIVEN,
@@ -1292,30 +1132,7 @@ async def create(
12921132
self,
12931133
*,
12941134
messages: Iterable[ChatCompletionMessageParam],
1295-
model: Union[
1296-
str,
1297-
Literal[
1298-
"gpt-4-turbo",
1299-
"gpt-4-turbo-2024-04-09",
1300-
"gpt-4-0125-preview",
1301-
"gpt-4-turbo-preview",
1302-
"gpt-4-1106-preview",
1303-
"gpt-4-vision-preview",
1304-
"gpt-4",
1305-
"gpt-4-0314",
1306-
"gpt-4-0613",
1307-
"gpt-4-32k",
1308-
"gpt-4-32k-0314",
1309-
"gpt-4-32k-0613",
1310-
"gpt-3.5-turbo",
1311-
"gpt-3.5-turbo-16k",
1312-
"gpt-3.5-turbo-0301",
1313-
"gpt-3.5-turbo-0613",
1314-
"gpt-3.5-turbo-1106",
1315-
"gpt-3.5-turbo-0125",
1316-
"gpt-3.5-turbo-16k-0613",
1317-
],
1318-
],
1135+
model: Union[str, ChatModel],
13191136
frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
13201137
function_call: completion_create_params.FunctionCall | NotGiven = NOT_GIVEN,
13211138
functions: Iterable[completion_create_params.Function] | NotGiven = NOT_GIVEN,

src/openai/types/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
FunctionParameters as FunctionParameters,
1212
)
1313
from .embedding import Embedding as Embedding
14+
from .chat_model import ChatModel as ChatModel
1415
from .completion import Completion as Completion
1516
from .moderation import Moderation as Moderation
1617
from .batch_error import BatchError as BatchError

src/openai/types/chat/completion_create_params.py

+2-26
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing_extensions import Literal, Required, TypedDict
77

88
from ...types import shared_params
9+
from ..chat_model import ChatModel
910
from .chat_completion_tool_param import ChatCompletionToolParam
1011
from .chat_completion_message_param import ChatCompletionMessageParam
1112
from .chat_completion_tool_choice_option_param import ChatCompletionToolChoiceOptionParam
@@ -28,32 +29,7 @@ class CompletionCreateParamsBase(TypedDict, total=False):
2829
[Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).
2930
"""
3031

31-
model: Required[
32-
Union[
33-
str,
34-
Literal[
35-
"gpt-4-turbo",
36-
"gpt-4-turbo-2024-04-09",
37-
"gpt-4-0125-preview",
38-
"gpt-4-turbo-preview",
39-
"gpt-4-1106-preview",
40-
"gpt-4-vision-preview",
41-
"gpt-4",
42-
"gpt-4-0314",
43-
"gpt-4-0613",
44-
"gpt-4-32k",
45-
"gpt-4-32k-0314",
46-
"gpt-4-32k-0613",
47-
"gpt-3.5-turbo",
48-
"gpt-3.5-turbo-16k",
49-
"gpt-3.5-turbo-0301",
50-
"gpt-3.5-turbo-0613",
51-
"gpt-3.5-turbo-1106",
52-
"gpt-3.5-turbo-0125",
53-
"gpt-3.5-turbo-16k-0613",
54-
],
55-
]
56-
]
32+
model: Required[Union[str, ChatModel]]
5733
"""ID of the model to use.
5834
5935
See the

src/openai/types/chat_model.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing_extensions import Literal
4+
5+
__all__ = ["ChatModel"]
6+
7+
ChatModel = Literal[
8+
"gpt-4-turbo",
9+
"gpt-4-turbo-2024-04-09",
10+
"gpt-4-0125-preview",
11+
"gpt-4-turbo-preview",
12+
"gpt-4-1106-preview",
13+
"gpt-4-vision-preview",
14+
"gpt-4",
15+
"gpt-4-0314",
16+
"gpt-4-0613",
17+
"gpt-4-32k",
18+
"gpt-4-32k-0314",
19+
"gpt-4-32k-0613",
20+
"gpt-3.5-turbo",
21+
"gpt-3.5-turbo-16k",
22+
"gpt-3.5-turbo-0301",
23+
"gpt-3.5-turbo-0613",
24+
"gpt-3.5-turbo-1106",
25+
"gpt-3.5-turbo-0125",
26+
"gpt-3.5-turbo-16k-0613",
27+
]

0 commit comments

Comments
 (0)