mistralai 1.0.3__py3-none-any.whl → 1.2.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.
Files changed (230) hide show
  1. mistralai/__init__.py +4 -0
  2. mistralai/_hooks/sdkhooks.py +23 -4
  3. mistralai/_hooks/types.py +27 -9
  4. mistralai/_version.py +12 -0
  5. mistralai/agents.py +334 -164
  6. mistralai/basesdk.py +90 -5
  7. mistralai/batch.py +17 -0
  8. mistralai/chat.py +316 -166
  9. mistralai/classifiers.py +396 -0
  10. mistralai/embeddings.py +79 -55
  11. mistralai/files.py +487 -194
  12. mistralai/fim.py +206 -132
  13. mistralai/fine_tuning.py +3 -2
  14. mistralai/jobs.py +392 -263
  15. mistralai/mistral_jobs.py +733 -0
  16. mistralai/models/__init__.py +593 -50
  17. mistralai/models/agentscompletionrequest.py +70 -17
  18. mistralai/models/agentscompletionstreamrequest.py +72 -17
  19. mistralai/models/apiendpoint.py +9 -0
  20. mistralai/models/archiveftmodelout.py +15 -5
  21. mistralai/models/assistantmessage.py +22 -10
  22. mistralai/models/{modelcard.py → basemodelcard.py} +53 -14
  23. mistralai/models/batcherror.py +17 -0
  24. mistralai/models/batchjobin.py +58 -0
  25. mistralai/models/batchjobout.py +117 -0
  26. mistralai/models/batchjobsout.py +30 -0
  27. mistralai/models/batchjobstatus.py +15 -0
  28. mistralai/models/chatclassificationrequest.py +104 -0
  29. mistralai/models/chatcompletionchoice.py +13 -6
  30. mistralai/models/chatcompletionrequest.py +86 -21
  31. mistralai/models/chatcompletionresponse.py +8 -4
  32. mistralai/models/chatcompletionstreamrequest.py +88 -21
  33. mistralai/models/checkpointout.py +4 -3
  34. mistralai/models/classificationobject.py +21 -0
  35. mistralai/models/classificationrequest.py +59 -0
  36. mistralai/models/classificationresponse.py +21 -0
  37. mistralai/models/completionchunk.py +12 -5
  38. mistralai/models/completionevent.py +2 -3
  39. mistralai/models/completionresponsestreamchoice.py +22 -8
  40. mistralai/models/contentchunk.py +13 -10
  41. mistralai/models/delete_model_v1_models_model_id_deleteop.py +5 -5
  42. mistralai/models/deletefileout.py +4 -3
  43. mistralai/models/deletemodelout.py +5 -4
  44. mistralai/models/deltamessage.py +23 -11
  45. mistralai/models/detailedjobout.py +70 -12
  46. mistralai/models/embeddingrequest.py +14 -9
  47. mistralai/models/embeddingresponse.py +7 -3
  48. mistralai/models/embeddingresponsedata.py +5 -4
  49. mistralai/models/eventout.py +11 -6
  50. mistralai/models/filepurpose.py +8 -0
  51. mistralai/models/files_api_routes_delete_fileop.py +5 -5
  52. mistralai/models/files_api_routes_download_fileop.py +16 -0
  53. mistralai/models/files_api_routes_list_filesop.py +96 -0
  54. mistralai/models/files_api_routes_retrieve_fileop.py +5 -5
  55. mistralai/models/files_api_routes_upload_fileop.py +33 -14
  56. mistralai/models/fileschema.py +22 -15
  57. mistralai/models/fimcompletionrequest.py +44 -16
  58. mistralai/models/fimcompletionresponse.py +8 -4
  59. mistralai/models/fimcompletionstreamrequest.py +44 -16
  60. mistralai/models/finetuneablemodel.py +7 -1
  61. mistralai/models/ftmodelcapabilitiesout.py +6 -4
  62. mistralai/models/ftmodelcard.py +121 -0
  63. mistralai/models/ftmodelout.py +39 -9
  64. mistralai/models/function.py +5 -4
  65. mistralai/models/functioncall.py +4 -3
  66. mistralai/models/functionname.py +17 -0
  67. mistralai/models/githubrepositoryin.py +24 -7
  68. mistralai/models/githubrepositoryout.py +24 -7
  69. mistralai/models/httpvalidationerror.py +1 -3
  70. mistralai/models/imageurl.py +47 -0
  71. mistralai/models/imageurlchunk.py +38 -0
  72. mistralai/models/jobin.py +24 -7
  73. mistralai/models/jobmetadataout.py +32 -8
  74. mistralai/models/jobout.py +65 -12
  75. mistralai/models/jobs_api_routes_batch_cancel_batch_jobop.py +16 -0
  76. mistralai/models/jobs_api_routes_batch_get_batch_jobop.py +16 -0
  77. mistralai/models/jobs_api_routes_batch_get_batch_jobsop.py +95 -0
  78. mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +5 -5
  79. mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +5 -5
  80. mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +3 -2
  81. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +5 -5
  82. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +85 -18
  83. mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +5 -5
  84. mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +5 -5
  85. mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +10 -6
  86. mistralai/models/jobsout.py +13 -5
  87. mistralai/models/legacyjobmetadataout.py +55 -9
  88. mistralai/models/listfilesout.py +7 -3
  89. mistralai/models/metricout.py +12 -8
  90. mistralai/models/modelcapabilities.py +9 -4
  91. mistralai/models/modellist.py +21 -7
  92. mistralai/models/responseformat.py +7 -8
  93. mistralai/models/responseformats.py +8 -0
  94. mistralai/models/retrieve_model_v1_models_model_id_getop.py +25 -6
  95. mistralai/models/retrievefileout.py +25 -15
  96. mistralai/models/sampletype.py +6 -2
  97. mistralai/models/security.py +14 -5
  98. mistralai/models/source.py +3 -2
  99. mistralai/models/systemmessage.py +10 -9
  100. mistralai/models/textchunk.py +14 -5
  101. mistralai/models/tool.py +10 -9
  102. mistralai/models/toolcall.py +10 -8
  103. mistralai/models/toolchoice.py +29 -0
  104. mistralai/models/toolchoiceenum.py +7 -0
  105. mistralai/models/toolmessage.py +13 -6
  106. mistralai/models/tooltypes.py +8 -0
  107. mistralai/models/trainingfile.py +4 -4
  108. mistralai/models/trainingparameters.py +34 -8
  109. mistralai/models/trainingparametersin.py +36 -10
  110. mistralai/models/unarchiveftmodelout.py +15 -5
  111. mistralai/models/updateftmodelin.py +9 -6
  112. mistralai/models/uploadfileout.py +22 -15
  113. mistralai/models/usageinfo.py +4 -3
  114. mistralai/models/usermessage.py +42 -10
  115. mistralai/models/validationerror.py +5 -3
  116. mistralai/models/wandbintegration.py +23 -7
  117. mistralai/models/wandbintegrationout.py +23 -8
  118. mistralai/models_.py +416 -294
  119. mistralai/sdk.py +31 -19
  120. mistralai/sdkconfiguration.py +9 -11
  121. mistralai/utils/__init__.py +14 -1
  122. mistralai/utils/annotations.py +13 -2
  123. mistralai/utils/logger.py +4 -1
  124. mistralai/utils/retries.py +2 -1
  125. mistralai/utils/security.py +13 -6
  126. mistralai/utils/serializers.py +25 -0
  127. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/METADATA +171 -66
  128. mistralai-1.2.0.dist-info/RECORD +276 -0
  129. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/WHEEL +1 -1
  130. mistralai_azure/__init__.py +4 -0
  131. mistralai_azure/_hooks/sdkhooks.py +23 -4
  132. mistralai_azure/_hooks/types.py +27 -9
  133. mistralai_azure/_version.py +12 -0
  134. mistralai_azure/basesdk.py +91 -6
  135. mistralai_azure/chat.py +308 -166
  136. mistralai_azure/models/__init__.py +164 -16
  137. mistralai_azure/models/assistantmessage.py +29 -11
  138. mistralai_azure/models/chatcompletionchoice.py +15 -6
  139. mistralai_azure/models/chatcompletionrequest.py +94 -22
  140. mistralai_azure/models/chatcompletionresponse.py +8 -4
  141. mistralai_azure/models/chatcompletionstreamrequest.py +96 -22
  142. mistralai_azure/models/completionchunk.py +12 -5
  143. mistralai_azure/models/completionevent.py +2 -3
  144. mistralai_azure/models/completionresponsestreamchoice.py +19 -8
  145. mistralai_azure/models/contentchunk.py +4 -11
  146. mistralai_azure/models/deltamessage.py +30 -12
  147. mistralai_azure/models/function.py +5 -4
  148. mistralai_azure/models/functioncall.py +4 -3
  149. mistralai_azure/models/functionname.py +17 -0
  150. mistralai_azure/models/httpvalidationerror.py +1 -3
  151. mistralai_azure/models/responseformat.py +7 -8
  152. mistralai_azure/models/responseformats.py +8 -0
  153. mistralai_azure/models/security.py +13 -5
  154. mistralai_azure/models/systemmessage.py +10 -9
  155. mistralai_azure/models/textchunk.py +14 -5
  156. mistralai_azure/models/tool.py +10 -9
  157. mistralai_azure/models/toolcall.py +10 -8
  158. mistralai_azure/models/toolchoice.py +29 -0
  159. mistralai_azure/models/toolchoiceenum.py +7 -0
  160. mistralai_azure/models/toolmessage.py +20 -7
  161. mistralai_azure/models/tooltypes.py +8 -0
  162. mistralai_azure/models/usageinfo.py +4 -3
  163. mistralai_azure/models/usermessage.py +42 -10
  164. mistralai_azure/models/validationerror.py +5 -3
  165. mistralai_azure/sdkconfiguration.py +9 -11
  166. mistralai_azure/utils/__init__.py +16 -3
  167. mistralai_azure/utils/annotations.py +13 -2
  168. mistralai_azure/utils/forms.py +10 -9
  169. mistralai_azure/utils/headers.py +8 -8
  170. mistralai_azure/utils/logger.py +6 -0
  171. mistralai_azure/utils/queryparams.py +16 -14
  172. mistralai_azure/utils/retries.py +2 -1
  173. mistralai_azure/utils/security.py +12 -6
  174. mistralai_azure/utils/serializers.py +42 -8
  175. mistralai_azure/utils/url.py +13 -8
  176. mistralai_azure/utils/values.py +6 -0
  177. mistralai_gcp/__init__.py +4 -0
  178. mistralai_gcp/_hooks/sdkhooks.py +23 -4
  179. mistralai_gcp/_hooks/types.py +27 -9
  180. mistralai_gcp/_version.py +12 -0
  181. mistralai_gcp/basesdk.py +91 -6
  182. mistralai_gcp/chat.py +308 -166
  183. mistralai_gcp/fim.py +198 -132
  184. mistralai_gcp/models/__init__.py +186 -18
  185. mistralai_gcp/models/assistantmessage.py +29 -11
  186. mistralai_gcp/models/chatcompletionchoice.py +15 -6
  187. mistralai_gcp/models/chatcompletionrequest.py +91 -22
  188. mistralai_gcp/models/chatcompletionresponse.py +8 -4
  189. mistralai_gcp/models/chatcompletionstreamrequest.py +93 -22
  190. mistralai_gcp/models/completionchunk.py +12 -5
  191. mistralai_gcp/models/completionevent.py +2 -3
  192. mistralai_gcp/models/completionresponsestreamchoice.py +19 -8
  193. mistralai_gcp/models/contentchunk.py +4 -11
  194. mistralai_gcp/models/deltamessage.py +30 -12
  195. mistralai_gcp/models/fimcompletionrequest.py +51 -17
  196. mistralai_gcp/models/fimcompletionresponse.py +8 -4
  197. mistralai_gcp/models/fimcompletionstreamrequest.py +51 -17
  198. mistralai_gcp/models/function.py +5 -4
  199. mistralai_gcp/models/functioncall.py +4 -3
  200. mistralai_gcp/models/functionname.py +17 -0
  201. mistralai_gcp/models/httpvalidationerror.py +1 -3
  202. mistralai_gcp/models/responseformat.py +7 -8
  203. mistralai_gcp/models/responseformats.py +8 -0
  204. mistralai_gcp/models/security.py +13 -5
  205. mistralai_gcp/models/systemmessage.py +10 -9
  206. mistralai_gcp/models/textchunk.py +14 -5
  207. mistralai_gcp/models/tool.py +10 -9
  208. mistralai_gcp/models/toolcall.py +10 -8
  209. mistralai_gcp/models/toolchoice.py +29 -0
  210. mistralai_gcp/models/toolchoiceenum.py +7 -0
  211. mistralai_gcp/models/toolmessage.py +20 -7
  212. mistralai_gcp/models/tooltypes.py +8 -0
  213. mistralai_gcp/models/usageinfo.py +4 -3
  214. mistralai_gcp/models/usermessage.py +42 -10
  215. mistralai_gcp/models/validationerror.py +5 -3
  216. mistralai_gcp/sdk.py +6 -7
  217. mistralai_gcp/sdkconfiguration.py +9 -11
  218. mistralai_gcp/utils/__init__.py +16 -3
  219. mistralai_gcp/utils/annotations.py +13 -2
  220. mistralai_gcp/utils/forms.py +10 -9
  221. mistralai_gcp/utils/headers.py +8 -8
  222. mistralai_gcp/utils/logger.py +6 -0
  223. mistralai_gcp/utils/queryparams.py +16 -14
  224. mistralai_gcp/utils/retries.py +2 -1
  225. mistralai_gcp/utils/security.py +12 -6
  226. mistralai_gcp/utils/serializers.py +42 -8
  227. mistralai_gcp/utils/url.py +13 -8
  228. mistralai_gcp/utils/values.py +6 -0
  229. mistralai-1.0.3.dist-info/RECORD +0 -236
  230. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/LICENSE +0 -0
