orq-ai-sdk 4.2.0rc28__py3-none-any.whl → 4.2.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. orq_ai_sdk/_hooks/globalhook.py +0 -1
  2. orq_ai_sdk/_version.py +3 -3
  3. orq_ai_sdk/audio.py +30 -0
  4. orq_ai_sdk/basesdk.py +20 -6
  5. orq_ai_sdk/chat.py +22 -0
  6. orq_ai_sdk/completions.py +332 -0
  7. orq_ai_sdk/contacts.py +43 -855
  8. orq_ai_sdk/deployments.py +61 -0
  9. orq_ai_sdk/edits.py +258 -0
  10. orq_ai_sdk/embeddings.py +238 -0
  11. orq_ai_sdk/generations.py +272 -0
  12. orq_ai_sdk/identities.py +1037 -0
  13. orq_ai_sdk/images.py +28 -0
  14. orq_ai_sdk/models/__init__.py +5341 -737
  15. orq_ai_sdk/models/actionreviewedstreamingevent.py +18 -1
  16. orq_ai_sdk/models/actionreviewrequestedstreamingevent.py +44 -1
  17. orq_ai_sdk/models/agenterroredstreamingevent.py +18 -1
  18. orq_ai_sdk/models/agentinactivestreamingevent.py +168 -70
  19. orq_ai_sdk/models/agentmessagecreatedstreamingevent.py +18 -2
  20. orq_ai_sdk/models/agentresponsemessage.py +18 -2
  21. orq_ai_sdk/models/agentstartedstreamingevent.py +127 -2
  22. orq_ai_sdk/models/agentthoughtstreamingevent.py +178 -211
  23. orq_ai_sdk/models/conversationresponse.py +31 -20
  24. orq_ai_sdk/models/conversationwithmessagesresponse.py +31 -20
  25. orq_ai_sdk/models/createagentrequestop.py +1922 -384
  26. orq_ai_sdk/models/createagentresponse.py +147 -91
  27. orq_ai_sdk/models/createagentresponserequestop.py +111 -2
  28. orq_ai_sdk/models/createchatcompletionop.py +1375 -861
  29. orq_ai_sdk/models/createchunkop.py +46 -19
  30. orq_ai_sdk/models/createcompletionop.py +1890 -0
  31. orq_ai_sdk/models/createcontactop.py +45 -56
  32. orq_ai_sdk/models/createconversationop.py +61 -39
  33. orq_ai_sdk/models/createconversationresponseop.py +68 -4
  34. orq_ai_sdk/models/createdatasetitemop.py +424 -80
  35. orq_ai_sdk/models/createdatasetop.py +19 -2
  36. orq_ai_sdk/models/createdatasourceop.py +92 -26
  37. orq_ai_sdk/models/createembeddingop.py +384 -0
  38. orq_ai_sdk/models/createevalop.py +552 -24
  39. orq_ai_sdk/models/createidentityop.py +176 -0
  40. orq_ai_sdk/models/createimageeditop.py +504 -0
  41. orq_ai_sdk/models/createimageop.py +208 -117
  42. orq_ai_sdk/models/createimagevariationop.py +486 -0
  43. orq_ai_sdk/models/createknowledgeop.py +186 -121
  44. orq_ai_sdk/models/creatememorydocumentop.py +50 -1
  45. orq_ai_sdk/models/creatememoryop.py +34 -21
  46. orq_ai_sdk/models/creatememorystoreop.py +34 -1
  47. orq_ai_sdk/models/createmoderationop.py +521 -0
  48. orq_ai_sdk/models/createpromptop.py +2748 -1252
  49. orq_ai_sdk/models/creatererankop.py +416 -0
  50. orq_ai_sdk/models/createresponseop.py +2567 -0
  51. orq_ai_sdk/models/createspeechop.py +316 -0
  52. orq_ai_sdk/models/createtoolop.py +537 -12
  53. orq_ai_sdk/models/createtranscriptionop.py +562 -0
  54. orq_ai_sdk/models/createtranslationop.py +540 -0
  55. orq_ai_sdk/models/datapart.py +18 -1
  56. orq_ai_sdk/models/deletechunksop.py +34 -1
  57. orq_ai_sdk/models/{deletecontactop.py → deleteidentityop.py} +9 -9
  58. orq_ai_sdk/models/deletepromptop.py +26 -0
  59. orq_ai_sdk/models/deploymentcreatemetricop.py +362 -76
  60. orq_ai_sdk/models/deploymentgetconfigop.py +635 -194
  61. orq_ai_sdk/models/deploymentinvokeop.py +168 -173
  62. orq_ai_sdk/models/deploymentsop.py +195 -58
  63. orq_ai_sdk/models/deploymentstreamop.py +652 -304
  64. orq_ai_sdk/models/errorpart.py +18 -1
  65. orq_ai_sdk/models/filecontentpartschema.py +18 -1
  66. orq_ai_sdk/models/filegetop.py +19 -2
  67. orq_ai_sdk/models/filelistop.py +35 -2
  68. orq_ai_sdk/models/filepart.py +50 -1
  69. orq_ai_sdk/models/fileuploadop.py +51 -2
  70. orq_ai_sdk/models/generateconversationnameop.py +31 -20
  71. orq_ai_sdk/models/get_v2_evaluators_id_versionsop.py +34 -1
  72. orq_ai_sdk/models/get_v2_tools_tool_id_versions_version_id_op.py +18 -1
  73. orq_ai_sdk/models/get_v2_tools_tool_id_versionsop.py +34 -1
  74. orq_ai_sdk/models/getallmemoriesop.py +34 -21
  75. orq_ai_sdk/models/getallmemorydocumentsop.py +42 -1
  76. orq_ai_sdk/models/getallmemorystoresop.py +34 -1
  77. orq_ai_sdk/models/getallpromptsop.py +1690 -230
  78. orq_ai_sdk/models/getalltoolsop.py +325 -8
  79. orq_ai_sdk/models/getchunkscountop.py +34 -1
  80. orq_ai_sdk/models/getevalsop.py +395 -43
  81. orq_ai_sdk/models/getonechunkop.py +14 -19
  82. orq_ai_sdk/models/getoneknowledgeop.py +116 -96
  83. orq_ai_sdk/models/getonepromptop.py +1673 -230
  84. orq_ai_sdk/models/getpromptversionop.py +1670 -216
  85. orq_ai_sdk/models/imagecontentpartschema.py +50 -1
  86. orq_ai_sdk/models/internal/globals.py +18 -1
  87. orq_ai_sdk/models/invokeagentop.py +140 -2
  88. orq_ai_sdk/models/invokedeploymentrequest.py +418 -80
  89. orq_ai_sdk/models/invokeevalop.py +160 -131
  90. orq_ai_sdk/models/listagentsop.py +793 -166
  91. orq_ai_sdk/models/listchunksop.py +32 -19
  92. orq_ai_sdk/models/listchunkspaginatedop.py +46 -19
  93. orq_ai_sdk/models/listconversationsop.py +18 -1
  94. orq_ai_sdk/models/listdatasetdatapointsop.py +252 -42
  95. orq_ai_sdk/models/listdatasetsop.py +35 -2
  96. orq_ai_sdk/models/listdatasourcesop.py +35 -26
  97. orq_ai_sdk/models/{listcontactsop.py → listidentitiesop.py} +89 -79
  98. orq_ai_sdk/models/listknowledgebasesop.py +132 -96
  99. orq_ai_sdk/models/listmodelsop.py +1 -0
  100. orq_ai_sdk/models/listpromptversionsop.py +1684 -216
  101. orq_ai_sdk/models/parseop.py +161 -17
  102. orq_ai_sdk/models/partdoneevent.py +19 -2
  103. orq_ai_sdk/models/post_v2_router_ocrop.py +408 -0
  104. orq_ai_sdk/models/publiccontact.py +27 -4
  105. orq_ai_sdk/models/publicidentity.py +62 -0
  106. orq_ai_sdk/models/reasoningpart.py +19 -2
  107. orq_ai_sdk/models/refusalpartschema.py +18 -1
  108. orq_ai_sdk/models/remoteconfigsgetconfigop.py +34 -1
  109. orq_ai_sdk/models/responsedoneevent.py +114 -84
  110. orq_ai_sdk/models/responsestartedevent.py +18 -1
  111. orq_ai_sdk/models/retrieveagentrequestop.py +787 -166
  112. orq_ai_sdk/models/retrievedatapointop.py +236 -42
  113. orq_ai_sdk/models/retrievedatasetop.py +19 -2
  114. orq_ai_sdk/models/retrievedatasourceop.py +17 -26
  115. orq_ai_sdk/models/{retrievecontactop.py → retrieveidentityop.py} +38 -41
  116. orq_ai_sdk/models/retrievememorydocumentop.py +18 -1
  117. orq_ai_sdk/models/retrievememoryop.py +18 -21
  118. orq_ai_sdk/models/retrievememorystoreop.py +18 -1
  119. orq_ai_sdk/models/retrievetoolop.py +309 -8
  120. orq_ai_sdk/models/runagentop.py +1451 -197
  121. orq_ai_sdk/models/searchknowledgeop.py +108 -1
  122. orq_ai_sdk/models/security.py +18 -1
  123. orq_ai_sdk/models/streamagentop.py +93 -2
  124. orq_ai_sdk/models/streamrunagentop.py +1428 -195
  125. orq_ai_sdk/models/textcontentpartschema.py +34 -1
  126. orq_ai_sdk/models/thinkingconfigenabledschema.py +18 -1
  127. orq_ai_sdk/models/toolcallpart.py +18 -1
  128. orq_ai_sdk/models/tooldoneevent.py +18 -1
  129. orq_ai_sdk/models/toolexecutionfailedstreamingevent.py +50 -1
  130. orq_ai_sdk/models/toolexecutionfinishedstreamingevent.py +34 -1
  131. orq_ai_sdk/models/toolexecutionstartedstreamingevent.py +34 -1
  132. orq_ai_sdk/models/toolresultpart.py +18 -1
  133. orq_ai_sdk/models/toolreviewrequestedevent.py +18 -1
  134. orq_ai_sdk/models/toolstartedevent.py +18 -1
  135. orq_ai_sdk/models/updateagentop.py +1951 -404
  136. orq_ai_sdk/models/updatechunkop.py +46 -19
  137. orq_ai_sdk/models/updateconversationop.py +61 -39
  138. orq_ai_sdk/models/updatedatapointop.py +424 -80
  139. orq_ai_sdk/models/updatedatasetop.py +51 -2
  140. orq_ai_sdk/models/updatedatasourceop.py +17 -26
  141. orq_ai_sdk/models/updateevalop.py +577 -16
  142. orq_ai_sdk/models/{updatecontactop.py → updateidentityop.py} +78 -68
  143. orq_ai_sdk/models/updateknowledgeop.py +234 -190
  144. orq_ai_sdk/models/updatememorydocumentop.py +50 -1
  145. orq_ai_sdk/models/updatememoryop.py +50 -21
  146. orq_ai_sdk/models/updatememorystoreop.py +66 -1
  147. orq_ai_sdk/models/updatepromptop.py +2844 -1450
  148. orq_ai_sdk/models/updatetoolop.py +592 -9
  149. orq_ai_sdk/models/usermessagerequest.py +18 -2
  150. orq_ai_sdk/moderations.py +218 -0
  151. orq_ai_sdk/orq_completions.py +660 -0
  152. orq_ai_sdk/orq_responses.py +398 -0
  153. orq_ai_sdk/prompts.py +28 -36
  154. orq_ai_sdk/rerank.py +232 -0
  155. orq_ai_sdk/router.py +89 -641
  156. orq_ai_sdk/sdk.py +3 -0
  157. orq_ai_sdk/speech.py +251 -0
  158. orq_ai_sdk/transcriptions.py +326 -0
  159. orq_ai_sdk/translations.py +298 -0
  160. orq_ai_sdk/utils/__init__.py +13 -1
  161. orq_ai_sdk/variations.py +254 -0
  162. orq_ai_sdk-4.2.6.dist-info/METADATA +888 -0
  163. orq_ai_sdk-4.2.6.dist-info/RECORD +263 -0
  164. {orq_ai_sdk-4.2.0rc28.dist-info → orq_ai_sdk-4.2.6.dist-info}/WHEEL +2 -1
  165. orq_ai_sdk-4.2.6.dist-info/top_level.txt +1 -0
  166. orq_ai_sdk-4.2.0rc28.dist-info/METADATA +0 -867
  167. orq_ai_sdk-4.2.0rc28.dist-info/RECORD +0 -233
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
  from .publiccontact import PublicContact, PublicContactTypedDict
