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_gcp/chat.py CHANGED
@@ -5,7 +5,8 @@ from mistralai_gcp import models, utils
5
5
  from mistralai_gcp._hooks import HookContext
6
6
  from mistralai_gcp.types import OptionalNullable, UNSET
7
7
  from mistralai_gcp.utils import eventstreaming
8
- from typing import Any, List, Mapping, Optional, Union
8
+ from mistralai_gcp.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,
@@ -41,11 +43,12 @@ class Chat(BaseSDK):
41
43
  Union[models.Prediction, models.PredictionTypedDict]
42
44
  ] = None,
43
45
  parallel_tool_calls: Optional[bool] = None,
46
+ prompt_mode: OptionalNullable[models.MistralPromptMode] = UNSET,
44
47
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
45
48
  server_url: Optional[str] = None,
46
49
  timeout_ms: Optional[int] = None,
47
50
  http_headers: Optional[Mapping[str, str]] = None,
48
- ) -> Optional[eventstreaming.EventStream[models.CompletionEvent]]:
51
+ ) -> eventstreaming.EventStream[models.CompletionEvent]:
49
52
  r"""Stream chat completion
50
53
 
51
54
  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.
@@ -58,14 +61,16 @@ class Chat(BaseSDK):
58
61
  :param stream:
59
62
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
60
63
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
61
- :param response_format:
62
- :param tools:
63
- :param tool_choice:
64
- :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.
65
- :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.
64
+ :param metadata:
65
+ :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.
66
+ :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.
67
+ :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.
68
+ :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.
69
+ :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.
66
70
  :param n: Number of completions to return for each request, input tokens are only billed once.
67
- :param prediction:
68
- :param parallel_tool_calls:
71
+ :param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
72
+ :param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
73
+ :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.
69
74
  :param retries: Override the default retry configuration for this method
70
75
  :param server_url: Override the default server URL for this method
71
76
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -89,6 +94,7 @@ class Chat(BaseSDK):
89
94
  stream=stream,
90
95
  stop=stop,
91
96
  random_seed=random_seed,
97
+ metadata=metadata,
92
98
  messages=utils.get_pydantic_model(messages, List[models.Messages]),
93
99
  response_format=utils.get_pydantic_model(
94
100
  response_format, Optional[models.ResponseFormat]
@@ -104,6 +110,7 @@ class Chat(BaseSDK):
104
110
  prediction, Optional[models.Prediction]
105
111
  ),
106
112
  parallel_tool_calls=parallel_tool_calls,
113
+ prompt_mode=prompt_mode,
107
114
  )
108
115
 
109
116
  req = self._build_request(
@@ -122,6 +129,7 @@ class Chat(BaseSDK):
122
129
  get_serialized_body=lambda: utils.serialize_request_body(
123
130
  request, False, False, "json", models.ChatCompletionStreamRequest
124
131
  ),
132
+ allow_empty_value=None,
125
133
  timeout_ms=timeout_ms,
126
134
  )
127
135
 
@@ -135,9 +143,10 @@ class Chat(BaseSDK):
135
143
 
136
144
  http_res = self.do_request(
137
145
  hook_ctx=HookContext(
146
+ config=self.sdk_configuration,
138
147
  base_url=base_url or "",
139
148
  operation_id="stream_chat",
140
- oauth2_scopes=[],
149
+ oauth2_scopes=None,
141
150
  security_source=self.sdk_configuration.security,
142
151
  ),
143
152
  request=req,
@@ -152,32 +161,23 @@ class Chat(BaseSDK):
152
161
  http_res,
153
162
  lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
154
163
  sentinel="[DONE]",
164
+ client_ref=self,
155
165
  )
156
166
  if utils.match_response(http_res, "422", "application/json"):
157
167
  http_res_text = utils.stream_to_text(http_res)
158
- response_data = utils.unmarshal_json(
159
- http_res_text, models.HTTPValidationErrorData
168
+ response_data = unmarshal_json_response(
169
+ models.HTTPValidationErrorData, http_res, http_res_text
160
170
  )
161
- raise models.HTTPValidationError(data=response_data)
171
+ raise models.HTTPValidationError(response_data, http_res, http_res_text)
162
172
  if utils.match_response(http_res, "4XX", "*"):
163
173
  http_res_text = utils.stream_to_text(http_res)
164
- raise models.SDKError(
165
- "API error occurred", http_res.status_code, http_res_text, http_res
166
- )
174
+ raise models.SDKError("API error occurred", http_res, http_res_text)
167
175
  if utils.match_response(http_res, "5XX", "*"):
168
176
  http_res_text = utils.stream_to_text(http_res)
169
- raise models.SDKError(
170
- "API error occurred", http_res.status_code, http_res_text, http_res
171
- )
177
+ raise models.SDKError("API error occurred", http_res, http_res_text)
172
178
 
173
- content_type = http_res.headers.get("Content-Type")
174
179
  http_res_text = utils.stream_to_text(http_res)
175
- raise models.SDKError(
176
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
177
- http_res.status_code,
178
- http_res_text,
179
- http_res,
180
- )
180
+ raise models.SDKError("Unexpected response received", http_res, http_res_text)
181
181
 
182
182
  async def stream_async(
183
183
  self,
@@ -190,6 +190,7 @@ class Chat(BaseSDK):
190
190
  stream: Optional[bool] = True,
191
191
  stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
192
192
  random_seed: OptionalNullable[int] = UNSET,
193
+ metadata: OptionalNullable[Dict[str, Any]] = UNSET,
193
194
  response_format: Optional[
194
195
  Union[models.ResponseFormat, models.ResponseFormatTypedDict]
195
196
  ] = None,
@@ -209,11 +210,12 @@ class Chat(BaseSDK):
209
210
  Union[models.Prediction, models.PredictionTypedDict]
210
211
  ] = None,
211
212
  parallel_tool_calls: Optional[bool] = None,
213
+ prompt_mode: OptionalNullable[models.MistralPromptMode] = UNSET,
212
214
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
213
215
  server_url: Optional[str] = None,
214
216
  timeout_ms: Optional[int] = None,
215
217
  http_headers: Optional[Mapping[str, str]] = None,
216
- ) -> Optional[eventstreaming.EventStreamAsync[models.CompletionEvent]]:
218
+ ) -> eventstreaming.EventStreamAsync[models.CompletionEvent]:
217
219
  r"""Stream chat completion
