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_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,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
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
41
45
|
server_url: Optional[str] = None,
|
|
42
46
|
timeout_ms: Optional[int] = None,
|
|
@@ -60,6 +64,8 @@ class Chat(BaseSDK):
|
|
|
60
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.
|
|
61
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.
|
|
62
66
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
67
|
+
:param prediction:
|
|
68
|
+
:param parallel_tool_calls:
|
|
63
69
|
:param retries: Override the default retry configuration for this method
|
|
64
70
|
:param server_url: Override the default server URL for this method
|
|
65
71
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -72,6 +78,8 @@ class Chat(BaseSDK):
|
|
|
72
78
|
|
|
73
79
|
if server_url is not None:
|
|
74
80
|
base_url = server_url
|
|
81
|
+
else:
|
|
82
|
+
base_url = self._get_url(base_url, url_variables)
|
|
75
83
|
|
|
76
84
|
request = models.ChatCompletionStreamRequest(
|
|
77
85
|
model=model,
|
|
@@ -92,6 +100,10 @@ class Chat(BaseSDK):
|
|
|
92
100
|
presence_penalty=presence_penalty,
|
|
93
101
|
frequency_penalty=frequency_penalty,
|
|
94
102
|
n=n,
|
|
103
|
+
prediction=utils.get_pydantic_model(
|
|
104
|
+
prediction, Optional[models.Prediction]
|
|
105
|
+
),
|
|
106
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
95
107
|
)
|
|
96
108
|
|
|
97
109
|
req = self._build_request(
|
|
@@ -123,6 +135,7 @@ class Chat(BaseSDK):
|
|
|
123
135
|
|
|
124
136
|
http_res = self.do_request(
|
|
125
137
|
hook_ctx=HookContext(
|
|
138
|
+
base_url=base_url or "",
|
|
126
139
|
operation_id="stream_chat",
|
|
127
140
|
oauth2_scopes=[],
|
|
128
141
|
security_source=self.sdk_configuration.security,
|
|
@@ -133,7 +146,7 @@ class Chat(BaseSDK):
|
|
|
133
146
|
retry_config=retry_config,
|
|
134
147
|
)
|
|
135
148
|
|
|
136
|
-
|
|
149
|
+
response_data: Any = None
|
|
137
150
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
138
151
|
return eventstreaming.EventStream(
|
|
139
152
|
http_res,
|
|
@@ -142,9 +155,16 @@ class Chat(BaseSDK):
|
|
|
142
155
|
)
|
|
143
156
|
if utils.match_response(http_res, "422", "application/json"):
|
|
144
157
|
http_res_text = utils.stream_to_text(http_res)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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", "*"):
|
|
148
168
|
http_res_text = utils.stream_to_text(http_res)
|
|
149
169
|
raise models.SDKError(
|
|
150
170
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -162,7 +182,7 @@ class Chat(BaseSDK):
|
|
|
162
182
|
async def stream_async(
|
|
163
183
|
self,
|
|
164
184
|
*,
|
|
165
|
-
model:
|
|
185
|
+
model: str,
|
|
166
186
|
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
167
187
|
temperature: OptionalNullable[float] = UNSET,
|
|
168
188
|
top_p: Optional[float] = None,
|
|
@@ -185,6 +205,10 @@ class Chat(BaseSDK):
|
|
|
185
205
|
presence_penalty: Optional[float] = None,
|
|
186
206
|
frequency_penalty: Optional[float] = None,
|
|
187
207
|
n: OptionalNullable[int] = UNSET,
|
|
208
|
+
prediction: Optional[
|
|
209
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
210
|
+
] = None,
|
|
211
|
+
parallel_tool_calls: Optional[bool] = None,
|
|
188
212
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
189
213
|
server_url: Optional[str] = None,
|
|
190
214
|
timeout_ms: Optional[int] = None,
|
|
@@ -208,6 +232,8 @@ class Chat(BaseSDK):
|
|
|
208
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.
|
|
209
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.
|
|
210
234
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
235
|
+
:param prediction:
|
|
236
|
+
:param parallel_tool_calls:
|
|
211
237
|
:param retries: Override the default retry configuration for this method
|
|
212
238
|
:param server_url: Override the default server URL for this method
|
|
213
239
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -220,6 +246,8 @@ class Chat(BaseSDK):
|
|
|
220
246
|
|
|
221
247
|
if server_url is not None:
|
|
222
248
|
base_url = server_url
|
|
249
|
+
else:
|
|
250
|
+
base_url = self._get_url(base_url, url_variables)
|
|
223
251
|
|
|
224
252
|
request = models.ChatCompletionStreamRequest(
|
|
225
253
|
model=model,
|
|
@@ -240,6 +268,10 @@ class Chat(BaseSDK):
|
|
|
240
268
|
presence_penalty=presence_penalty,
|
|
241
269
|
frequency_penalty=frequency_penalty,
|
|
242
270
|
n=n,
|
|
271
|
+
prediction=utils.get_pydantic_model(
|
|
272
|
+
prediction, Optional[models.Prediction]
|
|
273
|
+
),
|
|
274
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
243
275
|
)
|
|
244
276
|
|
|
245
277
|
req = self._build_request_async(
|
|
@@ -271,6 +303,7 @@ class Chat(BaseSDK):
|
|
|
271
303
|
|
|
272
304
|
http_res = await self.do_request_async(
|
|
273
305
|
hook_ctx=HookContext(
|
|
306
|
+
base_url=base_url or "",
|
|
274
307
|
operation_id="stream_chat",
|
|
275
308
|
oauth2_scopes=[],
|
|
276
309
|
security_source=self.sdk_configuration.security,
|
|
@@ -281,7 +314,7 @@ class Chat(BaseSDK):
|
|
|
281
314
|
retry_config=retry_config,
|
|
282
315
|
)
|
|
283
316
|
|
|
284
|
-
|
|
317
|
+
response_data: Any = None
|
|
285
318
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
286
319
|
return eventstreaming.EventStreamAsync(
|
|
287
320
|
http_res,
|
|
@@ -290,9 +323,16 @@ class Chat(BaseSDK):
|
|
|
290
323
|
)
|
|
291
324
|
if utils.match_response(http_res, "422", "application/json"):
|
|
292
325
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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", "*"):
|
|
296
336
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
297
337
|
raise models.SDKError(
|
|
298
338
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -310,7 +350,7 @@ class Chat(BaseSDK):
|
|
|
310
350
|
def complete(
|
|
311
351
|
self,
|
|
312
352
|
*,
|
|
313
|
-
model:
|
|
353
|
+
model: str,
|
|
314
354
|
messages: Union[
|
|
315
355
|
List[models.ChatCompletionRequestMessages],
|
|
316
356
|
List[models.ChatCompletionRequestMessagesTypedDict],
|
|
@@ -341,6 +381,10 @@ class Chat(BaseSDK):
|
|
|
341
381
|
presence_penalty: Optional[float] = None,
|
|
342
382
|
frequency_penalty: Optional[float] = None,
|
|
343
383
|
n: OptionalNullable[int] = UNSET,
|
|
384
|
+
prediction: Optional[
|
|
385
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
386
|
+
] = None,
|
|
387
|
+
parallel_tool_calls: Optional[bool] = None,
|
|
344
388
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
345
389
|
server_url: Optional[str] = None,
|
|
346
390
|
timeout_ms: Optional[int] = None,
|
|
@@ -362,6 +406,8 @@ class Chat(BaseSDK):
|
|
|
362
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.
|
|
363
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.
|
|
364
408
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
409
|
+
:param prediction:
|
|
410
|
+
:param parallel_tool_calls:
|
|
365
411
|
:param retries: Override the default retry configuration for this method
|
|
366
412
|
:param server_url: Override the default server URL for this method
|
|
367
413
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -374,6 +420,8 @@ class Chat(BaseSDK):
|
|
|
374
420
|
|
|
375
421
|
if server_url is not None:
|
|
376
422
|
base_url = server_url
|
|
423
|
+
else:
|
|
424
|
+
base_url = self._get_url(base_url, url_variables)
|
|
377
425
|
|
|
378
426
|
request = models.ChatCompletionRequest(
|
|
379
427
|
model=model,
|
|
@@ -396,6 +444,10 @@ class Chat(BaseSDK):
|
|
|
396
444
|
presence_penalty=presence_penalty,
|
|
397
445
|
frequency_penalty=frequency_penalty,
|
|
398
446
|
n=n,
|
|
447
|
+
prediction=utils.get_pydantic_model(
|
|
448
|
+
prediction, Optional[models.Prediction]
|
|
449
|
+
),
|
|
450
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
399
451
|
)
|
|
400
452
|
|
|
401
453
|
req = self._build_request(
|
|
@@ -427,6 +479,7 @@ class Chat(BaseSDK):
|
|
|
427
479
|
|
|
428
480
|
http_res = self.do_request(
|
|
429
481
|
hook_ctx=HookContext(
|
|
482
|
+
base_url=base_url or "",
|
|
430
483
|
operation_id="chat_completion_v1_chat_completions_post",
|
|
431
484
|
oauth2_scopes=[],
|
|
432
485
|
security_source=self.sdk_configuration.security,
|
|
@@ -436,15 +489,22 @@ class Chat(BaseSDK):
|
|
|
436
489
|
retry_config=retry_config,
|
|
437
490
|
)
|
|
438
491
|
|
|
439
|
-
|
|
492
|
+
response_data: Any = None
|
|
440
493
|
if utils.match_response(http_res, "200", "application/json"):
|
|
441
494
|
return utils.unmarshal_json(
|
|
442
495
|
http_res.text, Optional[models.ChatCompletionResponse]
|
|
443
496
|
)
|
|
444
497
|
if utils.match_response(http_res, "422", "application/json"):
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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", "*"):
|
|
448
508
|
http_res_text = utils.stream_to_text(http_res)
|
|
449
509
|
raise models.SDKError(
|
|
450
510
|
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
@@ -462,7 +522,7 @@ class Chat(BaseSDK):
|
|
|
462
522
|
async def complete_async(
|
|
463
523
|
self,
|
|
464
524
|
*,
|
|
465
|
-
model:
|
|
525
|
+
model: str,
|
|
466
526
|
messages: Union[
|
|
467
527
|
List[models.ChatCompletionRequestMessages],
|
|
468
528
|
List[models.ChatCompletionRequestMessagesTypedDict],
|
|
@@ -493,6 +553,10 @@ class Chat(BaseSDK):
|
|
|
493
553
|
presence_penalty: Optional[float] = None,
|
|
494
554
|
frequency_penalty: Optional[float] = None,
|
|
495
555
|
n: OptionalNullable[int] = UNSET,
|
|
556
|
+
prediction: Optional[
|
|
557
|
+
Union[models.Prediction, models.PredictionTypedDict]
|
|
558
|
+
] = None,
|
|
559
|
+
parallel_tool_calls: Optional[bool] = None,
|
|
496
560
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
497
561
|
server_url: Optional[str] = None,
|
|
498
562
|
timeout_ms: Optional[int] = None,
|
|
@@ -514,6 +578,8 @@ class Chat(BaseSDK):
|
|
|
514
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.
|
|
515
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.
|
|
516
580
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
581
|
+
:param prediction:
|
|
582
|
+
:param parallel_tool_calls:
|
|
517
583
|
:param retries: Override the default retry configuration for this method
|
|
518
584
|
:param server_url: Override the default server URL for this method
|
|
519
585
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -526,6 +592,8 @@ class Chat(BaseSDK):
|
|
|
526
592
|
|
|
527
593
|
if server_url is not None:
|
|
528
594
|
base_url = server_url
|
|
595
|
+
else:
|
|
596
|
+
base_url = self._get_url(base_url, url_variables)
|
|
529
597
|
|
|
530
598
|
request = models.ChatCompletionRequest(
|
|
531
599
|
model=model,
|
|
@@ -548,6 +616,10 @@ class Chat(BaseSDK):
|
|
|
548
616
|
presence_penalty=presence_penalty,
|
|
549
617
|
frequency_penalty=frequency_penalty,
|
|
550
618
|
n=n,
|
|
619
|
+
prediction=utils.get_pydantic_model(
|
|
620
|
+
prediction, Optional[models.Prediction]
|
|
621
|
+
),
|
|
622
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
551
623
|
)
|
|
552
624
|
|
|
553
625
|
req = self._build_request_async(
|
|
@@ -579,6 +651,7 @@ class Chat(BaseSDK):
|
|
|
579
651
|
|
|
580
652
|
http_res = await self.do_request_async(
|
|
581
653
|
hook_ctx=HookContext(
|
|
654
|
+
base_url=base_url or "",
|
|
582
655
|
operation_id="chat_completion_v1_chat_completions_post",
|
|
583
656
|
oauth2_scopes=[],
|
|
584
657
|
security_source=self.sdk_configuration.security,
|
|
@@ -588,15 +661,22 @@ class Chat(BaseSDK):
|
|
|
588
661
|
retry_config=retry_config,
|
|
589
662
|
)
|
|
590
663
|
|
|
591
|
-
|
|
664
|
+
response_data: Any = None
|
|
592
665
|
if utils.match_response(http_res, "200", "application/json"):
|
|
593
666
|
return utils.unmarshal_json(
|
|
594
667
|
http_res.text, Optional[models.ChatCompletionResponse]
|
|
595
668
|
)
|
|
596
669
|
if utils.match_response(http_res, "422", "application/json"):
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
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", "*"):
|
|
600
680
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
601
681
|
raise models.SDKError(
|
|
602
682
|
"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,16 @@ from .functioncall import (
|
|
|
67
67
|
)
|
|
68
68
|
from .functionname import FunctionName, FunctionNameTypedDict
|
|
69
69
|
from .httpvalidationerror import HTTPValidationError, HTTPValidationErrorData
|
|
70
|
+
from .imageurl import ImageURL, ImageURLTypedDict
|
|
71
|
+
from .imageurlchunk import (
|
|
72
|
+
ImageURLChunk,
|
|
73
|
+
ImageURLChunkImageURL,
|
|
74
|
+
ImageURLChunkImageURLTypedDict,
|
|
75
|
+
ImageURLChunkType,
|
|
76
|
+
ImageURLChunkTypedDict,
|
|
77
|
+
)
|
|
78
|
+
from .jsonschema import JSONSchema, JSONSchemaTypedDict
|
|
79
|
+
from .prediction import Prediction, PredictionTypedDict
|
|
70
80
|
from .referencechunk import ReferenceChunk, ReferenceChunkType, ReferenceChunkTypedDict
|
|
71
81
|
from .responseformat import ResponseFormat, ResponseFormatTypedDict
|
|
72
82
|
from .responseformats import ResponseFormats
|
|
@@ -107,6 +117,7 @@ from .validationerror import (
|
|
|
107
117
|
ValidationErrorTypedDict,
|
|
108
118
|
)
|
|
109
119
|
|
|
120
|
+
|
|
110
121
|
__all__ = [
|
|
111
122
|
"Arguments",
|
|
112
123
|
"ArgumentsTypedDict",
|
|
@@ -163,10 +174,21 @@ __all__ = [
|
|
|
163
174
|
"FunctionTypedDict",
|
|
164
175
|
"HTTPValidationError",
|
|
165
176
|
"HTTPValidationErrorData",
|
|
177
|
+
"ImageURL",
|
|
178
|
+
"ImageURLChunk",
|
|
179
|
+
"ImageURLChunkImageURL",
|
|
180
|
+
"ImageURLChunkImageURLTypedDict",
|
|
181
|
+
"ImageURLChunkType",
|
|
182
|
+
"ImageURLChunkTypedDict",
|
|
183
|
+
"ImageURLTypedDict",
|
|
184
|
+
"JSONSchema",
|
|
185
|
+
"JSONSchemaTypedDict",
|
|
166
186
|
"Loc",
|
|
167
187
|
"LocTypedDict",
|
|
168
188
|
"Messages",
|
|
169
189
|
"MessagesTypedDict",
|
|
190
|
+
"Prediction",
|
|
191
|
+
"PredictionTypedDict",
|
|
170
192
|
"ReferenceChunk",
|
|
171
193
|
"ReferenceChunkType",
|
|
172
194
|
"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
|
|