mistralai 1.9.10__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 +15 -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 +25 -3
- 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_.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.10.dist-info → mistralai-1.9.11.dist-info}/METADATA +61 -30
- {mistralai-1.9.10.dist-info → mistralai-1.9.11.dist-info}/RECORD +37 -33
- {mistralai-1.9.10.dist-info → mistralai-1.9.11.dist-info}/WHEEL +1 -1
- {mistralai-1.9.10.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 (
|
|
@@ -713,6 +716,7 @@ if TYPE_CHECKING:
|
|
|
713
716
|
from .modellist import Data, DataTypedDict, ModelList, ModelListTypedDict
|
|
714
717
|
from .moderationobject import ModerationObject, ModerationObjectTypedDict
|
|
715
718
|
from .moderationresponse import ModerationResponse, ModerationResponseTypedDict
|
|
719
|
+
from .no_response_error import NoResponseError
|
|
716
720
|
from .ocrimageobject import OCRImageObject, OCRImageObjectTypedDict
|
|
717
721
|
from .ocrpagedimensions import OCRPageDimensions, OCRPageDimensionsTypedDict
|
|
718
722
|
from .ocrpageobject import OCRPageObject, OCRPageObjectTypedDict
|
|
@@ -745,6 +749,7 @@ if TYPE_CHECKING:
|
|
|
745
749
|
ResponseStartedEventType,
|
|
746
750
|
ResponseStartedEventTypedDict,
|
|
747
751
|
)
|
|
752
|
+
from .responsevalidationerror import ResponseValidationError
|
|
748
753
|
from .retrieve_model_v1_models_model_id_getop import (
|
|
749
754
|
RetrieveModelV1ModelsModelIDGetRequest,
|
|
750
755
|
RetrieveModelV1ModelsModelIDGetRequestTypedDict,
|
|
@@ -1391,6 +1396,7 @@ __all__ = [
|
|
|
1391
1396
|
"MessagesTypedDict",
|
|
1392
1397
|
"MetricOut",
|
|
1393
1398
|
"MetricOutTypedDict",
|
|
1399
|
+
"MistralError",
|
|
1394
1400
|
"MistralPromptMode",
|
|
1395
1401
|
"ModelCapabilities",
|
|
1396
1402
|
"ModelCapabilitiesTypedDict",
|
|
@@ -1406,6 +1412,7 @@ __all__ = [
|
|
|
1406
1412
|
"ModerationObjectTypedDict",
|
|
1407
1413
|
"ModerationResponse",
|
|
1408
1414
|
"ModerationResponseTypedDict",
|
|
1415
|
+
"NoResponseError",
|
|
1409
1416
|
"OCRImageObject",
|
|
1410
1417
|
"OCRImageObjectTypedDict",
|
|
1411
1418
|
"OCRPageDimensions",
|
|
@@ -1453,6 +1460,7 @@ __all__ = [
|
|
|
1453
1460
|
"ResponseStartedEvent",
|
|
1454
1461
|
"ResponseStartedEventType",
|
|
1455
1462
|
"ResponseStartedEventTypedDict",
|
|
1463
|
+
"ResponseValidationError",
|
|
1456
1464
|
"RetrieveFileOut",
|
|
1457
1465
|
"RetrieveFileOutTypedDict",
|
|
1458
1466
|
"RetrieveModelV1ModelsModelIDGetRequest",
|
|
@@ -2107,6 +2115,7 @@ _dynamic_imports: dict[str, str] = {
|
|
|
2107
2115
|
"ModerationObjectTypedDict": ".moderationobject",
|
|
2108
2116
|
"ModerationResponse": ".moderationresponse",
|
|
2109
2117
|
"ModerationResponseTypedDict": ".moderationresponse",
|
|
2118
|
+
"NoResponseError": ".no_response_error",
|
|
2110
2119
|
"OCRImageObject": ".ocrimageobject",
|
|
2111
2120
|
"OCRImageObjectTypedDict": ".ocrimageobject",
|
|
2112
2121
|
"OCRPageDimensions": ".ocrpagedimensions",
|
|
@@ -2144,6 +2153,7 @@ _dynamic_imports: dict[str, str] = {
|
|
|
2144
2153
|
"ResponseStartedEvent": ".responsestartedevent",
|
|
2145
2154
|
"ResponseStartedEventType": ".responsestartedevent",
|
|
2146
2155
|
"ResponseStartedEventTypedDict": ".responsestartedevent",
|
|
2156
|
+
"ResponseValidationError": ".responsevalidationerror",
|
|
2147
2157
|
"RetrieveModelV1ModelsModelIDGetRequest": ".retrieve_model_v1_models_model_id_getop",
|
|
2148
2158
|
"RetrieveModelV1ModelsModelIDGetRequestTypedDict": ".retrieve_model_v1_models_model_id_getop",
|
|
2149
2159
|
"RetrieveModelV1ModelsModelIDGetResponseRetrieveModelV1ModelsModelIDGet": ".retrieve_model_v1_models_model_id_getop",
|
|
@@ -2268,6 +2278,18 @@ _dynamic_imports: dict[str, str] = {
|
|
|
2268
2278
|
}
|
|
2269
2279
|
|
|
2270
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
|
+
|
|
2271
2293
|
def __getattr__(attr_name: str) -> object:
|
|
2272
2294
|
module_name = _dynamic_imports.get(attr_name)
|
|
2273
2295
|
if module_name is None:
|
|
@@ -2276,7 +2298,7 @@ def __getattr__(attr_name: str) -> object:
|
|
|
2276
2298
|
)
|
|
2277
2299
|
|
|
2278
2300
|
try:
|
|
2279
|
-
module =
|
|
2301
|
+
module = dynamic_import(module_name)
|
|
2280
2302
|
result = getattr(module, attr_name)
|
|
2281
2303
|
return result
|
|
2282
2304
|
except ImportError as e:
|
|
@@ -2290,5 +2312,5 @@ def __getattr__(attr_name: str) -> object:
|
|
|
2290
2312
|
|
|
2291
2313
|
|
|
2292
2314
|
def __dir__():
|
|
2293
|
-
lazy_attrs = list(_dynamic_imports.keys())
|
|
2294
|
-
return sorted(lazy_attrs)
|
|
2315
|
+
lazy_attrs = builtins.list(_dynamic_imports.keys())
|
|
2316
|
+
return builtins.sorted(lazy_attrs)
|
|
@@ -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)
|