mistralai 1.5.2__py3-none-any.whl → 1.6.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 (80) hide show
  1. mistralai/_hooks/types.py +15 -3
  2. mistralai/_version.py +3 -3
  3. mistralai/agents.py +44 -12
  4. mistralai/basesdk.py +8 -0
  5. mistralai/chat.py +44 -12
  6. mistralai/classifiers.py +36 -16
  7. mistralai/embeddings.py +16 -6
  8. mistralai/files.py +36 -0
  9. mistralai/fim.py +32 -12
  10. mistralai/httpclient.py +4 -2
  11. mistralai/jobs.py +30 -0
  12. mistralai/mistral_jobs.py +24 -0
  13. mistralai/models/agentscompletionrequest.py +4 -0
  14. mistralai/models/agentscompletionstreamrequest.py +4 -0
  15. mistralai/models/chatcompletionrequest.py +4 -0
  16. mistralai/models/chatcompletionstreamrequest.py +4 -0
  17. mistralai/models/function.py +2 -2
  18. mistralai/models/jsonschema.py +1 -1
  19. mistralai/models_.py +66 -18
  20. mistralai/ocr.py +16 -6
  21. mistralai/sdk.py +19 -3
  22. mistralai/sdkconfiguration.py +4 -2
  23. mistralai/utils/__init__.py +2 -0
  24. mistralai/utils/serializers.py +10 -6
  25. mistralai/utils/values.py +4 -1
  26. {mistralai-1.5.2.dist-info → mistralai-1.6.0.dist-info}/METADATA +63 -16
  27. {mistralai-1.5.2.dist-info → mistralai-1.6.0.dist-info}/RECORD +80 -72
  28. mistralai_azure/__init__.py +10 -1
  29. mistralai_azure/_hooks/types.py +15 -3
  30. mistralai_azure/_version.py +4 -1
  31. mistralai_azure/basesdk.py +8 -0
  32. mistralai_azure/chat.py +100 -20
  33. mistralai_azure/httpclient.py +52 -0
  34. mistralai_azure/models/__init__.py +22 -0
  35. mistralai_azure/models/assistantmessage.py +2 -0
  36. mistralai_azure/models/chatcompletionrequest.py +12 -10
  37. mistralai_azure/models/chatcompletionstreamrequest.py +12 -10
  38. mistralai_azure/models/contentchunk.py +6 -2
  39. mistralai_azure/models/function.py +4 -1
  40. mistralai_azure/models/imageurl.py +53 -0
  41. mistralai_azure/models/imageurlchunk.py +33 -0
  42. mistralai_azure/models/jsonschema.py +61 -0
  43. mistralai_azure/models/prediction.py +25 -0
  44. mistralai_azure/models/responseformat.py +42 -1
  45. mistralai_azure/models/responseformats.py +1 -1
  46. mistralai_azure/models/toolcall.py +3 -0
  47. mistralai_azure/sdk.py +56 -14
  48. mistralai_azure/sdkconfiguration.py +14 -6
  49. mistralai_azure/utils/__init__.py +2 -0
  50. mistralai_azure/utils/serializers.py +10 -6
  51. mistralai_azure/utils/values.py +4 -1
  52. mistralai_gcp/__init__.py +10 -1
  53. mistralai_gcp/_hooks/types.py +15 -3
  54. mistralai_gcp/_version.py +4 -1
  55. mistralai_gcp/basesdk.py +8 -0
  56. mistralai_gcp/chat.py +101 -21
  57. mistralai_gcp/fim.py +61 -21
  58. mistralai_gcp/httpclient.py +52 -0
  59. mistralai_gcp/models/__init__.py +22 -0
  60. mistralai_gcp/models/assistantmessage.py +2 -0
  61. mistralai_gcp/models/chatcompletionrequest.py +12 -10
  62. mistralai_gcp/models/chatcompletionstreamrequest.py +12 -10
  63. mistralai_gcp/models/contentchunk.py +6 -2
  64. mistralai_gcp/models/fimcompletionrequest.py +2 -3
  65. mistralai_gcp/models/fimcompletionstreamrequest.py +2 -3
  66. mistralai_gcp/models/function.py +4 -1
  67. mistralai_gcp/models/imageurl.py +53 -0
  68. mistralai_gcp/models/imageurlchunk.py +33 -0
  69. mistralai_gcp/models/jsonschema.py +61 -0
  70. mistralai_gcp/models/prediction.py +25 -0
  71. mistralai_gcp/models/responseformat.py +42 -1
  72. mistralai_gcp/models/responseformats.py +1 -1
  73. mistralai_gcp/models/toolcall.py +3 -0
  74. mistralai_gcp/sdk.py +63 -19
  75. mistralai_gcp/sdkconfiguration.py +14 -6
  76. mistralai_gcp/utils/__init__.py +2 -0
  77. mistralai_gcp/utils/serializers.py +10 -6
  78. mistralai_gcp/utils/values.py +4 -1
  79. {mistralai-1.5.2.dist-info → mistralai-1.6.0.dist-info}/LICENSE +0 -0
  80. {mistralai-1.5.2.dist-info → mistralai-1.6.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,53 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from mistralai_azure.types import (
5
+ BaseModel,
6
+ Nullable,
7
+ OptionalNullable,
8
+ UNSET,
9
+ UNSET_SENTINEL,
10
+ )
11
+ from pydantic import model_serializer
12
+ from typing_extensions import NotRequired, TypedDict
13
+
14
+
15
+ class ImageURLTypedDict(TypedDict):
16
+ url: str
17
+ detail: NotRequired[Nullable[str]]
18
+
19
+
20
+ class ImageURL(BaseModel):
21
+ url: str
22
+
23
+ detail: OptionalNullable[str] = UNSET
24
+
25
+ @model_serializer(mode="wrap")
26
+ def serialize_model(self, handler):
27
+ optional_fields = ["detail"]
28
+ nullable_fields = ["detail"]
29
+ null_default_fields = []
30
+
31
+ serialized = handler(self)
32
+
33
+ m = {}
34
+
35
+ for n, f in self.model_fields.items():
36
+ k = f.alias or n
37
+ val = serialized.get(k)
38
+ serialized.pop(k, None)
39
+
40
+ optional_nullable = k in optional_fields and k in nullable_fields
41
+ is_set = (
42
+ self.__pydantic_fields_set__.intersection({n})
43
+ or k in null_default_fields
44
+ ) # pylint: disable=no-member
45
+
46
+ if val is not None and val != UNSET_SENTINEL:
47
+ m[k] = val
48
+ elif val != UNSET_SENTINEL and (
49
+ not k in optional_fields or (optional_nullable and is_set)
50
+ ):
51
+ m[k] = val
52
+
53
+ return m
@@ -0,0 +1,33 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .imageurl import ImageURL, ImageURLTypedDict
5
+ from mistralai_azure.types import BaseModel
6
+ from typing import Literal, Optional, Union
7
+ from typing_extensions import NotRequired, TypeAliasType, TypedDict
8
+
9
+
10
+ ImageURLChunkImageURLTypedDict = TypeAliasType(
11
+ "ImageURLChunkImageURLTypedDict", Union[ImageURLTypedDict, str]
12
+ )
13
+
14
+
15
+ ImageURLChunkImageURL = TypeAliasType("ImageURLChunkImageURL", Union[ImageURL, str])
16
+
17
+
18
+ ImageURLChunkType = Literal["image_url"]
19
+
20
+
21
+ class ImageURLChunkTypedDict(TypedDict):
22
+ r"""{\"type\":\"image_url\",\"image_url\":{\"url\":\"data:image/png;base64,iVBORw0"""
23
+
24
+ image_url: ImageURLChunkImageURLTypedDict
25
+ type: NotRequired[ImageURLChunkType]
26
+
27
+
28
+ class ImageURLChunk(BaseModel):
29
+ r"""{\"type\":\"image_url\",\"image_url\":{\"url\":\"data:image/png;base64,iVBORw0"""
30
+
31
+ image_url: ImageURLChunkImageURL
32
+
33
+ type: Optional[ImageURLChunkType] = "image_url"
@@ -0,0 +1,61 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from mistralai_azure.types import (
5
+ BaseModel,
6
+ Nullable,
7
+ OptionalNullable,
8
+ UNSET,
9
+ UNSET_SENTINEL,
10
+ )
11
+ import pydantic
12
+ from pydantic import model_serializer
13
+ from typing import Any, Dict, Optional
14
+ from typing_extensions import Annotated, NotRequired, TypedDict
15
+
16
+
17
+ class JSONSchemaTypedDict(TypedDict):
18
+ name: str
19
+ schema_definition: Dict[str, Any]
20
+ description: NotRequired[Nullable[str]]
21
+ strict: NotRequired[bool]
22
+
23
+
24
+ class JSONSchema(BaseModel):
25
+ name: str
26
+
27
+ schema_definition: Annotated[Dict[str, Any], pydantic.Field(alias="schema")]
28
+
29
+ description: OptionalNullable[str] = UNSET
30
+
31
+ strict: Optional[bool] = None
32
+
33
+ @model_serializer(mode="wrap")
34
+ def serialize_model(self, handler):
35
+ optional_fields = ["description", "strict"]
36
+ nullable_fields = ["description"]
37
+ null_default_fields = []
38
+
39
+ serialized = handler(self)
40
+
41
+ m = {}
42
+
43
+ for n, f in self.model_fields.items():
44
+ k = f.alias or n
45
+ val = serialized.get(k)
46
+ serialized.pop(k, None)
47
+
48
+ optional_nullable = k in optional_fields and k in nullable_fields
49
+ is_set = (
50
+ self.__pydantic_fields_set__.intersection({n})
51
+ or k in null_default_fields
52
+ ) # pylint: disable=no-member
53
+
54
+ if val is not None and val != UNSET_SENTINEL:
55
+ m[k] = val
56
+ elif val != UNSET_SENTINEL and (
57
+ not k in optional_fields or (optional_nullable and is_set)
58
+ ):
59
+ m[k] = val
60
+
61
+ return m
@@ -0,0 +1,25 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from mistralai_azure.types import BaseModel
5
+ from mistralai_azure.utils import validate_const
6
+ import pydantic
7
+ from pydantic.functional_validators import AfterValidator
8
+ from typing import Literal, Optional
9
+ from typing_extensions import Annotated, NotRequired, TypedDict
10
+
11
+
12
+ class PredictionTypedDict(TypedDict):
13
+ type: Literal["content"]
14
+ content: NotRequired[str]
15
+
16
+
17
+ class Prediction(BaseModel):
18
+ TYPE: Annotated[
19
+ Annotated[
20
+ Optional[Literal["content"]], AfterValidator(validate_const("content"))
21
+ ],
22
+ pydantic.Field(alias="type"),
23
+ ] = "content"
24
+
25
+ content: Optional[str] = ""
@@ -1,8 +1,16 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
3
  from __future__ import annotations
4
+ from .jsonschema import JSONSchema, JSONSchemaTypedDict
4
5
  from .responseformats import ResponseFormats
5
- from mistralai_azure.types import BaseModel
6
+ from mistralai_azure.types import (
7
+ BaseModel,
8
+ Nullable,
9
+ OptionalNullable,
10
+ UNSET,
11
+ UNSET_SENTINEL,
12
+ )
13
+ from pydantic import model_serializer
6
14
  from typing import Optional
7
15
  from typing_extensions import NotRequired, TypedDict
8
16
 
@@ -10,8 +18,41 @@ from typing_extensions import NotRequired, TypedDict
10
18
  class ResponseFormatTypedDict(TypedDict):
11
19
  type: NotRequired[ResponseFormats]
12
20
  r"""An object specifying the format that the model must output. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message."""
21
+ json_schema: NotRequired[Nullable[JSONSchemaTypedDict]]
13
22
 
14
23
 
15
24
  class ResponseFormat(BaseModel):
16
25
  type: Optional[ResponseFormats] = None
17
26
  r"""An object specifying the format that the model must output. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message."""
27
+
28
+ json_schema: OptionalNullable[JSONSchema] = UNSET
29
+
30
+ @model_serializer(mode="wrap")
31
+ def serialize_model(self, handler):
32
+ optional_fields = ["type", "json_schema"]
33
+ nullable_fields = ["json_schema"]
34
+ null_default_fields = []
35
+
36
+ serialized = handler(self)
37
+
38
+ m = {}
39
+
40
+ for n, f in self.model_fields.items():
41
+ k = f.alias or n
42
+ val = serialized.get(k)
43
+ serialized.pop(k, None)
44
+
45
+ optional_nullable = k in optional_fields and k in nullable_fields
46
+ is_set = (
47
+ self.__pydantic_fields_set__.intersection({n})
48
+ or k in null_default_fields
49
+ ) # pylint: disable=no-member
50
+
51
+ if val is not None and val != UNSET_SENTINEL:
52
+ m[k] = val
53
+ elif val != UNSET_SENTINEL and (
54
+ not k in optional_fields or (optional_nullable and is_set)
55
+ ):
56
+ m[k] = val
57
+
58
+ return m
@@ -4,5 +4,5 @@ from __future__ import annotations
4
4
  from typing import Literal
5
5
 
6
6
 
7
- ResponseFormats = Literal["text", "json_object"]
7
+ ResponseFormats = Literal["text", "json_object", "json_schema"]
8
8
  r"""An object specifying the format that the model must output. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message."""
@@ -14,6 +14,7 @@ class ToolCallTypedDict(TypedDict):
14
14
  function: FunctionCallTypedDict
15
15
  id: NotRequired[str]
16
16
  type: NotRequired[ToolTypes]
17
+ index: NotRequired[int]
17
18
 
18
19
 
19
20
  class ToolCall(BaseModel):
@@ -24,3 +25,5 @@ class ToolCall(BaseModel):
24
25
  type: Annotated[Optional[ToolTypes], PlainValidator(validate_open_enum(False))] = (
25
26
  None
26
27
  )
28
+
29
+ index: Optional[int] = 0
mistralai_azure/sdk.py CHANGED
@@ -1,17 +1,19 @@
1
- """Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
- from typing import Any, Callable, Dict, Optional, Union
3
+ import weakref
4
+ from typing import Any, Callable, Dict, Optional, Union, cast
4
5
 
5
6
  import httpx
7
+
6
8
  from mistralai_azure import models, utils
7
9
  from mistralai_azure._hooks import SDKHooks
8
10
  from mistralai_azure.chat import Chat
9
- from mistralai_azure.types import Nullable
11
+ from mistralai_azure.types import UNSET, OptionalNullable
10
12
 
11
13
  from .basesdk import BaseSDK
12
- from .httpclient import AsyncHttpClient, HttpClient
14
+ from .httpclient import AsyncHttpClient, ClientOwner, HttpClient, close_clients
13
15
  from .sdkconfiguration import SDKConfiguration
14
- from .utils.logger import Logger, NoOpLogger
16
+ from .utils.logger import Logger, get_default_logger
15
17
  from .utils.retries import RetryConfig
16
18
 
17
19
 
@@ -19,7 +21,7 @@ class MistralAzure(BaseSDK):
19
21
  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."""
20
22
 
21
23
  chat: Chat
22
- r"""Chat Completion API"""
24
+ r"""Chat Completion API."""
23
25
 
24
26
  def __init__(
25
27
  self,
@@ -28,7 +30,8 @@ class MistralAzure(BaseSDK):
28
30
  url_params: Optional[Dict[str, str]] = None,
29
31
  client: Optional[HttpClient] = None,
30
32
  async_client: Optional[AsyncHttpClient] = None,
31
- retry_config: Optional[Nullable[RetryConfig]] = None,
33
+ retry_config: OptionalNullable[RetryConfig] = UNSET,
34
+ timeout_ms: Optional[int] = None,
32
35
  debug_logger: Optional[Logger] = None,
33
36
  ) -> None:
34
37
  r"""Instantiates the SDK configuring it with the provided parameters.
@@ -39,7 +42,9 @@ class MistralAzure(BaseSDK):
39
42
  :param client: The HTTP client to use for all synchronous methods
40
43
  :param async_client: The Async HTTP client to use for all asynchronous methods
41
44
  :param retry_config: The retry configuration to use for all supported methods
45
+ :param timeout_ms: Optional request timeout applied to each operation in milliseconds
42
46
  """
47
+
43
48
  # if azure_endpoint doesn't end with `/v1` add it
44
49
  if not azure_endpoint.endswith("/"):
45
50
  azure_endpoint += "/"
@@ -47,28 +52,30 @@ class MistralAzure(BaseSDK):
47
52
  azure_endpoint += "v1/"
48
53
  server_url = azure_endpoint
49
54
 
55
+ client_supplied = True
50
56
  if client is None:
51
57
  client = httpx.Client()
58
+ client_supplied = False
52
59
 
53
60
  assert issubclass(
54
61
  type(client), HttpClient
55
62
  ), "The provided client must implement the HttpClient protocol."
56
63
 
64
+ async_client_supplied = True
57
65
  if async_client is None:
58
66
  async_client = httpx.AsyncClient()
67
+ async_client_supplied = False
68
+
69
+ if debug_logger is None:
70
+ debug_logger = get_default_logger()
59
71
 
60
72
  assert issubclass(
61
73
  type(async_client), AsyncHttpClient
62
74
  ), "The provided async_client must implement the AsyncHttpClient protocol."
63
75
 
64
- if debug_logger is None:
65
- debug_logger = NoOpLogger()
66
-
67
76
  security: Any = None
68
77
  if callable(azure_api_key):
69
- security = lambda: models.Security( # pylint: disable=unnecessary-lambda-assignment
70
- api_key=azure_api_key()
71
- )
78
+ security = lambda: models.Security(api_key=azure_api_key()) # pylint: disable=unnecessary-lambda-assignment
72
79
  else:
73
80
  security = models.Security(api_key=azure_api_key)
74
81
 
@@ -80,11 +87,14 @@ class MistralAzure(BaseSDK):
80
87
  self,
81
88
  SDKConfiguration(
82
89
  client=client,
90
+ client_supplied=client_supplied,
83
91
  async_client=async_client,
92
+ async_client_supplied=async_client_supplied,
84
93
  security=security,
85
94
  server_url=server_url,
86
95
  server=None,
87
96
  retry_config=retry_config,
97
+ timeout_ms=timeout_ms,
88
98
  debug_logger=debug_logger,
89
99
  ),
90
100
  )
