mistralai 1.0.3__py3-none-any.whl → 1.2.0__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 (230) hide show
  1. mistralai/__init__.py +4 -0
  2. mistralai/_hooks/sdkhooks.py +23 -4
  3. mistralai/_hooks/types.py +27 -9
  4. mistralai/_version.py +12 -0
  5. mistralai/agents.py +334 -164
  6. mistralai/basesdk.py +90 -5
  7. mistralai/batch.py +17 -0
  8. mistralai/chat.py +316 -166
  9. mistralai/classifiers.py +396 -0
  10. mistralai/embeddings.py +79 -55
  11. mistralai/files.py +487 -194
  12. mistralai/fim.py +206 -132
  13. mistralai/fine_tuning.py +3 -2
  14. mistralai/jobs.py +392 -263
  15. mistralai/mistral_jobs.py +733 -0
  16. mistralai/models/__init__.py +593 -50
  17. mistralai/models/agentscompletionrequest.py +70 -17
  18. mistralai/models/agentscompletionstreamrequest.py +72 -17
  19. mistralai/models/apiendpoint.py +9 -0
  20. mistralai/models/archiveftmodelout.py +15 -5
  21. mistralai/models/assistantmessage.py +22 -10
  22. mistralai/models/{modelcard.py → basemodelcard.py} +53 -14
  23. mistralai/models/batcherror.py +17 -0
  24. mistralai/models/batchjobin.py +58 -0
  25. mistralai/models/batchjobout.py +117 -0
  26. mistralai/models/batchjobsout.py +30 -0
  27. mistralai/models/batchjobstatus.py +15 -0
  28. mistralai/models/chatclassificationrequest.py +104 -0
  29. mistralai/models/chatcompletionchoice.py +13 -6
  30. mistralai/models/chatcompletionrequest.py +86 -21
  31. mistralai/models/chatcompletionresponse.py +8 -4
  32. mistralai/models/chatcompletionstreamrequest.py +88 -21
  33. mistralai/models/checkpointout.py +4 -3
  34. mistralai/models/classificationobject.py +21 -0
  35. mistralai/models/classificationrequest.py +59 -0
  36. mistralai/models/classificationresponse.py +21 -0
  37. mistralai/models/completionchunk.py +12 -5
  38. mistralai/models/completionevent.py +2 -3
  39. mistralai/models/completionresponsestreamchoice.py +22 -8
  40. mistralai/models/contentchunk.py +13 -10
  41. mistralai/models/delete_model_v1_models_model_id_deleteop.py +5 -5
  42. mistralai/models/deletefileout.py +4 -3
  43. mistralai/models/deletemodelout.py +5 -4
  44. mistralai/models/deltamessage.py +23 -11
  45. mistralai/models/detailedjobout.py +70 -12
  46. mistralai/models/embeddingrequest.py +14 -9
  47. mistralai/models/embeddingresponse.py +7 -3
  48. mistralai/models/embeddingresponsedata.py +5 -4
  49. mistralai/models/eventout.py +11 -6
  50. mistralai/models/filepurpose.py +8 -0
  51. mistralai/models/files_api_routes_delete_fileop.py +5 -5
  52. mistralai/models/files_api_routes_download_fileop.py +16 -0
  53. mistralai/models/files_api_routes_list_filesop.py +96 -0
  54. mistralai/models/files_api_routes_retrieve_fileop.py +5 -5
  55. mistralai/models/files_api_routes_upload_fileop.py +33 -14
  56. mistralai/models/fileschema.py +22 -15
  57. mistralai/models/fimcompletionrequest.py +44 -16
  58. mistralai/models/fimcompletionresponse.py +8 -4
  59. mistralai/models/fimcompletionstreamrequest.py +44 -16
  60. mistralai/models/finetuneablemodel.py +7 -1
  61. mistralai/models/ftmodelcapabilitiesout.py +6 -4
  62. mistralai/models/ftmodelcard.py +121 -0
  63. mistralai/models/ftmodelout.py +39 -9
  64. mistralai/models/function.py +5 -4
  65. mistralai/models/functioncall.py +4 -3
  66. mistralai/models/functionname.py +17 -0
  67. mistralai/models/githubrepositoryin.py +24 -7
  68. mistralai/models/githubrepositoryout.py +24 -7
  69. mistralai/models/httpvalidationerror.py +1 -3
  70. mistralai/models/imageurl.py +47 -0
  71. mistralai/models/imageurlchunk.py +38 -0
  72. mistralai/models/jobin.py +24 -7
  73. mistralai/models/jobmetadataout.py +32 -8
  74. mistralai/models/jobout.py +65 -12
  75. mistralai/models/jobs_api_routes_batch_cancel_batch_jobop.py +16 -0
  76. mistralai/models/jobs_api_routes_batch_get_batch_jobop.py +16 -0
  77. mistralai/models/jobs_api_routes_batch_get_batch_jobsop.py +95 -0
  78. mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +5 -5
  79. mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +5 -5
  80. mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +3 -2
  81. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +5 -5
  82. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +85 -18
  83. mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +5 -5
  84. mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +5 -5
  85. mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +10 -6
  86. mistralai/models/jobsout.py +13 -5
  87. mistralai/models/legacyjobmetadataout.py +55 -9
  88. mistralai/models/listfilesout.py +7 -3
  89. mistralai/models/metricout.py +12 -8
  90. mistralai/models/modelcapabilities.py +9 -4
  91. mistralai/models/modellist.py +21 -7
  92. mistralai/models/responseformat.py +7 -8
  93. mistralai/models/responseformats.py +8 -0
  94. mistralai/models/retrieve_model_v1_models_model_id_getop.py +25 -6
  95. mistralai/models/retrievefileout.py +25 -15
  96. mistralai/models/sampletype.py +6 -2
  97. mistralai/models/security.py +14 -5
  98. mistralai/models/source.py +3 -2
  99. mistralai/models/systemmessage.py +10 -9
  100. mistralai/models/textchunk.py +14 -5
  101. mistralai/models/tool.py +10 -9
  102. mistralai/models/toolcall.py +10 -8
  103. mistralai/models/toolchoice.py +29 -0
  104. mistralai/models/toolchoiceenum.py +7 -0
  105. mistralai/models/toolmessage.py +13 -6
  106. mistralai/models/tooltypes.py +8 -0
  107. mistralai/models/trainingfile.py +4 -4
  108. mistralai/models/trainingparameters.py +34 -8
  109. mistralai/models/trainingparametersin.py +36 -10
  110. mistralai/models/unarchiveftmodelout.py +15 -5
  111. mistralai/models/updateftmodelin.py +9 -6
  112. mistralai/models/uploadfileout.py +22 -15
  113. mistralai/models/usageinfo.py +4 -3
  114. mistralai/models/usermessage.py +42 -10
  115. mistralai/models/validationerror.py +5 -3
  116. mistralai/models/wandbintegration.py +23 -7
  117. mistralai/models/wandbintegrationout.py +23 -8
  118. mistralai/models_.py +416 -294
  119. mistralai/sdk.py +31 -19
  120. mistralai/sdkconfiguration.py +9 -11
  121. mistralai/utils/__init__.py +14 -1
  122. mistralai/utils/annotations.py +13 -2
  123. mistralai/utils/logger.py +4 -1
  124. mistralai/utils/retries.py +2 -1
  125. mistralai/utils/security.py +13 -6
  126. mistralai/utils/serializers.py +25 -0
  127. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/METADATA +171 -66
  128. mistralai-1.2.0.dist-info/RECORD +276 -0
  129. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/WHEEL +1 -1
  130. mistralai_azure/__init__.py +4 -0
  131. mistralai_azure/_hooks/sdkhooks.py +23 -4
  132. mistralai_azure/_hooks/types.py +27 -9
  133. mistralai_azure/_version.py +12 -0
  134. mistralai_azure/basesdk.py +91 -6
  135. mistralai_azure/chat.py +308 -166
  136. mistralai_azure/models/__init__.py +164 -16
  137. mistralai_azure/models/assistantmessage.py +29 -11
  138. mistralai_azure/models/chatcompletionchoice.py +15 -6
  139. mistralai_azure/models/chatcompletionrequest.py +94 -22
  140. mistralai_azure/models/chatcompletionresponse.py +8 -4
  141. mistralai_azure/models/chatcompletionstreamrequest.py +96 -22
  142. mistralai_azure/models/completionchunk.py +12 -5
  143. mistralai_azure/models/completionevent.py +2 -3
  144. mistralai_azure/models/completionresponsestreamchoice.py +19 -8
  145. mistralai_azure/models/contentchunk.py +4 -11
  146. mistralai_azure/models/deltamessage.py +30 -12
  147. mistralai_azure/models/function.py +5 -4
  148. mistralai_azure/models/functioncall.py +4 -3
  149. mistralai_azure/models/functionname.py +17 -0
  150. mistralai_azure/models/httpvalidationerror.py +1 -3
  151. mistralai_azure/models/responseformat.py +7 -8
  152. mistralai_azure/models/responseformats.py +8 -0
  153. mistralai_azure/models/security.py +13 -5
  154. mistralai_azure/models/systemmessage.py +10 -9
  155. mistralai_azure/models/textchunk.py +14 -5
  156. mistralai_azure/models/tool.py +10 -9
  157. mistralai_azure/models/toolcall.py +10 -8
  158. mistralai_azure/models/toolchoice.py +29 -0
  159. mistralai_azure/models/toolchoiceenum.py +7 -0
  160. mistralai_azure/models/toolmessage.py +20 -7
  161. mistralai_azure/models/tooltypes.py +8 -0
  162. mistralai_azure/models/usageinfo.py +4 -3
  163. mistralai_azure/models/usermessage.py +42 -10
  164. mistralai_azure/models/validationerror.py +5 -3
  165. mistralai_azure/sdkconfiguration.py +9 -11
  166. mistralai_azure/utils/__init__.py +16 -3
  167. mistralai_azure/utils/annotations.py +13 -2
  168. mistralai_azure/utils/forms.py +10 -9
  169. mistralai_azure/utils/headers.py +8 -8
  170. mistralai_azure/utils/logger.py +6 -0
  171. mistralai_azure/utils/queryparams.py +16 -14
  172. mistralai_azure/utils/retries.py +2 -1
  173. mistralai_azure/utils/security.py +12 -6
  174. mistralai_azure/utils/serializers.py +42 -8
  175. mistralai_azure/utils/url.py +13 -8
  176. mistralai_azure/utils/values.py +6 -0
  177. mistralai_gcp/__init__.py +4 -0
  178. mistralai_gcp/_hooks/sdkhooks.py +23 -4
  179. mistralai_gcp/_hooks/types.py +27 -9
  180. mistralai_gcp/_version.py +12 -0
  181. mistralai_gcp/basesdk.py +91 -6
  182. mistralai_gcp/chat.py +308 -166
  183. mistralai_gcp/fim.py +198 -132
  184. mistralai_gcp/models/__init__.py +186 -18
  185. mistralai_gcp/models/assistantmessage.py +29 -11
  186. mistralai_gcp/models/chatcompletionchoice.py +15 -6
  187. mistralai_gcp/models/chatcompletionrequest.py +91 -22
  188. mistralai_gcp/models/chatcompletionresponse.py +8 -4
  189. mistralai_gcp/models/chatcompletionstreamrequest.py +93 -22
  190. mistralai_gcp/models/completionchunk.py +12 -5
  191. mistralai_gcp/models/completionevent.py +2 -3
  192. mistralai_gcp/models/completionresponsestreamchoice.py +19 -8
  193. mistralai_gcp/models/contentchunk.py +4 -11
  194. mistralai_gcp/models/deltamessage.py +30 -12
  195. mistralai_gcp/models/fimcompletionrequest.py +51 -17
  196. mistralai_gcp/models/fimcompletionresponse.py +8 -4
  197. mistralai_gcp/models/fimcompletionstreamrequest.py +51 -17
  198. mistralai_gcp/models/function.py +5 -4
  199. mistralai_gcp/models/functioncall.py +4 -3
  200. mistralai_gcp/models/functionname.py +17 -0
  201. mistralai_gcp/models/httpvalidationerror.py +1 -3
  202. mistralai_gcp/models/responseformat.py +7 -8
  203. mistralai_gcp/models/responseformats.py +8 -0
  204. mistralai_gcp/models/security.py +13 -5
  205. mistralai_gcp/models/systemmessage.py +10 -9
  206. mistralai_gcp/models/textchunk.py +14 -5
  207. mistralai_gcp/models/tool.py +10 -9
  208. mistralai_gcp/models/toolcall.py +10 -8
  209. mistralai_gcp/models/toolchoice.py +29 -0
  210. mistralai_gcp/models/toolchoiceenum.py +7 -0
  211. mistralai_gcp/models/toolmessage.py +20 -7
  212. mistralai_gcp/models/tooltypes.py +8 -0
  213. mistralai_gcp/models/usageinfo.py +4 -3
  214. mistralai_gcp/models/usermessage.py +42 -10
  215. mistralai_gcp/models/validationerror.py +5 -3
  216. mistralai_gcp/sdk.py +6 -7
  217. mistralai_gcp/sdkconfiguration.py +9 -11
  218. mistralai_gcp/utils/__init__.py +16 -3
  219. mistralai_gcp/utils/annotations.py +13 -2
  220. mistralai_gcp/utils/forms.py +10 -9
  221. mistralai_gcp/utils/headers.py +8 -8
  222. mistralai_gcp/utils/logger.py +6 -0
  223. mistralai_gcp/utils/queryparams.py +16 -14
  224. mistralai_gcp/utils/retries.py +2 -1
  225. mistralai_gcp/utils/security.py +12 -6
  226. mistralai_gcp/utils/serializers.py +42 -8
  227. mistralai_gcp/utils/url.py +13 -8
  228. mistralai_gcp/utils/values.py +6 -0
  229. mistralai-1.0.3.dist-info/RECORD +0 -236
  230. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/LICENSE +0 -0