218
220
 
219
221
  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.
@@ -226,14 +228,16 @@ class Chat(BaseSDK):
226
228
  :param stream:
227
229
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
228
230
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
229
- :param response_format:
230
- :param tools:
231
- :param tool_choice:
232
- :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.
233
- :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.
231
+ :param metadata:
232
+ :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.
233
+ :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.
234
+ :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.
235
+ :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.
236
+ :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.
234
237
  :param n: Number of completions to return for each request, input tokens are only billed once.
235
- :param prediction:
236
- :param parallel_tool_calls:
238
+ :param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
239
+ :param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
240
+ :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.
237
241
  :param retries: Override the default retry configuration for this method
238
242
  :param server_url: Override the default server URL for this method
239
243
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -257,6 +261,7 @@ class Chat(BaseSDK):
257
261
  stream=stream,
258
262
  stop=stop,
259
263
  random_seed=random_seed,
264
+ metadata=metadata,
260
265
  messages=utils.get_pydantic_model(messages, List[models.Messages]),
261
266
  response_format=utils.get_pydantic_model(
262
267
  response_format, Optional[models.ResponseFormat]
@@ -272,6 +277,7 @@ class Chat(BaseSDK):
272
277
  prediction, Optional[models.Prediction]
273
278
  ),
274
279
  parallel_tool_calls=parallel_tool_calls,
280
+ prompt_mode=prompt_mode,
275
281
  )
276
282
 
277
283
  req = self._build_request_async(
@@ -290,6 +296,7 @@ class Chat(BaseSDK):
290
296
  get_serialized_body=lambda: utils.serialize_request_body(
291
297
  request, False, False, "json", models.ChatCompletionStreamRequest
292
298
  ),
299
+ allow_empty_value=None,
293
300
  timeout_ms=timeout_ms,
294
301
  )
295
302
 
@@ -303,9 +310,10 @@ class Chat(BaseSDK):
303
310
 