@@ -93,7 +103,7 @@ class MistralAzure(BaseSDK):
93
103
 
94
104
  current_server_url, *_ = self.sdk_configuration.get_server_details()
95
105
  server_url, self.sdk_configuration.client = hooks.sdk_init(
96
- current_server_url, self.sdk_configuration.client
106
+ current_server_url, client
97
107
  )
98
108
  if current_server_url != server_url:
99
109
  self.sdk_configuration.server_url = server_url
@@ -101,7 +111,39 @@ class MistralAzure(BaseSDK):
101
111
  # pylint: disable=protected-access
102
112
  self.sdk_configuration.__dict__["_hooks"] = hooks
103
113
 
114
+ weakref.finalize(
115
+ self,
116
+ close_clients,
117
+ cast(ClientOwner, self.sdk_configuration),
118
+ self.sdk_configuration.client,
119
+ self.sdk_configuration.client_supplied,
120
+ self.sdk_configuration.async_client,
121
+ self.sdk_configuration.async_client_supplied,
122
+ )
123
+
104
124
  self._init_sdks()
105
125
 
106
126
  def _init_sdks(self):
107
127
  self.chat = Chat(self.sdk_configuration)
128
+
129
+ def __enter__(self):
130
+ return self
131
+
132
+ async def __aenter__(self):
133
+ return self
134
+
135
+ def __exit__(self, exc_type, exc_val, exc_tb):
136
+ if (
137
+ self.sdk_configuration.client is not None
138
+ and not self.sdk_configuration.client_supplied
139
+ ):
140
+ self.sdk_configuration.client.close()
141
+ self.sdk_configuration.client = None
142
+
143
+ async def __aexit__(self, exc_type, exc_val, exc_tb):
144
+ if (
145
+ self.sdk_configuration.async_client is not None
146
+ and not self.sdk_configuration.async_client_supplied
147
+ ):
148
+ await self.sdk_configuration.async_client.aclose()
149
+ self.sdk_configuration.async_client = None
@@ -1,6 +1,12 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
3
  from ._hooks import SDKHooks
