mistralai 1.5.0__py3-none-any.whl → 1.5.2rc1__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.
- mistralai/_hooks/types.py +15 -3
- mistralai/_version.py +3 -3
- mistralai/agents.py +32 -12
- mistralai/basesdk.py +8 -0
- mistralai/chat.py +37 -17
- mistralai/classifiers.py +59 -37
- mistralai/embeddings.py +22 -18
- mistralai/extra/utils/response_format.py +3 -3
- mistralai/files.py +36 -0
- mistralai/fim.py +37 -17
- mistralai/httpclient.py +4 -2
- mistralai/jobs.py +30 -0
- mistralai/mistral_jobs.py +24 -0
- mistralai/models/__init__.py +43 -16
- mistralai/models/assistantmessage.py +2 -0
- mistralai/models/chatcompletionrequest.py +3 -10
- mistralai/models/chatcompletionstreamrequest.py +3 -10
- mistralai/models/chatmoderationrequest.py +86 -0
- mistralai/models/classificationrequest.py +7 -36
- mistralai/models/contentchunk.py +8 -1
- mistralai/models/documenturlchunk.py +56 -0
- mistralai/models/embeddingrequest.py +8 -44
- mistralai/models/filepurpose.py +1 -1
- mistralai/models/fimcompletionrequest.py +2 -3
- mistralai/models/fimcompletionstreamrequest.py +2 -3
- mistralai/models/ocrimageobject.py +77 -0
- mistralai/models/ocrpagedimensions.py +25 -0
- mistralai/models/ocrpageobject.py +64 -0
- mistralai/models/ocrrequest.py +97 -0
- mistralai/models/ocrresponse.py +26 -0
- mistralai/models/ocrusageinfo.py +51 -0
- mistralai/models/prediction.py +4 -5
- mistralai/models_.py +66 -18
- mistralai/ocr.py +248 -0
- mistralai/sdk.py +23 -3
- mistralai/sdkconfiguration.py +4 -2
- mistralai/utils/__init__.py +2 -0
- mistralai/utils/serializers.py +10 -6
- mistralai/utils/values.py +4 -1
- {mistralai-1.5.0.dist-info → mistralai-1.5.2rc1.dist-info}/METADATA +70 -19
- {mistralai-1.5.0.dist-info → mistralai-1.5.2rc1.dist-info}/RECORD +88 -76
- {mistralai-1.5.0.dist-info → mistralai-1.5.2rc1.dist-info}/WHEEL +1 -1
- mistralai_azure/__init__.py +10 -1
- mistralai_azure/_hooks/types.py +15 -3
- mistralai_azure/_version.py +3 -0
- mistralai_azure/basesdk.py +8 -0
- mistralai_azure/chat.py +88 -20
- mistralai_azure/httpclient.py +52 -0
- mistralai_azure/models/__init__.py +7 -0
- mistralai_azure/models/assistantmessage.py +2 -0
- mistralai_azure/models/chatcompletionrequest.py +8 -10
- mistralai_azure/models/chatcompletionstreamrequest.py +8 -10
- mistralai_azure/models/function.py +3 -0
- mistralai_azure/models/jsonschema.py +61 -0
- mistralai_azure/models/prediction.py +25 -0
- mistralai_azure/models/responseformat.py +42 -1
- mistralai_azure/models/responseformats.py +1 -1
- mistralai_azure/models/toolcall.py +3 -0
- mistralai_azure/sdk.py +56 -14
- mistralai_azure/sdkconfiguration.py +14 -6
- mistralai_azure/utils/__init__.py +2 -0
- mistralai_azure/utils/serializers.py +10 -6
- mistralai_azure/utils/values.py +4 -1
- mistralai_gcp/__init__.py +10 -1
- mistralai_gcp/_hooks/types.py +15 -3
- mistralai_gcp/_version.py +3 -0
- mistralai_gcp/basesdk.py +8 -0
- mistralai_gcp/chat.py +89 -21
- mistralai_gcp/fim.py +61 -21
- mistralai_gcp/httpclient.py +52 -0
- mistralai_gcp/models/__init__.py +7 -0
- mistralai_gcp/models/assistantmessage.py +2 -0
- mistralai_gcp/models/chatcompletionrequest.py +8 -10
- mistralai_gcp/models/chatcompletionstreamrequest.py +8 -10
- mistralai_gcp/models/fimcompletionrequest.py +2 -3
- mistralai_gcp/models/fimcompletionstreamrequest.py +2 -3
- mistralai_gcp/models/function.py +3 -0
- mistralai_gcp/models/jsonschema.py +61 -0
- mistralai_gcp/models/prediction.py +25 -0
- mistralai_gcp/models/responseformat.py +42 -1
- mistralai_gcp/models/responseformats.py +1 -1
- mistralai_gcp/models/toolcall.py +3 -0
- mistralai_gcp/sdk.py +63 -19
- mistralai_gcp/sdkconfiguration.py +14 -6
- mistralai_gcp/utils/__init__.py +2 -0
- mistralai_gcp/utils/serializers.py +10 -6
- mistralai_gcp/utils/values.py +4 -1
- mistralai/models/chatclassificationrequest.py +0 -113
- {mistralai-1.5.0.dist-info → mistralai-1.5.2rc1.dist-info}/LICENSE +0 -0
mistralai_azure/chat.py
CHANGED
|
@@ -15,7 +15,7 @@ class Chat(BaseSDK):
|
|
|
15
15
|
self,
|
|
16
16
|
*,
|
|
17
17
|
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
18
|
-
model:
|
|
18
|
+
model: Optional[str] = "azureai",
|
|
19
19
|
temperature: OptionalNullable[float] = UNSET,
|
|
20
20
|
top_p: Optional[float] = None,
|
|
21
21
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
@@ -37,6 +37,9 @@ class Chat(BaseSDK):
|
|
|
37
37
|
presence_penalty: Optional[float] = None,
|
|
38
38
|
frequency_penalty: Optional[float] = None,
|
|
39
39
|
n: OptionalNullable[int] = UNSET,
|
|
40
|
+
prediction: Optional[
|
|
41
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
42
|
+
] = None,
|
|
40
43
|
safe_prompt: Optional[bool] = None,
|
|
41
44
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
42
45
|
server_url: Optional[str] = None,
|
|
@@ -61,6 +64,7 @@ class Chat(BaseSDK):
|
|
|
61
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.
|
|
62
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.
|
|
63
66
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
67
|
+
:param prediction:
|
|
64
68
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
65
69
|
:param retries: Override the default retry configuration for this method
|
|
66
70
|
:param server_url: Override the default server URL for this method
|
|
@@ -74,6 +78,8 @@ class Chat(BaseSDK):
|
|
|
74
78
|
|
|
75
79
|
if server_url is not None:
|
|
76
80
|
base_url = server_url
|
|
81
|
+
else:
|
|
82
|
+
base_url = self._get_url(base_url, url_variables)
|
|
77
83
|
|
|
78
84
|
request = models.ChatCompletionStreamRequest(
|
|
79
85
|
model=model,
|
|
@@ -94,6 +100,9 @@ class Chat(BaseSDK):
|
|
|
94
100
|
presence_penalty=presence_penalty,
|
|
95
101
|
frequency_penalty=frequency_penalty,
|
|
96
102
|
n=n,
|
|
103
|
+
prediction=utils.get_pydantic_model(
|
|
104
|
+
prediction, Optional[models.Prediction]
|
|
105
|
+
),
|
|
97
106
|
safe_prompt=safe_prompt,
|
|
98
107
|
)
|
|
99
108
|
|
|
@@ -126,6 +135,7 @@ class Chat(BaseSDK):
|
|
|
126
135
|
|
|
127
136
|
http_res = self.do_request(
|
|
128
137
|
hook_ctx=HookContext(
|
|
138
|
+
base_url=base_url or "",
|
|
129
139
|
operation_id="stream_chat",
|
|
130
140
|
oauth2_scopes=[],
|
|
131
141
|
security_source=self.sdk_configuration.security,
|
|
@@ -136,7 +146,7 @@ class Chat(BaseSDK):
|
|
|
136
146
|
retry_config=retry_config,
|
|
137
147
|
)
|
|
138
148
|
|
|
139
|
-
|
|
149
|
+
response_data: Any = None
|
|
140
150
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
141
151
|
return eventstreaming.EventStream(
|
|
142
152
|
http_res,
|
|
@@ -145,9 +155,16 @@ class Chat(BaseSDK):
|
|
|
145
155
|
)
|
|
146
156
|
if utils.match_response(http_res, "422", "application/json"):
|
|
147
157
|
http_res_text = utils.stream_to_text(http_res)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
158
|
+
response_data = utils.unmarshal_json(
|
|
159
|
+
http_res_text, models.HTTPValidationErrorData
|
|
160
|
+
)
|
|
161
|
+
raise models.HTTPValidationError(data=response_data)
|
|
162
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
163
|
+
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
|
+
)
|
|
167
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
151
168
|
http_res_text = utils.stream_to_text(http_res)
|
|
152
169
|
raise models.SDKError(
|
|
153
170
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -166,7 +183,7 @@ class Chat(BaseSDK):
|
|
|
166
183
|
self,
|
|
167
184
|
*,
|
|
168
185
|
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
169
|
-
model:
|
|
186
|
+
model: Optional[str] = "azureai",
|
|
170
187
|
temperature: OptionalNullable[float] = UNSET,
|
|
171
188
|
top_p: Optional[float] = None,
|
|
172
189
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
@@ -188,6 +205,9 @@ class Chat(BaseSDK):
|
|
|
188
205
|
presence_penalty: Optional[float] = None,
|
|
189
206
|
frequency_penalty: Optional[float] = None,
|
|
190
207
|
n: OptionalNullable[int] = UNSET,
|
|
208
|
+
prediction: Optional[
|
|
209
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
210
|
+
] = None,
|
|
191
211
|
safe_prompt: Optional[bool] = None,
|
|
192
212
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
193
213
|
server_url: Optional[str] = None,
|
|
@@ -212,6 +232,7 @@ class Chat(BaseSDK):
|
|
|
212
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.
|
|
213
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.
|
|
214
234
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
235
|
+
:param prediction:
|
|
215
236
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
216
237
|
:param retries: Override the default retry configuration for this method
|
|
217
238
|
:param server_url: Override the default server URL for this method
|
|
@@ -225,6 +246,8 @@ class Chat(BaseSDK):
|
|
|
225
246
|
|
|
226
247
|
if server_url is not None:
|
|
227
248
|
base_url = server_url
|
|
249
|
+
else:
|
|
250
|
+
base_url = self._get_url(base_url, url_variables)
|
|
228
251
|
|
|
229
252
|
request = models.ChatCompletionStreamRequest(
|
|
230
253
|
model=model,
|
|
@@ -245,6 +268,9 @@ class Chat(BaseSDK):
|
|
|
245
268
|
presence_penalty=presence_penalty,
|
|
246
269
|
frequency_penalty=frequency_penalty,
|
|
247
270
|
n=n,
|
|
271
|
+
prediction=utils.get_pydantic_model(
|
|
272
|
+
prediction, Optional[models.Prediction]
|
|
273
|
+
),
|
|
248
274
|
safe_prompt=safe_prompt,
|
|
249
275
|
)
|
|
250
276
|
|
|
@@ -277,6 +303,7 @@ class Chat(BaseSDK):
|
|
|
277
303
|
|
|
278
304
|
http_res = await self.do_request_async(
|
|
279
305
|
hook_ctx=HookContext(
|
|
306
|
+
base_url=base_url or "",
|
|
280
307
|
operation_id="stream_chat",
|
|
281
308
|
oauth2_scopes=[],
|
|
282
309
|
security_source=self.sdk_configuration.security,
|
|
@@ -287,7 +314,7 @@ class Chat(BaseSDK):
|
|
|
287
314
|
retry_config=retry_config,
|
|
288
315
|
)
|
|
289
316
|
|
|
290
|
-
|
|
317
|
+
response_data: Any = None
|
|
291
318
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
292
319
|
return eventstreaming.EventStreamAsync(
|
|
293
320
|
http_res,
|
|
@@ -296,9 +323,16 @@ class Chat(BaseSDK):
|
|
|
296
323
|
)
|
|
297
324
|
if utils.match_response(http_res, "422", "application/json"):
|
|
298
325
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
326
|
+
response_data = utils.unmarshal_json(
|
|
327
|
+
http_res_text, models.HTTPValidationErrorData
|
|
328
|
+
)
|
|
329
|
+
raise models.HTTPValidationError(data=response_data)
|
|
330
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
331
|
+
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
|
+
)
|
|
335
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
302
336
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
303
337
|
raise models.SDKError(
|
|
304
338
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -320,7 +354,7 @@ class Chat(BaseSDK):
|
|
|
320
354
|
List[models.ChatCompletionRequestMessages],
|
|
321
355
|
List[models.ChatCompletionRequestMessagesTypedDict],
|
|
322
356
|
],
|
|
323
|
-
model:
|
|
357
|
+
model: Optional[str] = "azureai",
|
|
324
358
|
temperature: OptionalNullable[float] = UNSET,
|
|
325
359
|
top_p: Optional[float] = None,
|
|
326
360
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
@@ -347,6 +381,9 @@ class Chat(BaseSDK):
|
|
|
347
381
|
presence_penalty: Optional[float] = None,
|
|
348
382
|
frequency_penalty: Optional[float] = None,
|
|
349
383
|
n: OptionalNullable[int] = UNSET,
|
|
384
|
+
prediction: Optional[
|
|
385
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
386
|
+
] = None,
|
|
350
387
|
safe_prompt: Optional[bool] = None,
|
|
351
388
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
352
389
|
server_url: Optional[str] = None,
|
|
@@ -369,6 +406,7 @@ class Chat(BaseSDK):
|
|
|
369
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.
|
|
370
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.
|
|
371
408
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
409
|
+
:param prediction:
|
|
372
410
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
373
411
|
:param retries: Override the default retry configuration for this method
|
|
374
412
|
:param server_url: Override the default server URL for this method
|
|
@@ -382,6 +420,8 @@ class Chat(BaseSDK):
|
|
|
382
420
|
|
|
383
421
|
if server_url is not None:
|
|
384
422
|
base_url = server_url
|
|
423
|
+
else:
|
|
424
|
+
base_url = self._get_url(base_url, url_variables)
|
|
385
425
|
|
|
386
426
|
request = models.ChatCompletionRequest(
|
|
387
427
|
model=model,
|
|
@@ -404,6 +444,9 @@ class Chat(BaseSDK):
|
|
|
404
444
|
presence_penalty=presence_penalty,
|
|
405
445
|
frequency_penalty=frequency_penalty,
|
|
406
446
|
n=n,
|
|
447
|
+
prediction=utils.get_pydantic_model(
|
|
448
|
+
prediction, Optional[models.Prediction]
|
|
449
|
+
),
|
|
407
450
|
safe_prompt=safe_prompt,
|
|
408
451
|
)
|
|
409
452
|
|
|
@@ -436,6 +479,7 @@ class Chat(BaseSDK):
|
|
|
436
479
|
|
|
437
480
|
http_res = self.do_request(
|
|
438
481
|
hook_ctx=HookContext(
|
|
482
|
+
base_url=base_url or "",
|
|
439
483
|
operation_id="chat_completion_v1_chat_completions_post",
|
|
440
484
|
oauth2_scopes=[],
|
|
441
485
|
security_source=self.sdk_configuration.security,
|
|
@@ -445,15 +489,22 @@ class Chat(BaseSDK):
|
|
|
445
489
|
retry_config=retry_config,
|
|
446
490
|
)
|
|
447
491
|
|
|
448
|
-
|
|
492
|
+
response_data: Any = None
|
|
449
493
|
if utils.match_response(http_res, "200", "application/json"):
|
|
450
494
|
return utils.unmarshal_json(
|
|
451
495
|
http_res.text, Optional[models.ChatCompletionResponse]
|
|
452
496
|
)
|
|
453
497
|
if utils.match_response(http_res, "422", "application/json"):
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
498
|
+
response_data = utils.unmarshal_json(
|
|
499
|
+
http_res.text, models.HTTPValidationErrorData
|
|
500
|
+
)
|
|
501
|
+
raise models.HTTPValidationError(data=response_data)
|
|
502
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
503
|
+
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
|
+
)
|
|
507
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
457
508
|
http_res_text = utils.stream_to_text(http_res)
|
|
458
509
|
raise models.SDKError(
|
|
459
510
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -475,7 +526,7 @@ class Chat(BaseSDK):
|
|
|
475
526
|
List[models.ChatCompletionRequestMessages],
|
|
476
527
|
List[models.ChatCompletionRequestMessagesTypedDict],
|
|
477
528
|
],
|
|
478
|
-
model:
|
|
529
|
+
model: Optional[str] = "azureai",
|
|
479
530
|
temperature: OptionalNullable[float] = UNSET,
|
|
480
531
|
top_p: Optional[float] = None,
|
|
481
532
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
@@ -502,6 +553,9 @@ class Chat(BaseSDK):
|
|
|
502
553
|
presence_penalty: Optional[float] = None,
|
|
503
554
|
frequency_penalty: Optional[float] = None,
|
|
504
555
|
n: OptionalNullable[int] = UNSET,
|
|
556
|
+
prediction: Optional[
|
|
557
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
558
|
+
] = None,
|
|
505
559
|
safe_prompt: Optional[bool] = None,
|
|
506
560
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
507
561
|
server_url: Optional[str] = None,
|
|
@@ -524,6 +578,7 @@ class Chat(BaseSDK):
|
|
|
524
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.
|
|
525
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.
|
|
526
580
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
581
|
+
:param prediction:
|
|
527
582
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
528
583
|
:param retries: Override the default retry configuration for this method
|
|
529
584
|
:param server_url: Override the default server URL for this method
|
|
@@ -537,6 +592,8 @@ class Chat(BaseSDK):
|
|
|
537
592
|
|
|
538
593
|
if server_url is not None:
|
|
539
594
|
base_url = server_url
|
|
595
|
+
else:
|
|
596
|
+
base_url = self._get_url(base_url, url_variables)
|
|
540
597
|
|
|
541
598
|
request = models.ChatCompletionRequest(
|
|
542
599
|
model=model,
|
|
@@ -559,6 +616,9 @@ class Chat(BaseSDK):
|
|
|
559
616
|
presence_penalty=presence_penalty,
|
|
560
617
|
frequency_penalty=frequency_penalty,
|
|
561
618
|
n=n,
|
|
619
|
+
prediction=utils.get_pydantic_model(
|
|
620
|
+
prediction, Optional[models.Prediction]
|
|
621
|
+
),
|
|
562
622
|
safe_prompt=safe_prompt,
|
|
563
623
|
)
|
|
564
624
|
|
|
@@ -591,6 +651,7 @@ class Chat(BaseSDK):
|
|
|
591
651
|
|
|
592
652
|
http_res = await self.do_request_async(
|
|
593
653
|
hook_ctx=HookContext(
|
|
654
|
+
base_url=base_url or "",
|
|
594
655
|
operation_id="chat_completion_v1_chat_completions_post",
|
|
595
656
|
oauth2_scopes=[],
|
|
596
657
|
security_source=self.sdk_configuration.security,
|
|
@@ -600,15 +661,22 @@ class Chat(BaseSDK):
|
|
|
600
661
|
retry_config=retry_config,
|
|
601
662
|
)
|
|
602
663
|
|
|
603
|
-
|
|
664
|
+
response_data: Any = None
|
|
604
665
|
if utils.match_response(http_res, "200", "application/json"):
|
|
605
666
|
return utils.unmarshal_json(
|
|
606
667
|
http_res.text, Optional[models.ChatCompletionResponse]
|
|
607
668
|
)
|
|
608
669
|
if utils.match_response(http_res, "422", "application/json"):
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
670
|
+
response_data = utils.unmarshal_json(
|
|
671
|
+
http_res.text, models.HTTPValidationErrorData
|
|
672
|
+
)
|
|
673
|
+
raise models.HTTPValidationError(data=response_data)
|
|
674
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
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
|
+
)
|
|
679
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
612
680
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
613
681
|
raise models.SDKError(
|
|
614
682
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
mistralai_azure/httpclient.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
# pyright: reportReturnType = false
|
|
4
|
+
import asyncio
|
|
5
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
4
6
|
from typing_extensions import Protocol, runtime_checkable
|
|
5
7
|
import httpx
|
|
6
8
|
from typing import Any, Optional, Union
|
|
@@ -82,3 +84,53 @@ class AsyncHttpClient(Protocol):
|
|
|
82
84
|
|
|
83
85
|
async def aclose(self) -> None:
|
|
84
86
|
pass
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class ClientOwner(Protocol):
|
|
90
|
+
client: Union[HttpClient, None]
|
|
91
|
+
async_client: Union[AsyncHttpClient, None]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def close_clients(
|
|
95
|
+
owner: ClientOwner,
|
|
96
|
+
sync_client: Union[HttpClient, None],
|
|
97
|
+
sync_client_supplied: bool,
|
|
98
|
+
async_client: Union[AsyncHttpClient, None],
|
|
99
|
+
async_client_supplied: bool,
|
|
100
|
+
) -> None:
|
|
101
|
+
"""
|
|
102
|
+
A finalizer function that is meant to be used with weakref.finalize to close
|
|
103
|
+
httpx clients used by an SDK so that underlying resources can be garbage
|
|
104
|
+
collected.
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
# Unset the client/async_client properties so there are no more references
|
|
108
|
+
# to them from the owning SDK instance and they can be reaped.
|
|
109
|
+
owner.client = None
|
|
110
|
+
owner.async_client = None
|
|
111
|
+
|
|
112
|
+
if sync_client is not None and not sync_client_supplied:
|
|
113
|
+
try:
|
|
114
|
+
sync_client.close()
|
|
115
|
+
except Exception:
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
if async_client is not None and not async_client_supplied:
|
|
119
|
+
is_async = False
|
|
120
|
+
try:
|
|
121
|
+
asyncio.get_running_loop()
|
|
122
|
+
is_async = True
|
|
123
|
+
except RuntimeError:
|
|
124
|
+
pass
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
# If this function is called in an async loop then start another
|
|
128
|
+
# loop in a separate thread to close the async http client.
|
|
129
|
+
if is_async:
|
|
130
|
+
with ThreadPoolExecutor(max_workers=1) as executor:
|
|
131
|
+
future = executor.submit(asyncio.run, async_client.aclose())
|
|
132
|
+
future.result()
|
|
133
|
+
else:
|
|
134
|
+
asyncio.run(async_client.aclose())
|
|
135
|
+
except Exception:
|
|
136
|
+
pass
|
|
@@ -54,6 +54,8 @@ from .functioncall import (
|
|
|
54
54
|
)
|
|
55
55
|
from .functionname import FunctionName, FunctionNameTypedDict
|
|
56
56
|
from .httpvalidationerror import HTTPValidationError, HTTPValidationErrorData
|
|
57
|
+
from .jsonschema import JSONSchema, JSONSchemaTypedDict
|
|
58
|
+
from .prediction import Prediction, PredictionTypedDict
|
|
57
59
|
from .referencechunk import ReferenceChunk, ReferenceChunkType, ReferenceChunkTypedDict
|
|
58
60
|
from .responseformat import ResponseFormat, ResponseFormatTypedDict
|
|
59
61
|
from .responseformats import ResponseFormats
|
|
@@ -94,6 +96,7 @@ from .validationerror import (
|
|
|
94
96
|
ValidationErrorTypedDict,
|
|
95
97
|
)
|
|
96
98
|
|
|
99
|
+
|
|
97
100
|
__all__ = [
|
|
98
101
|
"Arguments",
|
|
99
102
|
"ArgumentsTypedDict",
|
|
@@ -140,10 +143,14 @@ __all__ = [
|
|
|
140
143
|
"FunctionTypedDict",
|
|
141
144
|
"HTTPValidationError",
|
|
142
145
|
"HTTPValidationErrorData",
|
|
146
|
+
"JSONSchema",
|
|
147
|
+
"JSONSchemaTypedDict",
|
|
143
148
|
"Loc",
|
|
144
149
|
"LocTypedDict",
|
|
145
150
|
"Messages",
|
|
146
151
|
"MessagesTypedDict",
|
|
152
|
+
"Prediction",
|
|
153
|
+
"PredictionTypedDict",
|
|
147
154
|
"ReferenceChunk",
|
|
148
155
|
"ReferenceChunkType",
|
|
149
156
|
"ReferenceChunkTypedDict",
|
|
@@ -32,6 +32,7 @@ class AssistantMessageTypedDict(TypedDict):
|
|
|
32
32
|
content: NotRequired[Nullable[AssistantMessageContentTypedDict]]
|
|
33
33
|
tool_calls: NotRequired[Nullable[List[ToolCallTypedDict]]]
|
|
34
34
|
prefix: NotRequired[bool]
|
|
35
|
+
r"""Set this to `true` when adding an assistant message as prefix to condition the model response. The role of the prefix message is to force the model to start its answer by the content of the message."""
|
|
35
36
|
role: NotRequired[AssistantMessageRole]
|
|
36
37
|
|
|
37
38
|
|
|
@@ -41,6 +42,7 @@ class AssistantMessage(BaseModel):
|
|
|
41
42
|
tool_calls: OptionalNullable[List[ToolCall]] = UNSET
|
|
42
43
|
|
|
43
44
|
prefix: Optional[bool] = False
|
|
45
|
+
r"""Set this to `true` when adding an assistant message as prefix to condition the model response. The role of the prefix message is to force the model to start its answer by the content of the message."""
|
|
44
46
|
|
|
45
47
|
role: Optional[AssistantMessageRole] = "assistant"
|
|
46
48
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
from .assistantmessage import AssistantMessage, AssistantMessageTypedDict
|
|
5
|
+
from .prediction import Prediction, PredictionTypedDict
|
|
5
6
|
from .responseformat import ResponseFormat, ResponseFormatTypedDict
|
|
6
7
|
from .systemmessage import SystemMessage, SystemMessageTypedDict
|
|
7
8
|
from .tool import Tool, ToolTypedDict
|
|
@@ -70,7 +71,7 @@ ChatCompletionRequestToolChoice = TypeAliasType(
|
|
|
70
71
|
class ChatCompletionRequestTypedDict(TypedDict):
|
|
71
72
|
messages: List[ChatCompletionRequestMessagesTypedDict]
|
|
72
73
|
r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
|
|
73
|
-
model: NotRequired[
|
|
74
|
+
model: NotRequired[str]
|
|
74
75
|
r"""The ID of the model to use for this request."""
|
|
75
76
|
temperature: NotRequired[Nullable[float]]
|
|
76
77
|
r"""What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value."""
|
|
@@ -93,6 +94,7 @@ class ChatCompletionRequestTypedDict(TypedDict):
|
|
|
93
94
|
r"""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."""
|
|
94
95
|
n: NotRequired[Nullable[int]]
|
|
95
96
|
r"""Number of completions to return for each request, input tokens are only billed once."""
|
|
97
|
+
prediction: NotRequired[PredictionTypedDict]
|
|
96
98
|
safe_prompt: NotRequired[bool]
|
|
97
99
|
r"""Whether to inject a safety prompt before all conversations."""
|
|
98
100
|
|
|
@@ -101,7 +103,7 @@ class ChatCompletionRequest(BaseModel):
|
|
|
101
103
|
messages: List[ChatCompletionRequestMessages]
|
|
102
104
|
r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
|
|
103
105
|
|
|
104
|
-
model:
|
|
106
|
+
model: Optional[str] = "azureai"
|
|
105
107
|
r"""The ID of the model to use for this request."""
|
|
106
108
|
|
|
107
109
|
temperature: OptionalNullable[float] = UNSET
|
|
@@ -137,6 +139,8 @@ class ChatCompletionRequest(BaseModel):
|
|
|
137
139
|
n: OptionalNullable[int] = UNSET
|
|
138
140
|
r"""Number of completions to return for each request, input tokens are only billed once."""
|
|
139
141
|
|
|
142
|
+
prediction: Optional[Prediction] = None
|
|
143
|
+
|
|
140
144
|
safe_prompt: Optional[bool] = None
|
|
141
145
|
r"""Whether to inject a safety prompt before all conversations."""
|
|
142
146
|
|
|
@@ -156,16 +160,10 @@ class ChatCompletionRequest(BaseModel):
|
|
|
156
160
|
"presence_penalty",
|
|
157
161
|
"frequency_penalty",
|
|
158
162
|
"n",
|
|
163
|
+
"prediction",
|
|
159
164
|
"safe_prompt",
|
|
160
165
|
]
|
|
161
|
-
nullable_fields = [
|
|
162
|
-
"model",
|
|
163
|
-
"temperature",
|
|
164
|
-
"max_tokens",
|
|
165
|
-
"random_seed",
|
|
166
|
-
"tools",
|
|
167
|
-
"n",
|
|
168
|
-
]
|
|
166
|
+
nullable_fields = ["temperature", "max_tokens", "random_seed", "tools", "n"]
|
|
169
167
|
null_default_fields = []
|
|
170
168
|
|
|
171
169
|
serialized = handler(self)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
from .assistantmessage import AssistantMessage, AssistantMessageTypedDict
|
|
5
|
+
from .prediction import Prediction, PredictionTypedDict
|
|
5
6
|
from .responseformat import ResponseFormat, ResponseFormatTypedDict
|
|
6
7
|
from .systemmessage import SystemMessage, SystemMessageTypedDict
|
|
7
8
|
from .tool import Tool, ToolTypedDict
|
|
@@ -66,7 +67,7 @@ ChatCompletionStreamRequestToolChoice = TypeAliasType(
|
|
|
66
67
|
class ChatCompletionStreamRequestTypedDict(TypedDict):
|
|
67
68
|
messages: List[MessagesTypedDict]
|
|
68
69
|
r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
|
|
69
|
-
model: NotRequired[
|
|
70
|
+
model: NotRequired[str]
|
|
70
71
|
r"""The ID of the model to use for this request."""
|
|
71
72
|
temperature: NotRequired[Nullable[float]]
|
|
72
73
|
r"""What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value."""
|
|
@@ -88,6 +89,7 @@ class ChatCompletionStreamRequestTypedDict(TypedDict):
|
|
|
88
89
|
r"""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."""
|
|
89
90
|
n: NotRequired[Nullable[int]]
|
|
90
91
|
r"""Number of completions to return for each request, input tokens are only billed once."""
|
|
92
|
+
prediction: NotRequired[PredictionTypedDict]
|
|
91
93
|
safe_prompt: NotRequired[bool]
|
|
92
94
|
r"""Whether to inject a safety prompt before all conversations."""
|
|
93
95
|
|
|
@@ -96,7 +98,7 @@ class ChatCompletionStreamRequest(BaseModel):
|
|
|
96
98
|
messages: List[Messages]
|
|
97
99
|
r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
|
|
98
100
|
|
|
99
|
-
model:
|
|
101
|
+
model: Optional[str] = "azureai"
|
|
100
102
|
r"""The ID of the model to use for this request."""
|
|
101
103
|
|
|
102
104
|
temperature: OptionalNullable[float] = UNSET
|
|
@@ -131,6 +133,8 @@ class ChatCompletionStreamRequest(BaseModel):
|
|
|
131
133
|
n: OptionalNullable[int] = UNSET
|
|
132
134
|
r"""Number of completions to return for each request, input tokens are only billed once."""
|
|
133
135
|
|
|
136
|
+
prediction: Optional[Prediction] = None
|
|
137
|
+
|
|
134
138
|
safe_prompt: Optional[bool] = None
|
|
135
139
|
r"""Whether to inject a safety prompt before all conversations."""
|
|
136
140
|
|
|
@@ -150,16 +154,10 @@ class ChatCompletionStreamRequest(BaseModel):
|
|
|
150
154
|
"presence_penalty",
|
|
151
155
|
"frequency_penalty",
|
|
152
156
|
"n",
|
|
157
|
+
"prediction",
|
|
153
158
|
"safe_prompt",
|
|
154
159
|
]
|
|
155
|
-
nullable_fields = [
|
|
156
|
-
"model",
|
|
157
|
-
"temperature",
|
|
158
|
-
"max_tokens",
|
|
159
|
-
"random_seed",
|
|
160
|
-
"tools",
|
|
161
|
-
"n",
|
|
162
|
-
]
|
|
160
|
+
nullable_fields = ["temperature", "max_tokens", "random_seed", "tools", "n"]
|
|
163
161
|
null_default_fields = []
|
|
164
162
|
|
|
165
163
|
serialized = handler(self)
|
|
@@ -10,6 +10,7 @@ class FunctionTypedDict(TypedDict):
|
|
|
10
10
|
name: str
|
|
11
11
|
parameters: Dict[str, Any]
|
|
12
12
|
description: NotRequired[str]
|
|
13
|
+
strict: NotRequired[bool]
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
class Function(BaseModel):
|
|
@@ -18,3 +19,5 @@ class Function(BaseModel):
|
|
|
18
19
|
parameters: Dict[str, Any]
|
|
19
20
|
|
|
20
21
|
description: Optional[str] = ""
|
|
22
|
+
|
|
23
|
+
strict: Optional[bool] = False
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from mistralai_azure.types import (
|
|
5
|
+
BaseModel,
|
|
6
|
+
Nullable,
|
|
7
|
+
OptionalNullable,
|
|
8
|
+
UNSET,
|
|
9
|
+
UNSET_SENTINEL,
|
|
10
|
+
)
|
|
11
|
+
import pydantic
|
|
12
|
+
from pydantic import model_serializer
|
|
13
|
+
from typing import Any, Dict, Optional
|
|
14
|
+
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class JSONSchemaTypedDict(TypedDict):
|
|
18
|
+
name: str
|
|
19
|
+
schema_definition: Dict[str, Any]
|
|
20
|
+
description: NotRequired[Nullable[str]]
|
|
21
|
+
strict: NotRequired[bool]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class JSONSchema(BaseModel):
|
|
25
|
+
name: str
|
|
26
|
+
|
|
27
|
+
schema_definition: Annotated[Dict[str, Any], pydantic.Field(alias="schema")]
|
|
28
|
+
|
|
29
|
+
description: OptionalNullable[str] = UNSET
|
|
30
|
+
|
|
31
|
+
strict: Optional[bool] = False
|
|
32
|
+
|
|
33
|
+
@model_serializer(mode="wrap")
|
|
34
|
+
def serialize_model(self, handler):
|
|
35
|
+
optional_fields = ["description", "strict"]
|
|
36
|
+
nullable_fields = ["description"]
|
|
37
|
+
null_default_fields = []
|
|
38
|
+
|
|
39
|
+
serialized = handler(self)
|
|
40
|
+
|
|
41
|
+
m = {}
|
|
42
|
+
|
|
43
|
+
for n, f in self.model_fields.items():
|
|
44
|
+
k = f.alias or n
|
|
45
|
+
val = serialized.get(k)
|
|
46
|
+
serialized.pop(k, None)
|
|
47
|
+
|
|
48
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
49
|
+
is_set = (
|
|
50
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
51
|
+
or k in null_default_fields
|
|
52
|
+
) # pylint: disable=no-member
|
|
53
|
+
|
|
54
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
55
|
+
m[k] = val
|
|
56
|
+
elif val != UNSET_SENTINEL and (
|
|
57
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
58
|
+
):
|
|
59
|
+
m[k] = val
|
|
60
|
+
|
|
61
|
+
return m
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from mistralai_azure.types import BaseModel
|
|
5
|
+
from mistralai_azure.utils import validate_const
|
|
6
|
+
import pydantic
|
|
7
|
+
from pydantic.functional_validators import AfterValidator
|
|
8
|
+
from typing import Literal, Optional
|
|
9
|
+
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PredictionTypedDict(TypedDict):
|
|
13
|
+
type: Literal["content"]
|
|
14
|
+
content: NotRequired[str]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Prediction(BaseModel):
|
|
18
|
+
TYPE: Annotated[
|
|
19
|
+
Annotated[
|
|
20
|
+
Optional[Literal["content"]], AfterValidator(validate_const("content"))
|
|
21
|
+
],
|
|
22
|
+
pydantic.Field(alias="type"),
|
|
23
|
+
] = "content"
|
|
24
|
+
|
|
25
|
+
content: Optional[str] = ""
|