mistralai 1.10.0__py3-none-any.whl → 1.11.1__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 (270) hide show
  1. mistralai/_hooks/tracing.py +28 -3
  2. mistralai/_version.py +3 -3
  3. mistralai/accesses.py +22 -12
  4. mistralai/agents.py +88 -44
  5. mistralai/basesdk.py +6 -0
  6. mistralai/chat.py +96 -40
  7. mistralai/classifiers.py +48 -23
  8. mistralai/conversations.py +186 -64
  9. mistralai/documents.py +72 -26
  10. mistralai/embeddings.py +24 -9
  11. mistralai/extra/README.md +1 -1
  12. mistralai/extra/mcp/auth.py +10 -11
  13. mistralai/extra/mcp/base.py +17 -16
  14. mistralai/extra/mcp/sse.py +13 -15
  15. mistralai/extra/mcp/stdio.py +5 -6
  16. mistralai/extra/observability/otel.py +47 -68
  17. mistralai/extra/run/context.py +33 -43
  18. mistralai/extra/run/result.py +29 -30
  19. mistralai/extra/run/tools.py +8 -9
  20. mistralai/extra/struct_chat.py +15 -8
  21. mistralai/extra/utils/response_format.py +5 -3
  22. mistralai/files.py +58 -24
  23. mistralai/fim.py +20 -12
  24. mistralai/httpclient.py +0 -1
  25. mistralai/jobs.py +65 -26
  26. mistralai/libraries.py +20 -10
  27. mistralai/mistral_agents.py +438 -30
  28. mistralai/mistral_jobs.py +62 -17
  29. mistralai/models/__init__.py +46 -1
  30. mistralai/models/agent.py +1 -1
  31. mistralai/models/agentconversation.py +1 -1
  32. mistralai/models/agenthandoffdoneevent.py +1 -1
  33. mistralai/models/agenthandoffentry.py +3 -2
  34. mistralai/models/agenthandoffstartedevent.py +1 -1
  35. mistralai/models/agents_api_v1_agents_get_versionop.py +21 -0
  36. mistralai/models/agents_api_v1_agents_list_versionsop.py +33 -0
  37. mistralai/models/agents_api_v1_agents_listop.py +5 -1
  38. mistralai/models/agents_api_v1_conversations_listop.py +1 -1
  39. mistralai/models/agentscompletionrequest.py +2 -5
  40. mistralai/models/agentscompletionstreamrequest.py +2 -5
  41. mistralai/models/archiveftmodelout.py +1 -1
  42. mistralai/models/assistantmessage.py +1 -1
  43. mistralai/models/audiochunk.py +1 -1
  44. mistralai/models/audioencoding.py +18 -0
  45. mistralai/models/audioformat.py +17 -0
  46. mistralai/models/basemodelcard.py +1 -1
  47. mistralai/models/batchjobin.py +18 -9
  48. mistralai/models/batchjobout.py +6 -1
  49. mistralai/models/batchjobsout.py +1 -1
  50. mistralai/models/batchrequest.py +48 -0
  51. mistralai/models/chatcompletionchoice.py +10 -5
  52. mistralai/models/chatcompletionrequest.py +2 -5
  53. mistralai/models/chatcompletionstreamrequest.py +2 -5
  54. mistralai/models/classificationrequest.py +37 -3
  55. mistralai/models/classifierdetailedjobout.py +4 -2
  56. mistralai/models/classifierftmodelout.py +3 -2
  57. mistralai/models/classifierjobout.py +4 -2
  58. mistralai/models/codeinterpretertool.py +1 -1
  59. mistralai/models/completiondetailedjobout.py +5 -2
  60. mistralai/models/completionftmodelout.py +3 -2
  61. mistralai/models/completionjobout.py +5 -2
  62. mistralai/models/completionresponsestreamchoice.py +9 -8
  63. mistralai/models/conversationappendrequest.py +4 -1
  64. mistralai/models/conversationappendstreamrequest.py +4 -1
  65. mistralai/models/conversationhistory.py +2 -1
  66. mistralai/models/conversationmessages.py +1 -1
  67. mistralai/models/conversationrequest.py +5 -1
  68. mistralai/models/conversationresponse.py +2 -1
  69. mistralai/models/conversationrestartrequest.py +4 -1
  70. mistralai/models/conversationrestartstreamrequest.py +4 -1
  71. mistralai/models/conversationstreamrequest.py +5 -1
  72. mistralai/models/documentlibrarytool.py +1 -1
  73. mistralai/models/documenturlchunk.py +1 -1
  74. mistralai/models/embeddingdtype.py +7 -1
  75. mistralai/models/embeddingrequest.py +11 -3
  76. mistralai/models/encodingformat.py +4 -1
  77. mistralai/models/entitytype.py +8 -1
  78. mistralai/models/filepurpose.py +8 -1
  79. mistralai/models/files_api_routes_list_filesop.py +4 -11
  80. mistralai/models/files_api_routes_upload_fileop.py +2 -6
  81. mistralai/models/fileschema.py +3 -5
  82. mistralai/models/finetuneablemodeltype.py +4 -1
  83. mistralai/models/ftclassifierlossfunction.py +4 -1
  84. mistralai/models/ftmodelcard.py +1 -1
  85. mistralai/models/functioncallentry.py +3 -2
  86. mistralai/models/functioncallevent.py +1 -1
  87. mistralai/models/functionresultentry.py +3 -2
  88. mistralai/models/functiontool.py +1 -1
  89. mistralai/models/githubrepositoryin.py +1 -1
  90. mistralai/models/githubrepositoryout.py +1 -1
  91. mistralai/models/httpvalidationerror.py +4 -2
  92. mistralai/models/imagegenerationtool.py +1 -1
  93. mistralai/models/imageurlchunk.py +1 -1
  94. mistralai/models/jobs_api_routes_batch_get_batch_jobop.py +40 -3
  95. mistralai/models/jobsout.py +1 -1
  96. mistralai/models/legacyjobmetadataout.py +1 -1
  97. mistralai/models/messageinputentry.py +9 -3
  98. mistralai/models/messageoutputentry.py +6 -3
  99. mistralai/models/messageoutputevent.py +4 -2
  100. mistralai/models/mistralerror.py +11 -7
  101. mistralai/models/mistralpromptmode.py +1 -1
  102. mistralai/models/modelconversation.py +1 -1
  103. mistralai/models/no_response_error.py +5 -1
  104. mistralai/models/ocrrequest.py +11 -1
  105. mistralai/models/ocrtableobject.py +4 -1
  106. mistralai/models/referencechunk.py +1 -1
  107. mistralai/models/requestsource.py +5 -1
  108. mistralai/models/responsedoneevent.py +1 -1
  109. mistralai/models/responseerrorevent.py +1 -1
  110. mistralai/models/responseformats.py +5 -1
  111. mistralai/models/responsestartedevent.py +1 -1
  112. mistralai/models/responsevalidationerror.py +2 -0
  113. mistralai/models/retrievefileout.py +3 -5
  114. mistralai/models/sampletype.py +7 -1
  115. mistralai/models/sdkerror.py +2 -0
  116. mistralai/models/shareenum.py +7 -1
  117. mistralai/models/sharingdelete.py +2 -4
  118. mistralai/models/sharingin.py +3 -5
  119. mistralai/models/source.py +8 -1
  120. mistralai/models/systemmessage.py +1 -1
  121. mistralai/models/textchunk.py +1 -1
  122. mistralai/models/thinkchunk.py +1 -1
  123. mistralai/models/timestampgranularity.py +1 -1
  124. mistralai/models/tool.py +2 -6
  125. mistralai/models/toolcall.py +2 -6
  126. mistralai/models/toolchoice.py +2 -6
  127. mistralai/models/toolchoiceenum.py +6 -1
  128. mistralai/models/toolexecutiondeltaevent.py +2 -1
  129. mistralai/models/toolexecutiondoneevent.py +2 -1
  130. mistralai/models/toolexecutionentry.py +4 -2
  131. mistralai/models/toolexecutionstartedevent.py +2 -1
  132. mistralai/models/toolfilechunk.py +13 -5
  133. mistralai/models/toolmessage.py +1 -1
  134. mistralai/models/toolreferencechunk.py +15 -5
  135. mistralai/models/tooltypes.py +1 -1
  136. mistralai/models/transcriptionsegmentchunk.py +1 -1
  137. mistralai/models/transcriptionstreamdone.py +1 -1
  138. mistralai/models/transcriptionstreamlanguage.py +1 -1
  139. mistralai/models/transcriptionstreamsegmentdelta.py +1 -1
  140. mistralai/models/transcriptionstreamtextdelta.py +1 -1
  141. mistralai/models/unarchiveftmodelout.py +1 -1
  142. mistralai/models/uploadfileout.py +3 -5
  143. mistralai/models/usermessage.py +1 -1
  144. mistralai/models/wandbintegration.py +1 -1
  145. mistralai/models/wandbintegrationout.py +1 -1
  146. mistralai/models/websearchpremiumtool.py +1 -1
  147. mistralai/models/websearchtool.py +1 -1
  148. mistralai/models_.py +24 -12
  149. mistralai/ocr.py +38 -10
  150. mistralai/sdk.py +2 -2
  151. mistralai/transcriptions.py +28 -12
  152. mistralai/types/basemodel.py +41 -3
  153. mistralai/utils/__init__.py +0 -3
  154. mistralai/utils/annotations.py +32 -8
  155. mistralai/utils/enums.py +60 -0
  156. mistralai/utils/forms.py +21 -10
  157. mistralai/utils/queryparams.py +14 -2
  158. mistralai/utils/requestbodies.py +3 -3
  159. mistralai/utils/retries.py +69 -5
  160. mistralai/utils/serializers.py +0 -20
  161. mistralai/utils/unmarshal_json_response.py +15 -1
  162. {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/METADATA +144 -159
  163. mistralai-1.11.1.dist-info/RECORD +495 -0
  164. {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/WHEEL +1 -1
  165. mistralai_azure/_version.py +3 -3
  166. mistralai_azure/basesdk.py +21 -5
  167. mistralai_azure/chat.py +82 -109
  168. mistralai_azure/httpclient.py +0 -1
  169. mistralai_azure/models/__init__.py +66 -4
  170. mistralai_azure/models/assistantmessage.py +1 -1
  171. mistralai_azure/models/chatcompletionchoice.py +10 -7
  172. mistralai_azure/models/chatcompletionrequest.py +24 -10
  173. mistralai_azure/models/chatcompletionstreamrequest.py +24 -10
  174. mistralai_azure/models/completionresponsestreamchoice.py +11 -7
  175. mistralai_azure/models/documenturlchunk.py +1 -1
  176. mistralai_azure/models/httpvalidationerror.py +15 -8
  177. mistralai_azure/models/imageurlchunk.py +1 -1
  178. mistralai_azure/models/mistralazureerror.py +30 -0
  179. mistralai_azure/models/mistralpromptmode.py +1 -1
  180. mistralai_azure/models/no_response_error.py +17 -0
  181. mistralai_azure/models/ocrpageobject.py +32 -5
  182. mistralai_azure/models/ocrrequest.py +20 -1
  183. mistralai_azure/models/ocrtableobject.py +34 -0
  184. mistralai_azure/models/prediction.py +4 -0
  185. mistralai_azure/models/referencechunk.py +1 -1
  186. mistralai_azure/models/responseformat.py +4 -2
  187. mistralai_azure/models/responseformats.py +5 -2
  188. mistralai_azure/models/responsevalidationerror.py +27 -0
  189. mistralai_azure/models/sdkerror.py +32 -14
  190. mistralai_azure/models/systemmessage.py +8 -4
  191. mistralai_azure/models/systemmessagecontentchunks.py +21 -0
  192. mistralai_azure/models/textchunk.py +1 -1
  193. mistralai_azure/models/thinkchunk.py +35 -0
  194. mistralai_azure/models/tool.py +2 -6
  195. mistralai_azure/models/toolcall.py +2 -6
  196. mistralai_azure/models/toolchoice.py +2 -6
  197. mistralai_azure/models/toolchoiceenum.py +6 -1
  198. mistralai_azure/models/toolmessage.py +1 -1
  199. mistralai_azure/models/tooltypes.py +1 -1
  200. mistralai_azure/models/usermessage.py +1 -1
  201. mistralai_azure/ocr.py +39 -40
  202. mistralai_azure/types/basemodel.py +41 -3
  203. mistralai_azure/utils/__init__.py +18 -8
  204. mistralai_azure/utils/annotations.py +32 -8
  205. mistralai_azure/utils/enums.py +60 -0
  206. mistralai_azure/utils/eventstreaming.py +10 -0
  207. mistralai_azure/utils/forms.py +21 -10
  208. mistralai_azure/utils/queryparams.py +14 -2
  209. mistralai_azure/utils/requestbodies.py +3 -3
  210. mistralai_azure/utils/retries.py +69 -5
  211. mistralai_azure/utils/serializers.py +3 -22
  212. mistralai_azure/utils/unmarshal_json_response.py +38 -0
  213. mistralai_gcp/_hooks/types.py +7 -0
  214. mistralai_gcp/_version.py +4 -4
  215. mistralai_gcp/basesdk.py +33 -25
  216. mistralai_gcp/chat.py +98 -109
  217. mistralai_gcp/fim.py +62 -85
  218. mistralai_gcp/httpclient.py +6 -17
  219. mistralai_gcp/models/__init__.py +321 -116
  220. mistralai_gcp/models/assistantmessage.py +2 -2
  221. mistralai_gcp/models/chatcompletionchoice.py +10 -7
  222. mistralai_gcp/models/chatcompletionrequest.py +38 -7
  223. mistralai_gcp/models/chatcompletionresponse.py +6 -6
  224. mistralai_gcp/models/chatcompletionstreamrequest.py +38 -7
  225. mistralai_gcp/models/completionresponsestreamchoice.py +12 -8
  226. mistralai_gcp/models/deltamessage.py +1 -1
  227. mistralai_gcp/models/fimcompletionrequest.py +9 -10
  228. mistralai_gcp/models/fimcompletionresponse.py +6 -6
  229. mistralai_gcp/models/fimcompletionstreamrequest.py +9 -10
  230. mistralai_gcp/models/httpvalidationerror.py +15 -8
  231. mistralai_gcp/models/imageurl.py +1 -1
  232. mistralai_gcp/models/imageurlchunk.py +1 -1
  233. mistralai_gcp/models/jsonschema.py +1 -1
  234. mistralai_gcp/models/mistralgcperror.py +30 -0
  235. mistralai_gcp/models/mistralpromptmode.py +8 -0
  236. mistralai_gcp/models/no_response_error.py +17 -0
  237. mistralai_gcp/models/prediction.py +4 -0
  238. mistralai_gcp/models/referencechunk.py +1 -1
  239. mistralai_gcp/models/responseformat.py +5 -3
  240. mistralai_gcp/models/responseformats.py +5 -2
  241. mistralai_gcp/models/responsevalidationerror.py +27 -0
  242. mistralai_gcp/models/sdkerror.py +32 -14
  243. mistralai_gcp/models/systemmessage.py +8 -4
  244. mistralai_gcp/models/systemmessagecontentchunks.py +21 -0
  245. mistralai_gcp/models/textchunk.py +1 -1
  246. mistralai_gcp/models/thinkchunk.py +35 -0
  247. mistralai_gcp/models/tool.py +2 -6
  248. mistralai_gcp/models/toolcall.py +2 -6
  249. mistralai_gcp/models/toolchoice.py +2 -6
  250. mistralai_gcp/models/toolchoiceenum.py +6 -1
  251. mistralai_gcp/models/toolmessage.py +2 -2
  252. mistralai_gcp/models/tooltypes.py +1 -1
  253. mistralai_gcp/models/usageinfo.py +71 -8
  254. mistralai_gcp/models/usermessage.py +2 -2
  255. mistralai_gcp/sdk.py +12 -10
  256. mistralai_gcp/sdkconfiguration.py +0 -7
  257. mistralai_gcp/types/basemodel.py +41 -3
  258. mistralai_gcp/utils/__init__.py +141 -46
  259. mistralai_gcp/utils/annotations.py +32 -8
  260. mistralai_gcp/utils/datetimes.py +23 -0
  261. mistralai_gcp/utils/enums.py +125 -25
  262. mistralai_gcp/utils/eventstreaming.py +10 -0
  263. mistralai_gcp/utils/forms.py +62 -30
  264. mistralai_gcp/utils/queryparams.py +14 -2
  265. mistralai_gcp/utils/requestbodies.py +3 -3
  266. mistralai_gcp/utils/retries.py +69 -5
  267. mistralai_gcp/utils/serializers.py +33 -23
  268. mistralai_gcp/utils/unmarshal_json_response.py +38 -0
  269. mistralai-1.10.0.dist-info/RECORD +0 -475
  270. {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/licenses/LICENSE +0 -0
mistralai_azure/chat.py CHANGED
@@ -5,7 +5,8 @@ from mistralai_azure import models, utils
5
5
  from mistralai_azure._hooks import HookContext
6
6
  from mistralai_azure.types import OptionalNullable, UNSET
7
7
  from mistralai_azure.utils import eventstreaming
8
- from typing import Any, List, Mapping, Optional, Union
8
+ from mistralai_azure.utils.unmarshal_json_response import unmarshal_json_response
9
+ from typing import Any, Dict, List, Mapping, Optional, Union
9
10
 
10
11
 
11
12
  class Chat(BaseSDK):
@@ -22,6 +23,7 @@ class Chat(BaseSDK):
22
23
  stream: Optional[bool] = True,
23
24
  stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
24
25
  random_seed: OptionalNullable[int] = UNSET,
26
+ metadata: OptionalNullable[Dict[str, Any]] = UNSET,
25
27
  response_format: Optional[
26
28
  Union[models.ResponseFormat, models.ResponseFormatTypedDict]
27
29
  ] = None,
@@ -47,7 +49,7 @@ class Chat(BaseSDK):
47
49
  server_url: Optional[str] = None,
48
50
  timeout_ms: Optional[int] = None,
49
51
  http_headers: Optional[Mapping[str, str]] = None,
50
- ) -> Optional[eventstreaming.EventStream[models.CompletionEvent]]:
52
+ ) -> eventstreaming.EventStream[models.CompletionEvent]:
51
53
  r"""Stream chat completion
52
54
 
53
55
  Mistral AI provides the ability to stream responses back to a client in order to allow partial results for certain requests. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
@@ -60,14 +62,15 @@ class Chat(BaseSDK):
60
62
  :param stream:
61
63
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
62
64
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
63
- :param response_format:
64
- :param tools:
65
- :param tool_choice:
66
- :param presence_penalty: presence_penalty determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
67
- :param frequency_penalty: frequency_penalty penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
65
+ :param metadata:
66
+ :param response_format: Specify the format that the model must output. By default it will use `{ \"type\": \"text\" }`. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message. Setting to `{ \"type\": \"json_schema\" }` enables JSON schema mode, which guarantees the message the model generates is in JSON and follows the schema you provide.
67
+ :param tools: A list of tools the model may call. Use this to provide a list of functions the model may generate JSON inputs for.
68
+ :param tool_choice: Controls which (if any) tool is called by the model. `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `any` or `required` means the model must call one or more tools. Specifying a particular tool via `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to call that tool.
69
+ :param presence_penalty: The `presence_penalty` determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
70
+ :param frequency_penalty: The `frequency_penalty` penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
68
71
  :param n: Number of completions to return for each request, input tokens are only billed once.
69
- :param prediction:
70
- :param parallel_tool_calls:
72
+ :param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
73
+ :param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
71
74
  :param prompt_mode: Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used.
72
75
  :param safe_prompt: Whether to inject a safety prompt before all conversations.
73
76
  :param retries: Override the default retry configuration for this method
@@ -93,6 +96,7 @@ class Chat(BaseSDK):
93
96
  stream=stream,
94
97
  stop=stop,
95
98
  random_seed=random_seed,
99
+ metadata=metadata,
96
100
  messages=utils.get_pydantic_model(messages, List[models.Messages]),
97
101
  response_format=utils.get_pydantic_model(
98
102
  response_format, Optional[models.ResponseFormat]
@@ -128,6 +132,7 @@ class Chat(BaseSDK):
128
132
  get_serialized_body=lambda: utils.serialize_request_body(
129
133
  request, False, False, "json", models.ChatCompletionStreamRequest
130
134
  ),
135
+ allow_empty_value=None,
131
136
  timeout_ms=timeout_ms,
132
137
  )
133
138
 
@@ -144,7 +149,7 @@ class Chat(BaseSDK):
144
149
  config=self.sdk_configuration,
145
150
  base_url=base_url or "",
146
151
  operation_id="stream_chat",
147
- oauth2_scopes=[],
152
+ oauth2_scopes=None,
148
153
  security_source=self.sdk_configuration.security,
149
154
  ),
150
155
  request=req,
@@ -159,32 +164,23 @@ class Chat(BaseSDK):
159
164
  http_res,
160
165
  lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
161
166
  sentinel="[DONE]",
167
+ client_ref=self,
162
168
  )
163
169
  if utils.match_response(http_res, "422", "application/json"):
164
170
  http_res_text = utils.stream_to_text(http_res)
165
- response_data = utils.unmarshal_json(
166
- http_res_text, models.HTTPValidationErrorData
171
+ response_data = unmarshal_json_response(
172
+ models.HTTPValidationErrorData, http_res, http_res_text
167
173
  )
168
- raise models.HTTPValidationError(data=response_data)
174
+ raise models.HTTPValidationError(response_data, http_res, http_res_text)
169
175
  if utils.match_response(http_res, "4XX", "*"):
170
176
  http_res_text = utils.stream_to_text(http_res)
171
- raise models.SDKError(
172
- "API error occurred", http_res.status_code, http_res_text, http_res
173
- )
177
+ raise models.SDKError("API error occurred", http_res, http_res_text)
174
178
  if utils.match_response(http_res, "5XX", "*"):
175
179
  http_res_text = utils.stream_to_text(http_res)
176
- raise models.SDKError(
177
- "API error occurred", http_res.status_code, http_res_text, http_res
178
- )
180
+ raise models.SDKError("API error occurred", http_res, http_res_text)
179
181
 
180
- content_type = http_res.headers.get("Content-Type")
181
182
  http_res_text = utils.stream_to_text(http_res)
182
- raise models.SDKError(
183
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
184
- http_res.status_code,
185
- http_res_text,
186
- http_res,
187
- )
183
+ raise models.SDKError("Unexpected response received", http_res, http_res_text)
188
184
 
189
185
  async def stream_async(
190
186
  self,
@@ -197,6 +193,7 @@ class Chat(BaseSDK):
197
193
  stream: Optional[bool] = True,
198
194
  stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
199
195
  random_seed: OptionalNullable[int] = UNSET,
196
+ metadata: OptionalNullable[Dict[str, Any]] = UNSET,
200
197
  response_format: Optional[
201
198
  Union[models.ResponseFormat, models.ResponseFormatTypedDict]
202
199
  ] = None,
@@ -222,7 +219,7 @@ class Chat(BaseSDK):
222
219
  server_url: Optional[str] = None,
223
220
  timeout_ms: Optional[int] = None,
224
221
  http_headers: Optional[Mapping[str, str]] = None,
225
- ) -> Optional[eventstreaming.EventStreamAsync[models.CompletionEvent]]:
222
+ ) -> eventstreaming.EventStreamAsync[models.CompletionEvent]:
226
223
  r"""Stream chat completion
227
224
 
228
225
  Mistral AI provides the ability to stream responses back to a client in order to allow partial results for certain requests. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
@@ -235,14 +232,15 @@ class Chat(BaseSDK):
235
232
  :param stream:
236
233
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
237
234
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
238
- :param response_format:
239
- :param tools:
240
- :param tool_choice:
241
- :param presence_penalty: presence_penalty determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
242
- :param frequency_penalty: frequency_penalty penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
235
+ :param metadata:
236
+ :param response_format: Specify the format that the model must output. By default it will use `{ \"type\": \"text\" }`. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message. Setting to `{ \"type\": \"json_schema\" }` enables JSON schema mode, which guarantees the message the model generates is in JSON and follows the schema you provide.
237
+ :param tools: A list of tools the model may call. Use this to provide a list of functions the model may generate JSON inputs for.
238
+ :param tool_choice: Controls which (if any) tool is called by the model. `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `any` or `required` means the model must call one or more tools. Specifying a particular tool via `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to call that tool.
239
+ :param presence_penalty: The `presence_penalty` determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
240
+ :param frequency_penalty: The `frequency_penalty` penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
243
241
  :param n: Number of completions to return for each request, input tokens are only billed once.
244
- :param prediction:
245
- :param parallel_tool_calls:
242
+ :param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
243
+ :param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
246
244
  :param prompt_mode: Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used.
247
245
  :param safe_prompt: Whether to inject a safety prompt before all conversations.
248
246
  :param retries: Override the default retry configuration for this method
@@ -268,6 +266,7 @@ class Chat(BaseSDK):
268
266
  stream=stream,
269
267
  stop=stop,
270
268
  random_seed=random_seed,
269
+ metadata=metadata,
271
270
  messages=utils.get_pydantic_model(messages, List[models.Messages]),
272
271
  response_format=utils.get_pydantic_model(
273
272
  response_format, Optional[models.ResponseFormat]
@@ -303,6 +302,7 @@ class Chat(BaseSDK):
303
302
  get_serialized_body=lambda: utils.serialize_request_body(
304
303
  request, False, False, "json", models.ChatCompletionStreamRequest
305
304
  ),
305
+ allow_empty_value=None,
306
306
  timeout_ms=timeout_ms,
307
307
  )
308
308
 
@@ -319,7 +319,7 @@ class Chat(BaseSDK):
319
319
  config=self.sdk_configuration,
320
320
  base_url=base_url or "",
321
321
  operation_id="stream_chat",
322
- oauth2_scopes=[],
322
+ oauth2_scopes=None,
323
323
  security_source=self.sdk_configuration.security,
324
324
  ),