@@ -0,0 +1,396 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basesdk import BaseSDK
4
+ from mistralai import models, utils
5
+ from mistralai._hooks import HookContext
6
+ from mistralai.types import Nullable, OptionalNullable, UNSET
7
+ from mistralai.utils import get_security_from_env
8
+ from typing import Any, Optional, Union
9
+
10
+
11
+ class Classifiers(BaseSDK):
12
+ r"""Classifiers API."""
13
+
14
+ def moderate(
15
+ self,
16
+ *,
17
+ inputs: Union[
18
+ models.ClassificationRequestInputs,
19
+ models.ClassificationRequestInputsTypedDict,
20
+ ],
21
+ model: OptionalNullable[str] = UNSET,
22
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
23
+ server_url: Optional[str] = None,
24
+ timeout_ms: Optional[int] = None,
25
+ ) -> Optional[models.ClassificationResponse]:
26
+ r"""Moderations
27
+
28
+ :param inputs: Text to classify.
29
+ :param model:
30
+ :param retries: Override the default retry configuration for this method
31
+ :param server_url: Override the default server URL for this method
32
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
33
+ """
34
+ base_url = None
35
+ url_variables = None
36
+ if timeout_ms is None:
37
+ timeout_ms = self.sdk_configuration.timeout_ms
38
+
39
+ if server_url is not None:
40
+ base_url = server_url
41
+
42
+ request = models.ClassificationRequest(
43
+ inputs=inputs,
44
+ model=model,
45
+ )
46
+
47
+ req = self.build_request(
48
+ method="POST",
49
+ path="/v1/moderations",
50
+ base_url=base_url,
51
+ url_variables=url_variables,
52
+ request=request,
53
+ request_body_required=True,
54
+ request_has_path_params=False,
55
+ request_has_query_params=True,
56
+ user_agent_header="user-agent",
57
+ accept_header_value="application/json",
58
+ security=self.sdk_configuration.security,
59
+ get_serialized_body=lambda: utils.serialize_request_body(
60
+ request, False, False, "json", models.ClassificationRequest
61
+ ),
62
+ timeout_ms=timeout_ms,
63
+ )
64
+
65
+ if retries == UNSET:
66
+ if self.sdk_configuration.retry_config is not UNSET:
67
+ retries = self.sdk_configuration.retry_config
68
+
69
+ retry_config = None
70
+ if isinstance(retries, utils.RetryConfig):
71
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
72
+
73
+ http_res = self.do_request(
74
+ hook_ctx=HookContext(
75
+ operation_id="moderations_v1_moderations_post",
76
+ oauth2_scopes=[],
77
+ security_source=get_security_from_env(
78
+ self.sdk_configuration.security, models.Security
79
+ ),
80
+ ),
81
+ request=req,
82
+ error_status_codes=["422", "4XX", "5XX"],
83
+ retry_config=retry_config,
84
+ )
85
+
86
+ data: Any = None
87
+ if utils.match_response(http_res, "200", "application/json"):
88
+ return utils.unmarshal_json(
89
+ http_res.text, Optional[models.ClassificationResponse]
90
+ )
91
+ if utils.match_response(http_res, "422", "application/json"):
92
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
93
+ raise models.HTTPValidationError(data=data)
94
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
95
+ http_res_text = utils.stream_to_text(http_res)
96
+ raise models.SDKError(
97
+ "API error occurred", http_res.status_code, http_res_text, http_res
98
+ )
99
+
100
+ content_type = http_res.headers.get("Content-Type")
101
+ http_res_text = utils.stream_to_text(http_res)
102
+ raise models.SDKError(
103
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
104
+ http_res.status_code,
105
+ http_res_text,
106
+ http_res,
107
+ )
108
+
109
+ async def moderate_async(
110
+ self,
111
+ *,
112
+ inputs: Union[
113
+ models.ClassificationRequestInputs,
114
+ models.ClassificationRequestInputsTypedDict,
115
+ ],
116
+ model: OptionalNullable[str] = UNSET,
117
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
118
+ server_url: Optional[str] = None,
119
+ timeout_ms: Optional[int] = None,
120
+ ) -> Optional[models.ClassificationResponse]:
121
+ r"""Moderations
122
+
123
+ :param inputs: Text to classify.
124
+ :param model:
125
+ :param retries: Override the default retry configuration for this method
126
+ :param server_url: Override the default server URL for this method
127
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
128
+ """
129
+ base_url = None
130
+ url_variables = None
131
+ if timeout_ms is None:
132
+ timeout_ms = self.sdk_configuration.timeout_ms
133
+
134
+ if server_url is not None:
135
+ base_url = server_url
136
+
137
+ request = models.ClassificationRequest(
138
+ inputs=inputs,
139
+ model=model,
140
+ )
141
+
142
+ req = self.build_request_async(
143
+ method="POST",
144
+ path="/v1/moderations",
145
+ base_url=base_url,
146
+ url_variables=url_variables,
147
+ request=request,
148
+ request_body_required=True,
149
+ request_has_path_params=False,
150
+ request_has_query_params=True,
151
+ user_agent_header="user-agent",
152
+ accept_header_value="application/json",
153
+ security=self.sdk_configuration.security,
154
+ get_serialized_body=lambda: utils.serialize_request_body(
155
+ request, False, False, "json", models.ClassificationRequest
156
+ ),
157
+ timeout_ms=timeout_ms,
158
+ )
159
+
160
+ if retries == UNSET:
161
+ if self.sdk_configuration.retry_config is not UNSET:
162
+ retries = self.sdk_configuration.retry_config
163
+
164
+ retry_config = None
165
+ if isinstance(retries, utils.RetryConfig):
166
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
167
+
168
+ http_res = await self.do_request_async(
169
+ hook_ctx=HookContext(
170
+ operation_id="moderations_v1_moderations_post",
171
+ oauth2_scopes=[],
172
+ security_source=get_security_from_env(
173
+ self.sdk_configuration.security, models.Security
174
+ ),
175
+ ),
176
+ request=req,
177
+ error_status_codes=["422", "4XX", "5XX"],
178
+ retry_config=retry_config,
179
+ )
180
+
181
+ data: Any = None
182
+ if utils.match_response(http_res, "200", "application/json"):
183
+ return utils.unmarshal_json(
184
+ http_res.text, Optional[models.ClassificationResponse]
185
+ )
186
+ if utils.match_response(http_res, "422", "application/json"):
187
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
188
+ raise models.HTTPValidationError(data=data)
189
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
190
+ http_res_text = await utils.stream_to_text_async(http_res)
191
+ raise models.SDKError(
192
+ "API error occurred", http_res.status_code, http_res_text, http_res
193
+ )
194
+
195
+ content_type = http_res.headers.get("Content-Type")
196
+ http_res_text = await utils.stream_to_text_async(http_res)
197
+ raise models.SDKError(
198
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
199
+ http_res.status_code,
200
+ http_res_text,
201
+ http_res,
202
+ )
203
+
204
+ def moderate_chat(
205
+ self,
206
+ *,
207
+ inputs: Union[
208
+ models.ChatClassificationRequestInputs,
209
+ models.ChatClassificationRequestInputsTypedDict,
210
+ ],
211
+ model: Nullable[str],
212
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
213
+ server_url: Optional[str] = None,
214
+ timeout_ms: Optional[int] = None,
215
+ ) -> Optional[models.ClassificationResponse]:
216
+ r"""Moderations Chat
217
+
218
+ :param inputs: Chat to classify
219
+ :param model:
220
+ :param retries: Override the default retry configuration for this method
221
+ :param server_url: Override the default server URL for this method
222
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
223
+ """
224
+ base_url = None
225
+ url_variables = None
226
+ if timeout_ms is None:
227
+ timeout_ms = self.sdk_configuration.timeout_ms
228
+
229
+ if server_url is not None:
230
+ base_url = server_url
231
+
232
+ request = models.ChatClassificationRequest(
233
+ inputs=utils.get_pydantic_model(
234
+ inputs, models.ChatClassificationRequestInputs
235
+ ),
236
+ model=model,
237
+ )
238
+
239
+ req = self.build_request(
240
+ method="POST",
241
+ path="/v1/chat/moderations",
242
+ base_url=base_url,
243
+ url_variables=url_variables,
244
+ request=request,
245
+ request_body_required=True,
246
+ request_has_path_params=False,
247
+ request_has_query_params=True,
248
+ user_agent_header="user-agent",
249
+ accept_header_value="application/json",
250
+ security=self.sdk_configuration.security,
251
+ get_serialized_body=lambda: utils.serialize_request_body(
252
+ request, False, False, "json", models.ChatClassificationRequest
253
+ ),
254
+ timeout_ms=timeout_ms,
255
+ )
256
+
257
+ if retries == UNSET:
258
+ if self.sdk_configuration.retry_config is not UNSET:
259
+ retries = self.sdk_configuration.retry_config
260
+
261
+ retry_config = None
262
+ if isinstance(retries, utils.RetryConfig):
263
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
264
+
265
+ http_res = self.do_request(
266
+ hook_ctx=HookContext(
267
+ operation_id="moderations_chat_v1_chat_moderations_post",
268
+ oauth2_scopes=[],
269
+ security_source=get_security_from_env(
270
+ self.sdk_configuration.security, models.Security
271
+ ),
272
+ ),
273
+ request=req,
274
+ error_status_codes=["422", "4XX", "5XX"],
275
+ retry_config=retry_config,
276
+ )
277
+
278
+ data: Any = None
279
+ if utils.match_response(http_res, "200", "application/json"):
280
+ return utils.unmarshal_json(
281
+ http_res.text, Optional[models.ClassificationResponse]
282
+ )
283
+ if utils.match_response(http_res, "422", "application/json"):
284
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
285
+ raise models.HTTPValidationError(data=data)
286
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
287
+ http_res_text = utils.stream_to_text(http_res)
288
+ raise models.SDKError(
289
+ "API error occurred", http_res.status_code, http_res_text, http_res
290
+ )
291
+
292
+ content_type = http_res.headers.get("Content-Type")
293
+ http_res_text = utils.stream_to_text(http_res)
294
+ raise models.SDKError(
295
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
296
+ http_res.status_code,
297
+ http_res_text,
298
+ http_res,
299
+ )
300
+
301
+ async def moderate_chat_async(
302
+ self,
303
+ *,
304
+ inputs: Union[
305
+ models.ChatClassificationRequestInputs,
306
+ models.ChatClassificationRequestInputsTypedDict,
307
+ ],
308
+ model: Nullable[str],
309
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
310
+ server_url: Optional[str] = None,
311
+ timeout_ms: Optional[int] = None,
312
+ ) -> Optional[models.ClassificationResponse]:
313
+ r"""Moderations Chat
314
+
315
+ :param inputs: Chat to classify
316
+ :param model:
317
+ :param retries: Override the default retry configuration for this method
318
+ :param server_url: Override the default server URL for this method
319
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
320
+ """
321
+ base_url = None
322
+ url_variables = None
323
+ if timeout_ms is None:
324
+ timeout_ms = self.sdk_configuration.timeout_ms
325
+
326
+ if server_url is not None:
327
+ base_url = server_url
328
+
329
+ request = models.ChatClassificationRequest(
330
+ inputs=utils.get_pydantic_model(
331
+ inputs, models.ChatClassificationRequestInputs
332
+ ),
333
+ model=model,
334
+ )
335
+
336
+ req = self.build_request_async(
337
+ method="POST",
338
+ path="/v1/chat/moderations",
339
+ base_url=base_url,
340
+ url_variables=url_variables,
341
+ request=request,
342
+ request_body_required=True,
343
+ request_has_path_params=False,
344
+ request_has_query_params=True,
345
+ user_agent_header="user-agent",
346
+ accept_header_value="application/json",
347
+ security=self.sdk_configuration.security,
348
+ get_serialized_body=lambda: utils.serialize_request_body(
349
+ request, False, False, "json", models.ChatClassificationRequest
350
+ ),
351
+ timeout_ms=timeout_ms,
352
+ )
353
+
354
+ if retries == UNSET:
355
+ if self.sdk_configuration.retry_config is not UNSET:
356
+ retries = self.sdk_configuration.retry_config
357
+
358
+ retry_config = None
359
+ if isinstance(retries, utils.RetryConfig):
360
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
361
+
362
+ http_res = await self.do_request_async(
363
+ hook_ctx=HookContext(
364
+ operation_id="moderations_chat_v1_chat_moderations_post",
365
+ oauth2_scopes=[],
366
+ security_source=get_security_from_env(
367
+ self.sdk_configuration.security, models.Security
368
+ ),
369
+ ),
370
+ request=req,
371
+ error_status_codes=["422", "4XX", "5XX"],
372
+ retry_config=retry_config,
373
+ )
374
+
375
+ data: Any = None
376
+ if utils.match_response(http_res, "200", "application/json"):
377
+ return utils.unmarshal_json(
378
+ http_res.text, Optional[models.ClassificationResponse]
379
+ )
380
+ if utils.match_response(http_res, "422", "application/json"):
381
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
382
+ raise models.HTTPValidationError(data=data)
383
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
384
+ http_res_text = await utils.stream_to_text_async(http_res)
385
+ raise models.SDKError(
386
+ "API error occurred", http_res.status_code, http_res_text, http_res
387
+ )
388
+
389
+ content_type = http_res.headers.get("Content-Type")
390
+ http_res_text = await utils.stream_to_text_async(http_res)
391
+ raise models.SDKError(
392
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
393
+ http_res.status_code,
394
+ http_res_text,
395
+ http_res,
396
+ )
mistralai/embeddings.py CHANGED
@@ -7,14 +7,15 @@ from mistralai.types import OptionalNullable, UNSET
7
7
  from mistralai.utils import get_security_from_env
