mistralai 1.9.9__py3-none-any.whl → 1.9.11__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/_version.py +3 -3
- mistralai/accesses.py +43 -108
- mistralai/agents.py +29 -68
- mistralai/audio.py +8 -3
- mistralai/basesdk.py +15 -5
- mistralai/batch.py +6 -3
- mistralai/beta.py +10 -5
- mistralai/chat.py +29 -68
- mistralai/classifiers.py +57 -144
- mistralai/conversations.py +143 -352
- mistralai/documents.py +137 -356
- mistralai/embeddings.py +21 -36
- mistralai/files.py +47 -176
- mistralai/fim.py +29 -68
- mistralai/fine_tuning.py +6 -3
- mistralai/jobs.py +49 -158
- mistralai/libraries.py +71 -178
- mistralai/mistral_agents.py +71 -180
- mistralai/mistral_jobs.py +41 -128
- mistralai/models/__init__.py +36 -3
- mistralai/models/apiendpoint.py +5 -0
- mistralai/models/embeddingrequest.py +5 -1
- mistralai/models/encodingformat.py +7 -0
- mistralai/models/httpvalidationerror.py +11 -6
- mistralai/models/mistralerror.py +26 -0
- mistralai/models/no_response_error.py +13 -0
- mistralai/models/responsevalidationerror.py +25 -0
- mistralai/models/sdkerror.py +30 -14
- mistralai/models/systemmessage.py +7 -3
- mistralai/models/systemmessagecontentchunks.py +21 -0
- mistralai/models_.py +71 -204
- mistralai/ocr.py +15 -36
- mistralai/sdk.py +15 -2
- mistralai/transcriptions.py +17 -56
- mistralai/utils/__init__.py +18 -5
- mistralai/utils/eventstreaming.py +10 -0
- mistralai/utils/serializers.py +3 -2
- mistralai/utils/unmarshal_json_response.py +24 -0
- {mistralai-1.9.9.dist-info → mistralai-1.9.11.dist-info}/METADATA +61 -30
- {mistralai-1.9.9.dist-info → mistralai-1.9.11.dist-info}/RECORD +42 -36
- {mistralai-1.9.9.dist-info → mistralai-1.9.11.dist-info}/WHEEL +1 -1
- {mistralai-1.9.9.dist-info → mistralai-1.9.11.dist-info/licenses}/LICENSE +0 -0
mistralai/models/__init__.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
|
+
from .mistralerror import MistralError
|
|
3
4
|
from typing import TYPE_CHECKING
|
|
4
5
|
from importlib import import_module
|
|
6
|
+
import builtins
|
|
7
|
+
import sys
|
|
5
8
|
|
|
6
9
|
if TYPE_CHECKING:
|
|
7
10
|
from .agent import (
|
|
@@ -389,6 +392,7 @@ if TYPE_CHECKING:
|
|
|
389
392
|
EmbeddingResponseData,
|
|
390
393
|
EmbeddingResponseDataTypedDict,
|
|
391
394
|
)
|
|
395
|
+
from .encodingformat import EncodingFormat
|
|
392
396
|
from .entitytype import EntityType
|
|
393
397
|
from .eventout import EventOut, EventOutTypedDict
|
|
394
398
|
from .file import File, FileTypedDict
|
|
@@ -712,6 +716,7 @@ if TYPE_CHECKING:
|
|
|
712
716
|
from .modellist import Data, DataTypedDict, ModelList, ModelListTypedDict
|
|
713
717
|
from .moderationobject import ModerationObject, ModerationObjectTypedDict
|
|
714
718
|
from .moderationresponse import ModerationResponse, ModerationResponseTypedDict
|
|
719
|
+
from .no_response_error import NoResponseError
|
|
715
720
|
from .ocrimageobject import OCRImageObject, OCRImageObjectTypedDict
|
|
716
721
|
from .ocrpagedimensions import OCRPageDimensions, OCRPageDimensionsTypedDict
|
|
717
722
|
from .ocrpageobject import OCRPageObject, OCRPageObjectTypedDict
|
|
@@ -744,6 +749,7 @@ if TYPE_CHECKING:
|
|
|
744
749
|
ResponseStartedEventType,
|
|
745
750
|
ResponseStartedEventTypedDict,
|
|
746
751
|
)
|
|
752
|
+
from .responsevalidationerror import ResponseValidationError
|
|
747
753
|
from .retrieve_model_v1_models_model_id_getop import (
|
|
748
754
|
RetrieveModelV1ModelsModelIDGetRequest,
|
|
749
755
|
RetrieveModelV1ModelsModelIDGetRequestTypedDict,
|
|
@@ -767,6 +773,10 @@ if TYPE_CHECKING:
|
|
|
767
773
|
SystemMessageContentTypedDict,
|
|
768
774
|
SystemMessageTypedDict,
|
|
769
775
|
)
|
|
776
|
+
from .systemmessagecontentchunks import (
|
|
777
|
+
SystemMessageContentChunks,
|
|
778
|
+
SystemMessageContentChunksTypedDict,
|
|
779
|
+
)
|
|
770
780
|
from .textchunk import TextChunk, TextChunkType, TextChunkTypedDict
|
|
771
781
|
from .thinkchunk import (
|
|
772
782
|
ThinkChunk,
|
|
@@ -1156,6 +1166,7 @@ __all__ = [
|
|
|
1156
1166
|
"EmbeddingResponseData",
|
|
1157
1167
|
"EmbeddingResponseDataTypedDict",
|
|
1158
1168
|
"EmbeddingResponseTypedDict",
|
|
1169
|
+
"EncodingFormat",
|
|
1159
1170
|
"EntityType",
|
|
1160
1171
|
"Entries",
|
|
1161
1172
|
"EntriesTypedDict",
|
|
@@ -1385,6 +1396,7 @@ __all__ = [
|
|
|
1385
1396
|
"MessagesTypedDict",
|
|
1386
1397
|
"MetricOut",
|
|
1387
1398
|
"MetricOutTypedDict",
|
|
1399
|
+
"MistralError",
|
|
1388
1400
|
"MistralPromptMode",
|
|
1389
1401
|
"ModelCapabilities",
|
|
1390
1402
|
"ModelCapabilitiesTypedDict",
|
|
@@ -1400,6 +1412,7 @@ __all__ = [
|
|
|
1400
1412
|
"ModerationObjectTypedDict",
|
|
1401
1413
|
"ModerationResponse",
|
|
1402
1414
|
"ModerationResponseTypedDict",
|
|
1415
|
+
"NoResponseError",
|
|
1403
1416
|
"OCRImageObject",
|
|
1404
1417
|
"OCRImageObjectTypedDict",
|
|
1405
1418
|
"OCRPageDimensions",
|
|
@@ -1447,6 +1460,7 @@ __all__ = [
|
|
|
1447
1460
|
"ResponseStartedEvent",
|
|
1448
1461
|
"ResponseStartedEventType",
|
|
1449
1462
|
"ResponseStartedEventTypedDict",
|
|
1463
|
+
"ResponseValidationError",
|
|
1450
1464
|
"RetrieveFileOut",
|
|
1451
1465
|
"RetrieveFileOutTypedDict",
|
|
1452
1466
|
"RetrieveModelV1ModelsModelIDGetRequest",
|
|
@@ -1472,6 +1486,8 @@ __all__ = [
|
|
|
1472
1486
|
"StopTypedDict",
|
|
1473
1487
|
"SystemMessage",
|
|
1474
1488
|
"SystemMessageContent",
|
|
1489
|
+
"SystemMessageContentChunks",
|
|
1490
|
+
"SystemMessageContentChunksTypedDict",
|
|
1475
1491
|
"SystemMessageContentTypedDict",
|
|
1476
1492
|
"SystemMessageTypedDict",
|
|
1477
1493
|
"TextChunk",
|
|
@@ -1858,6 +1874,7 @@ _dynamic_imports: dict[str, str] = {
|
|
|
1858
1874
|
"EmbeddingResponseTypedDict": ".embeddingresponse",
|
|
1859
1875
|
"EmbeddingResponseData": ".embeddingresponsedata",
|
|
1860
1876
|
"EmbeddingResponseDataTypedDict": ".embeddingresponsedata",
|
|
1877
|
+
"EncodingFormat": ".encodingformat",
|
|
1861
1878
|
"EntityType": ".entitytype",
|
|
1862
1879
|
"EventOut": ".eventout",
|
|
1863
1880
|
"EventOutTypedDict": ".eventout",
|
|
@@ -2098,6 +2115,7 @@ _dynamic_imports: dict[str, str] = {
|
|
|
2098
2115
|
"ModerationObjectTypedDict": ".moderationobject",
|
|
2099
2116
|
"ModerationResponse": ".moderationresponse",
|
|
2100
2117
|
"ModerationResponseTypedDict": ".moderationresponse",
|
|
2118
|
+
"NoResponseError": ".no_response_error",
|
|
2101
2119
|
"OCRImageObject": ".ocrimageobject",
|
|
2102
2120
|
"OCRImageObjectTypedDict": ".ocrimageobject",
|
|
2103
2121
|
"OCRPageDimensions": ".ocrpagedimensions",
|
|
@@ -2135,6 +2153,7 @@ _dynamic_imports: dict[str, str] = {
|
|
|
2135
2153
|
"ResponseStartedEvent": ".responsestartedevent",
|
|
2136
2154
|
"ResponseStartedEventType": ".responsestartedevent",
|
|
2137
2155
|
"ResponseStartedEventTypedDict": ".responsestartedevent",
|
|
2156
|
+
"ResponseValidationError": ".responsevalidationerror",
|
|
2138
2157
|
"RetrieveModelV1ModelsModelIDGetRequest": ".retrieve_model_v1_models_model_id_getop",
|
|
2139
2158
|
"RetrieveModelV1ModelsModelIDGetRequestTypedDict": ".retrieve_model_v1_models_model_id_getop",
|
|
2140
2159
|
"RetrieveModelV1ModelsModelIDGetResponseRetrieveModelV1ModelsModelIDGet": ".retrieve_model_v1_models_model_id_getop",
|
|
@@ -2159,6 +2178,8 @@ _dynamic_imports: dict[str, str] = {
|
|
|
2159
2178
|
"SystemMessageContent": ".systemmessage",
|
|
2160
2179
|
"SystemMessageContentTypedDict": ".systemmessage",
|
|
2161
2180
|
"SystemMessageTypedDict": ".systemmessage",
|
|
2181
|
+
"SystemMessageContentChunks": ".systemmessagecontentchunks",
|
|
2182
|
+
"SystemMessageContentChunksTypedDict": ".systemmessagecontentchunks",
|
|
2162
2183
|
"TextChunk": ".textchunk",
|
|
2163
2184
|
"TextChunkType": ".textchunk",
|
|
2164
2185
|
"TextChunkTypedDict": ".textchunk",
|
|
@@ -2257,6 +2278,18 @@ _dynamic_imports: dict[str, str] = {
|
|
|
2257
2278
|
}
|
|
2258
2279
|
|
|
2259
2280
|
|
|
2281
|
+
def dynamic_import(modname, retries=3):
|
|
2282
|
+
for attempt in range(retries):
|
|
2283
|
+
try:
|
|
2284
|
+
return import_module(modname, __package__)
|
|
2285
|
+
except KeyError:
|
|
2286
|
+
# Clear any half-initialized module and retry
|
|
2287
|
+
sys.modules.pop(modname, None)
|
|
2288
|
+
if attempt == retries - 1:
|
|
2289
|
+
break
|
|
2290
|
+
raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")
|
|
2291
|
+
|
|
2292
|
+
|
|
2260
2293
|
def __getattr__(attr_name: str) -> object:
|
|
2261
2294
|
module_name = _dynamic_imports.get(attr_name)
|
|
2262
2295
|
if module_name is None:
|
|
@@ -2265,7 +2298,7 @@ def __getattr__(attr_name: str) -> object:
|
|
|
2265
2298
|
)
|
|
2266
2299
|
|
|
2267
2300
|
try:
|
|
2268
|
-
module =
|
|
2301
|
+
module = dynamic_import(module_name)
|
|
2269
2302
|
result = getattr(module, attr_name)
|
|
2270
2303
|
return result
|
|
2271
2304
|
except ImportError as e:
|
|
@@ -2279,5 +2312,5 @@ def __getattr__(attr_name: str) -> object:
|
|
|
2279
2312
|
|
|
2280
2313
|
|
|
2281
2314
|
def __dir__():
|
|
2282
|
-
lazy_attrs = list(_dynamic_imports.keys())
|
|
2283
|
-
return sorted(lazy_attrs)
|
|
2315
|
+
lazy_attrs = builtins.list(_dynamic_imports.keys())
|
|
2316
|
+
return builtins.sorted(lazy_attrs)
|
mistralai/models/apiendpoint.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
from .embeddingdtype import EmbeddingDtype
|
|
5
|
+
from .encodingformat import EncodingFormat
|
|
5
6
|
from mistralai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
|
|
6
7
|
import pydantic
|
|
7
8
|
from pydantic import model_serializer
|
|
@@ -27,6 +28,7 @@ class EmbeddingRequestTypedDict(TypedDict):
|
|
|
27
28
|
output_dimension: NotRequired[Nullable[int]]
|
|
28
29
|
r"""The dimension of the output embeddings."""
|
|
29
30
|
output_dtype: NotRequired[EmbeddingDtype]
|
|
31
|
+
encoding_format: NotRequired[EncodingFormat]
|
|
30
32
|
|
|
31
33
|
|
|
32
34
|
class EmbeddingRequest(BaseModel):
|
|
@@ -41,9 +43,11 @@ class EmbeddingRequest(BaseModel):
|
|
|
41
43
|
|
|
42
44
|
output_dtype: Optional[EmbeddingDtype] = None
|
|
43
45
|
|
|
46
|
+
encoding_format: Optional[EncodingFormat] = None
|
|
47
|
+
|
|
44
48
|
@model_serializer(mode="wrap")
|
|
45
49
|
def serialize_model(self, handler):
|
|
46
|
-
optional_fields = ["output_dimension", "output_dtype"]
|
|
50
|
+
optional_fields = ["output_dimension", "output_dtype", "encoding_format"]
|
|
47
51
|
nullable_fields = ["output_dimension"]
|
|
48
52
|
null_default_fields = []
|
|
49
53
|
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
from .validationerror import ValidationError
|
|
5
|
-
|
|
5
|
+
import httpx
|
|
6
|
+
from mistralai.models import MistralError
|
|
6
7
|
from mistralai.types import BaseModel
|
|
7
8
|
from typing import List, Optional
|
|
8
9
|
|
|
@@ -11,11 +12,15 @@ class HTTPValidationErrorData(BaseModel):
|
|
|
11
12
|
detail: Optional[List[ValidationError]] = None
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
class HTTPValidationError(
|
|
15
|
+
class HTTPValidationError(MistralError):
|
|
15
16
|
data: HTTPValidationErrorData
|
|
16
17
|
|
|
17
|
-
def __init__(
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
data: HTTPValidationErrorData,
|
|
21
|
+
raw_response: httpx.Response,
|
|
22
|
+
body: Optional[str] = None,
|
|
23
|
+
):
|
|
24
|
+
message = body or raw_response.text
|
|
25
|
+
super().__init__(message, raw_response, body)
|
|
18
26
|
self.data = data
|
|
19
|
-
|
|
20
|
-
def __str__(self) -> str:
|
|
21
|
-
return utils.marshal_json(self.data, HTTPValidationErrorData)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
import httpx
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MistralError(Exception):
|
|
8
|
+
"""The base class for all HTTP error responses."""
|
|
9
|
+
|
|
10
|
+
message: str
|
|
11
|
+
status_code: int
|
|
12
|
+
body: str
|
|
13
|
+
headers: httpx.Headers
|
|
14
|
+
raw_response: httpx.Response
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self, message: str, raw_response: httpx.Response, body: Optional[str] = None
|
|
18
|
+
):
|
|
19
|
+
self.message = message
|
|
20
|
+
self.status_code = raw_response.status_code
|
|
21
|
+
self.body = body if body is not None else raw_response.text
|
|
22
|
+
self.headers = raw_response.headers
|
|
23
|
+
self.raw_response = raw_response
|
|
24
|
+
|
|
25
|
+
def __str__(self):
|
|
26
|
+
return self.message
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
class NoResponseError(Exception):
|
|
4
|
+
"""Error raised when no HTTP response is received from the server."""
|
|
5
|
+
|
|
6
|
+
message: str
|
|
7
|
+
|
|
8
|
+
def __init__(self, message: str = "No response received"):
|
|
9
|
+
self.message = message
|
|
10
|
+
super().__init__(message)
|
|
11
|
+
|
|
12
|
+
def __str__(self):
|
|
13
|
+
return self.message
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
import httpx
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from mistralai.models import MistralError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ResponseValidationError(MistralError):
|
|
10
|
+
"""Error raised when there is a type mismatch between the response data and the expected Pydantic model."""
|
|
11
|
+
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
message: str,
|
|
15
|
+
raw_response: httpx.Response,
|
|
16
|
+
cause: Exception,
|
|
17
|
+
body: Optional[str] = None,
|
|
18
|
+
):
|
|
19
|
+
message = f"{message}: {cause}"
|
|
20
|
+
super().__init__(message, raw_response, body)
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def cause(self):
|
|
24
|
+
"""Normally the Pydantic ValidationError"""
|
|
25
|
+
return self.__cause__
|
mistralai/models/sdkerror.py
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
|
-
from dataclasses import dataclass
|
|
4
|
-
from typing import Optional
|
|
5
3
|
import httpx
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from mistralai.models import MistralError
|
|
7
|
+
|
|
8
|
+
MAX_MESSAGE_LEN = 10_000
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SDKError(MistralError):
|
|
12
|
+
"""The fallback error class if no more specific error class is matched."""
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self, message: str, raw_response: httpx.Response, body: Optional[str] = None
|
|
16
|
+
):
|
|
17
|
+
body_display = body or raw_response.text or '""'
|
|
6
18
|
|
|
19
|
+
if message:
|
|
20
|
+
message += ": "
|
|
21
|
+
message += f"Status {raw_response.status_code}"
|
|
7
22
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
23
|
+
headers = raw_response.headers
|
|
24
|
+
content_type = headers.get("content-type", '""')
|
|
25
|
+
if content_type != "application/json":
|
|
26
|
+
if " " in content_type:
|
|
27
|
+
content_type = f'"{content_type}"'
|
|
28
|
+
message += f" Content-Type {content_type}"
|
|
11
29
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
30
|
+
if len(body_display) > MAX_MESSAGE_LEN:
|
|
31
|
+
truncated = body_display[:MAX_MESSAGE_LEN]
|
|
32
|
+
remaining = len(body_display) - MAX_MESSAGE_LEN
|
|
33
|
+
body_display = f"{truncated}...and {remaining} more chars"
|
|
16
34
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if len(self.body) > 0:
|
|
20
|
-
body = f"\n{self.body}"
|
|
35
|
+
message += f". Body: {body_display}"
|
|
36
|
+
message = message.strip()
|
|
21
37
|
|
|
22
|
-
|
|
38
|
+
super().__init__(message, raw_response, body)
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
-
from .
|
|
4
|
+
from .systemmessagecontentchunks import (
|
|
5
|
+
SystemMessageContentChunks,
|
|
6
|
+
SystemMessageContentChunksTypedDict,
|
|
7
|
+
)
|
|
5
8
|
from mistralai.types import BaseModel
|
|
6
9
|
from typing import List, Literal, Optional, Union
|
|
7
10
|
from typing_extensions import NotRequired, TypeAliasType, TypedDict
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
SystemMessageContentTypedDict = TypeAliasType(
|
|
11
|
-
"SystemMessageContentTypedDict",
|
|
14
|
+
"SystemMessageContentTypedDict",
|
|
15
|
+
Union[str, List[SystemMessageContentChunksTypedDict]],
|
|
12
16
|
)
|
|
13
17
|
|
|
14
18
|
|
|
15
19
|
SystemMessageContent = TypeAliasType(
|
|
16
|
-
"SystemMessageContent", Union[str, List[
|
|
20
|
+
"SystemMessageContent", Union[str, List[SystemMessageContentChunks]]
|
|
17
21
|
)
|
|
18
22
|
|
|
19
23
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from .textchunk import TextChunk, TextChunkTypedDict
|
|
5
|
+
from .thinkchunk import ThinkChunk, ThinkChunkTypedDict
|
|
6
|
+
from mistralai.utils import get_discriminator
|
|
7
|
+
from pydantic import Discriminator, Tag
|
|
8
|
+
from typing import Union
|
|
9
|
+
from typing_extensions import Annotated, TypeAliasType
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
SystemMessageContentChunksTypedDict = TypeAliasType(
|
|
13
|
+
"SystemMessageContentChunksTypedDict",
|
|
14
|
+
Union[TextChunkTypedDict, ThinkChunkTypedDict],
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
SystemMessageContentChunks = Annotated[
|
|
19
|
+
Union[Annotated[TextChunk, Tag("text")], Annotated[ThinkChunk, Tag("thinking")]],
|
|
20
|
+
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
|
21
|
+
]
|