325
325
  request=req,
@@ -334,32 +334,23 @@ class Chat(BaseSDK):
334
334
  http_res,
335
335
  lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
336
336
  sentinel="[DONE]",
337
+ client_ref=self,
337
338
  )
338
339
  if utils.match_response(http_res, "422", "application/json"):
339
340
  http_res_text = await utils.stream_to_text_async(http_res)
340
- response_data = utils.unmarshal_json(
341
- http_res_text, models.HTTPValidationErrorData
341
+ response_data = unmarshal_json_response(
342
+ models.HTTPValidationErrorData, http_res, http_res_text
342
343
  )
343
- raise models.HTTPValidationError(data=response_data)
344
+ raise models.HTTPValidationError(response_data, http_res, http_res_text)
344
345
  if utils.match_response(http_res, "4XX", "*"):
345
346
  http_res_text = await utils.stream_to_text_async(http_res)
346
- raise models.SDKError(
347
- "API error occurred", http_res.status_code, http_res_text, http_res
348
- )
347
+ raise models.SDKError("API error occurred", http_res, http_res_text)
349
348
  if utils.match_response(http_res, "5XX", "*"):
350
349
  http_res_text = await utils.stream_to_text_async(http_res)
351
- raise models.SDKError(
352
- "API error occurred", http_res.status_code, http_res_text, http_res
353
- )
350
+ raise models.SDKError("API error occurred", http_res, http_res_text)
354
351
 
355
- content_type = http_res.headers.get("Content-Type")
356
352
  http_res_text = await utils.stream_to_text_async(http_res)
357
- raise models.SDKError(
358
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
359
- http_res.status_code,
360
- http_res_text,
361
- http_res,
362
- )
353
+ raise models.SDKError("Unexpected response received", http_res, http_res_text)
363
354
 
364
355
  def complete(
365
356
  self,
@@ -380,6 +371,7 @@ class Chat(BaseSDK):
380
371
  ]
381
372
  ] = None,