304
311
  http_res = await self.do_request_async(
305
312
  hook_ctx=HookContext(
313
+ config=self.sdk_configuration,
306
314
  base_url=base_url or "",
307
315
  operation_id="stream_chat",
308
- oauth2_scopes=[],
316
+ oauth2_scopes=None,
309
317
  security_source=self.sdk_configuration.security,
310
318
  ),
311
319
  request=req,
@@ -320,32 +328,23 @@ class Chat(BaseSDK):
320
328
  http_res,
321
329
  lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
322
330
  sentinel="[DONE]",
331
+ client_ref=self,
323
332
  )
324
333
  if utils.match_response(http_res, "422", "application/json"):
325
334
  http_res_text = await utils.stream_to_text_async(http_res)
326
- response_data = utils.unmarshal_json(
327
- http_res_text, models.HTTPValidationErrorData
335
+ response_data = unmarshal_json_response(
336
+ models.HTTPValidationErrorData, http_res, http_res_text
328
337
  )
329
- raise models.HTTPValidationError(data=response_data)
338
+ raise models.HTTPValidationError(response_data, http_res, http_res_text)
330
339
  if utils.match_response(http_res, "4XX", "*"):
331
340
  http_res_text = await utils.stream_to_text_async(http_res)
332
- raise models.SDKError(
333
- "API error occurred", http_res.status_code, http_res_text, http_res
334
- )
341
+ raise models.SDKError("API error occurred", http_res, http_res_text)
335
342
  if utils.match_response(http_res, "5XX", "*"):
336
343
  http_res_text = await utils.stream_to_text_async(http_res)
337
- raise models.SDKError(
338
- "API error occurred", http_res.status_code, http_res_text, http_res
339
- )
344
+ raise models.SDKError("API error occurred", http_res, http_res_text)
340
345
 
341
- content_type = http_res.headers.get("Content-Type")
342
346
  http_res_text = await utils.stream_to_text_async(http_res)
343
- raise models.SDKError(
344
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
345
- http_res.status_code,
346
- http_res_text,
347
- http_res,
348
- )
347
+ raise models.SDKError("Unexpected response received", http_res, http_res_text)
349
348
 
350
349
  def complete(
351
350
  self,
@@ -366,6 +365,7 @@ class Chat(BaseSDK):
366
365
  ]
367
366
  ] = None,
368
367
  random_seed: OptionalNullable[int] = UNSET,
368
+ metadata: OptionalNullable[Dict[str, Any]] = UNSET,
369
369
  response_format: Optional[
370
370
  Union[models.ResponseFormat, models.ResponseFormatTypedDict]
371
371
  ] = None,
@@ -385,11 +385,12 @@ class Chat(BaseSDK):
385
385
  Union[models.Prediction, models.PredictionTypedDict]
386
386
  ] = None,
387
387
  parallel_tool_calls: Optional[bool] = None,
388
+ prompt_mode: OptionalNullable[models.MistralPromptMode] = UNSET,
388
389
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
389
390
  server_url: Optional[str] = None,
390
391
  timeout_ms: Optional[int] = None,
391
392
  http_headers: Optional[Mapping[str, str]] = None,