8
8
  from typing import Any, Optional, Union
9
9
 
10
+
10
11
  class Embeddings(BaseSDK):
11
12
  r"""Embeddings API."""
12
-
13
-
13
+
14
14
  def create(
15
- self, *,
15
+ self,
16
+ *,
16
17
  inputs: Union[models.Inputs, models.InputsTypedDict],
17
- model: str,
18
+ model: Optional[str] = "mistral-embed",
18
19
  encoding_format: OptionalNullable[str] = UNSET,
19
20
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
20
21
  server_url: Optional[str] = None,
@@ -35,16 +36,16 @@ class Embeddings(BaseSDK):
35
36
  url_variables = None
36
37
  if timeout_ms is None:
37
38
  timeout_ms = self.sdk_configuration.timeout_ms
38
-
39
+
39
40
  if server_url is not None:
40
41
  base_url = server_url
41
-
42
+
42
43
  request = models.EmbeddingRequest(
43
44
  inputs=inputs,
44
45
  model=model,
45
46
  encoding_format=encoding_format,
46
47
  )
47
-
48
+
48
49
  req = self.build_request(
49
50
  method="POST",
50
51
  path="/v1/embeddings",
@@ -57,49 +58,61 @@ class Embeddings(BaseSDK):
57
58
  user_agent_header="user-agent",
58
59
  accept_header_value="application/json",
59
60
  security=self.sdk_configuration.security,
60
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.EmbeddingRequest),
61
+ get_serialized_body=lambda: utils.serialize_request_body(
62
+ request, False, False, "json", models.EmbeddingRequest
63
+ ),
61
64
  timeout_ms=timeout_ms,
62
65
  )