5
+ from .publicidentity import PublicIdentity, PublicIdentityTypedDict
5
6
  from orq_ai_sdk.types import (
6
7
  BaseModel,
7
8
  Nullable,
@@ -9,9 +10,10 @@ from orq_ai_sdk.types import (
9
10
  UNSET,
10
11
  UNSET_SENTINEL,
11
12
  )
13
+ import pydantic
12
14
  from pydantic import model_serializer
13
- from typing import Any, Dict, List, Literal, Optional
14
- from typing_extensions import NotRequired, TypedDict, deprecated
15
+ from typing import List, Literal, Optional
16
+ from typing_extensions import Annotated, NotRequired, TypedDict
15
17
 
16
18
 
17
19
  Background = Literal[
@@ -80,6 +82,22 @@ class CreateImageRetry(BaseModel):
80
82
  on_codes: Optional[List[float]] = None
81
83
  r"""HTTP status codes that trigger retry logic"""
82
84
 
85
+ @model_serializer(mode="wrap")
86
+ def serialize_model(self, handler):
87
+ optional_fields = set(["count", "on_codes"])
88
+ serialized = handler(self)
89
+ m = {}
90
+
91
+ for n, f in type(self).model_fields.items():
92
+ k = f.alias or n
93
+ val = serialized.get(k)
94
+
95
+ if val != UNSET_SENTINEL:
96
+ if val is not None or k not in optional_fields:
97
+ m[k] = val
98
+
99
+ return m
100
+
83
101
 
84
102
  class CreateImageFallbacksTypedDict(TypedDict):
85
103
  model: str
@@ -91,51 +109,6 @@ class CreateImageFallbacks(BaseModel):
91
109
  r"""Fallback model identifier"""
92
110
 
93
111
 
94
- @deprecated(
95
- "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
96
- )
97
- class CreateImageContactTypedDict(TypedDict):
98
- r"""@deprecated Use identity instead. Information about the contact making the request."""
99
-
100
- id: str
101
- r"""Unique identifier for the contact"""
102
- display_name: NotRequired[str]
103
- r"""Display name of the contact"""
104
- email: NotRequired[str]
105
- r"""Email address of the contact"""
106
- metadata: NotRequired[List[Dict[str, Any]]]
107
- r"""A hash of key/value pairs containing any other data about the contact"""
108
- logo_url: NotRequired[str]
109
- r"""URL to the contact's avatar or logo"""
110
- tags: NotRequired[List[str]]
111
- r"""A list of tags associated with the contact"""
112
-
113
-
114
- @deprecated(
115
- "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
116
- )
117
- class CreateImageContact(BaseModel):
118
- r"""@deprecated Use identity instead. Information about the contact making the request."""
119
-
120
- id: str
121
- r"""Unique identifier for the contact"""
122
-
123
- display_name: Optional[str] = None
124
- r"""Display name of the contact"""
125
-
126
- email: Optional[str] = None
127
- r"""Email address of the contact"""
128
-
129
- metadata: Optional[List[Dict[str, Any]]] = None
130
- r"""A hash of key/value pairs containing any other data about the contact"""
131
-
132
- logo_url: Optional[str] = None
133
- r"""URL to the contact's avatar or logo"""
134
-
135
- tags: Optional[List[str]] = None
136
- r"""A list of tags associated with the contact"""
137
-
138
-
139
112
  CreateImageType = Literal["exact_match",]
140
113
 
141
114
 
@@ -155,32 +128,74 @@ class CreateImageCache(BaseModel):
155
128
  ttl: Optional[float] = 1800
156
129
  r"""Time to live for cached responses in seconds. Maximum 259200 seconds (3 days)."""
157
130
 
131
+ @model_serializer(mode="wrap")
132
+ def serialize_model(self, handler):
133
+ optional_fields = set(["ttl"])
134
+ serialized = handler(self)
135
+ m = {}
136
+
137
+ for n, f in type(self).model_fields.items():
138
+ k = f.alias or n
139
+ val = serialized.get(k)
140
+
141
+ if val != UNSET_SENTINEL:
142
+ if val is not None or k not in optional_fields:
143
+ m[k] = val
144
+
145
+ return m
146
+
158
147
 
159
148
  CreateImageLoadBalancerType = Literal["weight_based",]
160
149
 
161
150
 
162
- class CreateImageLoadBalancer1TypedDict(TypedDict):
163
- type: CreateImageLoadBalancerType
151
+ class CreateImageLoadBalancerModelsTypedDict(TypedDict):
164
152
  model: str
165
153
  r"""Model identifier for load balancing"""
166
154
  weight: NotRequired[float]
167
155
  r"""Weight assigned to this model for load balancing"""
168
156
 
169
157
 
170
- class CreateImageLoadBalancer1(BaseModel):
171
- type: CreateImageLoadBalancerType
172
-
158
+ class CreateImageLoadBalancerModels(BaseModel):
173
159
  model: str
174
160
  r"""Model identifier for load balancing"""
175
161
 
176
162
  weight: Optional[float] = 0.5
177
163
  r"""Weight assigned to this model for load balancing"""
178
164
 
165
+ @model_serializer(mode="wrap")
166
+ def serialize_model(self, handler):
167
+ optional_fields = set(["weight"])
168
+ serialized = handler(self)
169
+ m = {}
170
+
171
+ for n, f in type(self).model_fields.items():
172
+ k = f.alias or n
173
+ val = serialized.get(k)
174
+
175
+ if val != UNSET_SENTINEL:
176
+ if val is not None or k not in optional_fields:
177
+ m[k] = val
178
+
179
+ return m
180
+
181
+
182
+ class CreateImageLoadBalancer1TypedDict(TypedDict):
183
+ type: CreateImageLoadBalancerType
184
+ models: List[CreateImageLoadBalancerModelsTypedDict]
185
+
186
+
187
+ class CreateImageLoadBalancer1(BaseModel):
188
+ type: CreateImageLoadBalancerType
189
+
190
+ models: List[CreateImageLoadBalancerModels]
191
+
179
192
 
180
193
  CreateImageLoadBalancerTypedDict = CreateImageLoadBalancer1TypedDict
194
+ r"""Array of models with weights for load balancing requests"""
181
195
 
182
196
 
183
197
  CreateImageLoadBalancer = CreateImageLoadBalancer1
198
+ r"""Array of models with weights for load balancing requests"""
184
199
 
185
200
 
186
201
  class CreateImageTimeoutTypedDict(TypedDict):
@@ -204,12 +219,13 @@ class CreateImageOrqTypedDict(TypedDict):
204
219
  r"""Retry configuration for the request"""
205
220
  fallbacks: NotRequired[List[CreateImageFallbacksTypedDict]]
206
221
  r"""Array of fallback models to use if primary model fails"""
207
- identity: NotRequired[PublicContactTypedDict]
222
+ identity: NotRequired[PublicIdentityTypedDict]
208
223
  r"""Information about the identity making the request. If the identity does not exist, it will be created automatically."""
209
- contact: NotRequired[CreateImageContactTypedDict]
224
+ contact: NotRequired[PublicContactTypedDict]
225
+ r"""@deprecated Use identity instead. Information about the contact making the request."""
210
226
  cache: NotRequired[CreateImageCacheTypedDict]
211
227
  r"""Cache configuration for the request."""
212
- load_balancer: NotRequired[List[CreateImageLoadBalancerTypedDict]]
228
+ load_balancer: NotRequired[CreateImageLoadBalancerTypedDict]
213
229
  r"""Array of models with weights for load balancing requests"""
214
230
  timeout: NotRequired[CreateImageTimeoutTypedDict]
215
231
  r"""Timeout configuration to apply to the request. If the request exceeds the timeout, it will be retried or fallback to the next model if configured."""
@@ -225,20 +241,53 @@ class CreateImageOrq(BaseModel):
225
241
  fallbacks: Optional[List[CreateImageFallbacks]] = None
226
242
  r"""Array of fallback models to use if primary model fails"""
227
243
 
228
- identity: Optional[PublicContact] = None
244
+ identity: Optional[PublicIdentity] = None
229
245
  r"""Information about the identity making the request. If the identity does not exist, it will be created automatically."""
230
246
 
231
- contact: Optional[CreateImageContact] = None
247
+ contact: Annotated[
248
+ Optional[PublicContact],
249
+ pydantic.Field(
250
+ deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
251
+ ),
252
+ ] = None
253
+ r"""@deprecated Use identity instead. Information about the contact making the request."""
232
254
 
233
255
  cache: Optional[CreateImageCache] = None
234
256
  r"""Cache configuration for the request."""
235
257
 
236
- load_balancer: Optional[List[CreateImageLoadBalancer]] = None
258
+ load_balancer: Optional[CreateImageLoadBalancer] = None
237
259
  r"""Array of models with weights for load balancing requests"""
238
260
 
239
261
  timeout: Optional[CreateImageTimeout] = None
240
262
  r"""Timeout configuration to apply to the request. If the request exceeds the timeout, it will be retried or fallback to the next model if configured."""
241
263
 
264
+ @model_serializer(mode="wrap")
265
+ def serialize_model(self, handler):
266
+ optional_fields = set(
267
+ [
268
+ "name",
269
+ "retry",
270
+ "fallbacks",
271
+ "identity",
272
+ "contact",
273
+ "cache",
274
+ "load_balancer",
275
+ "timeout",
276
+ ]
277
+ )
278
+ serialized = handler(self)
279
+ m = {}
280
+
281
+ for n, f in type(self).model_fields.items():
282
+ k = f.alias or n
283
+ val = serialized.get(k)
284
+
285
+ if val != UNSET_SENTINEL:
286
+ if val is not None or k not in optional_fields:
287
+ m[k] = val
288
+
289
+ return m
290
+
242
291
 
243
292
  class CreateImageRequestBodyTypedDict(TypedDict):
244
293
  r"""input"""
@@ -308,52 +357,51 @@ class CreateImageRequestBody(BaseModel):
308
357
 
309
358
  @model_serializer(mode="wrap")
310
359
  def serialize_model(self, handler):
311
- optional_fields = [
312
- "background",
313
- "moderation",
314
- "n",
315
- "output_compression",
316
- "output_format",
317
- "quality",
318
- "response_format",
319
- "size",
320
- "style",
321
- "orq",
322
- ]
323
- nullable_fields = [
324
- "background",
325
- "moderation",
326
- "n",
327
- "output_compression",
328
- "output_format",
329
- "quality",
330
- "response_format",
331
- "size",
332
- "style",
333
- ]
334
- null_default_fields = []
335
-
360
+ optional_fields = set(
361
+ [
362
+ "background",
363
+ "moderation",
364
+ "n",
365
+ "output_compression",
366
+ "output_format",
367
+ "quality",
368
+ "response_format",
369
+ "size",
370
+ "style",
371
+ "orq",
372
+ ]
373
+ )
374
+ nullable_fields = set(
375
+ [
376
+ "background",
377
+ "moderation",
378
+ "n",
379
+ "output_compression",
380
+ "output_format",
381
+ "quality",
382
+ "response_format",
383
+ "size",
384
+ "style",
385
+ ]
386
+ )
336
387
  serialized = handler(self)
337
-
338
388
  m = {}
339
389
 
340
390
  for n, f in type(self).model_fields.items():
341
391
  k = f.alias or n
342
392
  val = serialized.get(k)
343
- serialized.pop(k, None)
344
-
345
- optional_nullable = k in optional_fields and k in nullable_fields
346
- is_set = (
347
- self.__pydantic_fields_set__.intersection({n})
348
- or k in null_default_fields
349
- ) # pylint: disable=no-member
350
-
351
- if val is not None and val != UNSET_SENTINEL:
352
- m[k] = val
353
- elif val != UNSET_SENTINEL and (
354
- not k in optional_fields or (optional_nullable and is_set)
355
- ):
356
- m[k] = val
393
+ is_nullable_and_explicitly_set = (
394
+ k in nullable_fields
395
+ and (self.__pydantic_fields_set__.intersection({n})) # pylint: disable=no-member
396
+ )
397
+
398
+ if val != UNSET_SENTINEL:
399
+ if (
400
+ val is not None
401
+ or k not in optional_fields
402
+ or is_nullable_and_explicitly_set
403
+ ):
404
+ m[k] = val
357
405
 
358
406
  return m
359
407
 
@@ -379,31 +427,26 @@ class CreateImageData(BaseModel):
379
427
 
380
428
  @model_serializer(mode="wrap")
381
429
  def serialize_model(self, handler):
382
- optional_fields = ["revised_prompt", "b64_json", "url"]
383
- nullable_fields = ["revised_prompt"]
384
- null_default_fields = []
385
-
430
+ optional_fields = set(["revised_prompt", "b64_json", "url"])
431
+ nullable_fields = set(["revised_prompt"])
386
432
  serialized = handler(self)
387
-
388
433
  m = {}
389
434
 
390
435
  for n, f in type(self).model_fields.items():
391
436
  k = f.alias or n
392
437
  val = serialized.get(k)
393
- serialized.pop(k, None)
394
-
395
- optional_nullable = k in optional_fields and k in nullable_fields
396
- is_set = (
397
- self.__pydantic_fields_set__.intersection({n})
398
- or k in null_default_fields
399
- ) # pylint: disable=no-member
400
-
401
- if val is not None and val != UNSET_SENTINEL:
402
- m[k] = val
403
- elif val != UNSET_SENTINEL and (
404
- not k in optional_fields or (optional_nullable and is_set)
405
- ):
406
- m[k] = val
438
+ is_nullable_and_explicitly_set = (
439
+ k in nullable_fields
440
+ and (self.__pydantic_fields_set__.intersection({n})) # pylint: disable=no-member
441
+ )
442
+
443
+ if val != UNSET_SENTINEL:
444
+ if (
445
+ val is not None
446
+ or k not in optional_fields
447
+ or is_nullable_and_explicitly_set
448
+ ):
449
+ m[k] = val
407
450
 
408
451
  return m
409
452
 
@@ -418,6 +461,22 @@ class InputTokensDetails(BaseModel):
418
461
 
419
462
  text_tokens: Optional[float] = None
420
463
 
464
+ @model_serializer(mode="wrap")
465
+ def serialize_model(self, handler):
466
+ optional_fields = set(["image_tokens", "text_tokens"])
467
+ serialized = handler(self)
468
+ m = {}
469
+
470
+ for n, f in type(self).model_fields.items():
471
+ k = f.alias or n
472
+ val = serialized.get(k)
473
+
474
+ if val != UNSET_SENTINEL:
475
+ if val is not None or k not in optional_fields:
476
+ m[k] = val
477
+
478
+ return m
479
+
421
480
 
422
481
  class CreateImageUsageTypedDict(TypedDict):
423
482
  input_tokens_details: InputTokensDetailsTypedDict
@@ -435,6 +494,22 @@ class CreateImageUsage(BaseModel):
435
494
 
436
495
  total_tokens: Optional[float] = None
437
496
 
497
+ @model_serializer(mode="wrap")
498
+ def serialize_model(self, handler):
499
+ optional_fields = set(["input_tokens", "output_tokens", "total_tokens"])
500
+ serialized = handler(self)
501
+ m = {}
502
+
503
+ for n, f in type(self).model_fields.items():
504
+ k = f.alias or n
505
+ val = serialized.get(k)
506
+
507
+ if val != UNSET_SENTINEL:
508
+ if val is not None or k not in optional_fields:
509
+ m[k] = val
510
+
511
+ return m
512
+
438
513
 
439
514
  class CreateImageResponseBodyTypedDict(TypedDict):
440
515
  r"""Represents an image generation response from the API."""
@@ -456,3 +531,19 @@ class CreateImageResponseBody(BaseModel):
456
531
  r"""Represents the url or the content of an image generated."""
457
532
 
458
533
  usage: Optional[CreateImageUsage] = None
534
+
535
+ @model_serializer(mode="wrap")
536
+ def serialize_model(self, handler):
537
+ optional_fields = set(["usage"])
538
+ serialized = handler(self)
539
+ m = {}
540
+
541
+ for n, f in type(self).model_fields.items():
542
+ k = f.alias or n
543
+ val = serialized.get(k)
544
+
545
+ if val != UNSET_SENTINEL:
546
+ if val is not None or k not in optional_fields:
547
+ m[k] = val
548
+
549
+ return m