mistralai 1.8.1__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.
Files changed (111) hide show
  1. mistralai/_hooks/types.py +7 -0
  2. mistralai/_version.py +3 -3
  3. mistralai/agents.py +16 -0
  4. mistralai/basesdk.py +12 -20
  5. mistralai/beta.py +1 -1
  6. mistralai/chat.py +16 -0
  7. mistralai/classifiers.py +8 -0
  8. mistralai/conversations.py +35 -15
  9. mistralai/embeddings.py +2 -0
  10. mistralai/extra/run/context.py +2 -4
  11. mistralai/files.py +12 -0
  12. mistralai/fim.py +4 -0
  13. mistralai/httpclient.py +6 -16
  14. mistralai/jobs.py +10 -0
  15. mistralai/mistral_agents.py +10 -0
  16. mistralai/mistral_jobs.py +8 -0
  17. mistralai/models/__init__.py +1357 -722
  18. mistralai/models/agent.py +1 -1
  19. mistralai/models/agentconversation.py +1 -1
  20. mistralai/models/agentcreationrequest.py +1 -1
  21. mistralai/models/agenthandoffentry.py +1 -1
  22. mistralai/models/agents_api_v1_conversations_getop.py +2 -0
  23. mistralai/models/agents_api_v1_conversations_historyop.py +2 -0
  24. mistralai/models/agents_api_v1_conversations_messagesop.py +2 -0
  25. mistralai/models/agents_api_v1_conversations_restart_streamop.py +2 -0
  26. mistralai/models/agents_api_v1_conversations_restartop.py +2 -0
  27. mistralai/models/agentscompletionrequest.py +13 -3
  28. mistralai/models/agentscompletionstreamrequest.py +13 -3
  29. mistralai/models/agentupdaterequest.py +1 -1
  30. mistralai/models/assistantmessage.py +1 -1
  31. mistralai/models/basemodelcard.py +8 -6
  32. mistralai/models/batchjobin.py +1 -1
  33. mistralai/models/batchjobout.py +1 -1
  34. mistralai/models/chatcompletionrequest.py +20 -3
  35. mistralai/models/chatcompletionstreamrequest.py +20 -3
  36. mistralai/models/classifierdetailedjobout.py +1 -1
  37. mistralai/models/classifierftmodelout.py +1 -1
  38. mistralai/models/classifierjobout.py +1 -1
  39. mistralai/models/classifiertargetin.py +1 -1
  40. mistralai/models/classifiertrainingparameters.py +1 -1
  41. mistralai/models/classifiertrainingparametersin.py +1 -1
  42. mistralai/models/completionargs.py +1 -1
  43. mistralai/models/completiondetailedjobout.py +1 -1
  44. mistralai/models/completionftmodelout.py +1 -1
  45. mistralai/models/completionjobout.py +1 -1
  46. mistralai/models/completionresponsestreamchoice.py +1 -1
  47. mistralai/models/completiontrainingparameters.py +1 -1
  48. mistralai/models/completiontrainingparametersin.py +1 -1
  49. mistralai/models/contentchunk.py +3 -0
  50. mistralai/models/conversationrequest.py +1 -1
  51. mistralai/models/conversationstreamrequest.py +1 -1
  52. mistralai/models/conversationusageinfo.py +1 -1
  53. mistralai/models/deltamessage.py +1 -1
  54. mistralai/models/documenturlchunk.py +1 -1
  55. mistralai/models/embeddingrequest.py +1 -1
  56. mistralai/models/eventout.py +1 -1
  57. mistralai/models/filechunk.py +23 -0
  58. mistralai/models/files_api_routes_list_filesop.py +1 -1
  59. mistralai/models/fileschema.py +1 -1
  60. mistralai/models/fimcompletionrequest.py +1 -1
  61. mistralai/models/fimcompletionstreamrequest.py +1 -1
  62. mistralai/models/ftmodelcard.py +9 -6
  63. mistralai/models/functioncallentry.py +1 -1
  64. mistralai/models/functionresultentry.py +1 -1
  65. mistralai/models/githubrepositoryin.py +1 -1
  66. mistralai/models/githubrepositoryout.py +1 -1
  67. mistralai/models/imageurl.py +1 -1
  68. mistralai/models/inputentries.py +21 -2
  69. mistralai/models/jobin.py +1 -1
  70. mistralai/models/jobmetadataout.py +1 -1
  71. mistralai/models/jobs_api_routes_batch_get_batch_jobsop.py +1 -1
  72. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +1 -1
  73. mistralai/models/jsonschema.py +1 -1
  74. mistralai/models/legacyjobmetadataout.py +1 -1
  75. mistralai/models/messageinputentry.py +4 -4
  76. mistralai/models/messageoutputentry.py +1 -1
  77. mistralai/models/messageoutputevent.py +1 -1
  78. mistralai/models/metricout.py +1 -1
  79. mistralai/models/mistralpromptmode.py +8 -0
  80. mistralai/models/modelcapabilities.py +3 -0
  81. mistralai/models/modelconversation.py +1 -1
  82. mistralai/models/ocrimageobject.py +1 -1
  83. mistralai/models/ocrpageobject.py +1 -1
  84. mistralai/models/ocrrequest.py +5 -3
  85. mistralai/models/ocrresponse.py +1 -1
  86. mistralai/models/ocrusageinfo.py +1 -1
  87. mistralai/models/responseformat.py +1 -1
  88. mistralai/models/retrievefileout.py +1 -1
  89. mistralai/models/toolexecutionentry.py +1 -1
  90. mistralai/models/toolfilechunk.py +1 -1
  91. mistralai/models/toolmessage.py +1 -1
  92. mistralai/models/toolreferencechunk.py +1 -1
  93. mistralai/models/updateftmodelin.py +1 -1
  94. mistralai/models/uploadfileout.py +1 -1
  95. mistralai/models/usermessage.py +1 -1
  96. mistralai/models/wandbintegration.py +1 -1
  97. mistralai/models/wandbintegrationout.py +1 -1
  98. mistralai/models_.py +14 -2
  99. mistralai/ocr.py +2 -0
  100. mistralai/sdk.py +68 -40
  101. mistralai/sdkconfiguration.py +0 -7
  102. mistralai/types/basemodel.py +3 -3
  103. mistralai/utils/__init__.py +131 -45
  104. mistralai/utils/datetimes.py +23 -0
  105. mistralai/utils/enums.py +67 -27
  106. mistralai/utils/forms.py +49 -28
  107. mistralai/utils/serializers.py +32 -3
  108. {mistralai-1.8.1.dist-info → mistralai-1.9.1.dist-info}/METADATA +13 -6
  109. {mistralai-1.8.1.dist-info → mistralai-1.9.1.dist-info}/RECORD +111 -108
  110. {mistralai-1.8.1.dist-info → mistralai-1.9.1.dist-info}/LICENSE +0 -0
  111. {mistralai-1.8.1.dist-info → mistralai-1.9.1.dist-info}/WHEEL +0 -0