382
373
  random_seed: OptionalNullable[int] = UNSET,
374
+ metadata: OptionalNullable[Dict[str, Any]] = UNSET,
383
375
  response_format: Optional[
384
376
  Union[models.ResponseFormat, models.ResponseFormatTypedDict]
385
377
  ] = None,
@@ -405,7 +397,7 @@ class Chat(BaseSDK):
405
397
  server_url: Optional[str] = None,
406
398
  timeout_ms: Optional[int] = None,
407
399
  http_headers: Optional[Mapping[str, str]] = None,
408
- ) -> Optional[models.ChatCompletionResponse]:
400
+ ) -> models.ChatCompletionResponse:
409
401
  r"""Chat Completion
410
402
 
411
403
  :param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
@@ -416,14 +408,15 @@ class Chat(BaseSDK):
416
408
  :param stream: Whether to stream back partial progress. If set, tokens will be sent as data-only server-side events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
417
409
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
418
410
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
419
- :param response_format:
420
- :param tools:
421
- :param tool_choice:
422
- :param presence_penalty: presence_penalty determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
423
- :param frequency_penalty: frequency_penalty penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
411
+ :param metadata:
412
+ :param response_format: Specify the format that the model must output. By default it will use `{ \"type\": \"text\" }`. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message. Setting to `{ \"type\": \"json_schema\" }` enables JSON schema mode, which guarantees the message the model generates is in JSON and follows the schema you provide.
413
+ :param tools: A list of tools the model may call. Use this to provide a list of functions the model may generate JSON inputs for.
414
+ :param tool_choice: Controls which (if any) tool is called by the model. `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `any` or `required` means the model must call one or more tools. Specifying a particular tool via `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to call that tool.
415
+ :param presence_penalty: The `presence_penalty` determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
416
+ :param frequency_penalty: The `frequency_penalty` penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
424
417
  :param n: Number of completions to return for each request, input tokens are only billed once.
425
- :param prediction:
426
- :param parallel_tool_calls:
418
+ :param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
419
+ :param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
427
420
  :param prompt_mode: Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used.
428
421
  :param safe_prompt: Whether to inject a safety prompt before all conversations.
429
422
  :param retries: Override the default retry configuration for this method
@@ -449,6 +442,7 @@ class Chat(BaseSDK):
449
442
  stream=stream,
450
443
  stop=stop,
451
444
  random_seed=random_seed,
445
+ metadata=metadata,
452
446
  messages=utils.get_pydantic_model(
453
447
  messages, List[models.ChatCompletionRequestMessages]
454
448
  ),
@@ -486,6 +480,7 @@ class Chat(BaseSDK):
486
480
  get_serialized_body=lambda: utils.serialize_request_body(
487
481
  request, False, False, "json", models.ChatCompletionRequest
488
482
  ),
483
+ allow_empty_value=None,
489
484
  timeout_ms=timeout_ms,
490
485
  )
491
486
 
@@ -502,7 +497,7 @@ class Chat(BaseSDK):
502
497
  config=self.sdk_configuration,
503
498
  base_url=base_url or "",
504
499
  operation_id="chat_completion_v1_chat_completions_post",
505
- oauth2_scopes=[],
500
+ oauth2_scopes=None,
506
501
  security_source=self.sdk_configuration.security,
507
502
  ),
508
503
  request=req,
@@ -512,33 +507,20 @@ class Chat(BaseSDK):
512
507
 
513
508
  response_data: Any = None
514
509
  if utils.match_response(http_res, "200", "application/json"):
515
- return utils.unmarshal_json(
516
- http_res.text, Optional[models.ChatCompletionResponse]
517
- )
510
+ return unmarshal_json_response(models.ChatCompletionResponse, http_res)
518
511
  if utils.match_response(http_res, "422", "application/json"):
519
- response_data = utils.unmarshal_json(
520
- http_res.text, models.HTTPValidationErrorData
512
+ response_data = unmarshal_json_response(
513
+ models.HTTPValidationErrorData, http_res
521
514
  )
522
- raise models.HTTPValidationError(data=response_data)
515
+ raise models.HTTPValidationError(response_data, http_res)
523
516
  if utils.match_response(http_res, "4XX", "*"):
524
517
  http_res_text = utils.stream_to_text(http_res)
525
- raise models.SDKError(
526
- "API error occurred", http_res.status_code, http_res_text, http_res
527
- )
518
+ raise models.SDKError("API error occurred", http_res, http_res_text)
528
519
  if utils.match_response(http_res, "5XX", "*"):
529
520
  http_res_text = utils.stream_to_text(http_res)
530
- raise models.SDKError(
531
- "API error occurred", http_res.status_code, http_res_text, http_res
532
- )
521
+ raise models.SDKError("API error occurred", http_res, http_res_text)
533
522
 
534
- content_type = http_res.headers.get("Content-Type")
535
- http_res_text = utils.stream_to_text(http_res)
536
- raise models.SDKError(
537
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
538
- http_res.status_code,
539
- http_res_text,
540
- http_res,
541
- )
523
+ raise models.SDKError("Unexpected response received", http_res)
542
524
 
543
525
  async def complete_async(
544
526
  self,
@@ -559,6 +541,7 @@ class Chat(BaseSDK):
559
541
  ]
560
542
  ] = None,
561
543
  random_seed: OptionalNullable[int] = UNSET,
544
+ metadata: OptionalNullable[Dict[str, Any]] = UNSET,
562
545
  response_format: Optional[
563
546
  Union[models.ResponseFormat, models.ResponseFormatTypedDict]
564
547
  ] = None,
@@ -584,7 +567,7 @@ class Chat(BaseSDK):
584
567
  server_url: Optional[str] = None,
585
568
  timeout_ms: Optional[int] = None,
586
569
  http_headers: Optional[Mapping[str, str]] = None,
587
- ) -> Optional[models.ChatCompletionResponse]:
570
+ ) -> models.ChatCompletionResponse:
588
571
  r"""Chat Completion