392
- ) -> Optional[models.ChatCompletionResponse]:
393
+ ) -> models.ChatCompletionResponse:
393
394
  r"""Chat Completion
394
395
 
395
396
  :param model: ID of the model to use. You can use the [List Available Models](/api/#tag/models/operation/list_models_v1_models_get) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
@@ -400,14 +401,16 @@ class Chat(BaseSDK):
400
401
  :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.
401
402
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
402
403
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
403
- :param response_format:
404
- :param tools:
405
- :param tool_choice:
406
- :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.
407
- :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.
404
+ :param metadata:
405
+ :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.
406
+ :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.
407
+ :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.
408
+ :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.
409
+ :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.
408
410
  :param n: Number of completions to return for each request, input tokens are only billed once.
409
- :param prediction:
410
- :param parallel_tool_calls:
411
+ :param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
412
+ :param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
413
+ :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.
411
414
  :param retries: Override the default retry configuration for this method
412
415
  :param server_url: Override the default server URL for this method
413
416
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -431,6 +434,7 @@ class Chat(BaseSDK):
431
434
  stream=stream,
432
435
  stop=stop,
433
436
  random_seed=random_seed,
437
+ metadata=metadata,
434
438
  messages=utils.get_pydantic_model(
435
439
  messages, List[models.ChatCompletionRequestMessages]
436
440
  ),
@@ -448,6 +452,7 @@ class Chat(BaseSDK):
448
452
  prediction, Optional[models.Prediction]
449
453
  ),
450
454
  parallel_tool_calls=parallel_tool_calls,
455
+ prompt_mode=prompt_mode,
451
456
  )
452
457
 
453
458
  req = self._build_request(
@@ -466,6 +471,7 @@ class Chat(BaseSDK):
466
471
  get_serialized_body=lambda: utils.serialize_request_body(
467
472
  request, False, False, "json", models.ChatCompletionRequest
468
473
  ),
474
+ allow_empty_value=None,
469
475
  timeout_ms=timeout_ms,
470
476
  )
471
477
 
@@ -479,9 +485,10 @@ class Chat(BaseSDK):
479
485
 
480
486
  http_res = self.do_request(
481
487
  hook_ctx=HookContext(
488
+ config=self.sdk_configuration,
482
489
  base_url=base_url or "",
483
490
  operation_id="chat_completion_v1_chat_completions_post",
484
- oauth2_scopes=[],
491
+ oauth2_scopes=None,
485
492
  security_source=self.sdk_configuration.security,
486
493
  ),
487
494
  request=req,
@@ -491,33 +498,20 @@ class Chat(BaseSDK):
491
498
 
492
499
  response_data: Any = None
493
500
  if utils.match_response(http_res, "200", "application/json"):
494
- return utils.unmarshal_json(
495
- http_res.text, Optional[models.ChatCompletionResponse]
496
- )
501
+ return unmarshal_json_response(models.ChatCompletionResponse, http_res)
497
502
  if utils.match_response(http_res, "422", "application/json"):
498
- response_data = utils.unmarshal_json(
499
- http_res.text, models.HTTPValidationErrorData
503
+ response_data = unmarshal_json_response(
504
+ models.HTTPValidationErrorData, http_res
500
505
  )
501
- raise models.HTTPValidationError(data=response_data)
506
+ raise models.HTTPValidationError(response_data, http_res)
502
507
  if utils.match_response(http_res, "4XX", "*"):
503
508
  http_res_text = utils.stream_to_text(http_res)
504
- raise models.SDKError(
505
- "API error occurred", http_res.status_code, http_res_text, http_res
506
- )
509
+ raise models.SDKError("API error occurred", http_res, http_res_text)
507
510
  if utils.match_response(http_res, "5XX", "*"):
508
511
  http_res_text = utils.stream_to_text(http_res)
509
- raise models.SDKError(
510
- "API error occurred", http_res.status_code, http_res_text, http_res
511
- )
512
+ raise models.SDKError("API error occurred", http_res, http_res_text)
512
513
 
513
- content_type = http_res.headers.get("Content-Type")
514
- http_res_text = utils.stream_to_text(http_res)
515
- raise models.SDKError(
516
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
517
- http_res.status_code,
518
- http_res_text,
519
- http_res,
520
- )
514
+ raise models.SDKError("Unexpected response received", http_res)
521
515
 
522
516
  async def complete_async(
523
517
  self,
@@ -538,6 +532,7 @@ class Chat(BaseSDK):
538
532
  ]
539
533
  ] = None,
540
534
  random_seed: OptionalNullable[int] = UNSET,
535
+ metadata: OptionalNullable[Dict[str, Any]] = UNSET,
541
536
  response_format: Optional[
542
537
  Union[models.ResponseFormat, models.ResponseFormatTypedDict]
543
538
  ] = None,
@@ -557,11 +552,12 @@ class Chat(BaseSDK):
557
552
  Union[models.Prediction, models.PredictionTypedDict]
558
553
  ] = None,
559
554
  parallel_tool_calls: Optional[bool] = None,
555
+ prompt_mode: OptionalNullable[models.MistralPromptMode] = UNSET,
560
556
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
561
557
  server_url: Optional[str] = None,
562
558
  timeout_ms: Optional[int] = None,
563
559
  http_headers: Optional[Mapping[str, str]] = None,
564
- ) -> Optional[models.ChatCompletionResponse]:
560
+ ) -> models.ChatCompletionResponse:
565
561
  r"""Chat Completion
