mistralai 1.0.2__py3-none-any.whl → 1.1.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/sdkhooks.py +23 -4
- mistralai/_hooks/types.py +27 -9
- mistralai/agents.py +286 -150
- mistralai/basesdk.py +90 -5
- mistralai/chat.py +260 -144
- mistralai/embeddings.py +73 -53
- mistralai/files.py +252 -192
- mistralai/fim.py +174 -110
- mistralai/fine_tuning.py +3 -2
- mistralai/jobs.py +372 -263
- mistralai/models/__init__.py +499 -46
- mistralai/models/agentscompletionrequest.py +47 -11
- mistralai/models/agentscompletionstreamrequest.py +49 -11
- mistralai/models/archiveftmodelout.py +6 -2
- mistralai/models/assistantmessage.py +11 -4
- mistralai/models/{modelcard.py → basemodelcard.py} +37 -14
- mistralai/models/chatcompletionchoice.py +4 -2
- mistralai/models/chatcompletionrequest.py +57 -11
- mistralai/models/chatcompletionresponse.py +6 -2
- mistralai/models/chatcompletionstreamrequest.py +59 -11
- mistralai/models/checkpointout.py +3 -2
- mistralai/models/completionchunk.py +10 -3
- mistralai/models/completionevent.py +1 -2
- mistralai/models/completionresponsestreamchoice.py +13 -5
- mistralai/models/contentchunk.py +13 -10
- mistralai/models/delete_model_v1_models_model_id_deleteop.py +4 -3
- mistralai/models/deletefileout.py +3 -2
- mistralai/models/deletemodelout.py +3 -2
- mistralai/models/deltamessage.py +9 -4
- mistralai/models/detailedjobout.py +59 -7
- mistralai/models/embeddingrequest.py +9 -4
- mistralai/models/embeddingresponse.py +5 -2
- mistralai/models/embeddingresponsedata.py +3 -2
- mistralai/models/eventout.py +9 -4
- mistralai/models/files_api_routes_delete_fileop.py +4 -3
- mistralai/models/files_api_routes_retrieve_fileop.py +4 -3
- mistralai/models/files_api_routes_upload_fileop.py +27 -8
- mistralai/models/fileschema.py +26 -5
- mistralai/models/fimcompletionrequest.py +26 -5
- mistralai/models/fimcompletionresponse.py +6 -2
- mistralai/models/fimcompletionstreamrequest.py +26 -5
- mistralai/models/finetuneablemodel.py +7 -1
- mistralai/models/ftmodelcapabilitiesout.py +4 -2
- mistralai/models/ftmodelcard.py +103 -0
- mistralai/models/ftmodelout.py +32 -6
- mistralai/models/function.py +3 -2
- mistralai/models/functioncall.py +2 -2
- mistralai/models/functionname.py +17 -0
- mistralai/models/githubrepositoryin.py +15 -4
- mistralai/models/githubrepositoryout.py +15 -4
- mistralai/models/httpvalidationerror.py +2 -2
- mistralai/models/imageurl.py +48 -0
- mistralai/models/imageurlchunk.py +32 -0
- mistralai/models/jobin.py +22 -5
- mistralai/models/jobmetadataout.py +31 -6
- mistralai/models/jobout.py +55 -7
- mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +3 -2
- mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +83 -16
- mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +9 -4
- mistralai/models/jobsout.py +6 -2
- mistralai/models/legacyjobmetadataout.py +45 -6
- mistralai/models/listfilesout.py +2 -2
- mistralai/models/metricout.py +11 -6
- mistralai/models/modelcapabilities.py +7 -2
- mistralai/models/modellist.py +21 -7
- mistralai/models/responseformat.py +6 -7
- mistralai/models/responseformats.py +8 -0
- mistralai/models/retrieve_model_v1_models_model_id_getop.py +24 -5
- mistralai/models/retrievefileout.py +26 -5
- mistralai/models/security.py +12 -3
- mistralai/models/systemmessage.py +6 -5
- mistralai/models/textchunk.py +9 -4
- mistralai/models/tool.py +9 -8
- mistralai/models/toolcall.py +9 -7
- mistralai/models/toolchoice.py +29 -0
- mistralai/models/toolchoiceenum.py +7 -0
- mistralai/models/toolmessage.py +11 -4
- mistralai/models/tooltypes.py +8 -0
- mistralai/models/trainingfile.py +2 -2
- mistralai/models/trainingparameters.py +27 -6
- mistralai/models/trainingparametersin.py +29 -8
- mistralai/models/unarchiveftmodelout.py +6 -2
- mistralai/models/updateftmodelin.py +8 -4
- mistralai/models/uploadfileout.py +26 -5
- mistralai/models/usageinfo.py +3 -2
- mistralai/models/usermessage.py +6 -5
- mistralai/models/validationerror.py +3 -2
- mistralai/models/wandbintegration.py +14 -4
- mistralai/models/wandbintegrationout.py +13 -4
- mistralai/models_.py +392 -294
- mistralai/sdk.py +24 -19
- mistralai/sdkconfiguration.py +6 -8
- mistralai/utils/__init__.py +6 -1
- mistralai/utils/logger.py +4 -1
- mistralai/utils/retries.py +2 -1
- mistralai/utils/security.py +13 -6
- {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/METADATA +103 -74
- mistralai-1.1.0.dist-info/RECORD +254 -0
- mistralai_azure/_hooks/sdkhooks.py +23 -4
- mistralai_azure/_hooks/types.py +27 -9
- mistralai_azure/basesdk.py +91 -6
- mistralai_azure/chat.py +252 -144
- mistralai_azure/models/__init__.py +157 -15
- mistralai_azure/models/assistantmessage.py +18 -5
- mistralai_azure/models/chatcompletionchoice.py +7 -3
- mistralai_azure/models/chatcompletionrequest.py +65 -12
- mistralai_azure/models/chatcompletionresponse.py +6 -2
- mistralai_azure/models/chatcompletionstreamrequest.py +67 -12
- mistralai_azure/models/completionchunk.py +10 -3
- mistralai_azure/models/completionevent.py +1 -2
- mistralai_azure/models/completionresponsestreamchoice.py +10 -4
- mistralai_azure/models/contentchunk.py +4 -11
- mistralai_azure/models/deltamessage.py +16 -5
- mistralai_azure/models/function.py +3 -2
- mistralai_azure/models/functioncall.py +2 -2
- mistralai_azure/models/functionname.py +17 -0
- mistralai_azure/models/httpvalidationerror.py +2 -2
- mistralai_azure/models/responseformat.py +6 -7
- mistralai_azure/models/responseformats.py +8 -0
- mistralai_azure/models/security.py +12 -3
- mistralai_azure/models/systemmessage.py +6 -5
- mistralai_azure/models/textchunk.py +9 -4
- mistralai_azure/models/tool.py +9 -8
- mistralai_azure/models/toolcall.py +9 -7
- mistralai_azure/models/toolchoice.py +29 -0
- mistralai_azure/models/toolchoiceenum.py +7 -0
- mistralai_azure/models/toolmessage.py +18 -5
- mistralai_azure/models/tooltypes.py +8 -0
- mistralai_azure/models/usageinfo.py +3 -2
- mistralai_azure/models/usermessage.py +6 -5
- mistralai_azure/models/validationerror.py +3 -2
- mistralai_azure/sdkconfiguration.py +6 -8
- mistralai_azure/utils/__init__.py +8 -3
- mistralai_azure/utils/forms.py +10 -9
- mistralai_azure/utils/headers.py +8 -8
- mistralai_azure/utils/logger.py +6 -0
- mistralai_azure/utils/queryparams.py +16 -14
- mistralai_azure/utils/retries.py +2 -1
- mistralai_azure/utils/security.py +12 -6
- mistralai_azure/utils/serializers.py +17 -8
- mistralai_azure/utils/url.py +13 -8
- mistralai_azure/utils/values.py +6 -0
- mistralai_gcp/_hooks/sdkhooks.py +23 -4
- mistralai_gcp/_hooks/types.py +27 -9
- mistralai_gcp/basesdk.py +91 -6
- mistralai_gcp/chat.py +252 -144
- mistralai_gcp/fim.py +166 -110
- mistralai_gcp/models/__init__.py +179 -17
- mistralai_gcp/models/assistantmessage.py +18 -5
- mistralai_gcp/models/chatcompletionchoice.py +7 -3
- mistralai_gcp/models/chatcompletionrequest.py +62 -12
- mistralai_gcp/models/chatcompletionresponse.py +6 -2
- mistralai_gcp/models/chatcompletionstreamrequest.py +64 -12
- mistralai_gcp/models/completionchunk.py +10 -3
- mistralai_gcp/models/completionevent.py +1 -2
- mistralai_gcp/models/completionresponsestreamchoice.py +10 -4
- mistralai_gcp/models/contentchunk.py +4 -11
- mistralai_gcp/models/deltamessage.py +16 -5
- mistralai_gcp/models/fimcompletionrequest.py +33 -6
- mistralai_gcp/models/fimcompletionresponse.py +6 -2
- mistralai_gcp/models/fimcompletionstreamrequest.py +33 -6
- mistralai_gcp/models/function.py +3 -2
- mistralai_gcp/models/functioncall.py +2 -2
- mistralai_gcp/models/functionname.py +17 -0
- mistralai_gcp/models/httpvalidationerror.py +2 -2
- mistralai_gcp/models/responseformat.py +6 -7
- mistralai_gcp/models/responseformats.py +8 -0
- mistralai_gcp/models/security.py +12 -3
- mistralai_gcp/models/systemmessage.py +6 -5
- mistralai_gcp/models/textchunk.py +9 -4
- mistralai_gcp/models/tool.py +9 -8
- mistralai_gcp/models/toolcall.py +9 -7
- mistralai_gcp/models/toolchoice.py +29 -0
- mistralai_gcp/models/toolchoiceenum.py +7 -0
- mistralai_gcp/models/toolmessage.py +18 -5
- mistralai_gcp/models/tooltypes.py +8 -0
- mistralai_gcp/models/usageinfo.py +3 -2
- mistralai_gcp/models/usermessage.py +6 -5
- mistralai_gcp/models/validationerror.py +3 -2
- mistralai_gcp/sdk.py +14 -10
- mistralai_gcp/sdkconfiguration.py +6 -8
- mistralai_gcp/utils/__init__.py +8 -3
- mistralai_gcp/utils/forms.py +10 -9
- mistralai_gcp/utils/headers.py +8 -8
- mistralai_gcp/utils/logger.py +6 -0
- mistralai_gcp/utils/queryparams.py +16 -14
- mistralai_gcp/utils/retries.py +2 -1
- mistralai_gcp/utils/security.py +12 -6
- mistralai_gcp/utils/serializers.py +17 -8
- mistralai_gcp/utils/url.py +13 -8
- mistralai_gcp/utils/values.py +6 -0
- mistralai-1.0.2.dist-info/RECORD +0 -236
- {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/LICENSE +0 -0
- {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/WHEEL +0 -0
mistralai_azure/utils/headers.py
CHANGED
|
@@ -15,16 +15,16 @@ from .metadata import (
|
|
|
15
15
|
find_field_metadata,
|
|
16
16
|
)
|
|
17
17
|
|
|
18
|
-
from .values import _populate_from_globals, _val_to_string
|
|
18
|
+
from .values import _is_set, _populate_from_globals, _val_to_string
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def get_headers(headers_params: Any, gbls: Optional[Any] = None) -> Dict[str, str]:
|
|
22
22
|
headers: Dict[str, str] = {}
|
|
23
23
|
|
|
24
24
|
globals_already_populated = []
|
|
25
|
-
if headers_params
|
|
25
|
+
if _is_set(headers_params):
|
|
26
26
|
globals_already_populated = _populate_headers(headers_params, gbls, headers, [])
|
|
27
|
-
if gbls
|
|
27
|
+
if _is_set(gbls):
|
|
28
28
|
_populate_headers(gbls, None, headers, globals_already_populated)
|
|
29
29
|
|
|
30
30
|
return headers
|
|
@@ -67,7 +67,7 @@ def _populate_headers(
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
def _serialize_header(explode: bool, obj: Any) -> str:
|
|
70
|
-
if obj
|
|
70
|
+
if not _is_set(obj):
|
|
71
71
|
return ""
|
|
72
72
|
|
|
73
73
|
if isinstance(obj, BaseModel):
|
|
@@ -83,7 +83,7 @@ def _serialize_header(explode: bool, obj: Any) -> str:
|
|
|
83
83
|
f_name = obj_field.alias if obj_field.alias is not None else name
|
|
84
84
|
|
|
85
85
|
val = getattr(obj, name)
|
|
86
|
-
if val
|
|
86
|
+
if not _is_set(val):
|
|
87
87
|
continue
|
|
88
88
|
|
|
89
89
|
if explode:
|
|
@@ -98,7 +98,7 @@ def _serialize_header(explode: bool, obj: Any) -> str:
|
|
|
98
98
|
items = []
|
|
99
99
|
|
|
100
100
|
for key, value in obj.items():
|
|
101
|
-
if value
|
|
101
|
+
if not _is_set(value):
|
|
102
102
|
continue
|
|
103
103
|
|
|
104
104
|
if explode:
|
|
@@ -113,14 +113,14 @@ def _serialize_header(explode: bool, obj: Any) -> str:
|
|
|
113
113
|
items = []
|
|
114
114
|
|
|
115
115
|
for value in obj:
|
|
116
|
-
if value
|
|
116
|
+
if not _is_set(value):
|
|
117
117
|
continue
|
|
118
118
|
|
|
119
119
|
items.append(_val_to_string(value))
|
|
120
120
|
|
|
121
121
|
if len(items) > 0:
|
|
122
122
|
return ",".join(items)
|
|
123
|
-
|
|
123
|
+
elif _is_set(obj):
|
|
124
124
|
return f"{_val_to_string(obj)}"
|
|
125
125
|
|
|
126
126
|
return ""
|
mistralai_azure/utils/logger.py
CHANGED
|
@@ -3,14 +3,20 @@
|
|
|
3
3
|
import httpx
|
|
4
4
|
from typing import Any, Protocol
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
class Logger(Protocol):
|
|
7
8
|
def debug(self, msg: str, *args: Any, **kwargs: Any) -> None:
|
|
8
9
|
pass
|
|
9
10
|
|
|
11
|
+
|
|
10
12
|
class NoOpLogger:
|
|
11
13
|
def debug(self, msg: str, *args: Any, **kwargs: Any) -> None:
|
|
12
14
|
pass
|
|
13
15
|
|
|
16
|
+
|
|
14
17
|
def get_body_content(req: httpx.Request) -> str:
|
|
15
18
|
return "<streaming body>" if not hasattr(req, "_content") else str(req.content)
|
|
16
19
|
|
|
20
|
+
|
|
21
|
+
def get_default_logger() -> Logger:
|
|
22
|
+
return NoOpLogger()
|
|
@@ -15,7 +15,12 @@ from .metadata import (
|
|
|
15
15
|
QueryParamMetadata,
|
|
16
16
|
find_field_metadata,
|
|
17
17
|
)
|
|
18
|
-
from .values import
|
|
18
|
+
from .values import (
|
|
19
|
+
_get_serialized_params,
|
|
20
|
+
_is_set,
|
|
21
|
+
_populate_from_globals,
|
|
22
|
+
_val_to_string,
|
|
23
|
+
)
|
|
19
24
|
from .forms import _populate_form
|
|
20
25
|
|
|
21
26
|
|
|
@@ -26,7 +31,7 @@ def get_query_params(
|
|
|
26
31
|
params: Dict[str, List[str]] = {}
|
|
27
32
|
|
|
28
33
|
globals_already_populated = _populate_query_params(query_params, gbls, params, [])
|
|
29
|
-
if gbls
|
|
34
|
+
if _is_set(gbls):
|
|
30
35
|
_populate_query_params(gbls, None, params, globals_already_populated)
|
|
31
36
|
|
|
32
37
|
return params
|
|
@@ -55,7 +60,7 @@ def _populate_query_params(
|
|
|
55
60
|
if not metadata:
|
|
56
61
|
continue
|
|
57
62
|
|
|
58
|
-
value = getattr(query_params, name) if query_params
|
|
63
|
+
value = getattr(query_params, name) if _is_set(query_params) else None
|
|
59
64
|
|
|
60
65
|
value, global_found = _populate_from_globals(
|
|
61
66
|
name, value, QueryParamMetadata, gbls
|
|
@@ -99,7 +104,7 @@ def _populate_deep_object_query_params(
|
|
|
99
104
|
obj: Any,
|
|
100
105
|
params: Dict[str, List[str]],
|
|
101
106
|
):
|
|
102
|
-
if obj
|
|
107
|
+
if not _is_set(obj):
|
|
103
108
|
return
|
|
104
109
|
|
|
105
110
|
if isinstance(obj, BaseModel):
|
|
@@ -113,10 +118,7 @@ def _populate_deep_object_query_params_basemodel(
|
|
|
113
118
|
obj: Any,
|
|
114
119
|
params: Dict[str, List[str]],
|
|
115
120
|
):
|
|
116
|
-
if obj
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
if not isinstance(obj, BaseModel):
|
|
121
|
+
if not _is_set(obj) or not isinstance(obj, BaseModel):
|
|
120
122
|
return
|
|
121
123
|
|
|
122
124
|
obj_fields: Dict[str, FieldInfo] = obj.__class__.model_fields
|
|
@@ -128,11 +130,11 @@ def _populate_deep_object_query_params_basemodel(
|
|
|
128
130
|
params_key = f"{prior_params_key}[{f_name}]"
|
|
129
131
|
|
|
130
132
|
obj_param_metadata = find_field_metadata(obj_field, QueryParamMetadata)
|
|
131
|
-
if obj_param_metadata
|
|
133
|
+
if not _is_set(obj_param_metadata):
|
|
132
134
|
continue
|
|
133
135
|
|
|
134
136
|
obj_val = getattr(obj, name)
|
|
135
|
-
if obj_val
|
|
137
|
+
if not _is_set(obj_val):
|
|
136
138
|
continue
|
|
137
139
|
|
|
138
140
|
if isinstance(obj_val, BaseModel):
|
|
@@ -150,11 +152,11 @@ def _populate_deep_object_query_params_dict(
|
|
|
150
152
|
value: Dict,
|
|
151
153
|
params: Dict[str, List[str]],
|
|
152
154
|
):
|
|
153
|
-
if value
|
|
155
|
+
if not _is_set(value):
|
|
154
156
|
return
|
|
155
157
|
|
|
156
158
|
for key, val in value.items():
|
|
157
|
-
if val
|
|
159
|
+
if not _is_set(val):
|
|
158
160
|
continue
|
|
159
161
|
|
|
160
162
|
params_key = f"{prior_params_key}[{key}]"
|
|
@@ -174,11 +176,11 @@ def _populate_deep_object_query_params_list(
|
|
|
174
176
|
value: List,
|
|
175
177
|
params: Dict[str, List[str]],
|
|
176
178
|
):
|
|
177
|
-
if value
|
|
179
|
+
if not _is_set(value):
|
|
178
180
|
return
|
|
179
181
|
|
|
180
182
|
for val in value:
|
|
181
|
-
if val
|
|
183
|
+
if not _is_set(val):
|
|
182
184
|
continue
|
|
183
185
|
|
|
184
186
|
if params.get(params_key) is None:
|
mistralai_azure/utils/retries.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
3
4
|
import random
|
|
4
5
|
import time
|
|
5
6
|
from typing import List
|
|
@@ -212,5 +213,5 @@ async def retry_with_backoff_async(
|
|
|
212
213
|
raise
|
|
213
214
|
sleep = (initial_interval / 1000) * exponent**retries + random.uniform(0, 1)
|
|
214
215
|
sleep = min(sleep, max_interval / 1000)
|
|
215
|
-
|
|
216
|
+
await asyncio.sleep(sleep)
|
|
216
217
|
retries += 1
|
|
@@ -16,7 +16,6 @@ from .metadata import (
|
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
def get_security(security: Any) -> Tuple[Dict[str, str], Dict[str, List[str]]]:
|
|
21
20
|
headers: Dict[str, str] = {}
|
|
22
21
|
query_params: Dict[str, List[str]] = {}
|
|
@@ -42,8 +41,10 @@ def get_security(security: Any) -> Tuple[Dict[str, str], Dict[str, List[str]]]:
|
|
|
42
41
|
_parse_security_option(headers, query_params, value)
|
|
43
42
|
return headers, query_params
|
|
44
43
|
if metadata.scheme:
|
|
45
|
-
# Special case for basic auth which could be a flattened model
|
|
46
|
-
if metadata.sub_type
|
|
44
|
+
# Special case for basic auth or custom auth which could be a flattened model
|
|
45
|
+
if metadata.sub_type in ["basic", "custom"] and not isinstance(
|
|
46
|
+
value, BaseModel
|
|
47
|
+
):
|
|
47
48
|
_parse_security_scheme(headers, query_params, metadata, name, security)
|
|
48
49
|
else:
|
|
49
50
|
_parse_security_scheme(headers, query_params, metadata, name, value)
|
|
@@ -80,9 +81,12 @@ def _parse_security_scheme(
|
|
|
80
81
|
sub_type = scheme_metadata.sub_type
|
|
81
82
|
|
|
82
83
|
if isinstance(scheme, BaseModel):
|
|
83
|
-
if scheme_type == "http"
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
if scheme_type == "http":
|
|
85
|
+
if sub_type == "basic":
|
|
86
|
+
_parse_basic_auth_scheme(headers, scheme)
|
|
87
|
+
return
|
|
88
|
+
if sub_type == "custom":
|
|
89
|
+
return
|
|
86
90
|
|
|
87
91
|
scheme_fields: Dict[str, FieldInfo] = scheme.__class__.model_fields
|
|
88
92
|
for name in scheme_fields:
|
|
@@ -131,6 +135,8 @@ def _parse_security_scheme_value(
|
|
|
131
135
|
elif scheme_type == "http":
|
|
132
136
|
if sub_type == "bearer":
|
|
133
137
|
headers[header_name] = _apply_bearer(value)
|
|
138
|
+
elif sub_type == "custom":
|
|
139
|
+
return
|
|
134
140
|
else:
|
|
135
141
|
raise ValueError("sub type {sub_type} not supported")
|
|
136
142
|
else:
|
|
@@ -9,13 +9,15 @@ from pydantic import ConfigDict, create_model
|
|
|
9
9
|
from pydantic_core import from_json
|
|
10
10
|
from typing_inspect import is_optional_type
|
|
11
11
|
|
|
12
|
-
from ..types.basemodel import BaseModel, Nullable, OptionalNullable
|
|
12
|
+
from ..types.basemodel import BaseModel, Nullable, OptionalNullable, Unset
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def serialize_decimal(as_str: bool):
|
|
16
16
|
def serialize(d):
|
|
17
17
|
if is_optional_type(type(d)) and d is None:
|
|
18
18
|
return None
|
|
19
|
+
if isinstance(d, Unset):
|
|
20
|
+
return d
|
|
19
21
|
|
|
20
22
|
if not isinstance(d, Decimal):
|
|
21
23
|
raise ValueError("Expected Decimal object")
|
|
@@ -29,7 +31,7 @@ def validate_decimal(d):
|
|
|
29
31
|
if d is None:
|
|
30
32
|
return None
|
|
31
33
|
|
|
32
|
-
if isinstance(d, Decimal):
|
|
34
|
+
if isinstance(d, (Decimal, Unset)):
|
|
33
35
|
return d
|
|
34
36
|
|
|
35
37
|
if not isinstance(d, (str, int, float)):
|
|
@@ -42,6 +44,8 @@ def serialize_float(as_str: bool):
|
|
|
42
44
|
def serialize(f):
|
|
43
45
|
if is_optional_type(type(f)) and f is None:
|
|
44
46
|
return None
|
|
47
|
+
if isinstance(f, Unset):
|
|
48
|
+
return f
|
|
45
49
|
|
|
46
50
|
if not isinstance(f, float):
|
|
47
51
|
raise ValueError("Expected float")
|
|
@@ -55,7 +59,7 @@ def validate_float(f):
|
|
|
55
59
|
if f is None:
|
|
56
60
|
return None
|
|
57
61
|
|
|
58
|
-
if isinstance(f, float):
|
|
62
|
+
if isinstance(f, (float, Unset)):
|
|
59
63
|
return f
|
|
60
64
|
|
|
61
65
|
if not isinstance(f, str):
|
|
@@ -65,14 +69,16 @@ def validate_float(f):
|
|
|
65
69
|
|
|
66
70
|
|
|
67
71
|
def serialize_int(as_str: bool):
|
|
68
|
-
def serialize(
|
|
69
|
-
if is_optional_type(type(
|
|
72
|
+
def serialize(i):
|
|
73
|
+
if is_optional_type(type(i)) and i is None:
|
|
70
74
|
return None
|
|
75
|
+
if isinstance(i, Unset):
|
|
76
|
+
return i
|
|
71
77
|
|
|
72
|
-
if not isinstance(
|
|
78
|
+
if not isinstance(i, int):
|
|
73
79
|
raise ValueError("Expected int")
|
|
74
80
|
|
|
75
|
-
return str(
|
|
81
|
+
return str(i) if as_str else i
|
|
76
82
|
|
|
77
83
|
return serialize
|
|
78
84
|
|
|
@@ -81,7 +87,7 @@ def validate_int(b):
|
|
|
81
87
|
if b is None:
|
|
82
88
|
return None
|
|
83
89
|
|
|
84
|
-
if isinstance(b, int):
|
|
90
|
+
if isinstance(b, (int, Unset)):
|
|
85
91
|
return b
|
|
86
92
|
|
|
87
93
|
if not isinstance(b, str):
|
|
@@ -95,6 +101,9 @@ def validate_open_enum(is_int: bool):
|
|
|
95
101
|
if e is None:
|
|
96
102
|
return None
|
|
97
103
|
|
|
104
|
+
if isinstance(e, Unset):
|
|
105
|
+
return e
|
|
106
|
+
|
|
98
107
|
if is_int:
|
|
99
108
|
if not isinstance(e, int):
|
|
100
109
|
raise ValueError("Expected int")
|
mistralai_azure/utils/url.py
CHANGED
|
@@ -18,7 +18,12 @@ from .metadata import (
|
|
|
18
18
|
PathParamMetadata,
|
|
19
19
|
find_field_metadata,
|
|
20
20
|
)
|
|
21
|
-
from .values import
|
|
21
|
+
from .values import (
|
|
22
|
+
_get_serialized_params,
|
|
23
|
+
_is_set,
|
|
24
|
+
_populate_from_globals,
|
|
25
|
+
_val_to_string,
|
|
26
|
+
)
|
|
22
27
|
|
|
23
28
|
|
|
24
29
|
def generate_url(
|
|
@@ -32,7 +37,7 @@ def generate_url(
|
|
|
32
37
|
globals_already_populated = _populate_path_params(
|
|
33
38
|
path_params, gbls, path_param_values, []
|
|
34
39
|
)
|
|
35
|
-
if gbls
|
|
40
|
+
if _is_set(gbls):
|
|
36
41
|
_populate_path_params(gbls, None, path_param_values, globals_already_populated)
|
|
37
42
|
|
|
38
43
|
for key, value in path_param_values.items():
|
|
@@ -64,14 +69,14 @@ def _populate_path_params(
|
|
|
64
69
|
if param_metadata is None:
|
|
65
70
|
continue
|
|
66
71
|
|
|
67
|
-
param = getattr(path_params, name) if path_params
|
|
72
|
+
param = getattr(path_params, name) if _is_set(path_params) else None
|
|
68
73
|
param, global_found = _populate_from_globals(
|
|
69
74
|
name, param, PathParamMetadata, gbls
|
|
70
75
|
)
|
|
71
76
|
if global_found:
|
|
72
77
|
globals_already_populated.append(name)
|
|
73
78
|
|
|
74
|
-
if param
|
|
79
|
+
if not _is_set(param):
|
|
75
80
|
continue
|
|
76
81
|
|
|
77
82
|
f_name = field.alias if field.alias is not None else name
|
|
@@ -87,13 +92,13 @@ def _populate_path_params(
|
|
|
87
92
|
if param_metadata.style == "simple":
|
|
88
93
|
if isinstance(param, List):
|
|
89
94
|
for pp_val in param:
|
|
90
|
-
if pp_val
|
|
95
|
+
if not _is_set(pp_val):
|
|
91
96
|
continue
|
|
92
97
|
pp_vals.append(_val_to_string(pp_val))
|
|
93
98
|
path_param_values[f_name] = ",".join(pp_vals)
|
|
94
99
|
elif isinstance(param, Dict):
|
|
95
100
|
for pp_key in param:
|
|
96
|
-
if param[pp_key]
|
|
101
|
+
if not _is_set(param[pp_key]):
|
|
97
102
|
continue
|
|
98
103
|
if param_metadata.explode:
|
|
99
104
|
pp_vals.append(f"{pp_key}={_val_to_string(param[pp_key])}")
|
|
@@ -116,7 +121,7 @@ def _populate_path_params(
|
|
|
116
121
|
)
|
|
117
122
|
|
|
118
123
|
param_field_val = getattr(param, name)
|
|
119
|
-
if param_field_val
|
|
124
|
+
if not _is_set(param_field_val):
|
|
120
125
|
continue
|
|
121
126
|
if param_metadata.explode:
|
|
122
127
|
pp_vals.append(
|
|
@@ -127,7 +132,7 @@ def _populate_path_params(
|
|
|
127
132
|
f"{param_name},{_val_to_string(param_field_val)}"
|
|
128
133
|
)
|
|
129
134
|
path_param_values[f_name] = ",".join(pp_vals)
|
|
130
|
-
|
|
135
|
+
elif _is_set(param):
|
|
131
136
|
path_param_values[f_name] = _val_to_string(param)
|
|
132
137
|
|
|
133
138
|
return globals_already_populated
|
mistralai_azure/utils/values.py
CHANGED
|
@@ -10,6 +10,8 @@ from httpx import Response
|
|
|
10
10
|
from pydantic import BaseModel
|
|
11
11
|
from pydantic.fields import FieldInfo
|
|
12
12
|
|
|
13
|
+
from ..types.basemodel import Unset
|
|
14
|
+
|
|
13
15
|
from .serializers import marshal_json
|
|
14
16
|
|
|
15
17
|
from .metadata import ParamMetadata, find_field_metadata
|
|
@@ -126,3 +128,7 @@ def _get_serialized_params(
|
|
|
126
128
|
params[field_name] = marshal_json(obj, typ)
|
|
127
129
|
|
|
128
130
|
return params
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _is_set(value: Any) -> bool:
|
|
134
|
+
return value is not None and not isinstance(value, Unset)
|
mistralai_gcp/_hooks/sdkhooks.py
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
import httpx
|
|
4
|
-
from .types import
|
|
4
|
+
from .types import (
|
|
5
|
+
SDKInitHook,
|
|
6
|
+
BeforeRequestContext,
|
|
7
|
+
BeforeRequestHook,
|
|
8
|
+
AfterSuccessContext,
|
|
9
|
+
AfterSuccessHook,
|
|
10
|
+
AfterErrorContext,
|
|
11
|
+
AfterErrorHook,
|
|
12
|
+
Hooks,
|
|
13
|
+
)
|
|
5
14
|
from .registration import init_hooks
|
|
6
15
|
from typing import List, Optional, Tuple
|
|
7
16
|
from mistralai_gcp.httpclient import HttpClient
|
|
8
17
|
|
|
18
|
+
|
|
9
19
|
class SDKHooks(Hooks):
|
|
10
20
|
def __init__(self) -> None:
|
|
11
21
|
self.sdk_init_hooks: List[SDKInitHook] = []
|
|
@@ -31,7 +41,9 @@ class SDKHooks(Hooks):
|
|
|
31
41
|
base_url, client = hook.sdk_init(base_url, client)
|
|
32
42
|
return base_url, client
|
|
33
43
|
|
|
34
|
-
def before_request(
|
|
44
|
+
def before_request(
|
|
45
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
46
|
+
) -> httpx.Request:
|
|
35
47
|
for hook in self.before_request_hooks:
|
|
36
48
|
out = hook.before_request(hook_ctx, request)
|
|
37
49
|
if isinstance(out, Exception):
|
|
@@ -40,7 +52,9 @@ class SDKHooks(Hooks):
|
|
|
40
52
|
|
|
41
53
|
return request
|
|
42
54
|
|
|
43
|
-
def after_success(
|
|
55
|
+
def after_success(
|
|
56
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
|
57
|
+
) -> httpx.Response:
|
|
44
58
|
for hook in self.after_success_hooks:
|
|
45
59
|
out = hook.after_success(hook_ctx, response)
|
|
46
60
|
if isinstance(out, Exception):
|
|
@@ -48,7 +62,12 @@ class SDKHooks(Hooks):
|
|
|
48
62
|
response = out
|
|
49
63
|
return response
|
|
50
64
|
|
|
51
|
-
def after_error(
|
|
65
|
+
def after_error(
|
|
66
|
+
self,
|
|
67
|
+
hook_ctx: AfterErrorContext,
|
|
68
|
+
response: Optional[httpx.Response],
|
|
69
|
+
error: Optional[Exception],
|
|
70
|
+
) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
|
|
52
71
|
for hook in self.after_error_hooks:
|
|
53
72
|
result = hook.after_error(hook_ctx, response, error)
|
|
54
73
|
if isinstance(result, Exception):
|
mistralai_gcp/_hooks/types.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
from abc import ABC, abstractmethod
|
|
5
4
|
import httpx
|
|
6
5
|
from mistralai_gcp.httpclient import HttpClient
|
|
@@ -12,7 +11,12 @@ class HookContext:
|
|
|
12
11
|
oauth2_scopes: Optional[List[str]] = None
|
|
13
12
|
security_source: Optional[Union[Any, Callable[[], Any]]] = None
|
|
14
13
|
|
|
15
|
-
def __init__(
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
operation_id: str,
|
|
17
|
+
oauth2_scopes: Optional[List[str]],
|
|
18
|
+
security_source: Optional[Union[Any, Callable[[], Any]]],
|
|
19
|
+
):
|
|
16
20
|
self.operation_id = operation_id
|
|
17
21
|
self.oauth2_scopes = oauth2_scopes
|
|
18
22
|
self.security_source = security_source
|
|
@@ -20,18 +24,23 @@ class HookContext:
|
|
|
20
24
|
|
|
21
25
|
class BeforeRequestContext(HookContext):
|
|
22
26
|
def __init__(self, hook_ctx: HookContext):
|
|
23
|
-
super().__init__(
|
|
27
|
+
super().__init__(
|
|
28
|
+
hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source
|
|
29
|
+
)
|
|
24
30
|
|
|
25
31
|
|
|
26
32
|
class AfterSuccessContext(HookContext):
|
|
27
33
|
def __init__(self, hook_ctx: HookContext):
|
|
28
|
-
super().__init__(
|
|
29
|
-
|
|
34
|
+
super().__init__(
|
|
35
|
+
hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source
|
|
36
|
+
)
|
|
30
37
|
|
|
31
38
|
|
|
32
39
|
class AfterErrorContext(HookContext):
|
|
33
40
|
def __init__(self, hook_ctx: HookContext):
|
|
34
|
-
super().__init__(
|
|
41
|
+
super().__init__(
|
|
42
|
+
hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source
|
|
43
|
+
)
|
|
35
44
|
|
|
36
45
|
|
|
37
46
|
class SDKInitHook(ABC):
|
|
@@ -42,19 +51,28 @@ class SDKInitHook(ABC):
|
|
|
42
51
|
|
|
43
52
|
class BeforeRequestHook(ABC):
|
|
44
53
|
@abstractmethod
|
|
45
|
-
def before_request(
|
|
54
|
+
def before_request(
|
|
55
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
56
|
+
) -> Union[httpx.Request, Exception]:
|
|
46
57
|
pass
|
|
47
58
|
|
|
48
59
|
|
|
49
60
|
class AfterSuccessHook(ABC):
|
|
50
61
|
@abstractmethod
|
|
51
|
-
def after_success(
|
|
62
|
+
def after_success(
|
|
63
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
|
64
|
+
) -> Union[httpx.Response, Exception]:
|
|
52
65
|
pass
|
|
53
66
|
|
|
54
67
|
|
|
55
68
|
class AfterErrorHook(ABC):
|
|
56
69
|
@abstractmethod
|
|
57
|
-
def after_error(
|
|
70
|
+
def after_error(
|
|
71
|
+
self,
|
|
72
|
+
hook_ctx: AfterErrorContext,
|
|
73
|
+
response: Optional[httpx.Response],
|
|
74
|
+
error: Optional[Exception],
|
|
75
|
+
) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
|
|
58
76
|
pass
|
|
59
77
|
|
|
60
78
|
|