589
572
 
590
573
  :param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
@@ -595,14 +578,15 @@ class Chat(BaseSDK):
595
578
  :param stream: Whether to stream back partial progress. If set, tokens will be sent as data-only server-side events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
596
579
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
597
580
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
598
- :param response_format:
599
- :param tools:
600
- :param tool_choice:
601
- :param presence_penalty: presence_penalty determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
602
- :param frequency_penalty: frequency_penalty penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
581
+ :param metadata:
582
+ :param response_format: Specify the format that the model must output. By default it will use `{ \"type\": \"text\" }`. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message. Setting to `{ \"type\": \"json_schema\" }` enables JSON schema mode, which guarantees the message the model generates is in JSON and follows the schema you provide.
583
+ :param tools: A list of tools the model may call. Use this to provide a list of functions the model may generate JSON inputs for.
584
+ :param tool_choice: Controls which (if any) tool is called by the model. `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `any` or `required` means the model must call one or more tools. Specifying a particular tool via `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to call that tool.
585
+ :param presence_penalty: The `presence_penalty` determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
586
+ :param frequency_penalty: The `frequency_penalty` penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
603
587
  :param n: Number of completions to return for each request, input tokens are only billed once.
604
- :param prediction:
605
- :param parallel_tool_calls:
588
+ :param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
589
+ :param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
606
590
  :param prompt_mode: Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used.