4
+ from ._version import (
5
+ __gen_version__,
6
+ __openapi_doc_version__,
7
+ __user_agent__,
8
+ __version__,
9
+ )
4
10
  from .httpclient import AsyncHttpClient, HttpClient
5
11
  from .utils import Logger, RetryConfig, remove_suffix
6
12
  from dataclasses import dataclass
@@ -20,17 +26,19 @@ SERVERS = {
20
26
 
21
27
  @dataclass
22
28
  class SDKConfiguration:
23
- client: HttpClient
24
- async_client: AsyncHttpClient
29
+ client: Union[HttpClient, None]
30
+ client_supplied: bool
31
+ async_client: Union[AsyncHttpClient, None]
32
+ async_client_supplied: bool
25
33
  debug_logger: Logger
26
34
  security: Optional[Union[models.Security, Callable[[], models.Security]]] = None
27
35
  server_url: Optional[str] = ""
28
36
  server: Optional[str] = ""
29
37
  language: str = "python"
30
- openapi_doc_version: str = "0.0.2"
31
- sdk_version: str = "1.2.6"
32
- gen_version: str = "2.486.1"
33
- user_agent: str = "speakeasy-sdk/python 1.2.6 2.486.1 0.0.2 mistralai_azure"
38
+ openapi_doc_version: str = __openapi_doc_version__
39
+ sdk_version: str = __version__
40
+ gen_version: str = __gen_version__
41
+ user_agent: str = __user_agent__
34
42
  retry_config: OptionalNullable[RetryConfig] = Field(default_factory=lambda: UNSET)
35
43
  timeout_ms: Optional[int] = None
36
44
 
@@ -42,6 +42,7 @@ from .values import (
42
42
  match_content_type,
43
43
  match_status_codes,
44
44
  match_response,
45
+ cast_partial,
45
46
  )
46
47
  from .logger import Logger, get_body_content, get_default_logger
47
48
 
@@ -94,4 +95,5 @@ __all__ = [
94
95
  "validate_float",
95
96
  "validate_int",
96
97
  "validate_open_enum",
98
+ "cast_partial",
97
99
  ]
@@ -7,14 +7,15 @@ import httpx
7
7
  from typing_extensions import get_origin
8
8
  from pydantic import ConfigDict, create_model
9
9
  from pydantic_core import from_json
10
- from typing_inspect import is_optional_type
10
+ from typing_inspection.typing_objects import is_union
11
11
 
12
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
- if is_optional_type(type(d)) and d is None:
17
+ # Optional[T] is a Union[T, None]
18
+ if is_union(type(d)) and type(None) in get_args(type(d)) and d is None:
18
19
  return None
19
20
  if isinstance(d, Unset):
20
21
  return d
@@ -42,7 +43,8 @@ def validate_decimal(d):
42
43
 
43
44
  def serialize_float(as_str: bool):
44
45
  def serialize(f):
45
- if is_optional_type(type(f)) and f is None:
46
+ # Optional[T] is a Union[T, None]
47
+ if is_union(type(f)) and type(None) in get_args(type(f)) and f is None:
46
48
  return None
47
49
  if isinstance(f, Unset):
48
50
  return f
@@ -70,7 +72,8 @@ def validate_float(f):
70
72
 
71
73
  def serialize_int(as_str: bool):
72
74
  def serialize(i):
73
- if is_optional_type(type(i)) and i is None:
75
+ # Optional[T] is a Union[T, None]
76
+ if is_union(type(i)) and type(None) in get_args(type(i)) and i is None:
74
77
  return None
75
78
  if isinstance(i, Unset):
76
79
  return i
@@ -118,7 +121,8 @@ def validate_open_enum(is_int: bool):
118
121
 
119
122
  def validate_const(v):
120
123
  def validate(c):
121
- if is_optional_type(type(c)) and c is None:
124
+ # Optional[T] is a Union[T, None]
125
+ if is_union(type(c)) and type(None) in get_args(type(c)) and c is None:
122
126
  return None
123
127
 
124
128
  if v != c:
@@ -163,7 +167,7 @@ def marshal_json(val, typ):
163
167
  if len(d) == 0:
164
168
  return ""
165
169
 
166
- return json.dumps(d[next(iter(d))], separators=(",", ":"), sort_keys=True)
170
+ return json.dumps(d[next(iter(d))], separators=(",", ":"))
167
171
 
168
172
 
169
173
  def is_nullable(field):
@@ -3,8 +3,9 @@
3
3
  from datetime import datetime
4
4
  from enum import Enum
5
5
  from email.message import Message
6
+ from functools import partial
6
7
  import os
7
- from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union
8
+ from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union, cast
8
9
 
9
10
  from httpx import Response
10
11
  from pydantic import BaseModel
@@ -51,6 +52,8 @@ def match_status_codes(status_codes: List[str], status_code: int) -> bool:
51
52
 
52
53
  T = TypeVar("T")
53
54
 
55
+ def cast_partial(typ):
56
+ return partial(cast, typ)
54
57
 
55
58
  def get_global_from_env(
56
59
  value: Optional[T], env_key: str, type_cast: Callable[[str], T]
mistralai_gcp/__init__.py CHANGED
@@ -1,9 +1,18 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
- from ._version import __title__, __version__
3
+ from ._version import (
4
+ __title__,
5
+ __version__,
6
+ __openapi_doc_version__,
7
+ __gen_version__,
8
+ __user_agent__,
9
+ )
4
10
  from .sdk import *
5
11
  from .sdkconfiguration import *
6
12
  from .models import *
7
13
 
8
14
 
9
15
  VERSION: str = __version__
16
+ OPENAPI_DOC_VERSION = __openapi_doc_version__
17
+ SPEAKEASY_GENERATOR_VERSION = __gen_version__
18
+ USER_AGENT = __user_agent__
@@ -7,16 +7,19 @@ from typing import Any, Callable, List, Optional, Tuple, Union
7
7
 
8
8
 
9
9
  class HookContext:
10
+ base_url: str
10
11
  operation_id: str
11
12
  oauth2_scopes: Optional[List[str]] = None
12
13
  security_source: Optional[Union[Any, Callable[[], Any]]] = None
13
14
 
14
15
  def __init__(
15
16
  self,
17
+ base_url: str,
16
18
  operation_id: str,
17
19
  oauth2_scopes: Optional[List[str]],
18
20
  security_source: Optional[Union[Any, Callable[[], Any]]],
19
21
  ):
22
+ self.base_url = base_url
20
23
  self.operation_id = operation_id
21
24
  self.oauth2_scopes = oauth2_scopes
22
25
  self.security_source = security_source
@@ -25,21 +28,30 @@ class HookContext:
25
28
  class BeforeRequestContext(HookContext):
26
29
  def __init__(self, hook_ctx: HookContext):
27
30
  super().__init__(
28
- hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source
31
+ hook_ctx.base_url,
32
+ hook_ctx.operation_id,
33
+ hook_ctx.oauth2_scopes,
34
+ hook_ctx.security_source,
29
35
  )
30
36
 
31
37
 
32
38
  class AfterSuccessContext(HookContext):
33
39
  def __init__(self, hook_ctx: HookContext):
34
40
  super().__init__(
35
- hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source
41
+ hook_ctx.base_url,
42
+ hook_ctx.operation_id,
43
+ hook_ctx.oauth2_scopes,
44
+ hook_ctx.security_source,
36
45
  )
37
46
 
38
47
 
39
48
  class AfterErrorContext(HookContext):
40
49
  def __init__(self, hook_ctx: HookContext):
41
50
  super().__init__(
42
- hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source
51
+ hook_ctx.base_url,
52
+ hook_ctx.operation_id,
53
+ hook_ctx.oauth2_scopes,
54
+ hook_ctx.security_source,
43
55
  )
44
56
 
45
57
 
mistralai_gcp/_version.py CHANGED
@@ -3,7 +3,10 @@
3
3
  import importlib.metadata
4
4
 
5
5
  __title__: str = "mistralai-gcp"
6
- __version__: str = "1.2.6"
6
+ __version__: str = "1.6.0"
7
+ __openapi_doc_version__: str = "0.0.2"
8
+ __gen_version__: str = "2.548.6"
9
+ __user_agent__: str = "speakeasy-sdk/python 1.6.0 2.548.6 0.0.2 mistralai-gcp"
7
10
 
8
11
  try:
9
12
  if __package__ is not None:
mistralai_gcp/basesdk.py CHANGED
@@ -231,6 +231,10 @@ class BaseSDK:
231
231
  req.headers,
232
232
  get_body_content(req),
233
233
  )
234
+
235
+ if client is None:
236
+ raise ValueError("client is required")
237
+
234
238
  http_res = client.send(req, stream=stream)
235
239
  except Exception as e:
236
240
  _, e = self.sdk_configuration.get_hooks().after_error(
@@ -303,6 +307,10 @@ class BaseSDK:
303
307
  req.headers,
304
308
  get_body_content(req),
305
309
  )
310
+
311
+ if client is None:
312
+ raise ValueError("client is required")
313
+
306
314
  http_res = await client.send(req, stream=stream)
307
315
  except Exception as e:
308
316
  _, e = self.sdk_configuration.get_hooks().after_error(