mistralai 1.8.2__py3-none-any.whl → 1.9.1__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 +7 -0
- mistralai/_version.py +3 -3
- mistralai/agents.py +8 -4
- mistralai/basesdk.py +12 -20
- mistralai/chat.py +8 -4
- mistralai/classifiers.py +8 -0
- mistralai/conversations.py +34 -14
- mistralai/embeddings.py +2 -0
- mistralai/extra/run/context.py +2 -4
- mistralai/files.py +12 -0
- mistralai/fim.py +4 -0
- mistralai/httpclient.py +6 -16
- mistralai/jobs.py +10 -0
- mistralai/mistral_agents.py +10 -0
- mistralai/mistral_jobs.py +8 -0
- mistralai/models/__init__.py +1356 -723
- mistralai/models/agent.py +1 -1
- mistralai/models/agentconversation.py +1 -1
- mistralai/models/agentcreationrequest.py +1 -1
- mistralai/models/agenthandoffentry.py +1 -1
- mistralai/models/agents_api_v1_conversations_getop.py +2 -0
- mistralai/models/agents_api_v1_conversations_historyop.py +2 -0
- mistralai/models/agents_api_v1_conversations_messagesop.py +2 -0
- mistralai/models/agents_api_v1_conversations_restart_streamop.py +2 -0
- mistralai/models/agents_api_v1_conversations_restartop.py +2 -0
- mistralai/models/agentscompletionrequest.py +3 -1
- mistralai/models/agentscompletionstreamrequest.py +3 -1
- mistralai/models/agentupdaterequest.py +1 -1
- mistralai/models/assistantmessage.py +1 -1
- mistralai/models/basemodelcard.py +8 -6
- mistralai/models/batchjobin.py +1 -1
- mistralai/models/batchjobout.py +1 -1
- mistralai/models/chatcompletionrequest.py +3 -1
- mistralai/models/chatcompletionstreamrequest.py +3 -1
- mistralai/models/classifierdetailedjobout.py +1 -1
- mistralai/models/classifierftmodelout.py +1 -1
- mistralai/models/classifierjobout.py +1 -1
- mistralai/models/classifiertargetin.py +1 -1
- mistralai/models/classifiertrainingparameters.py +1 -1
- mistralai/models/classifiertrainingparametersin.py +1 -1
- mistralai/models/completionargs.py +1 -1
- mistralai/models/completiondetailedjobout.py +1 -1
- mistralai/models/completionftmodelout.py +1 -1
- mistralai/models/completionjobout.py +1 -1
- mistralai/models/completionresponsestreamchoice.py +1 -1
- mistralai/models/completiontrainingparameters.py +1 -1
- mistralai/models/completiontrainingparametersin.py +1 -1
- mistralai/models/contentchunk.py +3 -0
- mistralai/models/conversationrequest.py +1 -1
- mistralai/models/conversationstreamrequest.py +1 -1
- mistralai/models/conversationusageinfo.py +1 -1
- mistralai/models/deltamessage.py +1 -1
- mistralai/models/documenturlchunk.py +1 -1
- mistralai/models/embeddingrequest.py +1 -1
- mistralai/models/eventout.py +1 -1
- mistralai/models/filechunk.py +23 -0
- mistralai/models/files_api_routes_list_filesop.py +1 -1
- mistralai/models/fileschema.py +1 -1
- mistralai/models/fimcompletionrequest.py +1 -1
- mistralai/models/fimcompletionstreamrequest.py +1 -1
- mistralai/models/ftmodelcard.py +9 -6
- mistralai/models/functioncallentry.py +1 -1
- mistralai/models/functionresultentry.py +1 -1
- mistralai/models/githubrepositoryin.py +1 -1
- mistralai/models/githubrepositoryout.py +1 -1
- mistralai/models/imageurl.py +1 -1
- mistralai/models/inputentries.py +21 -2
- mistralai/models/jobin.py +1 -1
- mistralai/models/jobmetadataout.py +1 -1
- mistralai/models/jobs_api_routes_batch_get_batch_jobsop.py +1 -1
- mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +1 -1
- mistralai/models/jsonschema.py +1 -1
- mistralai/models/legacyjobmetadataout.py +1 -1
- mistralai/models/messageinputentry.py +4 -4
- mistralai/models/messageoutputentry.py +1 -1
- mistralai/models/messageoutputevent.py +1 -1
- mistralai/models/metricout.py +1 -1
- mistralai/models/modelcapabilities.py +3 -0
- mistralai/models/modelconversation.py +1 -1
- mistralai/models/ocrimageobject.py +1 -1
- mistralai/models/ocrpageobject.py +1 -1
- mistralai/models/ocrrequest.py +5 -3
- mistralai/models/ocrresponse.py +1 -1
- mistralai/models/ocrusageinfo.py +1 -1
- mistralai/models/responseformat.py +1 -1
- mistralai/models/retrievefileout.py +1 -1
- mistralai/models/toolexecutionentry.py +1 -1
- mistralai/models/toolfilechunk.py +1 -1
- mistralai/models/toolmessage.py +1 -1
- mistralai/models/toolreferencechunk.py +1 -1
- mistralai/models/updateftmodelin.py +1 -1
- mistralai/models/uploadfileout.py +1 -1
- mistralai/models/usermessage.py +1 -1
- mistralai/models/wandbintegration.py +1 -1
- mistralai/models/wandbintegrationout.py +1 -1
- mistralai/models_.py +14 -2
- mistralai/ocr.py +2 -0
- mistralai/sdk.py +68 -40
- mistralai/sdkconfiguration.py +0 -7
- mistralai/types/basemodel.py +3 -3
- mistralai/utils/__init__.py +131 -45
- mistralai/utils/datetimes.py +23 -0
- mistralai/utils/enums.py +67 -27
- mistralai/utils/forms.py +49 -28
- mistralai/utils/serializers.py +32 -3
- {mistralai-1.8.2.dist-info → mistralai-1.9.1.dist-info}/METADATA +13 -6
- {mistralai-1.8.2.dist-info → mistralai-1.9.1.dist-info}/RECORD +109 -107
- {mistralai-1.8.2.dist-info → mistralai-1.9.1.dist-info}/LICENSE +0 -0
- {mistralai-1.8.2.dist-info → mistralai-1.9.1.dist-info}/WHEEL +0 -0
mistralai/sdk.py
CHANGED
|
@@ -6,46 +6,62 @@ from .sdkconfiguration import SDKConfiguration
|
|
|
6
6
|
from .utils.logger import Logger, get_default_logger
|
|
7
7
|
from .utils.retries import RetryConfig
|
|
8
8
|
import httpx
|
|
9
|
+
import importlib
|
|
9
10
|
from mistralai import models, utils
|
|
10
11
|
from mistralai._hooks import SDKHooks
|
|
11
|
-
from mistralai.agents import Agents
|
|
12
|
-
from mistralai.batch import Batch
|
|
13
|
-
from mistralai.beta import Beta
|
|
14
|
-
from mistralai.chat import Chat
|
|
15
|
-
from mistralai.classifiers import Classifiers
|
|
16
|
-
from mistralai.embeddings import Embeddings
|
|
17
|
-
from mistralai.files import Files
|
|
18
|
-
from mistralai.fim import Fim
|
|
19
|
-
from mistralai.fine_tuning import FineTuning
|
|
20
|
-
from mistralai.models_ import Models
|
|
21
|
-
from mistralai.ocr import Ocr
|
|
22
12
|
from mistralai.types import OptionalNullable, UNSET
|
|
23
|
-
from typing import Any, Callable, Dict, Optional, Union, cast
|
|
13
|
+
from typing import Any, Callable, Dict, Optional, TYPE_CHECKING, Union, cast
|
|
24
14
|
import weakref
|
|
25
15
|
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from mistralai.agents import Agents
|
|
18
|
+
from mistralai.batch import Batch
|
|
19
|
+
from mistralai.beta import Beta
|
|
20
|
+
from mistralai.chat import Chat
|
|
21
|
+
from mistralai.classifiers import Classifiers
|
|
22
|
+
from mistralai.embeddings import Embeddings
|
|
23
|
+
from mistralai.files import Files
|
|
24
|
+
from mistralai.fim import Fim
|
|
25
|
+
from mistralai.fine_tuning import FineTuning
|
|
26
|
+
from mistralai.models_ import Models
|
|
27
|
+
from mistralai.ocr import Ocr
|
|
28
|
+
|
|
26
29
|
|
|
27
30
|
class Mistral(BaseSDK):
|
|
28
31
|
r"""Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create your account on [La Plateforme](https://console.mistral.ai) to get access and read the [docs](https://docs.mistral.ai) to learn how to use it."""
|
|
29
32
|
|
|
30
|
-
models: Models
|
|
33
|
+
models: "Models"
|
|
31
34
|
r"""Model Management API"""
|
|
32
|
-
beta: Beta
|
|
33
|
-
files: Files
|
|
35
|
+
beta: "Beta"
|
|
36
|
+
files: "Files"
|
|
34
37
|
r"""Files API"""
|
|
35
|
-
fine_tuning: FineTuning
|
|
36
|
-
batch: Batch
|
|
37
|
-
chat: Chat
|
|
38
|
+
fine_tuning: "FineTuning"
|
|
39
|
+
batch: "Batch"
|
|
40
|
+
chat: "Chat"
|
|
38
41
|
r"""Chat Completion API."""
|
|
39
|
-
fim: Fim
|
|
42
|
+
fim: "Fim"
|
|
40
43
|
r"""Fill-in-the-middle API."""
|
|
41
|
-
agents: Agents
|
|
44
|
+
agents: "Agents"
|
|
42
45
|
r"""Agents API."""
|
|
43
|
-
embeddings: Embeddings
|
|
46
|
+
embeddings: "Embeddings"
|
|
44
47
|
r"""Embeddings API."""
|
|
45
|
-
classifiers: Classifiers
|
|
48
|
+
classifiers: "Classifiers"
|
|
46
49
|
r"""Classifiers API."""
|
|
47
|
-
ocr: Ocr
|
|
50
|
+
ocr: "Ocr"
|
|
48
51
|
r"""OCR API"""
|
|
52
|
+
_sub_sdk_map = {
|
|
53
|
+
"models": ("mistralai.models_", "Models"),
|
|
54
|
+
"beta": ("mistralai.beta", "Beta"),
|
|
55
|
+
"files": ("mistralai.files", "Files"),
|
|
56
|
+
"fine_tuning": ("mistralai.fine_tuning", "FineTuning"),
|
|
57
|
+
"batch": ("mistralai.batch", "Batch"),
|
|
58
|
+
"chat": ("mistralai.chat", "Chat"),
|
|
59
|
+
"fim": ("mistralai.fim", "Fim"),
|
|
60
|
+
"agents": ("mistralai.agents", "Agents"),
|
|
61
|
+
"embeddings": ("mistralai.embeddings", "Embeddings"),
|
|
62
|
+
"classifiers": ("mistralai.classifiers", "Classifiers"),
|
|
63
|
+
"ocr": ("mistralai.ocr", "Ocr"),
|
|
64
|
+
}
|
|
49
65
|
|
|
50
66
|
def __init__(
|
|
51
67
|
self,
|
|
@@ -120,6 +136,9 @@ class Mistral(BaseSDK):
|
|
|
120
136
|
|
|
121
137
|
hooks = SDKHooks()
|
|
122
138
|
|
|
139
|
+
# pylint: disable=protected-access
|
|
140
|
+
self.sdk_configuration.__dict__["_hooks"] = hooks
|
|
141
|
+
|
|
123
142
|
current_server_url, *_ = self.sdk_configuration.get_server_details()
|
|
124
143
|
server_url, self.sdk_configuration.client = hooks.sdk_init(
|
|
125
144
|
current_server_url, client
|
|
@@ -127,9 +146,6 @@ class Mistral(BaseSDK):
|
|
|
127
146
|
if current_server_url != server_url:
|
|
128
147
|
self.sdk_configuration.server_url = server_url
|
|
129
148
|
|
|
130
|
-
# pylint: disable=protected-access
|
|
131
|
-
self.sdk_configuration.__dict__["_hooks"] = hooks
|
|
132
|
-
|
|
133
149
|
weakref.finalize(
|
|
134
150
|
self,
|
|
135
151
|
close_clients,
|
|
@@ -140,20 +156,32 @@ class Mistral(BaseSDK):
|
|
|
140
156
|
self.sdk_configuration.async_client_supplied,
|
|
141
157
|
)
|
|
142
158
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
def __getattr__(self, name: str):
|
|
160
|
+
if name in self._sub_sdk_map:
|
|
161
|
+
module_path, class_name = self._sub_sdk_map[name]
|
|
162
|
+
try:
|
|
163
|
+
module = importlib.import_module(module_path)
|
|
164
|
+
klass = getattr(module, class_name)
|
|
165
|
+
instance = klass(self.sdk_configuration)
|
|
166
|
+
setattr(self, name, instance)
|
|
167
|
+
return instance
|
|
168
|
+
except ImportError as e:
|
|
169
|
+
raise AttributeError(
|
|
170
|
+
f"Failed to import module {module_path} for attribute {name}: {e}"
|
|
171
|
+
) from e
|
|
172
|
+
except AttributeError as e:
|
|
173
|
+
raise AttributeError(
|
|
174
|
+
f"Failed to find class {class_name} in module {module_path} for attribute {name}: {e}"
|
|
175
|
+
) from e
|
|
176
|
+
|
|
177
|
+
raise AttributeError(
|
|
178
|
+
f"'{type(self).__name__}' object has no attribute '{name}'"
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
def __dir__(self):
|
|
182
|
+
default_attrs = list(super().__dir__())
|
|
183
|
+
lazy_attrs = list(self._sub_sdk_map.keys())
|
|
184
|
+
return sorted(list(set(default_attrs + lazy_attrs)))
|
|
157
185
|
|
|
158
186
|
def __enter__(self):
|
|
159
187
|
return self
|
mistralai/sdkconfiguration.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
|
-
from ._hooks import SDKHooks
|
|
4
3
|
from ._version import (
|
|
5
4
|
__gen_version__,
|
|
6
5
|
__openapi_doc_version__,
|
|
@@ -42,9 +41,6 @@ class SDKConfiguration:
|
|
|
42
41
|
retry_config: OptionalNullable[RetryConfig] = Field(default_factory=lambda: UNSET)
|
|
43
42
|
timeout_ms: Optional[int] = None
|
|
44
43
|
|
|
45
|
-
def __post_init__(self):
|
|
46
|
-
self._hooks = SDKHooks()
|
|
47
|
-
|
|
48
44
|
def get_server_details(self) -> Tuple[str, Dict[str, str]]:
|
|
49
45
|
if self.server_url is not None and self.server_url:
|
|
50
46
|
return remove_suffix(self.server_url, "/"), {}
|
|
@@ -55,6 +51,3 @@ class SDKConfiguration:
|
|
|
55
51
|
raise ValueError(f'Invalid server "{self.server}"')
|
|
56
52
|
|
|
57
53
|
return SERVERS[self.server], {}
|
|
58
|
-
|
|
59
|
-
def get_hooks(self) -> SDKHooks:
|
|
60
|
-
return self._hooks
|
mistralai/types/basemodel.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from pydantic import ConfigDict, model_serializer
|
|
4
4
|
from pydantic import BaseModel as PydanticBaseModel
|
|
5
|
-
from typing import TYPE_CHECKING, Literal, Optional, TypeVar, Union
|
|
5
|
+
from typing import TYPE_CHECKING, Literal, Optional, TypeVar, Union
|
|
6
6
|
from typing_extensions import TypeAliasType, TypeAlias
|
|
7
7
|
|
|
8
8
|
|
|
@@ -35,5 +35,5 @@ else:
|
|
|
35
35
|
"OptionalNullable", Union[Optional[Nullable[T]], Unset], type_params=(T,)
|
|
36
36
|
)
|
|
37
37
|
|
|
38
|
-
UnrecognizedInt =
|
|
39
|
-
UnrecognizedStr =
|
|
38
|
+
UnrecognizedInt: TypeAlias = int
|
|
39
|
+
UnrecognizedStr: TypeAlias = str
|
mistralai/utils/__init__.py
CHANGED
|
@@ -1,51 +1,56 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from
|
|
5
|
-
from .headers import get_headers, get_response_headers
|
|
6
|
-
from .metadata import (
|
|
7
|
-
FieldMetadata,
|
|
8
|
-
find_metadata,
|
|
9
|
-
FormMetadata,
|
|
10
|
-
HeaderMetadata,
|
|
11
|
-
MultipartFormMetadata,
|
|
12
|
-
PathParamMetadata,
|
|
13
|
-
QueryParamMetadata,
|
|
14
|
-
RequestMetadata,
|
|
15
|
-
SecurityMetadata,
|
|
16
|
-
)
|
|
17
|
-
from .queryparams import get_query_params
|
|
18
|
-
from .retries import BackoffStrategy, Retries, retry, retry_async, RetryConfig
|
|
19
|
-
from .requestbodies import serialize_request_body, SerializedRequestBody
|
|
20
|
-
from .security import get_security, get_security_from_env
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
from importlib import import_module
|
|
21
5
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
from .
|
|
41
|
-
from .
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from .annotations import get_discriminator
|
|
8
|
+
from .datetimes import parse_datetime
|
|
9
|
+
from .enums import OpenEnumMeta
|
|
10
|
+
from .headers import get_headers, get_response_headers
|
|
11
|
+
from .metadata import (
|
|
12
|
+
FieldMetadata,
|
|
13
|
+
find_metadata,
|
|
14
|
+
FormMetadata,
|
|
15
|
+
HeaderMetadata,
|
|
16
|
+
MultipartFormMetadata,
|
|
17
|
+
PathParamMetadata,
|
|
18
|
+
QueryParamMetadata,
|
|
19
|
+
RequestMetadata,
|
|
20
|
+
SecurityMetadata,
|
|
21
|
+
)
|
|
22
|
+
from .queryparams import get_query_params
|
|
23
|
+
from .retries import BackoffStrategy, Retries, retry, retry_async, RetryConfig
|
|
24
|
+
from .requestbodies import serialize_request_body, SerializedRequestBody
|
|
25
|
+
from .security import get_security, get_security_from_env
|
|
26
|
+
|
|
27
|
+
from .serializers import (
|
|
28
|
+
get_pydantic_model,
|
|
29
|
+
marshal_json,
|
|
30
|
+
unmarshal,
|
|
31
|
+
unmarshal_json,
|
|
32
|
+
serialize_decimal,
|
|
33
|
+
serialize_float,
|
|
34
|
+
serialize_int,
|
|
35
|
+
stream_to_text,
|
|
36
|
+
stream_to_text_async,
|
|
37
|
+
stream_to_bytes,
|
|
38
|
+
stream_to_bytes_async,
|
|
39
|
+
validate_const,
|
|
40
|
+
validate_decimal,
|
|
41
|
+
validate_float,
|
|
42
|
+
validate_int,
|
|
43
|
+
validate_open_enum,
|
|
44
|
+
)
|
|
45
|
+
from .url import generate_url, template_url, remove_suffix
|
|
46
|
+
from .values import (
|
|
47
|
+
get_global_from_env,
|
|
48
|
+
match_content_type,
|
|
49
|
+
match_status_codes,
|
|
50
|
+
match_response,
|
|
51
|
+
cast_partial,
|
|
52
|
+
)
|
|
53
|
+
from .logger import Logger, get_body_content, get_default_logger
|
|
49
54
|
|
|
50
55
|
__all__ = [
|
|
51
56
|
"BackoffStrategy",
|
|
@@ -56,6 +61,7 @@ __all__ = [
|
|
|
56
61
|
"get_body_content",
|
|
57
62
|
"get_default_logger",
|
|
58
63
|
"get_discriminator",
|
|
64
|
+
"parse_datetime",
|
|
59
65
|
"get_global_from_env",
|
|
60
66
|
"get_headers",
|
|
61
67
|
"get_pydantic_model",
|
|
@@ -99,3 +105,83 @@ __all__ = [
|
|
|
99
105
|
"validate_open_enum",
|
|
100
106
|
"cast_partial",
|
|
101
107
|
]
|
|
108
|
+
|
|
109
|
+
_dynamic_imports: dict[str, str] = {
|
|
110
|
+
"BackoffStrategy": ".retries",
|
|
111
|
+
"FieldMetadata": ".metadata",
|
|
112
|
+
"find_metadata": ".metadata",
|
|
113
|
+
"FormMetadata": ".metadata",
|
|
114
|
+
"generate_url": ".url",
|
|
115
|
+
"get_body_content": ".logger",
|
|
116
|
+
"get_default_logger": ".logger",
|
|
117
|
+
"get_discriminator": ".annotations",
|
|
118
|
+
"parse_datetime": ".datetimes",
|
|
119
|
+
"get_global_from_env": ".values",
|
|
120
|
+
"get_headers": ".headers",
|
|
121
|
+
"get_pydantic_model": ".serializers",
|
|
122
|
+
"get_query_params": ".queryparams",
|
|
123
|
+
"get_response_headers": ".headers",
|
|
124
|
+
"get_security": ".security",
|
|
125
|
+
"get_security_from_env": ".security",
|
|
126
|
+
"HeaderMetadata": ".metadata",
|
|
127
|
+
"Logger": ".logger",
|
|
128
|
+
"marshal_json": ".serializers",
|
|
129
|
+
"match_content_type": ".values",
|
|
130
|
+
"match_status_codes": ".values",
|
|
131
|
+
"match_response": ".values",
|
|
132
|
+
"MultipartFormMetadata": ".metadata",
|
|
133
|
+
"OpenEnumMeta": ".enums",
|
|
134
|
+
"PathParamMetadata": ".metadata",
|
|
135
|
+
"QueryParamMetadata": ".metadata",
|
|
136
|
+
"remove_suffix": ".url",
|
|
137
|
+
"Retries": ".retries",
|
|
138
|
+
"retry": ".retries",
|
|
139
|
+
"retry_async": ".retries",
|
|
140
|
+
"RetryConfig": ".retries",
|
|
141
|
+
"RequestMetadata": ".metadata",
|
|
142
|
+
"SecurityMetadata": ".metadata",
|
|
143
|
+
"serialize_decimal": ".serializers",
|
|
144
|
+
"serialize_float": ".serializers",
|
|
145
|
+
"serialize_int": ".serializers",
|
|
146
|
+
"serialize_request_body": ".requestbodies",
|
|
147
|
+
"SerializedRequestBody": ".requestbodies",
|
|
148
|
+
"stream_to_text": ".serializers",
|
|
149
|
+
"stream_to_text_async": ".serializers",
|
|
150
|
+
"stream_to_bytes": ".serializers",
|
|
151
|
+
"stream_to_bytes_async": ".serializers",
|
|
152
|
+
"template_url": ".url",
|
|
153
|
+
"unmarshal": ".serializers",
|
|
154
|
+
"unmarshal_json": ".serializers",
|
|
155
|
+
"validate_decimal": ".serializers",
|
|
156
|
+
"validate_const": ".serializers",
|
|
157
|
+
"validate_float": ".serializers",
|
|
158
|
+
"validate_int": ".serializers",
|
|
159
|
+
"validate_open_enum": ".serializers",
|
|
160
|
+
"cast_partial": ".values",
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def __getattr__(attr_name: str) -> object:
|
|
165
|
+
module_name = _dynamic_imports.get(attr_name)
|
|
166
|
+
if module_name is None:
|
|
167
|
+
raise AttributeError(
|
|
168
|
+
f"no {attr_name} found in _dynamic_imports, module name -> {__name__} "
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
try:
|
|
172
|
+
module = import_module(module_name, __package__)
|
|
173
|
+
result = getattr(module, attr_name)
|
|
174
|
+
return result
|
|
175
|
+
except ImportError as e:
|
|
176
|
+
raise ImportError(
|
|
177
|
+
f"Failed to import {attr_name} from {module_name}: {e}"
|
|
178
|
+
) from e
|
|
179
|
+
except AttributeError as e:
|
|
180
|
+
raise AttributeError(
|
|
181
|
+
f"Failed to get {attr_name} from {module_name}: {e}"
|
|
182
|
+
) from e
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def __dir__():
|
|
186
|
+
lazy_attrs = list(_dynamic_imports.keys())
|
|
187
|
+
return sorted(lazy_attrs)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def parse_datetime(datetime_string: str) -> datetime:
|
|
8
|
+
"""
|
|
9
|
+
Convert a RFC 3339 / ISO 8601 formatted string into a datetime object.
|
|
10
|
+
Python versions 3.11 and later support parsing RFC 3339 directly with
|
|
11
|
+
datetime.fromisoformat(), but for earlier versions, this function
|
|
12
|
+
encapsulates the necessary extra logic.
|
|
13
|
+
"""
|
|
14
|
+
# Python 3.11 and later can parse RFC 3339 directly
|
|
15
|
+
if sys.version_info >= (3, 11):
|
|
16
|
+
return datetime.fromisoformat(datetime_string)
|
|
17
|
+
|
|
18
|
+
# For Python 3.10 and earlier, a common ValueError is trailing 'Z' suffix,
|
|
19
|
+
# so fix that upfront.
|
|
20
|
+
if datetime_string.endswith("Z"):
|
|
21
|
+
datetime_string = datetime_string[:-1] + "+00:00"
|
|
22
|
+
|
|
23
|
+
return datetime.fromisoformat(datetime_string)
|
mistralai/utils/enums.py
CHANGED
|
@@ -1,34 +1,74 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
import enum
|
|
4
|
-
|
|
4
|
+
import sys
|
|
5
5
|
|
|
6
6
|
class OpenEnumMeta(enum.EnumMeta):
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
# The __call__ method `boundary` kwarg was added in 3.11 and must be present
|
|
8
|
+
# for pyright. Refer also: https://github.com/pylint-dev/pylint/issues/9622
|
|
9
|
+
# pylint: disable=unexpected-keyword-arg
|
|
10
|
+
# The __call__ method `values` varg must be named for pyright.
|
|
11
|
+
# pylint: disable=keyword-arg-before-vararg
|
|
12
|
+
|
|
13
|
+
if sys.version_info >= (3, 11):
|
|
14
|
+
def __call__(
|
|
15
|
+
cls, value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None
|
|
16
|
+
):
|
|
17
|
+
# The `type` kwarg also happens to be a built-in that pylint flags as
|
|
18
|
+
# redeclared. Safe to ignore this lint rule with this scope.
|
|
19
|
+
# pylint: disable=redefined-builtin
|
|
20
|
+
|
|
21
|
+
if names is not None:
|
|
22
|
+
return super().__call__(
|
|
23
|
+
value,
|
|
24
|
+
names=names,
|
|
25
|
+
*values,
|
|
26
|
+
module=module,
|
|
27
|
+
qualname=qualname,
|
|
28
|
+
type=type,
|
|
29
|
+
start=start,
|
|
30
|
+
boundary=boundary,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
return super().__call__(
|
|
35
|
+
value,
|
|
36
|
+
names=names, # pyright: ignore[reportArgumentType]
|
|
37
|
+
*values,
|
|
38
|
+
module=module,
|
|
39
|
+
qualname=qualname,
|
|
40
|
+
type=type,
|
|
41
|
+
start=start,
|
|
42
|
+
boundary=boundary,
|
|
43
|
+
)
|
|
44
|
+
except ValueError:
|
|
45
|
+
return value
|
|
46
|
+
else:
|
|
47
|
+
def __call__(
|
|
48
|
+
cls, value, names=None, *, module=None, qualname=None, type=None, start=1
|
|
49
|
+
):
|
|
50
|
+
# The `type` kwarg also happens to be a built-in that pylint flags as
|
|
51
|
+
# redeclared. Safe to ignore this lint rule with this scope.
|
|
52
|
+
# pylint: disable=redefined-builtin
|
|
13
53
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
54
|
+
if names is not None:
|
|
55
|
+
return super().__call__(
|
|
56
|
+
value,
|
|
57
|
+
names=names,
|
|
58
|
+
module=module,
|
|
59
|
+
qualname=qualname,
|
|
60
|
+
type=type,
|
|
61
|
+
start=start,
|
|
62
|
+
)
|
|
23
63
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
64
|
+
try:
|
|
65
|
+
return super().__call__(
|
|
66
|
+
value,
|
|
67
|
+
names=names, # pyright: ignore[reportArgumentType]
|
|
68
|
+
module=module,
|
|
69
|
+
qualname=qualname,
|
|
70
|
+
type=type,
|
|
71
|
+
start=start,
|
|
72
|
+
)
|
|
73
|
+
except ValueError:
|
|
74
|
+
return value
|
mistralai/utils/forms.py
CHANGED
|
@@ -86,11 +86,39 @@ def _populate_form(
|
|
|
86
86
|
return form
|
|
87
87
|
|
|
88
88
|
|
|
89
|
+
def _extract_file_properties(file_obj: Any) -> Tuple[str, Any, Any]:
|
|
90
|
+
"""Extract file name, content, and content type from a file object."""
|
|
91
|
+
file_fields: Dict[str, FieldInfo] = file_obj.__class__.model_fields
|
|
92
|
+
|
|
93
|
+
file_name = ""
|
|
94
|
+
content = None
|
|
95
|
+
content_type = None
|
|
96
|
+
|
|
97
|
+
for file_field_name in file_fields:
|
|
98
|
+
file_field = file_fields[file_field_name]
|
|
99
|
+
|
|
100
|
+
file_metadata = find_field_metadata(file_field, MultipartFormMetadata)
|
|
101
|
+
if file_metadata is None:
|
|
102
|
+
continue
|
|
103
|
+
|
|
104
|
+
if file_metadata.content:
|
|
105
|
+
content = getattr(file_obj, file_field_name, None)
|
|
106
|
+
elif file_field_name == "content_type":
|
|
107
|
+
content_type = getattr(file_obj, file_field_name, None)
|
|
108
|
+
else:
|
|
109
|
+
file_name = getattr(file_obj, file_field_name)
|
|
110
|
+
|
|
111
|
+
if file_name == "" or content is None:
|
|
112
|
+
raise ValueError("invalid multipart/form-data file")
|
|
113
|
+
|
|
114
|
+
return file_name, content, content_type
|
|
115
|
+
|
|
116
|
+
|
|
89
117
|
def serialize_multipart_form(
|
|
90
118
|
media_type: str, request: Any
|
|
91
|
-
) -> Tuple[str, Dict[str, Any],
|
|
119
|
+
) -> Tuple[str, Dict[str, Any], List[Tuple[str, Any]]]:
|
|
92
120
|
form: Dict[str, Any] = {}
|
|
93
|
-
files:
|
|
121
|
+
files: List[Tuple[str, Any]] = []
|
|
94
122
|
|
|
95
123
|
if not isinstance(request, BaseModel):
|
|
96
124
|
raise TypeError("invalid request body type")
|
|
@@ -112,39 +140,32 @@ def serialize_multipart_form(
|
|
|
112
140
|
f_name = field.alias if field.alias else name
|
|
113
141
|
|
|
114
142
|
if field_metadata.file:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
file_field = file_fields[file_field_name]
|
|
143
|
+
if isinstance(val, List):
|
|
144
|
+
# Handle array of files
|
|
145
|
+
for file_obj in val:
|
|
146
|
+
if not _is_set(file_obj):
|
|
147
|
+
continue
|
|
148
|
+
|
|
149
|
+
file_name, content, content_type = _extract_file_properties(file_obj)
|
|
123
150
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
151
|
+
if content_type is not None:
|
|
152
|
+
files.append((f_name + "[]", (file_name, content, content_type)))
|
|
153
|
+
else:
|
|
154
|
+
files.append((f_name + "[]", (file_name, content)))
|
|
155
|
+
else:
|
|
156
|
+
# Handle single file
|
|
157
|
+
file_name, content, content_type = _extract_file_properties(val)
|
|
127
158
|
|
|
128
|
-
if
|
|
129
|
-
|
|
130
|
-
elif file_field_name == "content_type":
|
|
131
|
-
content_type = getattr(val, file_field_name, None)
|
|
159
|
+
if content_type is not None:
|
|
160
|
+
files.append((f_name, (file_name, content, content_type)))
|
|
132
161
|
else:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if file_name == "" or content is None:
|
|
136
|
-
raise ValueError("invalid multipart/form-data file")
|
|
137
|
-
|
|
138
|
-
if content_type is not None:
|
|
139
|
-
files[f_name] = (file_name, content, content_type)
|
|
140
|
-
else:
|
|
141
|
-
files[f_name] = (file_name, content)
|
|
162
|
+
files.append((f_name, (file_name, content)))
|
|
142
163
|
elif field_metadata.json:
|
|
143
|
-
files
|
|
164
|
+
files.append((f_name, (
|
|
144
165
|
None,
|
|
145
166
|
marshal_json(val, request_field_types[name]),
|
|
146
167
|
"application/json",
|
|
147
|
-
)
|
|
168
|
+
)))
|
|
148
169
|
else:
|
|
149
170
|
if isinstance(val, List):
|
|
150
171
|
values = []
|
mistralai/utils/serializers.py
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from decimal import Decimal
|
|
4
|
+
import functools
|
|
4
5
|
import json
|
|
5
|
-
|
|
6
|
-
import
|
|
6
|
+
import typing
|
|
7
|
+
from typing import Any, Dict, List, Tuple, Union, get_args
|
|
8
|
+
import typing_extensions
|
|
7
9
|
from typing_extensions import get_origin
|
|
10
|
+
|
|
11
|
+
import httpx
|
|
8
12
|
from pydantic import ConfigDict, create_model
|
|
9
13
|
from pydantic_core import from_json
|
|
10
|
-
from typing_inspection.typing_objects import is_union
|
|
11
14
|
|
|
12
15
|
from ..types.basemodel import BaseModel, Nullable, OptionalNullable, Unset
|
|
13
16
|
|
|
@@ -185,6 +188,13 @@ def is_nullable(field):
|
|
|
185
188
|
return False
|
|
186
189
|
|
|
187
190
|
|
|
191
|
+
def is_union(obj: object) -> bool:
|
|
192
|
+
"""
|
|
193
|
+
Returns True if the given object is a typing.Union or typing_extensions.Union.
|
|
194
|
+
"""
|
|
195
|
+
return any(obj is typing_obj for typing_obj in _get_typing_objects_by_name_of("Union"))
|
|
196
|
+
|
|
197
|
+
|
|
188
198
|
def stream_to_text(stream: httpx.Response) -> str:
|
|
189
199
|
return "".join(stream.iter_text())
|
|
190
200
|
|
|
@@ -217,3 +227,22 @@ def _contains_pydantic_model(data: Any) -> bool:
|
|
|
217
227
|
return any(_contains_pydantic_model(value) for value in data.values())
|
|
218
228
|
|
|
219
229
|
return False
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
@functools.cache
|
|
233
|
+
def _get_typing_objects_by_name_of(name: str) -> Tuple[Any, ...]:
|
|
234
|
+
"""
|
|
235
|
+
Get typing objects by name from typing and typing_extensions.
|
|
236
|
+
Reference: https://typing-extensions.readthedocs.io/en/latest/#runtime-use-of-types
|
|
237
|
+
"""
|
|
238
|
+
result = tuple(
|
|
239
|
+
getattr(module, name)
|
|
240
|
+
for module in (typing, typing_extensions)
|
|
241
|
+
if hasattr(module, name)
|
|
242
|
+
)
|
|
243
|
+
if not result:
|
|
244
|
+
raise ValueError(
|
|
245
|
+
f"Neither typing nor typing_extensions has an object called {name!r}"
|
|
246
|
+
)
|
|
247
|
+
return result
|
|
248
|
+
|