607
591
  :param safe_prompt: Whether to inject a safety prompt before all conversations.
608
592
  :param retries: Override the default retry configuration for this method
@@ -628,6 +612,7 @@ class Chat(BaseSDK):
628
612
  stream=stream,
629
613
  stop=stop,
630
614
  random_seed=random_seed,
615
+ metadata=metadata,
631
616
  messages=utils.get_pydantic_model(
632
617
  messages, List[models.ChatCompletionRequestMessages]
633
618
  ),
@@ -665,6 +650,7 @@ class Chat(BaseSDK):
665
650
  get_serialized_body=lambda: utils.serialize_request_body(
666
651
  request, False, False, "json", models.ChatCompletionRequest
667
652
  ),
653
+ allow_empty_value=None,
668
654
  timeout_ms=timeout_ms,
669
655
  )
670
656
 
@@ -681,7 +667,7 @@ class Chat(BaseSDK):
681
667
  config=self.sdk_configuration,
682
668
  base_url=base_url or "",
683
669
  operation_id="chat_completion_v1_chat_completions_post",
684
- oauth2_scopes=[],
670
+ oauth2_scopes=None,
685
671
  security_source=self.sdk_configuration.security,
686
672
  ),
687
673
  request=req,
@@ -691,30 +677,17 @@ class Chat(BaseSDK):
691
677
 
