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_gcp/chat.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from .basesdk import BaseSDK
|
|
4
4
|
from mistralai_gcp import models, utils
|
|
5
5
|
from mistralai_gcp._hooks import HookContext
|
|
6
|
-
from mistralai_gcp.types import
|
|
6
|
+
from mistralai_gcp.types import OptionalNullable, UNSET
|
|
7
7
|
from mistralai_gcp.utils import eventstreaming
|
|
8
8
|
from typing import Any, List, Mapping, Optional, Union
|
|
9
9
|
|
|
@@ -14,7 +14,7 @@ class Chat(BaseSDK):
|
|
|
14
14
|
def stream(
|
|
15
15
|
self,
|
|
16
16
|
*,
|
|
17
|
-
model:
|
|
17
|
+
model: str,
|
|
18
18
|
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
19
19
|
temperature: OptionalNullable[float] = UNSET,
|
|
20
20
|
top_p: Optional[float] = None,
|
|
@@ -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
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
41
44
|
server_url: Optional[str] = None,
|
|
42
45
|
timeout_ms: Optional[int] = None,
|
|
@@ -60,6 +63,7 @@ class Chat(BaseSDK):
|
|
|
60
63
|
: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.
|
|
61
64
|
: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.
|
|
62
65
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
66
|
+
:param prediction:
|
|
63
67
|
:param retries: Override the default retry configuration for this method
|
|
64
68
|
:param server_url: Override the default server URL for this method
|
|
65
69
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -72,6 +76,8 @@ class Chat(BaseSDK):
|
|
|
72
76
|
|
|
73
77
|
if server_url is not None:
|
|
74
78
|
base_url = server_url
|
|
79
|
+
else:
|
|
80
|
+
base_url = self._get_url(base_url, url_variables)
|
|
75
81
|
|
|
76
82
|
request = models.ChatCompletionStreamRequest(
|
|
77
83
|
model=model,
|
|
@@ -92,6 +98,9 @@ class Chat(BaseSDK):
|
|
|
92
98
|
presence_penalty=presence_penalty,
|
|
93
99
|
frequency_penalty=frequency_penalty,
|
|
94
100
|
n=n,
|
|
101
|
+
prediction=utils.get_pydantic_model(
|
|
102
|
+
prediction, Optional[models.Prediction]
|
|
103
|
+
),
|
|
95
104
|
)
|
|
96
105
|
|
|
97
106
|
req = self._build_request(
|
|
@@ -123,6 +132,7 @@ class Chat(BaseSDK):
|
|
|
123
132
|
|
|
124
133
|
http_res = self.do_request(
|
|
125
134
|
hook_ctx=HookContext(
|
|
135
|
+
base_url=base_url or "",
|
|
126
136
|
operation_id="stream_chat",
|
|
127
137
|
oauth2_scopes=[],
|
|
128
138
|
security_source=self.sdk_configuration.security,
|
|
@@ -133,7 +143,7 @@ class Chat(BaseSDK):
|
|
|
133
143
|
retry_config=retry_config,
|
|
134
144
|
)
|
|
135
145
|
|
|
136
|
-
|
|
146
|
+
response_data: Any = None
|
|
137
147
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
138
148
|
return eventstreaming.EventStream(
|
|
139
149
|
http_res,
|
|
@@ -142,9 +152,16 @@ class Chat(BaseSDK):
|
|
|
142
152
|
)
|
|
143
153
|
if utils.match_response(http_res, "422", "application/json"):
|
|
144
154
|
http_res_text = utils.stream_to_text(http_res)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
155
|
+
response_data = utils.unmarshal_json(
|
|
156
|
+
http_res_text, models.HTTPValidationErrorData
|
|
157
|
+
)
|
|
158
|
+
raise models.HTTPValidationError(data=response_data)
|
|
159
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
160
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
161
|
+
raise models.SDKError(
|
|
162
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
163
|
+
)
|
|
164
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
148
165
|
http_res_text = utils.stream_to_text(http_res)
|
|
149
166
|
raise models.SDKError(
|
|
150
167
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -162,7 +179,7 @@ class Chat(BaseSDK):
|
|
|
162
179
|
async def stream_async(
|
|
163
180
|
self,
|
|
164
181
|
*,
|
|
165
|
-
model:
|
|
182
|
+
model: str,
|
|
166
183
|
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
167
184
|
temperature: OptionalNullable[float] = UNSET,
|
|
168
185
|
top_p: Optional[float] = None,
|
|
@@ -185,6 +202,9 @@ class Chat(BaseSDK):
|
|
|
185
202
|
presence_penalty: Optional[float] = None,
|
|
186
203
|
frequency_penalty: Optional[float] = None,
|
|
187
204
|
n: OptionalNullable[int] = UNSET,
|
|
205
|
+
prediction: Optional[
|
|
206
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
207
|
+
] = None,
|
|
188
208
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
189
209
|
server_url: Optional[str] = None,
|
|
190
210
|
timeout_ms: Optional[int] = None,
|
|
@@ -208,6 +228,7 @@ class Chat(BaseSDK):
|
|
|
208
228
|
: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.
|
|
209
229
|
: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.
|
|
210
230
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
231
|
+
:param prediction:
|
|
211
232
|
:param retries: Override the default retry configuration for this method
|
|
212
233
|
:param server_url: Override the default server URL for this method
|
|
213
234
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -220,6 +241,8 @@ class Chat(BaseSDK):
|
|
|
220
241
|
|
|
221
242
|
if server_url is not None:
|
|
222
243
|
base_url = server_url
|
|
244
|
+
else:
|
|
245
|
+
base_url = self._get_url(base_url, url_variables)
|
|
223
246
|
|
|
224
247
|
request = models.ChatCompletionStreamRequest(
|
|
225
248
|
model=model,
|
|
@@ -240,6 +263,9 @@ class Chat(BaseSDK):
|
|
|
240
263
|
presence_penalty=presence_penalty,
|
|
241
264
|
frequency_penalty=frequency_penalty,
|
|
242
265
|
n=n,
|
|
266
|
+
prediction=utils.get_pydantic_model(
|
|
267
|
+
prediction, Optional[models.Prediction]
|
|
268
|
+
),
|
|
243
269
|
)
|
|
244
270
|
|
|
245
271
|
req = self._build_request_async(
|
|
@@ -271,6 +297,7 @@ class Chat(BaseSDK):
|
|
|
271
297
|
|
|
272
298
|
http_res = await self.do_request_async(
|
|
273
299
|
hook_ctx=HookContext(
|
|
300
|
+
base_url=base_url or "",
|
|
274
301
|
operation_id="stream_chat",
|
|
275
302
|
oauth2_scopes=[],
|
|
276
303
|
security_source=self.sdk_configuration.security,
|
|
@@ -281,7 +308,7 @@ class Chat(BaseSDK):
|
|
|
281
308
|
retry_config=retry_config,
|
|
282
309
|
)
|
|
283
310
|
|
|
284
|
-
|
|
311
|
+
response_data: Any = None
|
|
285
312
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
286
313
|
return eventstreaming.EventStreamAsync(
|
|
287
314
|
http_res,
|
|
@@ -290,9 +317,16 @@ class Chat(BaseSDK):
|
|
|
290
317
|
)
|
|
291
318
|
if utils.match_response(http_res, "422", "application/json"):
|
|
292
319
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
320
|
+
response_data = utils.unmarshal_json(
|
|
321
|
+
http_res_text, models.HTTPValidationErrorData
|
|
322
|
+
)
|
|
323
|
+
raise models.HTTPValidationError(data=response_data)
|
|
324
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
325
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
326
|
+
raise models.SDKError(
|
|
327
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
328
|
+
)
|
|
329
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
296
330
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
297
331
|
raise models.SDKError(
|
|
298
332
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -310,7 +344,7 @@ class Chat(BaseSDK):
|
|
|
310
344
|
def complete(
|
|
311
345
|
self,
|
|
312
346
|
*,
|
|
313
|
-
model:
|
|
347
|
+
model: str,
|
|
314
348
|
messages: Union[
|
|
315
349
|
List[models.ChatCompletionRequestMessages],
|
|
316
350
|
List[models.ChatCompletionRequestMessagesTypedDict],
|
|
@@ -341,6 +375,9 @@ class Chat(BaseSDK):
|
|
|
341
375
|
presence_penalty: Optional[float] = None,
|
|
342
376
|
frequency_penalty: Optional[float] = None,
|
|
343
377
|
n: OptionalNullable[int] = UNSET,
|
|
378
|
+
prediction: Optional[
|
|
379
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
380
|
+
] = None,
|
|
344
381
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
345
382
|
server_url: Optional[str] = None,
|
|
346
383
|
timeout_ms: Optional[int] = None,
|
|
@@ -362,6 +399,7 @@ class Chat(BaseSDK):
|
|
|
362
399
|
: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.
|
|
363
400
|
: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.
|
|
364
401
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
402
|
+
:param prediction:
|
|
365
403
|
:param retries: Override the default retry configuration for this method
|
|
366
404
|
:param server_url: Override the default server URL for this method
|
|
367
405
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -374,6 +412,8 @@ class Chat(BaseSDK):
|
|
|
374
412
|
|
|
375
413
|
if server_url is not None:
|
|
376
414
|
base_url = server_url
|
|
415
|
+
else:
|
|
416
|
+
base_url = self._get_url(base_url, url_variables)
|
|
377
417
|
|
|
378
418
|
request = models.ChatCompletionRequest(
|
|
379
419
|
model=model,
|
|
@@ -396,6 +436,9 @@ class Chat(BaseSDK):
|
|
|
396
436
|
presence_penalty=presence_penalty,
|
|
397
437
|
frequency_penalty=frequency_penalty,
|
|
398
438
|
n=n,
|
|
439
|
+
prediction=utils.get_pydantic_model(
|
|
440
|
+
prediction, Optional[models.Prediction]
|
|
441
|
+
),
|
|
399
442
|
)
|
|
400
443
|
|
|
401
444
|
req = self._build_request(
|
|
@@ -427,6 +470,7 @@ class Chat(BaseSDK):
|
|
|
427
470
|
|
|
428
471
|
http_res = self.do_request(
|
|
429
472
|
hook_ctx=HookContext(
|
|
473
|
+
base_url=base_url or "",
|
|
430
474
|
operation_id="chat_completion_v1_chat_completions_post",
|
|
431
475
|
oauth2_scopes=[],
|
|
432
476
|
security_source=self.sdk_configuration.security,
|
|
@@ -436,15 +480,22 @@ class Chat(BaseSDK):
|
|
|
436
480
|
retry_config=retry_config,
|
|
437
481
|
)
|
|
438
482
|
|
|
439
|
-
|
|
483
|
+
response_data: Any = None
|
|
440
484
|
if utils.match_response(http_res, "200", "application/json"):
|
|
441
485
|
return utils.unmarshal_json(
|
|
442
486
|
http_res.text, Optional[models.ChatCompletionResponse]
|
|
443
487
|
)
|
|
444
488
|
if utils.match_response(http_res, "422", "application/json"):
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
489
|
+
response_data = utils.unmarshal_json(
|
|
490
|
+
http_res.text, models.HTTPValidationErrorData
|
|
491
|
+
)
|
|
492
|
+
raise models.HTTPValidationError(data=response_data)
|
|
493
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
494
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
495
|
+
raise models.SDKError(
|
|
496
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
497
|
+
)
|
|
498
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
448
499
|
http_res_text = utils.stream_to_text(http_res)
|
|
449
500
|
raise models.SDKError(
|
|
450
501
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -462,7 +513,7 @@ class Chat(BaseSDK):
|
|
|
462
513
|
async def complete_async(
|
|
463
514
|
self,
|
|
464
515
|
*,
|
|
465
|
-
model:
|
|
516
|
+
model: str,
|
|
466
517
|
messages: Union[
|
|
467
518
|
List[models.ChatCompletionRequestMessages],
|
|
468
519
|
List[models.ChatCompletionRequestMessagesTypedDict],
|
|
@@ -493,6 +544,9 @@ class Chat(BaseSDK):
|
|
|
493
544
|
presence_penalty: Optional[float] = None,
|
|
494
545
|
frequency_penalty: Optional[float] = None,
|
|
495
546
|
n: OptionalNullable[int] = UNSET,
|
|
547
|
+
prediction: Optional[
|
|
548
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
549
|
+
] = None,
|
|
496
550
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
497
551
|
server_url: Optional[str] = None,
|
|
498
552
|
timeout_ms: Optional[int] = None,
|
|
@@ -514,6 +568,7 @@ class Chat(BaseSDK):
|
|
|
514
568
|
: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.
|
|
515
569
|
: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.
|
|
516
570
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
571
|
+
:param prediction:
|
|
517
572
|
:param retries: Override the default retry configuration for this method
|
|
518
573
|
:param server_url: Override the default server URL for this method
|
|
519
574
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -526,6 +581,8 @@ class Chat(BaseSDK):
|
|
|
526
581
|
|
|
527
582
|
if server_url is not None:
|
|
528
583
|
base_url = server_url
|
|
584
|
+
else:
|
|
585
|
+
base_url = self._get_url(base_url, url_variables)
|
|
529
586
|
|
|
530
587
|
request = models.ChatCompletionRequest(
|
|
531
588
|
model=model,
|
|
@@ -548,6 +605,9 @@ class Chat(BaseSDK):
|
|
|
548
605
|
presence_penalty=presence_penalty,
|
|
549
606
|
frequency_penalty=frequency_penalty,
|
|
550
607
|
n=n,
|
|
608
|
+
prediction=utils.get_pydantic_model(
|
|
609
|
+
prediction, Optional[models.Prediction]
|
|
610
|
+
),
|
|
551
611
|
)
|
|
552
612
|
|
|
553
613
|
req = self._build_request_async(
|
|
@@ -579,6 +639,7 @@ class Chat(BaseSDK):
|
|
|
579
639
|
|
|
580
640
|
http_res = await self.do_request_async(
|
|
581
641
|
hook_ctx=HookContext(
|
|
642
|
+
base_url=base_url or "",
|
|
582
643
|
operation_id="chat_completion_v1_chat_completions_post",
|
|
583
644
|
oauth2_scopes=[],
|
|
584
645
|
security_source=self.sdk_configuration.security,
|
|
@@ -588,15 +649,22 @@ class Chat(BaseSDK):
|
|
|
588
649
|
retry_config=retry_config,
|
|
589
650
|
)
|
|
590
651
|
|
|
591
|
-
|
|
652
|
+
response_data: Any = None
|
|
592
653
|
if utils.match_response(http_res, "200", "application/json"):
|
|
593
654
|
return utils.unmarshal_json(
|
|
594
655
|
http_res.text, Optional[models.ChatCompletionResponse]
|
|
595
656
|
)
|
|
596
657
|
if utils.match_response(http_res, "422", "application/json"):
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
658
|
+
response_data = utils.unmarshal_json(
|
|
659
|
+
http_res.text, models.HTTPValidationErrorData
|
|
660
|
+
)
|
|
661
|
+
raise models.HTTPValidationError(data=response_data)
|
|
662
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
663
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
664
|
+
raise models.SDKError(
|
|
665
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
666
|
+
)
|
|
667
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
600
668
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
601
669
|
raise models.SDKError(
|
|
602
670
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
mistralai_gcp/fim.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from .basesdk import BaseSDK
|
|
4
4
|
from mistralai_gcp import models, utils
|
|
5
5
|
from mistralai_gcp._hooks import HookContext
|
|
6
|
-
from mistralai_gcp.types import
|
|
6
|
+
from mistralai_gcp.types import OptionalNullable, UNSET
|
|
7
7
|
from mistralai_gcp.utils import eventstreaming
|
|
8
8
|
from typing import Any, Mapping, Optional, Union
|
|
9
9
|
|
|
@@ -14,7 +14,7 @@ class Fim(BaseSDK):
|
|
|
14
14
|
def stream(
|
|
15
15
|
self,
|
|
16
16
|
*,
|
|
17
|
-
model:
|
|
17
|
+
model: str,
|
|
18
18
|
prompt: str,
|
|
19
19
|
temperature: OptionalNullable[float] = UNSET,
|
|
20
20
|
top_p: Optional[float] = 1,
|
|
@@ -60,6 +60,8 @@ class Fim(BaseSDK):
|
|
|
60
60
|
|
|
61
61
|
if server_url is not None:
|
|
62
62
|
base_url = server_url
|
|
63
|
+
else:
|
|
64
|
+
base_url = self._get_url(base_url, url_variables)
|
|
63
65
|
|
|
64
66
|
request = models.FIMCompletionStreamRequest(
|
|
65
67
|
model=model,
|
|
@@ -103,6 +105,7 @@ class Fim(BaseSDK):
|
|
|
103
105
|
|
|
104
106
|
http_res = self.do_request(
|
|
105
107
|
hook_ctx=HookContext(
|
|
108
|
+
base_url=base_url or "",
|
|
106
109
|
operation_id="stream_fim",
|
|
107
110
|
oauth2_scopes=[],
|
|
108
111
|
security_source=self.sdk_configuration.security,
|
|
@@ -113,7 +116,7 @@ class Fim(BaseSDK):
|
|
|
113
116
|
retry_config=retry_config,
|
|
114
117
|
)
|
|
115
118
|
|
|
116
|
-
|
|
119
|
+
response_data: Any = None
|
|
117
120
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
118
121
|
return eventstreaming.EventStream(
|
|
119
122
|
http_res,
|
|
@@ -122,9 +125,16 @@ class Fim(BaseSDK):
|
|
|
122
125
|
)
|
|
123
126
|
if utils.match_response(http_res, "422", "application/json"):
|
|
124
127
|
http_res_text = utils.stream_to_text(http_res)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
response_data = utils.unmarshal_json(
|
|
129
|
+
http_res_text, models.HTTPValidationErrorData
|
|
130
|
+
)
|
|
131
|
+
raise models.HTTPValidationError(data=response_data)
|
|
132
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
133
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
134
|
+
raise models.SDKError(
|
|
135
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
136
|
+
)
|
|
137
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
128
138
|
http_res_text = utils.stream_to_text(http_res)
|
|
129
139
|
raise models.SDKError(
|
|
130
140
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -142,7 +152,7 @@ class Fim(BaseSDK):
|
|
|
142
152
|
async def stream_async(
|
|
143
153
|
self,
|
|
144
154
|
*,
|
|
145
|
-
model:
|
|
155
|
+
model: str,
|
|
146
156
|
prompt: str,
|
|
147
157
|
temperature: OptionalNullable[float] = UNSET,
|
|
148
158
|
top_p: Optional[float] = 1,
|
|
@@ -188,6 +198,8 @@ class Fim(BaseSDK):
|
|
|
188
198
|
|
|
189
199
|
if server_url is not None:
|
|
190
200
|
base_url = server_url
|
|
201
|
+
else:
|
|
202
|
+
base_url = self._get_url(base_url, url_variables)
|
|
191
203
|
|
|
192
204
|
request = models.FIMCompletionStreamRequest(
|
|
193
205
|
model=model,
|
|
@@ -231,6 +243,7 @@ class Fim(BaseSDK):
|
|
|
231
243
|
|
|
232
244
|
http_res = await self.do_request_async(
|
|
233
245
|
hook_ctx=HookContext(
|
|
246
|
+
base_url=base_url or "",
|
|
234
247
|
operation_id="stream_fim",
|
|
235
248
|
oauth2_scopes=[],
|
|
236
249
|
security_source=self.sdk_configuration.security,
|
|
@@ -241,7 +254,7 @@ class Fim(BaseSDK):
|
|
|
241
254
|
retry_config=retry_config,
|
|
242
255
|
)
|
|
243
256
|
|
|
244
|
-
|
|
257
|
+
response_data: Any = None
|
|
245
258
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
246
259
|
return eventstreaming.EventStreamAsync(
|
|
247
260
|
http_res,
|
|
@@ -250,9 +263,16 @@ class Fim(BaseSDK):
|
|
|
250
263
|
)
|
|
251
264
|
if utils.match_response(http_res, "422", "application/json"):
|
|
252
265
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
266
|
+
response_data = utils.unmarshal_json(
|
|
267
|
+
http_res_text, models.HTTPValidationErrorData
|
|
268
|
+
)
|
|
269
|
+
raise models.HTTPValidationError(data=response_data)
|
|
270
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
271
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
272
|
+
raise models.SDKError(
|
|
273
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
274
|
+
)
|
|
275
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
256
276
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
257
277
|
raise models.SDKError(
|
|
258
278
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -270,7 +290,7 @@ class Fim(BaseSDK):
|
|
|
270
290
|
def complete(
|
|
271
291
|
self,
|
|
272
292
|
*,
|
|
273
|
-
model:
|
|
293
|
+
model: str,
|
|
274
294
|
prompt: str,
|
|
275
295
|
temperature: OptionalNullable[float] = UNSET,
|
|
276
296
|
top_p: Optional[float] = 1,
|
|
@@ -316,6 +336,8 @@ class Fim(BaseSDK):
|
|
|
316
336
|
|
|
317
337
|
if server_url is not None:
|
|
318
338
|
base_url = server_url
|
|
339
|
+
else:
|
|
340
|
+
base_url = self._get_url(base_url, url_variables)
|
|
319
341
|
|
|
320
342
|
request = models.FIMCompletionRequest(
|
|
321
343
|
model=model,
|
|
@@ -359,6 +381,7 @@ class Fim(BaseSDK):
|
|
|
359
381
|
|
|
360
382
|
http_res = self.do_request(
|
|
361
383
|
hook_ctx=HookContext(
|
|
384
|
+
base_url=base_url or "",
|
|
362
385
|
operation_id="fim_completion_v1_fim_completions_post",
|
|
363
386
|
oauth2_scopes=[],
|
|
364
387
|
security_source=self.sdk_configuration.security,
|
|
@@ -368,15 +391,22 @@ class Fim(BaseSDK):
|
|
|
368
391
|
retry_config=retry_config,
|
|
369
392
|
)
|
|
370
393
|
|
|
371
|
-
|
|
394
|
+
response_data: Any = None
|
|
372
395
|
if utils.match_response(http_res, "200", "application/json"):
|
|
373
396
|
return utils.unmarshal_json(
|
|
374
397
|
http_res.text, Optional[models.FIMCompletionResponse]
|
|
375
398
|
)
|
|
376
399
|
if utils.match_response(http_res, "422", "application/json"):
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
400
|
+
response_data = utils.unmarshal_json(
|
|
401
|
+
http_res.text, models.HTTPValidationErrorData
|
|
402
|
+
)
|
|
403
|
+
raise models.HTTPValidationError(data=response_data)
|
|
404
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
405
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
406
|
+
raise models.SDKError(
|
|
407
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
408
|
+
)
|
|
409
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
380
410
|
http_res_text = utils.stream_to_text(http_res)
|
|
381
411
|
raise models.SDKError(
|
|
382
412
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -394,7 +424,7 @@ class Fim(BaseSDK):
|
|
|
394
424
|
async def complete_async(
|
|
395
425
|
self,
|
|
396
426
|
*,
|
|
397
|
-
model:
|
|
427
|
+
model: str,
|
|
398
428
|
prompt: str,
|
|
399
429
|
temperature: OptionalNullable[float] = UNSET,
|
|
400
430
|
top_p: Optional[float] = 1,
|
|
@@ -440,6 +470,8 @@ class Fim(BaseSDK):
|
|
|
440
470
|
|
|
441
471
|
if server_url is not None:
|
|
442
472
|
base_url = server_url
|
|
473
|
+
else:
|
|
474
|
+
base_url = self._get_url(base_url, url_variables)
|
|
443
475
|
|
|
444
476
|
request = models.FIMCompletionRequest(
|
|
445
477
|
model=model,
|
|
@@ -483,6 +515,7 @@ class Fim(BaseSDK):
|
|
|
483
515
|
|
|
484
516
|
http_res = await self.do_request_async(
|
|
485
517
|
hook_ctx=HookContext(
|
|
518
|
+
base_url=base_url or "",
|
|
486
519
|
operation_id="fim_completion_v1_fim_completions_post",
|
|
487
520
|
oauth2_scopes=[],
|
|
488
521
|
security_source=self.sdk_configuration.security,
|
|
@@ -492,15 +525,22 @@ class Fim(BaseSDK):
|
|
|
492
525
|
retry_config=retry_config,
|
|
493
526
|
)
|
|
494
527
|
|
|
495
|
-
|
|
528
|
+
response_data: Any = None
|
|
496
529
|
if utils.match_response(http_res, "200", "application/json"):
|
|
497
530
|
return utils.unmarshal_json(
|
|
498
531
|
http_res.text, Optional[models.FIMCompletionResponse]
|
|
499
532
|
)
|
|
500
533
|
if utils.match_response(http_res, "422", "application/json"):
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
534
|
+
response_data = utils.unmarshal_json(
|
|
535
|
+
http_res.text, models.HTTPValidationErrorData
|
|
536
|
+
)
|
|
537
|
+
raise models.HTTPValidationError(data=response_data)
|
|
538
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
539
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
540
|
+
raise models.SDKError(
|
|
541
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
542
|
+
)
|
|
543
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
504
544
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
505
545
|
raise models.SDKError(
|
|
506
546
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
mistralai_gcp/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
|
mistralai_gcp/models/__init__.py
CHANGED
|
@@ -67,6 +67,8 @@ from .functioncall import (
|
|
|
67
67
|
)
|
|
68
68
|
from .functionname import FunctionName, FunctionNameTypedDict
|
|
69
69
|
from .httpvalidationerror import HTTPValidationError, HTTPValidationErrorData
|
|
70
|
+
from .jsonschema import JSONSchema, JSONSchemaTypedDict
|
|
71
|
+
from .prediction import Prediction, PredictionTypedDict
|
|
70
72
|
from .referencechunk import ReferenceChunk, ReferenceChunkType, ReferenceChunkTypedDict
|
|
71
73
|
from .responseformat import ResponseFormat, ResponseFormatTypedDict
|
|
72
74
|
from .responseformats import ResponseFormats
|
|
@@ -107,6 +109,7 @@ from .validationerror import (
|
|
|
107
109
|
ValidationErrorTypedDict,
|
|
108
110
|
)
|
|
109
111
|
|
|
112
|
+
|
|
110
113
|
__all__ = [
|
|
111
114
|
"Arguments",
|
|
112
115
|
"ArgumentsTypedDict",
|
|
@@ -163,10 +166,14 @@ __all__ = [
|
|
|
163
166
|
"FunctionTypedDict",
|
|
164
167
|
"HTTPValidationError",
|
|
165
168
|
"HTTPValidationErrorData",
|
|
169
|
+
"JSONSchema",
|
|
170
|
+
"JSONSchemaTypedDict",
|
|
166
171
|
"Loc",
|
|
167
172
|
"LocTypedDict",
|
|
168
173
|
"Messages",
|
|
169
174
|
"MessagesTypedDict",
|
|
175
|
+
"Prediction",
|
|
176
|
+
"PredictionTypedDict",
|
|
170
177
|
"ReferenceChunk",
|
|
171
178
|
"ReferenceChunkType",
|
|
172
179
|
"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
|
|