mistralai 1.5.2__py3-none-any.whl → 1.6.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.
- mistralai/_hooks/types.py +15 -3
- mistralai/_version.py +3 -3
- mistralai/agents.py +44 -12
- mistralai/basesdk.py +8 -0
- mistralai/chat.py +44 -12
- mistralai/classifiers.py +36 -16
- mistralai/embeddings.py +16 -6
- mistralai/files.py +36 -0
- mistralai/fim.py +32 -12
- mistralai/httpclient.py +4 -2
- mistralai/jobs.py +30 -0
- mistralai/mistral_jobs.py +24 -0
- mistralai/models/agentscompletionrequest.py +4 -0
- mistralai/models/agentscompletionstreamrequest.py +4 -0
- mistralai/models/chatcompletionrequest.py +4 -0
- mistralai/models/chatcompletionstreamrequest.py +4 -0
- mistralai/models/function.py +2 -2
- mistralai/models/jsonschema.py +1 -1
- mistralai/models_.py +66 -18
- mistralai/ocr.py +16 -6
- mistralai/sdk.py +19 -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.2.dist-info → mistralai-1.6.0.dist-info}/METADATA +63 -16
- {mistralai-1.5.2.dist-info → mistralai-1.6.0.dist-info}/RECORD +80 -72
- mistralai_azure/__init__.py +10 -1
- mistralai_azure/_hooks/types.py +15 -3
- mistralai_azure/_version.py +4 -1
- mistralai_azure/basesdk.py +8 -0
- mistralai_azure/chat.py +100 -20
- mistralai_azure/httpclient.py +52 -0
- mistralai_azure/models/__init__.py +22 -0
- mistralai_azure/models/assistantmessage.py +2 -0
- mistralai_azure/models/chatcompletionrequest.py +12 -10
- mistralai_azure/models/chatcompletionstreamrequest.py +12 -10
- mistralai_azure/models/contentchunk.py +6 -2
- mistralai_azure/models/function.py +4 -1
- mistralai_azure/models/imageurl.py +53 -0
- mistralai_azure/models/imageurlchunk.py +33 -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 +4 -1
- mistralai_gcp/basesdk.py +8 -0
- mistralai_gcp/chat.py +101 -21
- mistralai_gcp/fim.py +61 -21
- mistralai_gcp/httpclient.py +52 -0
- mistralai_gcp/models/__init__.py +22 -0
- mistralai_gcp/models/assistantmessage.py +2 -0
- mistralai_gcp/models/chatcompletionrequest.py +12 -10
- mistralai_gcp/models/chatcompletionstreamrequest.py +12 -10
- mistralai_gcp/models/contentchunk.py +6 -2
- mistralai_gcp/models/fimcompletionrequest.py +2 -3
- mistralai_gcp/models/fimcompletionstreamrequest.py +2 -3
- mistralai_gcp/models/function.py +4 -1
- mistralai_gcp/models/imageurl.py +53 -0
- mistralai_gcp/models/imageurlchunk.py +33 -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-1.5.2.dist-info → mistralai-1.6.0.dist-info}/LICENSE +0 -0
- {mistralai-1.5.2.dist-info → mistralai-1.6.0.dist-info}/WHEEL +0 -0
mistralai_azure/basesdk.py
CHANGED
|
@@ -231,6 +231,10 @@ class BaseSDK:
|
|
|
231
231
|
req.headers,
|
|
232
232
|
get_body_content(req),
|
|
233
233
|
)
|
|
234
|
+
|
|
235
|
+
if client is None:
|
|
236
|
+
raise ValueError("client is required")
|
|
237
|
+
|
|
234
238
|
http_res = client.send(req, stream=stream)
|
|
235
239
|
except Exception as e:
|
|
236
240
|
_, e = self.sdk_configuration.get_hooks().after_error(
|
|
@@ -303,6 +307,10 @@ class BaseSDK:
|
|
|
303
307
|
req.headers,
|
|
304
308
|
get_body_content(req),
|
|
305
309
|
)
|
|
310
|
+
|
|
311
|
+
if client is None:
|
|
312
|
+
raise ValueError("client is required")
|
|
313
|
+
|
|
306
314
|
http_res = await client.send(req, stream=stream)
|
|
307
315
|
except Exception as e:
|
|
308
316
|
_, e = self.sdk_configuration.get_hooks().after_error(
|
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,10 @@ 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,
|
|
43
|
+
parallel_tool_calls: Optional[bool] = None,
|
|
40
44
|
safe_prompt: Optional[bool] = None,
|
|
41
45
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
42
46
|
server_url: Optional[str] = None,
|
|
@@ -61,6 +65,8 @@ class Chat(BaseSDK):
|
|
|
61
65
|
: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
66
|
: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
67
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
68
|
+
:param prediction:
|
|
69
|
+
:param parallel_tool_calls:
|
|
64
70
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
65
71
|
:param retries: Override the default retry configuration for this method
|
|
66
72
|
:param server_url: Override the default server URL for this method
|
|
@@ -74,6 +80,8 @@ class Chat(BaseSDK):
|
|
|
74
80
|
|
|
75
81
|
if server_url is not None:
|
|
76
82
|
base_url = server_url
|
|
83
|
+
else:
|
|
84
|
+
base_url = self._get_url(base_url, url_variables)
|
|
77
85
|
|
|
78
86
|
request = models.ChatCompletionStreamRequest(
|
|
79
87
|
model=model,
|
|
@@ -94,6 +102,10 @@ class Chat(BaseSDK):
|
|
|
94
102
|
presence_penalty=presence_penalty,
|
|
95
103
|
frequency_penalty=frequency_penalty,
|
|
96
104
|
n=n,
|
|
105
|
+
prediction=utils.get_pydantic_model(
|
|
106
|
+
prediction, Optional[models.Prediction]
|
|
107
|
+
),
|
|
108
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
97
109
|
safe_prompt=safe_prompt,
|
|
98
110
|
)
|
|
99
111
|
|
|
@@ -126,6 +138,7 @@ class Chat(BaseSDK):
|
|
|
126
138
|
|
|
127
139
|
http_res = self.do_request(
|
|
128
140
|
hook_ctx=HookContext(
|
|
141
|
+
base_url=base_url or "",
|
|
129
142
|
operation_id="stream_chat",
|
|
130
143
|
oauth2_scopes=[],
|
|
131
144
|
security_source=self.sdk_configuration.security,
|
|
@@ -136,7 +149,7 @@ class Chat(BaseSDK):
|
|
|
136
149
|
retry_config=retry_config,
|
|
137
150
|
)
|
|
138
151
|
|
|
139
|
-
|
|
152
|
+
response_data: Any = None
|
|
140
153
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
141
154
|
return eventstreaming.EventStream(
|
|
142
155
|
http_res,
|
|
@@ -145,9 +158,16 @@ class Chat(BaseSDK):
|
|
|
145
158
|
)
|
|
146
159
|
if utils.match_response(http_res, "422", "application/json"):
|
|
147
160
|
http_res_text = utils.stream_to_text(http_res)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
161
|
+
response_data = utils.unmarshal_json(
|
|
162
|
+
http_res_text, models.HTTPValidationErrorData
|
|
163
|
+
)
|
|
164
|
+
raise models.HTTPValidationError(data=response_data)
|
|
165
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
166
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
167
|
+
raise models.SDKError(
|
|
168
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
169
|
+
)
|
|
170
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
151
171
|
http_res_text = utils.stream_to_text(http_res)
|
|
152
172
|
raise models.SDKError(
|
|
153
173
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -166,7 +186,7 @@ class Chat(BaseSDK):
|
|
|
166
186
|
self,
|
|
167
187
|
*,
|
|
168
188
|
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
169
|
-
model:
|
|
189
|
+
model: Optional[str] = "azureai",
|
|
170
190
|
temperature: OptionalNullable[float] = UNSET,
|
|
171
191
|
top_p: Optional[float] = None,
|
|
172
192
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
@@ -188,6 +208,10 @@ class Chat(BaseSDK):
|
|
|
188
208
|
presence_penalty: Optional[float] = None,
|
|
189
209
|
frequency_penalty: Optional[float] = None,
|
|
190
210
|
n: OptionalNullable[int] = UNSET,
|
|
211
|
+
prediction: Optional[
|
|
212
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
213
|
+
] = None,
|
|
214
|
+
parallel_tool_calls: Optional[bool] = None,
|
|
191
215
|
safe_prompt: Optional[bool] = None,
|
|
192
216
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
193
217
|
server_url: Optional[str] = None,
|
|
@@ -212,6 +236,8 @@ class Chat(BaseSDK):
|
|
|
212
236
|
: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
237
|
: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
238
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
239
|
+
:param prediction:
|
|
240
|
+
:param parallel_tool_calls:
|
|
215
241
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
216
242
|
:param retries: Override the default retry configuration for this method
|
|
217
243
|
:param server_url: Override the default server URL for this method
|
|
@@ -225,6 +251,8 @@ class Chat(BaseSDK):
|
|
|
225
251
|
|
|
226
252
|
if server_url is not None:
|
|
227
253
|
base_url = server_url
|
|
254
|
+
else:
|
|
255
|
+
base_url = self._get_url(base_url, url_variables)
|
|
228
256
|
|
|
229
257
|
request = models.ChatCompletionStreamRequest(
|
|
230
258
|
model=model,
|
|
@@ -245,6 +273,10 @@ class Chat(BaseSDK):
|
|
|
245
273
|
presence_penalty=presence_penalty,
|
|
246
274
|
frequency_penalty=frequency_penalty,
|
|
247
275
|
n=n,
|
|
276
|
+
prediction=utils.get_pydantic_model(
|
|
277
|
+
prediction, Optional[models.Prediction]
|
|
278
|
+
),
|
|
279
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
248
280
|
safe_prompt=safe_prompt,
|
|
249
281
|
)
|
|
250
282
|
|
|
@@ -277,6 +309,7 @@ class Chat(BaseSDK):
|
|
|
277
309
|
|
|
278
310
|
http_res = await self.do_request_async(
|
|
279
311
|
hook_ctx=HookContext(
|
|
312
|
+
base_url=base_url or "",
|
|
280
313
|
operation_id="stream_chat",
|
|
281
314
|
oauth2_scopes=[],
|
|
282
315
|
security_source=self.sdk_configuration.security,
|
|
@@ -287,7 +320,7 @@ class Chat(BaseSDK):
|
|
|
287
320
|
retry_config=retry_config,
|
|
288
321
|
)
|
|
289
322
|
|
|
290
|
-
|
|
323
|
+
response_data: Any = None
|
|
291
324
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
292
325
|
return eventstreaming.EventStreamAsync(
|
|
293
326
|
http_res,
|
|
@@ -296,9 +329,16 @@ class Chat(BaseSDK):
|
|
|
296
329
|
)
|
|
297
330
|
if utils.match_response(http_res, "422", "application/json"):
|
|
298
331
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
332
|
+
response_data = utils.unmarshal_json(
|
|
333
|
+
http_res_text, models.HTTPValidationErrorData
|
|
334
|
+
)
|
|
335
|
+
raise models.HTTPValidationError(data=response_data)
|
|
336
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
337
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
338
|
+
raise models.SDKError(
|
|
339
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
340
|
+
)
|
|
341
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
302
342
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
303
343
|
raise models.SDKError(
|
|
304
344
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -320,7 +360,7 @@ class Chat(BaseSDK):
|
|
|
320
360
|
List[models.ChatCompletionRequestMessages],
|
|
321
361
|
List[models.ChatCompletionRequestMessagesTypedDict],
|
|
322
362
|
],
|
|
323
|
-
model:
|
|
363
|
+
model: Optional[str] = "azureai",
|
|
324
364
|
temperature: OptionalNullable[float] = UNSET,
|
|
325
365
|
top_p: Optional[float] = None,
|
|
326
366
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
@@ -347,6 +387,10 @@ class Chat(BaseSDK):
|
|
|
347
387
|
presence_penalty: Optional[float] = None,
|
|
348
388
|
frequency_penalty: Optional[float] = None,
|
|
349
389
|
n: OptionalNullable[int] = UNSET,
|
|
390
|
+
prediction: Optional[
|
|
391
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
392
|
+
] = None,
|
|
393
|
+
parallel_tool_calls: Optional[bool] = None,
|
|
350
394
|
safe_prompt: Optional[bool] = None,
|
|
351
395
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
352
396
|
server_url: Optional[str] = None,
|
|
@@ -369,6 +413,8 @@ class Chat(BaseSDK):
|
|
|
369
413
|
: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
414
|
: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
415
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
416
|
+
:param prediction:
|
|
417
|
+
:param parallel_tool_calls:
|
|
372
418
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
373
419
|
:param retries: Override the default retry configuration for this method
|
|
374
420
|
:param server_url: Override the default server URL for this method
|
|
@@ -382,6 +428,8 @@ class Chat(BaseSDK):
|
|
|
382
428
|
|
|
383
429
|
if server_url is not None:
|
|
384
430
|
base_url = server_url
|
|
431
|
+
else:
|
|
432
|
+
base_url = self._get_url(base_url, url_variables)
|
|
385
433
|
|
|
386
434
|
request = models.ChatCompletionRequest(
|
|
387
435
|
model=model,
|
|
@@ -404,6 +452,10 @@ class Chat(BaseSDK):
|
|
|
404
452
|
presence_penalty=presence_penalty,
|
|
405
453
|
frequency_penalty=frequency_penalty,
|
|
406
454
|
n=n,
|
|
455
|
+
prediction=utils.get_pydantic_model(
|
|
456
|
+
prediction, Optional[models.Prediction]
|
|
457
|
+
),
|
|
458
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
407
459
|
safe_prompt=safe_prompt,
|
|
408
460
|
)
|
|
409
461
|
|
|
@@ -436,6 +488,7 @@ class Chat(BaseSDK):
|
|
|
436
488
|
|
|
437
489
|
http_res = self.do_request(
|
|
438
490
|
hook_ctx=HookContext(
|
|
491
|
+
base_url=base_url or "",
|
|
439
492
|
operation_id="chat_completion_v1_chat_completions_post",
|
|
440
493
|
oauth2_scopes=[],
|
|
441
494
|
security_source=self.sdk_configuration.security,
|
|
@@ -445,15 +498,22 @@ class Chat(BaseSDK):
|
|
|
445
498
|
retry_config=retry_config,
|
|
446
499
|
)
|
|
447
500
|
|
|
448
|
-
|
|
501
|
+
response_data: Any = None
|
|
449
502
|
if utils.match_response(http_res, "200", "application/json"):
|
|
450
503
|
return utils.unmarshal_json(
|
|
451
504
|
http_res.text, Optional[models.ChatCompletionResponse]
|
|
452
505
|
)
|
|
453
506
|
if utils.match_response(http_res, "422", "application/json"):
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
507
|
+
response_data = utils.unmarshal_json(
|
|
508
|
+
http_res.text, models.HTTPValidationErrorData
|
|
509
|
+
)
|
|
510
|
+
raise models.HTTPValidationError(data=response_data)
|
|
511
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
512
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
513
|
+
raise models.SDKError(
|
|
514
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
515
|
+
)
|
|
516
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
457
517
|
http_res_text = utils.stream_to_text(http_res)
|
|
458
518
|
raise models.SDKError(
|
|
459
519
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -475,7 +535,7 @@ class Chat(BaseSDK):
|
|
|
475
535
|
List[models.ChatCompletionRequestMessages],
|
|
476
536
|
List[models.ChatCompletionRequestMessagesTypedDict],
|
|
477
537
|
],
|
|
478
|
-
model:
|
|
538
|
+
model: Optional[str] = "azureai",
|
|
479
539
|
temperature: OptionalNullable[float] = UNSET,
|
|
480
540
|
top_p: Optional[float] = None,
|
|
481
541
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
@@ -502,6 +562,10 @@ class Chat(BaseSDK):
|
|
|
502
562
|
presence_penalty: Optional[float] = None,
|
|
503
563
|
frequency_penalty: Optional[float] = None,
|
|
504
564
|
n: OptionalNullable[int] = UNSET,
|
|
565
|
+
prediction: Optional[
|
|
566
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
567
|
+
] = None,
|
|
568
|
+
parallel_tool_calls: Optional[bool] = None,
|
|
505
569
|
safe_prompt: Optional[bool] = None,
|
|
506
570
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
507
571
|
server_url: Optional[str] = None,
|
|
@@ -524,6 +588,8 @@ class Chat(BaseSDK):
|
|
|
524
588
|
: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
589
|
: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
590
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
591
|
+
:param prediction:
|
|
592
|
+
:param parallel_tool_calls:
|
|
527
593
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
528
594
|
:param retries: Override the default retry configuration for this method
|
|
529
595
|
:param server_url: Override the default server URL for this method
|
|
@@ -537,6 +603,8 @@ class Chat(BaseSDK):
|
|
|
537
603
|
|
|
538
604
|
if server_url is not None:
|
|
539
605
|
base_url = server_url
|
|
606
|
+
else:
|
|
607
|
+
base_url = self._get_url(base_url, url_variables)
|
|
540
608
|
|
|
541
609
|
request = models.ChatCompletionRequest(
|
|
542
610
|
model=model,
|
|
@@ -559,6 +627,10 @@ class Chat(BaseSDK):
|
|
|
559
627
|
presence_penalty=presence_penalty,
|
|
560
628
|
frequency_penalty=frequency_penalty,
|
|
561
629
|
n=n,
|
|
630
|
+
prediction=utils.get_pydantic_model(
|
|
631
|
+
prediction, Optional[models.Prediction]
|
|
632
|
+
),
|
|
633
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
562
634
|
safe_prompt=safe_prompt,
|
|
563
635
|
)
|
|
564
636
|
|
|
@@ -591,6 +663,7 @@ class Chat(BaseSDK):
|
|
|
591
663
|
|
|
592
664
|
http_res = await self.do_request_async(
|
|
593
665
|
hook_ctx=HookContext(
|
|
666
|
+
base_url=base_url or "",
|
|
594
667
|
operation_id="chat_completion_v1_chat_completions_post",
|
|
595
668
|
oauth2_scopes=[],
|
|
596
669
|
security_source=self.sdk_configuration.security,
|
|
@@ -600,15 +673,22 @@ class Chat(BaseSDK):
|
|
|
600
673
|
retry_config=retry_config,
|
|
601
674
|
)
|
|
602
675
|
|
|
603
|
-
|
|
676
|
+
response_data: Any = None
|
|
604
677
|
if utils.match_response(http_res, "200", "application/json"):
|
|
605
678
|
return utils.unmarshal_json(
|
|
606
679
|
http_res.text, Optional[models.ChatCompletionResponse]
|
|
607
680
|
)
|
|
608
681
|
if utils.match_response(http_res, "422", "application/json"):
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
682
|
+
response_data = utils.unmarshal_json(
|
|
683
|
+
http_res.text, models.HTTPValidationErrorData
|
|
684
|
+
)
|
|
685
|
+
raise models.HTTPValidationError(data=response_data)
|
|
686
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
687
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
688
|
+
raise models.SDKError(
|
|
689
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
690
|
+
)
|
|
691
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
612
692
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
613
693
|
raise models.SDKError(
|
|
614
694
|
"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,16 @@ from .functioncall import (
|
|
|
54
54
|
)
|
|
55
55
|
from .functionname import FunctionName, FunctionNameTypedDict
|
|
56
56
|
from .httpvalidationerror import HTTPValidationError, HTTPValidationErrorData
|
|
57
|
+
from .imageurl import ImageURL, ImageURLTypedDict
|
|
58
|
+
from .imageurlchunk import (
|
|
59
|
+
ImageURLChunk,
|
|
60
|
+
ImageURLChunkImageURL,
|
|
61
|
+
ImageURLChunkImageURLTypedDict,
|
|
62
|
+
ImageURLChunkType,
|
|
63
|
+
ImageURLChunkTypedDict,
|
|
64
|
+
)
|
|
65
|
+
from .jsonschema import JSONSchema, JSONSchemaTypedDict
|
|
66
|
+
from .prediction import Prediction, PredictionTypedDict
|
|
57
67
|
from .referencechunk import ReferenceChunk, ReferenceChunkType, ReferenceChunkTypedDict
|
|
58
68
|
from .responseformat import ResponseFormat, ResponseFormatTypedDict
|
|
59
69
|
from .responseformats import ResponseFormats
|
|
@@ -94,6 +104,7 @@ from .validationerror import (
|
|
|
94
104
|
ValidationErrorTypedDict,
|
|
95
105
|
)
|
|
96
106
|
|
|
107
|
+
|
|
97
108
|
__all__ = [
|
|
98
109
|
"Arguments",
|
|
99
110
|
"ArgumentsTypedDict",
|
|
@@ -140,10 +151,21 @@ __all__ = [
|
|
|
140
151
|
"FunctionTypedDict",
|
|
141
152
|
"HTTPValidationError",
|
|
142
153
|
"HTTPValidationErrorData",
|
|
154
|
+
"ImageURL",
|
|
155
|
+
"ImageURLChunk",
|
|
156
|
+
"ImageURLChunkImageURL",
|
|
157
|
+
"ImageURLChunkImageURLTypedDict",
|
|
158
|
+
"ImageURLChunkType",
|
|
159
|
+
"ImageURLChunkTypedDict",
|
|
160
|
+
"ImageURLTypedDict",
|
|
161
|
+
"JSONSchema",
|
|
162
|
+
"JSONSchemaTypedDict",
|
|
143
163
|
"Loc",
|
|
144
164
|
"LocTypedDict",
|
|
145
165
|
"Messages",
|
|
146
166
|
"MessagesTypedDict",
|
|
167
|
+
"Prediction",
|
|
168
|
+
"PredictionTypedDict",
|
|
147
169
|
"ReferenceChunk",
|
|
148
170
|
"ReferenceChunkType",
|
|
149
171
|
"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,8 @@ 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]
|
|
98
|
+
parallel_tool_calls: NotRequired[bool]
|
|
96
99
|
safe_prompt: NotRequired[bool]
|
|
97
100
|
r"""Whether to inject a safety prompt before all conversations."""
|
|
98
101
|
|
|
@@ -101,7 +104,7 @@ class ChatCompletionRequest(BaseModel):
|
|
|
101
104
|
messages: List[ChatCompletionRequestMessages]
|
|
102
105
|
r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
|
|
103
106
|
|
|
104
|
-
model:
|
|
107
|
+
model: Optional[str] = "azureai"
|
|
105
108
|
r"""The ID of the model to use for this request."""
|
|
106
109
|
|
|
107
110
|
temperature: OptionalNullable[float] = UNSET
|
|
@@ -137,6 +140,10 @@ class ChatCompletionRequest(BaseModel):
|
|
|
137
140
|
n: OptionalNullable[int] = UNSET
|
|
138
141
|
r"""Number of completions to return for each request, input tokens are only billed once."""
|
|
139
142
|
|
|
143
|
+
prediction: Optional[Prediction] = None
|
|
144
|
+
|
|
145
|
+
parallel_tool_calls: Optional[bool] = None
|
|
146
|
+
|
|
140
147
|
safe_prompt: Optional[bool] = None
|
|
141
148
|
r"""Whether to inject a safety prompt before all conversations."""
|
|
142
149
|
|
|
@@ -156,16 +163,11 @@ class ChatCompletionRequest(BaseModel):
|
|
|
156
163
|
"presence_penalty",
|
|
157
164
|
"frequency_penalty",
|
|
158
165
|
"n",
|
|
166
|
+
"prediction",
|
|
167
|
+
"parallel_tool_calls",
|
|
159
168
|
"safe_prompt",
|
|
160
169
|
]
|
|
161
|
-
nullable_fields = [
|
|
162
|
-
"model",
|
|
163
|
-
"temperature",
|
|
164
|
-
"max_tokens",
|
|
165
|
-
"random_seed",
|
|
166
|
-
"tools",
|
|
167
|
-
"n",
|
|
168
|
-
]
|
|
170
|
+
nullable_fields = ["temperature", "max_tokens", "random_seed", "tools", "n"]
|
|
169
171
|
null_default_fields = []
|
|
170
172
|
|
|
171
173
|
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,8 @@ 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]
|
|
93
|
+
parallel_tool_calls: NotRequired[bool]
|
|
91
94
|
safe_prompt: NotRequired[bool]
|
|
92
95
|
r"""Whether to inject a safety prompt before all conversations."""
|
|
93
96
|
|
|
@@ -96,7 +99,7 @@ class ChatCompletionStreamRequest(BaseModel):
|
|
|
96
99
|
messages: List[Messages]
|
|
97
100
|
r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
|
|
98
101
|
|
|
99
|
-
model:
|
|
102
|
+
model: Optional[str] = "azureai"
|
|
100
103
|
r"""The ID of the model to use for this request."""
|
|
101
104
|
|
|
102
105
|
temperature: OptionalNullable[float] = UNSET
|
|
@@ -131,6 +134,10 @@ class ChatCompletionStreamRequest(BaseModel):
|
|
|
131
134
|
n: OptionalNullable[int] = UNSET
|
|
132
135
|
r"""Number of completions to return for each request, input tokens are only billed once."""
|
|
133
136
|
|
|
137
|
+
prediction: Optional[Prediction] = None
|
|
138
|
+
|
|
139
|
+
parallel_tool_calls: Optional[bool] = None
|
|
140
|
+
|
|
134
141
|
safe_prompt: Optional[bool] = None
|
|
135
142
|
r"""Whether to inject a safety prompt before all conversations."""
|
|
136
143
|
|
|
@@ -150,16 +157,11 @@ class ChatCompletionStreamRequest(BaseModel):
|
|
|
150
157
|
"presence_penalty",
|
|
151
158
|
"frequency_penalty",
|
|
152
159
|
"n",
|
|
160
|
+
"prediction",
|
|
161
|
+
"parallel_tool_calls",
|
|
153
162
|
"safe_prompt",
|
|
154
163
|
]
|
|
155
|
-
nullable_fields = [
|
|
156
|
-
"model",
|
|
157
|
-
"temperature",
|
|
158
|
-
"max_tokens",
|
|
159
|
-
"random_seed",
|
|
160
|
-
"tools",
|
|
161
|
-
"n",
|
|
162
|
-
]
|
|
164
|
+
nullable_fields = ["temperature", "max_tokens", "random_seed", "tools", "n"]
|
|
163
165
|
null_default_fields = []
|
|
164
166
|
|
|
165
167
|
serialized = handler(self)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
+
from .imageurlchunk import ImageURLChunk, ImageURLChunkTypedDict
|
|
4
5
|
from .referencechunk import ReferenceChunk, ReferenceChunkTypedDict
|
|
5
6
|
from .textchunk import TextChunk, TextChunkTypedDict
|
|
6
7
|
from mistralai_azure.utils import get_discriminator
|
|
@@ -10,13 +11,16 @@ from typing_extensions import Annotated, TypeAliasType
|
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
ContentChunkTypedDict = TypeAliasType(
|
|
13
|
-
"ContentChunkTypedDict",
|
|
14
|
+
"ContentChunkTypedDict",
|
|
15
|
+
Union[TextChunkTypedDict, ImageURLChunkTypedDict, ReferenceChunkTypedDict],
|
|
14
16
|
)
|
|
15
17
|
|
|
16
18
|
|
|
17
19
|
ContentChunk = Annotated[
|
|
18
20
|
Union[
|
|
19
|
-
Annotated[
|
|
21
|
+
Annotated[ImageURLChunk, Tag("image_url")],
|
|
22
|
+
Annotated[TextChunk, Tag("text")],
|
|
23
|
+
Annotated[ReferenceChunk, Tag("reference")],
|
|
20
24
|
],
|
|
21
25
|
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
|
22
26
|
]
|
|
@@ -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):
|
|
@@ -17,4 +18,6 @@ class Function(BaseModel):
|
|
|
17
18
|
|
|
18
19
|
parameters: Dict[str, Any]
|
|
19
20
|
|
|
20
|
-
description: Optional[str] =
|
|
21
|
+
description: Optional[str] = None
|
|
22
|
+
|
|
23
|
+
strict: Optional[bool] = None
|