692
678
  response_data: Any = None
693
679
  if utils.match_response(http_res, "200", "application/json"):
694
- return utils.unmarshal_json(
695
- http_res.text, Optional[models.ChatCompletionResponse]
696
- )
680
+ return unmarshal_json_response(models.ChatCompletionResponse, http_res)
697
681
  if utils.match_response(http_res, "422", "application/json"):
698
- response_data = utils.unmarshal_json(
699
- http_res.text, models.HTTPValidationErrorData
682
+ response_data = unmarshal_json_response(
683
+ models.HTTPValidationErrorData, http_res
700
684
  )
701
- raise models.HTTPValidationError(data=response_data)
685
+ raise models.HTTPValidationError(response_data, http_res)
702
686
  if utils.match_response(http_res, "4XX", "*"):
703
687
  http_res_text = await utils.stream_to_text_async(http_res)
704
- raise models.SDKError(
705
- "API error occurred", http_res.status_code, http_res_text, http_res
706
- )
688
+ raise models.SDKError("API error occurred", http_res, http_res_text)
707
689
  if utils.match_response(http_res, "5XX", "*"):
708
690
  http_res_text = await utils.stream_to_text_async(http_res)
709
- raise models.SDKError(
710
- "API error occurred", http_res.status_code, http_res_text, http_res
711
- )
691
+ raise models.SDKError("API error occurred", http_res, http_res_text)
712
692
 
713
- content_type = http_res.headers.get("Content-Type")
714
- http_res_text = await utils.stream_to_text_async(http_res)
715
- raise models.SDKError(
716
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
717
- http_res.status_code,
718
- http_res_text,
719
- http_res,
720
- )
693
+ raise models.SDKError("Unexpected response received", http_res)
@@ -107,7 +107,6 @@ def close_clients(
107
107
  # to them from the owning SDK instance and they can be reaped.
108
108
  owner.client = None
109
109
  owner.async_client = None
110
-
111
110
  if sync_client is not None and not sync_client_supplied:
112
111
  try:
113
112
  sync_client.close()
@@ -1,7 +1,10 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
+ from .mistralazureerror import MistralAzureError
3
4
  from typing import TYPE_CHECKING
4
5
  from importlib import import_module
6
+ import builtins
7
+ import sys
5
8
 
6
9
  if TYPE_CHECKING:
7
10
  from .assistantmessage import (
@@ -79,11 +82,19 @@ if TYPE_CHECKING:
79
82
  )
80
83
  from .jsonschema import JSONSchema, JSONSchemaTypedDict
81
84
  from .mistralpromptmode import MistralPromptMode
85
+ from .no_response_error import NoResponseError
82
86
  from .ocrimageobject import OCRImageObject, OCRImageObjectTypedDict
83
87
  from .ocrpagedimensions import OCRPageDimensions, OCRPageDimensionsTypedDict
84
88
  from .ocrpageobject import OCRPageObject, OCRPageObjectTypedDict
85
- from .ocrrequest import Document, DocumentTypedDict, OCRRequest, OCRRequestTypedDict
89
+ from .ocrrequest import (
90
+ Document,
91
+ DocumentTypedDict,
92
+ OCRRequest,
93
+ OCRRequestTypedDict,
94
+ TableFormat,
95
+ )
86
96
  from .ocrresponse import OCRResponse, OCRResponseTypedDict
97
+ from .ocrtableobject import Format, OCRTableObject, OCRTableObjectTypedDict
87
98
  from .ocrusageinfo import OCRUsageInfo, OCRUsageInfoTypedDict
88
99
  from .prediction import Prediction, PredictionTypedDict
89
100
  from .referencechunk import (
@@ -93,6 +104,7 @@ if TYPE_CHECKING:
93
104
  )
94
105
  from .responseformat import ResponseFormat, ResponseFormatTypedDict
95
106
  from .responseformats import ResponseFormats
107
+ from .responsevalidationerror import ResponseValidationError
96
108
  from .sdkerror import SDKError
97
109
  from .security import Security, SecurityTypedDict
98
110
  from .systemmessage import (
@@ -102,7 +114,18 @@ if TYPE_CHECKING:
102
114
  SystemMessageContentTypedDict,
103
115
  SystemMessageTypedDict,
104
116
  )
117
+ from .systemmessagecontentchunks import (
118
+ SystemMessageContentChunks,
119
+ SystemMessageContentChunksTypedDict,
120
+ )
105
121
  from .textchunk import TextChunk, TextChunkTypedDict, Type
122
+ from .thinkchunk import (
123
+ ThinkChunk,
124
+ ThinkChunkType,
125
+ ThinkChunkTypedDict,
126
+ Thinking,
127
+ ThinkingTypedDict,
128
+ )
106
129
  from .tool import Tool, ToolTypedDict
107
130
  from .toolcall import ToolCall, ToolCallTypedDict
108
131
  from .toolchoice import ToolChoice, ToolChoiceTypedDict
@@ -175,6 +198,7 @@ __all__ = [
175
198
  "FileChunk",
176
199
  "FileChunkTypedDict",
177
200
  "FinishReason",
201
+ "Format",
178
202
  "Function",
179
203
  "FunctionCall",
180
204
  "FunctionCallTypedDict",
@@ -196,7 +220,9 @@ __all__ = [
196
220
  "LocTypedDict",
197
221
  "Messages",
198
222
  "MessagesTypedDict",
223
+ "MistralAzureError",
199
224
  "MistralPromptMode",
225
+ "NoResponseError",
200
226
  "OCRImageObject",
201
227
  "OCRImageObjectTypedDict",
202
228
  "OCRPageDimensions",
@@ -207,6 +233,8 @@ __all__ = [
207
233
  "OCRRequestTypedDict",
208
234
  "OCRResponse",
209
235
  "OCRResponseTypedDict",
236
+ "OCRTableObject",
237
+ "OCRTableObjectTypedDict",
210
238
  "OCRUsageInfo",
211
239
  "OCRUsageInfoTypedDict",
212
240
  "Prediction",
@@ -217,6 +245,7 @@ __all__ = [
217
245
  "ResponseFormat",
218
246
  "ResponseFormatTypedDict",
219
247
  "ResponseFormats",
248
+ "ResponseValidationError",
220
249
  "Role",
221
250
  "SDKError",
222
251
  "Security",
@@ -225,10 +254,18 @@ __all__ = [
225
254
  "StopTypedDict",
226
255
  "SystemMessage",
227
256
  "SystemMessageContent",
257
+ "SystemMessageContentChunks",
258
+ "SystemMessageContentChunksTypedDict",
228
259
  "SystemMessageContentTypedDict",
229
260
  "SystemMessageTypedDict",
261
+ "TableFormat",
230
262
  "TextChunk",
231
263
  "TextChunkTypedDict",
264
+ "ThinkChunk",
265
+ "ThinkChunkType",
266
+ "ThinkChunkTypedDict",
267
+ "Thinking",
268
+ "ThinkingTypedDict",
232
269
  "Tool",
233
270
  "ToolCall",
234
271
  "ToolCallTypedDict",
@@ -319,6 +356,7 @@ _dynamic_imports: dict[str, str] = {
319
356
  "JSONSchema": ".jsonschema",
320
357
  "JSONSchemaTypedDict": ".jsonschema",
321
358
  "MistralPromptMode": ".mistralpromptmode",
359
+ "NoResponseError": ".no_response_error",
322
360
  "OCRImageObject": ".ocrimageobject",
323
361
  "OCRImageObjectTypedDict": ".ocrimageobject",
324
362
  "OCRPageDimensions": ".ocrpagedimensions",
@@ -329,8 +367,12 @@ _dynamic_imports: dict[str, str] = {
329
367
  "DocumentTypedDict": ".ocrrequest",
330
368
  "OCRRequest": ".ocrrequest",
331
369
  "OCRRequestTypedDict": ".ocrrequest",
370
+ "TableFormat": ".ocrrequest",
332
371
  "OCRResponse": ".ocrresponse",
333
372
  "OCRResponseTypedDict": ".ocrresponse",
373
+ "Format": ".ocrtableobject",
374
+ "OCRTableObject": ".ocrtableobject",
375
+ "OCRTableObjectTypedDict": ".ocrtableobject",
334
376
  "OCRUsageInfo": ".ocrusageinfo",
335
377
  "OCRUsageInfoTypedDict": ".ocrusageinfo",
336
378
  "Prediction": ".prediction",
@@ -341,6 +383,7 @@ _dynamic_imports: dict[str, str] = {
341
383
  "ResponseFormat": ".responseformat",
342
384
  "ResponseFormatTypedDict": ".responseformat",
343
385
  "ResponseFormats": ".responseformats",
386
+ "ResponseValidationError": ".responsevalidationerror",
344
387
  "SDKError": ".sdkerror",
345
388
  "Security": ".security",
346
389
  "SecurityTypedDict": ".security",
@@ -349,9 +392,16 @@ _dynamic_imports: dict[str, str] = {
349
392
  "SystemMessageContent": ".systemmessage",
350
393
  "SystemMessageContentTypedDict": ".systemmessage",
351
394
  "SystemMessageTypedDict": ".systemmessage",
395
+ "SystemMessageContentChunks": ".systemmessagecontentchunks",
396
+ "SystemMessageContentChunksTypedDict": ".systemmessagecontentchunks",
352
397
  "TextChunk": ".textchunk",
353
398
  "TextChunkTypedDict": ".textchunk",
354
399
  "Type": ".textchunk",
400
+ "ThinkChunk": ".thinkchunk",
401
+ "ThinkChunkType": ".thinkchunk",
402
+ "ThinkChunkTypedDict": ".thinkchunk",
403
+ "Thinking": ".thinkchunk",
404
+ "ThinkingTypedDict": ".thinkchunk",
355
405
  "Tool": ".tool",
356
406
  "ToolTypedDict": ".tool",
357
407
  "ToolCall": ".toolcall",
@@ -379,6 +429,18 @@ _dynamic_imports: dict[str, str] = {
379
429
  }
380
430
 
381
431
 
432
+ def dynamic_import(modname, retries=3):
433
+ for attempt in range(retries):
434
+ try:
435
+ return import_module(modname, __package__)
436
+ except KeyError:
437
+ # Clear any half-initialized module and retry
438
+ sys.modules.pop(modname, None)
439
+ if attempt == retries - 1:
440
+ break
441
+ raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")
442
+
443
+
382
444
  def __getattr__(attr_name: str) -> object:
383
445
  module_name = _dynamic_imports.get(attr_name)
384
446
  if module_name is None:
@@ -387,7 +449,7 @@ def __getattr__(attr_name: str) -> object:
387
449
  )
388
450
 
389
451
  try:
390
- module = import_module(module_name, __package__)
452
+ module = dynamic_import(module_name)
391
453
  result = getattr(module, attr_name)
392
454
  return result
393
455
  except ImportError as e:
@@ -401,5 +463,5 @@ def __getattr__(attr_name: str) -> object:
401
463
 
402
464
 
403
465
  def __dir__():
404
- lazy_attrs = list(_dynamic_imports.keys())
405
- return sorted(lazy_attrs)
466
+ lazy_attrs = builtins.list(_dynamic_imports.keys())
467
+ return builtins.sorted(lazy_attrs)
@@ -25,7 +25,7 @@ AssistantMessageContent = TypeAliasType(
25
25
  )
26
26
 
27
27
 
28
- AssistantMessageRole = Literal["assistant"]
28
+ AssistantMessageRole = Literal["assistant",]
29
29
 
30
30
 
31
31
  class AssistantMessageTypedDict(TypedDict):