566
562
 
567
563
  :param model: ID of the model to use. You can use the [List Available Models](/api/#tag/models/operation/list_models_v1_models_get) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
@@ -572,14 +568,16 @@ class Chat(BaseSDK):
572
568
  :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.
573
569
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
574
570
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
575
- :param response_format:
576
- :param tools:
577
- :param tool_choice:
578
- :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.
579
- :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.
571
+ :param metadata:
572
+ :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.
573
+ :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.
574
+ :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.
575
+ :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.
576
+ :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.
580
577
  :param n: Number of completions to return for each request, input tokens are only billed once.
581
- :param prediction:
582
- :param parallel_tool_calls:
578
+ :param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
579
+ :param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
580
+ :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.
583
581
  :param retries: Override the default retry configuration for this method
584
582
  :param server_url: Override the default server URL for this method
585
583
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -603,6 +601,7 @@ class Chat(BaseSDK):
603
601
  stream=stream,
604
602
  stop=stop,
605
603
  random_seed=random_seed,
604
+ metadata=metadata,
606
605
  messages=utils.get_pydantic_model(
607
606
  messages, List[models.ChatCompletionRequestMessages]
608
607
  ),
@@ -620,6 +619,7 @@ class Chat(BaseSDK):
620
619
  prediction, Optional[models.Prediction]
621
620
  ),
622
621
  parallel_tool_calls=parallel_tool_calls,
622
+ prompt_mode=prompt_mode,
623
623
  )
624
624
 
625
625
  req = self._build_request_async(
@@ -638,6 +638,7 @@ class Chat(BaseSDK):
638
638
  get_serialized_body=lambda: utils.serialize_request_body(
639
639
  request, False, False, "json", models.ChatCompletionRequest
640
640
  ),
641
+ allow_empty_value=None,
641
642
  timeout_ms=timeout_ms,
642
643
  )
643
644
 
@@ -651,9 +652,10 @@ class Chat(BaseSDK):
651
652
 
652
653
  http_res = await self.do_request_async(
653
654
  hook_ctx=HookContext(
655
+ config=self.sdk_configuration,
654
656
  base_url=base_url or "",
655
657
  operation_id="chat_completion_v1_chat_completions_post",
656
- oauth2_scopes=[],
658
+ oauth2_scopes=None,
657
659
  security_source=self.sdk_configuration.security,
658
660
  ),
659
661
  request=req,
@@ -663,30 +665,17 @@ class Chat(BaseSDK):
663
665
 
664
666
  response_data: Any = None
665
667
  if utils.match_response(http_res, "200", "application/json"):
666
- return utils.unmarshal_json(
667
- http_res.text, Optional[models.ChatCompletionResponse]
668
- )
668
+ return unmarshal_json_response(models.ChatCompletionResponse, http_res)
669
669
  if utils.match_response(http_res, "422", "application/json"):
670
- response_data = utils.unmarshal_json(
671
- http_res.text, models.HTTPValidationErrorData
670
+ response_data = unmarshal_json_response(
671
+ models.HTTPValidationErrorData, http_res
672
672
  )
673
- raise models.HTTPValidationError(data=response_data)
673
+ raise models.HTTPValidationError(response_data, http_res)
674
674
  if utils.match_response(http_res, "4XX", "*"):
675
675
  http_res_text = await utils.stream_to_text_async(http_res)
676
- raise models.SDKError(
677
- "API error occurred", http_res.status_code, http_res_text, http_res
678
- )
676
+ raise models.SDKError("API error occurred", http_res, http_res_text)
679
677
  if utils.match_response(http_res, "5XX", "*"):
680
678
  http_res_text = await utils.stream_to_text_async(http_res)
681
- raise models.SDKError(
682
- "API error occurred", http_res.status_code, http_res_text, http_res
683
- )
679
+ raise models.SDKError("API error occurred", http_res, http_res_text)
684
680
 
685
- content_type = http_res.headers.get("Content-Type")
686
- http_res_text = await utils.stream_to_text_async(http_res)
687
- raise models.SDKError(
688
- f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
689
- http_res.status_code,
690
- http_res_text,
691
- http_res,
692
- )
681
+ raise models.SDKError("Unexpected response received", http_res)