@@ -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 == "basic" and not isinstance(value, BaseModel):
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" and sub_type == "basic":
84
- _parse_basic_auth_scheme(headers, scheme)
85
- return
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(b):
69
- if is_optional_type(type(b)) and b is None:
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(b, int):
78
+ if not isinstance(i, int):
73
79
  raise ValueError("Expected int")
74
80
 
75
- return str(b) if as_str else b
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")
@@ -107,6 +116,19 @@ def validate_open_enum(is_int: bool):
107
116
  return validate
108
117
 
109
118
 
119
+ def validate_const(v):
120
+ def validate(c):
121
+ if is_optional_type(type(c)) and c is None:
122
+ return None
123
+
124
+ if v != c:
125
+ raise ValueError(f"Expected {v}")
126
+
127
+ return c
128
+
129
+ return validate
130
+
131
+
110
132
  def unmarshal_json(raw, typ: Any) -> Any:
111
133
  return unmarshal(from_json(raw), typ)
112
134
 
@@ -163,6 +185,18 @@ def stream_to_text(stream: httpx.Response) -> str:
163
185
  return "".join(stream.iter_text())
164
186
 
165
187
 
188
+ async def stream_to_text_async(stream: httpx.Response) -> str:
189
+ return "".join([chunk async for chunk in stream.aiter_text()])
190
+
191
+
192
+ def stream_to_bytes(stream: httpx.Response) -> bytes:
193
+ return stream.content
194
+
195
+
196
+ async def stream_to_bytes_async(stream: httpx.Response) -> bytes:
197
+ return await stream.aread()
198
+
199
+
166
200
  def get_pydantic_model(data: Any, typ: Any) -> Any:
167
201
  if not _contains_pydantic_model(data):
168
202
  return unmarshal(data, typ)
@@ -18,7 +18,12 @@ from .metadata import (
18
18
  PathParamMetadata,
19
19
  find_field_metadata,
20
20
  )
21
- from .values import _get_serialized_params, _populate_from_globals, _val_to_string
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 is not None:
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 is not None else None
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 is None:
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 is None:
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] is None:
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 is None:
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
- else:
135
+ elif _is_set(param):
131
136
  path_param_values[f_name] = _val_to_string(param)
132
137
 
133
138
  return globals_already_populated
@@ -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/__init__.py CHANGED
@@ -1,5 +1,9 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
+ from ._version import __title__, __version__
3
4
  from .sdk import *
4
5
  from .sdkconfiguration import *
5
6
  from .models import *
7
+
8
+
9
+ VERSION: str = __version__
@@ -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 SDKInitHook, BeforeRequestContext, BeforeRequestHook, AfterSuccessContext, AfterSuccessHook, AfterErrorContext, AfterErrorHook, Hooks
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(self, hook_ctx: BeforeRequestContext, request: httpx.Request) -> httpx.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(self, hook_ctx: AfterSuccessContext, response: httpx.Response) -> httpx.Response:
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(self, hook_ctx: AfterErrorContext, response: Optional[httpx.Response], error: Optional[Exception]) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
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):
@@ -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__(self, operation_id: str, oauth2_scopes: Optional[List[str]], security_source: Optional[Union[Any, Callable[[], Any]]]):
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__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source)
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__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source)
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__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source)
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(self, hook_ctx: BeforeRequestContext, request: httpx.Request) -> Union[httpx.Request, Exception]:
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(self, hook_ctx: AfterSuccessContext, response: httpx.Response) -> Union[httpx.Response, Exception]:
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(self, hook_ctx: AfterErrorContext, response: Optional[httpx.Response], error: Optional[Exception]) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
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
 