mistralai/models_.py CHANGED
@@ -63,6 +63,7 @@ class Models(BaseSDK):
63
63
 
64
64
  http_res = self.do_request(
65
65
  hook_ctx=HookContext(
66
+ config=self.sdk_configuration,
66
67
  base_url=base_url or "",
67
68
  operation_id="list_models_v1_models_get",
68
69
  oauth2_scopes=[],
@@ -155,6 +156,7 @@ class Models(BaseSDK):
155
156
 
156
157
  http_res = await self.do_request_async(
157
158
  hook_ctx=HookContext(
159
+ config=self.sdk_configuration,
158
160
  base_url=base_url or "",
159
161
  operation_id="list_models_v1_models_get",
160
162
  oauth2_scopes=[],
@@ -206,7 +208,7 @@ class Models(BaseSDK):
206
208
  ) -> models.RetrieveModelV1ModelsModelIDGetResponseRetrieveModelV1ModelsModelIDGet:
207
209
  r"""Retrieve Model
208
210
 
209
- Retrieve a model information.
211
+ Retrieve information about a model.
210
212
 
211
213
  :param model_id: The ID of the model to retrieve.
212
214
  :param retries: Override the default retry configuration for this method
@@ -254,6 +256,7 @@ class Models(BaseSDK):
254
256
 
255
257
  http_res = self.do_request(
256
258
  hook_ctx=HookContext(
259
+ config=self.sdk_configuration,
257
260
  base_url=base_url or "",
258
261
  operation_id="retrieve_model_v1_models__model_id__get",
259
262
  oauth2_scopes=[],
@@ -308,7 +311,7 @@ class Models(BaseSDK):
308
311
  ) -> models.RetrieveModelV1ModelsModelIDGetResponseRetrieveModelV1ModelsModelIDGet:
309
312
  r"""Retrieve Model
310
313
 
311
- Retrieve a model information.
314
+ Retrieve information about a model.
312
315
 
313
316
  :param model_id: The ID of the model to retrieve.
314
317
  :param retries: Override the default retry configuration for this method
@@ -356,6 +359,7 @@ class Models(BaseSDK):
356
359
 
357
360
  http_res = await self.do_request_async(
358
361
  hook_ctx=HookContext(
362
+ config=self.sdk_configuration,
359
363
  base_url=base_url or "",
360
364
  operation_id="retrieve_model_v1_models__model_id__get",
361
365
  oauth2_scopes=[],
@@ -458,6 +462,7 @@ class Models(BaseSDK):
458
462
 
459
463
  http_res = self.do_request(
460
464
  hook_ctx=HookContext(
465
+ config=self.sdk_configuration,
461
466
  base_url=base_url or "",
462
467
  operation_id="delete_model_v1_models__model_id__delete",
463
468
  oauth2_scopes=[],
@@ -557,6 +562,7 @@ class Models(BaseSDK):
557
562
 
558
563
  http_res = await self.do_request_async(
559
564
  hook_ctx=HookContext(
565
+ config=self.sdk_configuration,
560
566
  base_url=base_url or "",
561
567
  operation_id="delete_model_v1_models__model_id__delete",
562
568
  oauth2_scopes=[],
@@ -667,6 +673,7 @@ class Models(BaseSDK):
667
673
 
668
674
  http_res = self.do_request(
669
675
  hook_ctx=HookContext(
676
+ config=self.sdk_configuration,
670
677
  base_url=base_url or "",
671
678
  operation_id="jobs_api_routes_fine_tuning_update_fine_tuned_model",
672
679
  oauth2_scopes=[],
@@ -774,6 +781,7 @@ class Models(BaseSDK):
774
781
 
775
782
  http_res = await self.do_request_async(
776
783
  hook_ctx=HookContext(
784
+ config=self.sdk_configuration,
777
785
  base_url=base_url or "",
778
786
  operation_id="jobs_api_routes_fine_tuning_update_fine_tuned_model",
779
787
  oauth2_scopes=[],
@@ -870,6 +878,7 @@ class Models(BaseSDK):
870
878
 
871
879
  http_res = self.do_request(
872
880
  hook_ctx=HookContext(
881
+ config=self.sdk_configuration,
873
882
  base_url=base_url or "",
874
883
  operation_id="jobs_api_routes_fine_tuning_archive_fine_tuned_model",
875
884
  oauth2_scopes=[],
@@ -963,6 +972,7 @@ class Models(BaseSDK):
963
972
 
964
973
  http_res = await self.do_request_async(
965
974
  hook_ctx=HookContext(
975
+ config=self.sdk_configuration,
966
976
  base_url=base_url or "",
967
977
  operation_id="jobs_api_routes_fine_tuning_archive_fine_tuned_model",
968
978
  oauth2_scopes=[],
@@ -1056,6 +1066,7 @@ class Models(BaseSDK):
1056
1066
 
1057
1067
  http_res = self.do_request(
1058
1068
  hook_ctx=HookContext(
1069
+ config=self.sdk_configuration,
1059
1070
  base_url=base_url or "",
1060
1071
  operation_id="jobs_api_routes_fine_tuning_unarchive_fine_tuned_model",
1061
1072
  oauth2_scopes=[],
@@ -1149,6 +1160,7 @@ class Models(BaseSDK):
1149
1160
 
1150
1161
  http_res = await self.do_request_async(
1151
1162
  hook_ctx=HookContext(
1163
+ config=self.sdk_configuration,
1152
1164
  base_url=base_url or "",
1153
1165
  operation_id="jobs_api_routes_fine_tuning_unarchive_fine_tuned_model",
1154
1166
  oauth2_scopes=[],
mistralai/ocr.py CHANGED
@@ -103,6 +103,7 @@ class Ocr(BaseSDK):
103
103
 
104
104
  http_res = self.do_request(
105
105
  hook_ctx=HookContext(
106
+ config=self.sdk_configuration,
106
107
  base_url=base_url or "",
107
108
  operation_id="ocr_v1_ocr_post",
108
109
  oauth2_scopes=[],
@@ -235,6 +236,7 @@ class Ocr(BaseSDK):
235
236
 
236
237
  http_res = await self.do_request_async(
237
238
  hook_ctx=HookContext(
239
+ config=self.sdk_configuration,
238
240
  base_url=base_url or "",
239
241
  operation_id="ocr_v1_ocr_post",
240
242
  oauth2_scopes=[],
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
- self._init_sdks()
144
-
145
- def _init_sdks(self):
146
- self.models = Models(self.sdk_configuration)
147
- self.beta = Beta(self.sdk_configuration)
148
- self.files = Files(self.sdk_configuration)
149
- self.fine_tuning = FineTuning(self.sdk_configuration)
150
- self.batch = Batch(self.sdk_configuration)
151
- self.chat = Chat(self.sdk_configuration)
152
- self.fim = Fim(self.sdk_configuration)
153
- self.agents = Agents(self.sdk_configuration)
154
- self.embeddings = Embeddings(self.sdk_configuration)
155
- self.classifiers = Classifiers(self.sdk_configuration)
156
- self.ocr = Ocr(self.sdk_configuration)
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
@@ -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
@@ -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, NewType
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 = NewType("UnrecognizedInt", int)
39
- UnrecognizedStr = NewType("UnrecognizedStr", str)
38
+ UnrecognizedInt: TypeAlias = int
39
+ UnrecognizedStr: TypeAlias = str
@@ -1,51 +1,56 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
- from .annotations import get_discriminator
4
- from .enums import OpenEnumMeta
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
- from .serializers import (
23
- get_pydantic_model,
24
- marshal_json,
25
- unmarshal,
26
- unmarshal_json,
27
- serialize_decimal,
28
- serialize_float,
29
- serialize_int,
30
- stream_to_text,
31
- stream_to_text_async,
32
- stream_to_bytes,
33
- stream_to_bytes_async,
34
- validate_const,
35
- validate_decimal,
36
- validate_float,
37
- validate_int,
38
- validate_open_enum,
39
- )
40
- from .url import generate_url, template_url, remove_suffix
41
- from .values import (
42
- get_global_from_env,
43
- match_content_type,
44
- match_status_codes,
45
- match_response,
46
- cast_partial,
47
- )
48
- from .logger import Logger, get_body_content, get_default_logger
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
- def __call__(
8
- cls, value, names=None, *, module=None, qualname=None, type=None, start=1
9
- ):
10
- # The `type` kwarg also happens to be a built-in that pylint flags as
11
- # redeclared. Safe to ignore this lint rule with this scope.
12
- # pylint: disable=redefined-builtin
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
- if names is not None:
15
- return super().__call__(
16
- value,
17
- names=names,
18
- module=module,
19
- qualname=qualname,
20
- type=type,
21
- start=start,
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
- try:
25
- return super().__call__(
26
- value,
27
- names=names, # pyright: ignore[reportArgumentType]
28
- module=module,
29
- qualname=qualname,
30
- type=type,
31
- start=start,
32
- )
33
- except ValueError:
34
- return value
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