9
9
10
10
from typing import Any , Dict , List , Optional , Union
11
11
12
- from typing_extensions import NotRequired , Literal , TypedDict
12
+ from typing_extensions import Literal , NotRequired , TypedDict
13
13
14
14
# NOTE: Defining this correctly using annotations seems to break pydantic validation.
15
15
# This is a workaround until we can figure out how to do this correctly
16
16
# JsonType = Union[None, int, str, bool, List["JsonType"], Dict[str, "JsonType"]]
17
- JsonType = Union [None , int , str , bool , list [Any ], dict [str , Any ]]
17
+ JsonType = Union [None , int , str , bool , List [Any ], Dict [str , Any ]]
18
18
19
19
20
20
class EmbeddingUsage (TypedDict ):
@@ -31,22 +31,22 @@ class Embedding(TypedDict):
31
31
class CreateEmbeddingResponse (TypedDict ):
32
32
object : Literal ["list" ]
33
33
model : str
34
- data : list [Embedding ]
34
+ data : List [Embedding ]
35
35
usage : EmbeddingUsage
36
36
37
37
38
38
class CompletionLogprobs (TypedDict ):
39
- text_offset : list [int ]
40
- token_logprobs : list [ float | None ]
41
- tokens : list [str ]
42
- top_logprobs : list [ dict [ str , float ] | None ]
39
+ text_offset : List [int ]
40
+ token_logprobs : List [ Optional [ float ] ]
41
+ tokens : List [str ]
42
+ top_logprobs : List [ Optional [ Dict [ str , float ]] ]
43
43
44
44
45
45
class CompletionChoice (TypedDict ):
46
46
text : str
47
47
index : int
48
- logprobs : CompletionLogprobs | None
49
- finish_reason : Literal ["stop" , "length" ] | None
48
+ logprobs : Optional [ CompletionLogprobs ]
49
+ finish_reason : Optional [ Literal ["stop" , "length" ]]
50
50
51
51
52
52
class CompletionUsage (TypedDict ):
@@ -60,7 +60,7 @@ class CreateCompletionResponse(TypedDict):
60
60
object : Literal ["text_completion" ]
61
61
created : int
62
62
model : str
63
- choices : list [CompletionChoice ]
63
+ choices : List [CompletionChoice ]
64
64
usage : NotRequired [CompletionUsage ]
65
65
66
66
@@ -70,7 +70,7 @@ class ChatCompletionResponseFunctionCall(TypedDict):
70
70
71
71
72
72
class ChatCompletionResponseMessage (TypedDict ):
73
- content : str | None
73
+ content : Optional [ str ]
74
74
tool_calls : NotRequired ["ChatCompletionMessageToolCalls" ]
75
75
role : Literal ["assistant" , "function" ] # NOTE: "function" may be incorrect here
76
76
function_call : NotRequired [ChatCompletionResponseFunctionCall ] # DEPRECATED
@@ -79,27 +79,27 @@ class ChatCompletionResponseMessage(TypedDict):
79
79
class ChatCompletionFunction (TypedDict ):
80
80
name : str
81
81
description : NotRequired [str ]
82
- parameters : dict [str , JsonType ] # TODO: make this more specific
82
+ parameters : Dict [str , JsonType ] # TODO: make this more specific
83
83
84
84
85
85
class ChatCompletionResponseChoice (TypedDict ):
86
86
index : int
87
87
message : "ChatCompletionResponseMessage"
88
- logprobs : CompletionLogprobs | None
89
- finish_reason : str | None
88
+ logprobs : Optional [ CompletionLogprobs ]
89
+ finish_reason : Optional [ str ]
90
90
91
91
92
92
class CreateChatCompletionResponse (TypedDict ):
93
93
id : str
94
94
object : Literal ["chat.completion" ]
95
95
created : int
96
96
model : str
97
- choices : list ["ChatCompletionResponseChoice" ]
97
+ choices : List ["ChatCompletionResponseChoice" ]
98
98
usage : CompletionUsage
99
99
100
100
101
101
class ChatCompletionMessageToolCallChunkFunction (TypedDict ):
102
- name : str | None
102
+ name : Optional [ str ]
103
103
arguments : str
104
104
105
105
@@ -120,33 +120,35 @@ class ChatCompletionStreamResponseDeltaFunctionCall(TypedDict):
120
120
121
121
122
122
class ChatCompletionStreamResponseDelta (TypedDict ):
123
- content : NotRequired [str | None ]
123
+ content : NotRequired [Optional [ str ] ]
124
124
function_call : NotRequired [
125
- ChatCompletionStreamResponseDeltaFunctionCall | None
125
+ Optional [ ChatCompletionStreamResponseDeltaFunctionCall ]
126
126
] # DEPRECATED
127
- tool_calls : NotRequired [list [ ChatCompletionMessageToolCallChunk ] | None ]
128
- role : NotRequired [Literal ["system" , "user" , "assistant" , "tool" ] | None ]
127
+ tool_calls : NotRequired [Optional [ List [ ChatCompletionMessageToolCallChunk ]] ]
128
+ role : NotRequired [Optional [ Literal ["system" , "user" , "assistant" , "tool" ]] ]
129
129
130
130
131
131
class ChatCompletionStreamResponseChoice (TypedDict ):
132
132
index : int
133
- delta : ChatCompletionStreamResponseDelta | ChatCompletionStreamResponseDeltaEmpty
134
- finish_reason : Literal ["stop" , "length" , "tool_calls" , "function_call" ] | None
135
- logprobs : NotRequired [CompletionLogprobs | None ]
133
+ delta : Union [
134
+ ChatCompletionStreamResponseDelta , ChatCompletionStreamResponseDeltaEmpty ,
135
+ ]
136
+ finish_reason : Optional [Literal ["stop" , "length" , "tool_calls" , "function_call" ]]
137
+ logprobs : NotRequired [Optional [CompletionLogprobs ]]
136
138
137
139
138
140
class CreateChatCompletionStreamResponse (TypedDict ):
139
141
id : str
140
142
model : str
141
143
object : Literal ["chat.completion.chunk" ]
142
144
created : int
143
- choices : list [ChatCompletionStreamResponseChoice ]
145
+ choices : List [ChatCompletionStreamResponseChoice ]
144
146
145
147
146
148
class ChatCompletionFunctions (TypedDict ):
147
149
name : str
148
150
description : NotRequired [str ]
149
- parameters : dict [str , JsonType ] # TODO: make this more specific
151
+ parameters : Dict [str , JsonType ] # TODO: make this more specific
150
152
151
153
152
154
class ChatCompletionFunctionCallOption (TypedDict ):
@@ -172,7 +174,7 @@ class ChatCompletionRequestMessageContentPartImageImageUrl(TypedDict):
172
174
173
175
class ChatCompletionRequestMessageContentPartImage (TypedDict ):
174
176
type : Literal ["image_url" ]
175
- image_url : str | ChatCompletionRequestMessageContentPartImageImageUrl
177
+ image_url : Union [ str , ChatCompletionRequestMessageContentPartImageImageUrl ]
176
178
177
179
178
180
ChatCompletionRequestMessageContentPart = Union [
@@ -183,12 +185,12 @@ class ChatCompletionRequestMessageContentPartImage(TypedDict):
183
185
184
186
class ChatCompletionRequestSystemMessage (TypedDict ):
185
187
role : Literal ["system" ]
186
- content : str | None
188
+ content : Optional [ str ]
187
189
188
190
189
191
class ChatCompletionRequestUserMessage (TypedDict ):
190
192
role : Literal ["user" ]
191
- content : str | list [ChatCompletionRequestMessageContentPart ] | None
193
+ content : Optional [ Union [ str , List [ChatCompletionRequestMessageContentPart ]]]
192
194
193
195
194
196
class ChatCompletionMessageToolCallFunction (TypedDict ):
@@ -202,7 +204,7 @@ class ChatCompletionMessageToolCall(TypedDict):
202
204
function : ChatCompletionMessageToolCallFunction
203
205
204
206
205
- ChatCompletionMessageToolCalls = list [ChatCompletionMessageToolCall ]
207
+ ChatCompletionMessageToolCalls = List [ChatCompletionMessageToolCall ]
206
208
207
209
208
210
class ChatCompletionRequestAssistantMessageFunctionCall (TypedDict ):
@@ -212,7 +214,7 @@ class ChatCompletionRequestAssistantMessageFunctionCall(TypedDict):
212
214
213
215
class ChatCompletionRequestAssistantMessage (TypedDict ):
214
216
role : Literal ["assistant" ]
215
- content : str | None
217
+ content : Optional [ str ]
216
218
tool_calls : NotRequired [ChatCompletionMessageToolCalls ]
217
219
function_call : NotRequired [
218
220
ChatCompletionRequestAssistantMessageFunctionCall
@@ -221,13 +223,13 @@ class ChatCompletionRequestAssistantMessage(TypedDict):
221
223
222
224
class ChatCompletionRequestToolMessage (TypedDict ):
223
225
role : Literal ["tool" ]
224
- content : str | None
226
+ content : Optional [ str ]
225
227
tool_call_id : str
226
228
227
229
228
230
class ChatCompletionRequestFunctionMessage (TypedDict ):
229
231
role : Literal ["function" ]
230
- content : str | None
232
+ content : Optional [ str ]
231
233
name : str
232
234
233
235
@@ -249,7 +251,7 @@ class ChatCompletionRequestFunctionCallOption(TypedDict):
249
251
Literal ["none" , "auto" ], ChatCompletionRequestFunctionCallOption ,
250
252
]
251
253
252
- ChatCompletionFunctionParameters = dict [str , JsonType ] # TODO: make this more specific
254
+ ChatCompletionFunctionParameters = Dict [str , JsonType ] # TODO: make this more specific
253
255
254
256
255
257
class ChatCompletionToolFunction (TypedDict ):
0 commit comments