63
-
66
+
64
67
  if retries == UNSET:
65
68
  if self.sdk_configuration.retry_config is not UNSET:
66
69
  retries = self.sdk_configuration.retry_config
67
70
 
68
71
  retry_config = None
69
72
  if isinstance(retries, utils.RetryConfig):
70
- retry_config = (retries, [
71
- "429",
72
- "500",
73
- "502",
74
- "503",
75
- "504"
76
- ])
77
-
73
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
74
+
78
75
  http_res = self.do_request(
79
- hook_ctx=HookContext(operation_id="embeddings_v1_embeddings_post", oauth2_scopes=[], security_source=get_security_from_env(self.sdk_configuration.security, models.Security)),
76
+ hook_ctx=HookContext(
77
+ operation_id="embeddings_v1_embeddings_post",
78
+ oauth2_scopes=[],
79
+ security_source=get_security_from_env(
80
+ self.sdk_configuration.security, models.Security
81
+ ),
82
+ ),
80
83
  request=req,
81
- error_status_codes=["422","4XX","5XX"],
82
- retry_config=retry_config
84
+ error_status_codes=["422", "4XX", "5XX"],
85
+ retry_config=retry_config,
83
86
  )
84
-
87
+
85
88
  data: Any = None
86
89
  if utils.match_response(http_res, "200", "application/json"):