@@ -0,0 +1,12 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ import importlib.metadata
4
+
5
+ __title__: str = "mistralai-gcp"
6
+ __version__: str = "1.2.0"
7
+
8
+ try:
9
+ if __package__ is not None:
10
+ __version__ = importlib.metadata.version(__package__)
11
+ except importlib.metadata.PackageNotFoundError:
12
+ pass
mistralai_gcp/basesdk.py CHANGED
@@ -3,10 +3,15 @@
3
3
  from .sdkconfiguration import SDKConfiguration
4
4
  import httpx
5
5
  from mistralai_gcp import models, utils
6
- from mistralai_gcp._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext
6
+ from mistralai_gcp._hooks import (
7
+ AfterErrorContext,
8
+ AfterSuccessContext,
9
+ BeforeRequestContext,
10
+ )
7
11
  from mistralai_gcp.utils import RetryConfig, SerializedRequestBody, get_body_content
8
12
  from typing import Callable, List, Optional, Tuple
9
13
 
14
+
10
15
  class BaseSDK:
11
16
  sdk_configuration: SDKConfiguration
12
17
 
@@ -24,6 +29,46 @@ class BaseSDK:
24
29
 
25
30
  return utils.template_url(base_url, url_variables)
26
31
 
32
+ def build_request_async(
33
+ self,
34
+ method,
35
+ path,
36
+ base_url,
37
+ url_variables,
38
+ request,
39
+ request_body_required,
40
+ request_has_path_params,
41
+ request_has_query_params,
42
+ user_agent_header,
43
+ accept_header_value,
44
+ _globals=None,
45
+ security=None,
46
+ timeout_ms: Optional[int] = None,
47
+ get_serialized_body: Optional[
48
+ Callable[[], Optional[SerializedRequestBody]]
49
+ ] = None,
50
+ url_override: Optional[str] = None,
51
+ ) -> httpx.Request:
52
+ client = self.sdk_configuration.async_client
53
+ return self.build_request_with_client(
54
+ client,
55
+ method,
56
+ path,
57
+ base_url,
58
+ url_variables,
59
+ request,
60
+ request_body_required,
61
+ request_has_path_params,
62
+ request_has_query_params,
63
+ user_agent_header,
64
+ accept_header_value,
65
+ _globals,
66
+ security,
67
+ timeout_ms,
68
+ get_serialized_body,
69
+ url_override,
70
+ )
71
+
27
72
  def build_request(
28
73
  self,
29
74
  method,
@@ -45,7 +90,46 @@ class BaseSDK:
45
90
  url_override: Optional[str] = None,
46
91
  ) -> httpx.Request:
47
92
  client = self.sdk_configuration.client
93
+ return self.build_request_with_client(
94
+ client,
95
+ method,
96
+ path,
97
+ base_url,
98
+ url_variables,
99
+ request,
100
+ request_body_required,
101
+ request_has_path_params,
102
+ request_has_query_params,
103
+ user_agent_header,
104
+ accept_header_value,
105
+ _globals,
106
+ security,
107
+ timeout_ms,
108
+ get_serialized_body,
109
+ url_override,
110
+ )
48
111
 
112
+ def build_request_with_client(
113
+ self,
114
+ client,
115
+ method,
116
+ path,
117
+ base_url,
118
+ url_variables,
119
+ request,
120
+ request_body_required,
121
+ request_has_path_params,
122
+ request_has_query_params,
123
+ user_agent_header,
124
+ accept_header_value,
125
+ _globals=None,
126
+ security=None,
127
+ timeout_ms: Optional[int] = None,
128
+ get_serialized_body: Optional[
129
+ Callable[[], Optional[SerializedRequestBody]]
130
+ ] = None,
131
+ url_override: Optional[str] = None,
132
+ ) -> httpx.Request:
49
133
  query_params = {}
50
134
 
51
135
  url = url_override
@@ -69,7 +153,7 @@ class BaseSDK:
69
153
  if security is not None:
70
154
  if callable(security):
71
155
  security = security()
72
-
156
+
73
157
  if security is not None:
74
158
  security_headers, security_query_params = utils.get_security(security)
75
159
  headers = {**headers, **security_headers}
@@ -129,7 +213,7 @@ class BaseSDK:
129
213
  req.method,
130
214
  req.url,
131
215
  req.headers,
132
- get_body_content(req)
216
+ get_body_content(req),
133
217
  )
134
218
  http_res = client.send(req, stream=stream)
135
219
  except Exception as e:
@@ -149,7 +233,7 @@ class BaseSDK:
149
233
  http_res.status_code,
150
234
  http_res.url,
151
235
  http_res.headers,
152
- "<streaming response>" if stream else http_res.text
236
+ "<streaming response>" if stream else http_res.text,
153
237
  )
154
238
 
155
239
  if utils.match_status_codes(error_status_codes, http_res.status_code):
@@ -189,6 +273,7 @@ class BaseSDK:
189
273
  ) -> httpx.Response:
190
274
  client = self.sdk_configuration.async_client
191
275
  logger = self.sdk_configuration.debug_logger
276
+
192
277
  async def do():
193
278
  http_res = None
194
279
  try:
@@ -200,7 +285,7 @@ class BaseSDK:
200
285
  req.method,
201
286
  req.url,
202
287
  req.headers,
203
- get_body_content(req)
288
+ get_body_content(req),
204
289
  )
205
290
  http_res = await client.send(req, stream=stream)
206
291
  except Exception as e:
@@ -220,7 +305,7 @@ class BaseSDK:
220
305
  http_res.status_code,
221
306
  http_res.url,
222
307
  http_res.headers,
223
- "<streaming response>" if stream else http_res.text
308
+ "<streaming response>" if stream else http_res.text,
224
309
  )
225
310
 
226
311
  if utils.match_status_codes(error_status_codes, http_res.status_code):