87
- return utils.unmarshal_json(http_res.text, Optional[models.EmbeddingResponse])
90
+ return utils.unmarshal_json(
91
+ http_res.text, Optional[models.EmbeddingResponse]
92
+ )
88
93
  if utils.match_response(http_res, "422", "application/json"):
89
94
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
90
95
  raise models.HTTPValidationError(data=data)
91
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
92
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
93
-
96
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
97
+ http_res_text = utils.stream_to_text(http_res)
98
+ raise models.SDKError(
99
+ "API error occurred", http_res.status_code, http_res_text, http_res
100
+ )
101
+
94
102
  content_type = http_res.headers.get("Content-Type")
95
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
103
+ http_res_text = utils.stream_to_text(http_res)
104
+ raise models.SDKError(
105
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
106
+ http_res.status_code,
107
+ http_res_text,
108
+ http_res,
109
+ )
96
110
 
97
-
98
-
99
111
  async def create_async(
100
- self, *,
112
+ self,
113
+ *,
101
114
  inputs: Union[models.Inputs, models.InputsTypedDict],
102
- model: str,
115
+ model: Optional[str] = "mistral-embed",
103
116
  encoding_format: OptionalNullable[str] = UNSET,
104
117
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
105
118
  server_url: Optional[str] = None,
@@ -120,17 +133,17 @@ class Embeddings(BaseSDK):
120
133
  url_variables = None
121
134
  if timeout_ms is None:
122
135
  timeout_ms = self.sdk_configuration.timeout_ms
123
-
136
+
124
137
  if server_url is not None:
125
138
  base_url = server_url
126
-
139
+
127
140
  request = models.EmbeddingRequest(
128
141
  inputs=inputs,
129
142
  model=model,
130
143
  encoding_format=encoding_format,
131
144
  )
132
-
133
- req = self.build_request(
145
+
146
+ req = self.build_request_async(
134
147
  method="POST",
135
148
  path="/v1/embeddings",
136
149
  base_url=base_url,
@@ -142,41 +155,52 @@ class Embeddings(BaseSDK):
142
155
  user_agent_header="user-agent",
143
156
  accept_header_value="application/json",
144
157
  security=self.sdk_configuration.security,
145
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.EmbeddingRequest),
158
+ get_serialized_body=lambda: utils.serialize_request_body(
159
+ request, False, False, "json", models.EmbeddingRequest
160
+ ),
146
161
  timeout_ms=timeout_ms,
147
162
  )
148
-
163
+
149
164
  if retries == UNSET:
150
165
  if self.sdk_configuration.retry_config is not UNSET:
151
166
  retries = self.sdk_configuration.retry_config
152
167
 
153
168
  retry_config = None
154
169
  if isinstance(retries, utils.RetryConfig):
155
- retry_config = (retries, [
156
- "429",
157
- "500",
158
- "502",
159
- "503",
160
- "504"
161
- ])
162
-
170
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
171
+
163
172
  http_res = await self.do_request_async(
164
- hook_ctx=HookContext(operation_id="embeddings_v1_embeddings_post", oauth2_scopes=[], security_source=get_security_from_env(self.sdk_configuration.security, models.Security)),
173
+ hook_ctx=HookContext(
174
+ operation_id="embeddings_v1_embeddings_post",
175
+ oauth2_scopes=[],
176
+ security_source=get_security_from_env(
177
+ self.sdk_configuration.security, models.Security
178
+ ),
179
+ ),
165
180
  request=req,
166
- error_status_codes=["422","4XX","5XX"],
167
- retry_config=retry_config
181
+ error_status_codes=["422", "4XX", "5XX"],
182
+ retry_config=retry_config,
168
183
  )
169
-
184
+
170
185
  data: Any = None
171
186
  if utils.match_response(http_res, "200", "application/json"):
172
- return utils.unmarshal_json(http_res.text, Optional[models.EmbeddingResponse])
187
+ return utils.unmarshal_json(
188
+ http_res.text, Optional[models.EmbeddingResponse]
189
+ )
173
190
  if utils.match_response(http_res, "422", "application/json"):
174
191
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
175
192
  raise models.HTTPValidationError(data=data)
176
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
177
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
178
-
179
- content_type = http_res.headers.get("Content-Type")
180
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
193
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
194
+ http_res_text = await utils.stream_to_text_async(http_res)
195
+ raise models.SDKError(
196
+ "API error occurred", http_res.status_code, http_res_text, http_res
197
+ )
181
198
 
182
-
199
+ content_type = http_res.headers.get("Content-Type")
200
+ http_res_text = await utils.stream_to_text_async(http_res)
201
+ raise models.SDKError(
202
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
203
+ http_res.status_code,
204
+ http_res_text,
205
+ http_res,
206
+ )