relaxai 0.2.1__py3-none-any.whl → 0.3.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.
- relaxai/__init__.py +3 -1
- relaxai/_base_client.py +12 -12
- relaxai/_client.py +27 -11
- relaxai/_compat.py +48 -48
- relaxai/_models.py +50 -44
- relaxai/_qs.py +7 -7
- relaxai/_types.py +53 -12
- relaxai/_utils/__init__.py +9 -2
- relaxai/_utils/_compat.py +45 -0
- relaxai/_utils/_datetime_parse.py +136 -0
- relaxai/_utils/_transform.py +13 -3
- relaxai/_utils/_typing.py +6 -1
- relaxai/_utils/_utils.py +4 -5
- relaxai/_version.py +1 -1
- relaxai/resources/__init__.py +28 -0
- relaxai/resources/chat.py +60 -60
- relaxai/resources/deep_research.py +165 -0
- relaxai/resources/embeddings.py +9 -9
- relaxai/resources/models.py +5 -5
- relaxai/resources/tools.py +165 -0
- relaxai/types/__init__.py +4 -0
- relaxai/types/chat_create_completion_params.py +3 -2
- relaxai/types/deep_research_create_params.py +13 -0
- relaxai/types/deepresearch_request_param.py +59 -0
- relaxai/types/tool_execute_code_params.py +13 -0
- relaxai/types/tool_request_param.py +17 -0
- {relaxai-0.2.1.dist-info → relaxai-0.3.0.dist-info}/METADATA +1 -1
- {relaxai-0.2.1.dist-info → relaxai-0.3.0.dist-info}/RECORD +30 -22
- {relaxai-0.2.1.dist-info → relaxai-0.3.0.dist-info}/WHEEL +0 -0
- {relaxai-0.2.1.dist-info → relaxai-0.3.0.dist-info}/licenses/LICENSE +0 -0
relaxai/__init__.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import typing as _t
|
|
4
4
|
|
|
5
5
|
from . import types
|
|
6
|
-
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes
|
|
6
|
+
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes, omit, not_given
|
|
7
7
|
from ._utils import file_from_path
|
|
8
8
|
from ._client import Client, Stream, Relaxai, Timeout, Transport, AsyncClient, AsyncStream, AsyncRelaxai, RequestOptions
|
|
9
9
|
from ._models import BaseModel
|
|
@@ -38,7 +38,9 @@ __all__ = [
|
|
|
38
38
|
"ProxiesTypes",
|
|
39
39
|
"NotGiven",
|
|
40
40
|
"NOT_GIVEN",
|
|
41
|
+
"not_given",
|
|
41
42
|
"Omit",
|
|
43
|
+
"omit",
|
|
42
44
|
"RelaxaiError",
|
|
43
45
|
"APIError",
|
|
44
46
|
"APIStatusError",
|
relaxai/_base_client.py
CHANGED
|
@@ -42,7 +42,6 @@ from . import _exceptions
|
|
|
42
42
|
from ._qs import Querystring
|
|
43
43
|
from ._files import to_httpx_files, async_to_httpx_files
|
|
44
44
|
from ._types import (
|
|
45
|
-
NOT_GIVEN,
|
|
46
45
|
Body,
|
|
47
46
|
Omit,
|
|
48
47
|
Query,
|
|
@@ -57,9 +56,10 @@ from ._types import (
|
|
|
57
56
|
RequestOptions,
|
|
58
57
|
HttpxRequestFiles,
|
|
59
58
|
ModelBuilderProtocol,
|
|
59
|
+
not_given,
|
|
60
60
|
)
|
|
61
61
|
from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
|
|
62
|
-
from ._compat import
|
|
62
|
+
from ._compat import PYDANTIC_V1, model_copy, model_dump
|
|
63
63
|
from ._models import GenericModel, FinalRequestOptions, validate_type, construct_type
|
|
64
64
|
from ._response import (
|
|
65
65
|
APIResponse,
|
|
@@ -145,9 +145,9 @@ class PageInfo:
|
|
|
145
145
|
def __init__(
|
|
146
146
|
self,
|
|
147
147
|
*,
|
|
148
|
-
url: URL | NotGiven =
|
|
149
|
-
json: Body | NotGiven =
|
|
150
|
-
params: Query | NotGiven =
|
|
148
|
+
url: URL | NotGiven = not_given,
|
|
149
|
+
json: Body | NotGiven = not_given,
|
|
150
|
+
params: Query | NotGiven = not_given,
|
|
151
151
|
) -> None:
|
|
152
152
|
self.url = url
|
|
153
153
|
self.json = json
|
|
@@ -232,7 +232,7 @@ class BaseSyncPage(BasePage[_T], Generic[_T]):
|
|
|
232
232
|
model: Type[_T],
|
|
233
233
|
options: FinalRequestOptions,
|
|
234
234
|
) -> None:
|
|
235
|
-
if
|
|
235
|
+
if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
|
|
236
236
|
self.__pydantic_private__ = {}
|
|
237
237
|
|
|
238
238
|
self._model = model
|
|
@@ -320,7 +320,7 @@ class BaseAsyncPage(BasePage[_T], Generic[_T]):
|
|
|
320
320
|
client: AsyncAPIClient,
|
|
321
321
|
options: FinalRequestOptions,
|
|
322
322
|
) -> None:
|
|
323
|
-
if
|
|
323
|
+
if (not PYDANTIC_V1) and getattr(self, "__pydantic_private__", None) is None:
|
|
324
324
|
self.__pydantic_private__ = {}
|
|
325
325
|
|
|
326
326
|
self._model = model
|
|
@@ -595,7 +595,7 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
|
|
595
595
|
# we internally support defining a temporary header to override the
|
|
596
596
|
# default `cast_to` type for use with `.with_raw_response` and `.with_streaming_response`
|
|
597
597
|
# see _response.py for implementation details
|
|
598
|
-
override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER,
|
|
598
|
+
override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, not_given)
|
|
599
599
|
if is_given(override_cast_to):
|
|
600
600
|
options.headers = headers
|
|
601
601
|
return cast(Type[ResponseT], override_cast_to)
|
|
@@ -825,7 +825,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
|
|
|
825
825
|
version: str,
|
|
826
826
|
base_url: str | URL,
|
|
827
827
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
828
|
-
timeout: float | Timeout | None | NotGiven =
|
|
828
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
|
829
829
|
http_client: httpx.Client | None = None,
|
|
830
830
|
custom_headers: Mapping[str, str] | None = None,
|
|
831
831
|
custom_query: Mapping[str, object] | None = None,
|
|
@@ -1356,7 +1356,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
|
|
|
1356
1356
|
base_url: str | URL,
|
|
1357
1357
|
_strict_response_validation: bool,
|
|
1358
1358
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
1359
|
-
timeout: float | Timeout | None | NotGiven =
|
|
1359
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
|
1360
1360
|
http_client: httpx.AsyncClient | None = None,
|
|
1361
1361
|
custom_headers: Mapping[str, str] | None = None,
|
|
1362
1362
|
custom_query: Mapping[str, object] | None = None,
|
|
@@ -1818,8 +1818,8 @@ def make_request_options(
|
|
|
1818
1818
|
extra_query: Query | None = None,
|
|
1819
1819
|
extra_body: Body | None = None,
|
|
1820
1820
|
idempotency_key: str | None = None,
|
|
1821
|
-
timeout: float | httpx.Timeout | None | NotGiven =
|
|
1822
|
-
post_parser: PostParser | NotGiven =
|
|
1821
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
1822
|
+
post_parser: PostParser | NotGiven = not_given,
|
|
1823
1823
|
) -> RequestOptions:
|
|
1824
1824
|
"""Create a dict of type RequestOptions without keys of NotGiven values."""
|
|
1825
1825
|
options: RequestOptions = {}
|
relaxai/_client.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import os
|
|
6
|
-
from typing import Any,
|
|
6
|
+
from typing import Any, Mapping
|
|
7
7
|
from typing_extensions import Self, override
|
|
8
8
|
|
|
9
9
|
import httpx
|
|
@@ -11,7 +11,6 @@ import httpx
|
|
|
11
11
|
from . import _exceptions
|
|
12
12
|
from ._qs import Querystring
|
|
13
13
|
from ._types import (
|
|
14
|
-
NOT_GIVEN,
|
|
15
14
|
Body,
|
|
16
15
|
Omit,
|
|
17
16
|
Query,
|
|
@@ -21,6 +20,7 @@ from ._types import (
|
|
|
21
20
|
Transport,
|
|
22
21
|
ProxiesTypes,
|
|
23
22
|
RequestOptions,
|
|
23
|
+
not_given,
|
|
24
24
|
)
|
|
25
25
|
from ._utils import is_given, get_async_library
|
|
26
26
|
from ._version import __version__
|
|
@@ -30,7 +30,7 @@ from ._response import (
|
|
|
30
30
|
async_to_raw_response_wrapper,
|
|
31
31
|
async_to_streamed_response_wrapper,
|
|
32
32
|
)
|
|
33
|
-
from .resources import chat, models, embeddings
|
|
33
|
+
from .resources import chat, tools, models, embeddings, deep_research
|
|
34
34
|
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
|
|
35
35
|
from ._exceptions import RelaxaiError, APIStatusError
|
|
36
36
|
from ._base_client import (
|
|
@@ -47,6 +47,8 @@ class Relaxai(SyncAPIClient):
|
|
|
47
47
|
chat: chat.ChatResource
|
|
48
48
|
embeddings: embeddings.EmbeddingsResource
|
|
49
49
|
models: models.ModelsResource
|
|
50
|
+
tools: tools.ToolsResource
|
|
51
|
+
deep_research: deep_research.DeepResearchResource
|
|
50
52
|
with_raw_response: RelaxaiWithRawResponse
|
|
51
53
|
with_streaming_response: RelaxaiWithStreamedResponse
|
|
52
54
|
|
|
@@ -58,7 +60,7 @@ class Relaxai(SyncAPIClient):
|
|
|
58
60
|
*,
|
|
59
61
|
api_key: str | None = None,
|
|
60
62
|
base_url: str | httpx.URL | None = None,
|
|
61
|
-
timeout:
|
|
63
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
|
62
64
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
63
65
|
default_headers: Mapping[str, str] | None = None,
|
|
64
66
|
default_query: Mapping[str, object] | None = None,
|
|
@@ -107,6 +109,8 @@ class Relaxai(SyncAPIClient):
|
|
|
107
109
|
self.chat = chat.ChatResource(self)
|
|
108
110
|
self.embeddings = embeddings.EmbeddingsResource(self)
|
|
109
111
|
self.models = models.ModelsResource(self)
|
|
112
|
+
self.tools = tools.ToolsResource(self)
|
|
113
|
+
self.deep_research = deep_research.DeepResearchResource(self)
|
|
110
114
|
self.with_raw_response = RelaxaiWithRawResponse(self)
|
|
111
115
|
self.with_streaming_response = RelaxaiWithStreamedResponse(self)
|
|
112
116
|
|
|
@@ -135,9 +139,9 @@ class Relaxai(SyncAPIClient):
|
|
|
135
139
|
*,
|
|
136
140
|
api_key: str | None = None,
|
|
137
141
|
base_url: str | httpx.URL | None = None,
|
|
138
|
-
timeout: float | Timeout | None | NotGiven =
|
|
142
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
|
139
143
|
http_client: httpx.Client | None = None,
|
|
140
|
-
max_retries: int | NotGiven =
|
|
144
|
+
max_retries: int | NotGiven = not_given,
|
|
141
145
|
default_headers: Mapping[str, str] | None = None,
|
|
142
146
|
set_default_headers: Mapping[str, str] | None = None,
|
|
143
147
|
default_query: Mapping[str, object] | None = None,
|
|
@@ -189,7 +193,7 @@ class Relaxai(SyncAPIClient):
|
|
|
189
193
|
extra_headers: Headers | None = None,
|
|
190
194
|
extra_query: Query | None = None,
|
|
191
195
|
extra_body: Body | None = None,
|
|
192
|
-
timeout: float | httpx.Timeout | None | NotGiven =
|
|
196
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
193
197
|
) -> str:
|
|
194
198
|
"""Check the health of the service."""
|
|
195
199
|
return self.get(
|
|
@@ -238,6 +242,8 @@ class AsyncRelaxai(AsyncAPIClient):
|
|
|
238
242
|
chat: chat.AsyncChatResource
|
|
239
243
|
embeddings: embeddings.AsyncEmbeddingsResource
|
|
240
244
|
models: models.AsyncModelsResource
|
|
245
|
+
tools: tools.AsyncToolsResource
|
|
246
|
+
deep_research: deep_research.AsyncDeepResearchResource
|
|
241
247
|
with_raw_response: AsyncRelaxaiWithRawResponse
|
|
242
248
|
with_streaming_response: AsyncRelaxaiWithStreamedResponse
|
|
243
249
|
|
|
@@ -249,7 +255,7 @@ class AsyncRelaxai(AsyncAPIClient):
|
|
|
249
255
|
*,
|
|
250
256
|
api_key: str | None = None,
|
|
251
257
|
base_url: str | httpx.URL | None = None,
|
|
252
|
-
timeout:
|
|
258
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
|
253
259
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
254
260
|
default_headers: Mapping[str, str] | None = None,
|
|
255
261
|
default_query: Mapping[str, object] | None = None,
|
|
@@ -298,6 +304,8 @@ class AsyncRelaxai(AsyncAPIClient):
|
|
|
298
304
|
self.chat = chat.AsyncChatResource(self)
|
|
299
305
|
self.embeddings = embeddings.AsyncEmbeddingsResource(self)
|
|
300
306
|
self.models = models.AsyncModelsResource(self)
|
|
307
|
+
self.tools = tools.AsyncToolsResource(self)
|
|
308
|
+
self.deep_research = deep_research.AsyncDeepResearchResource(self)
|
|
301
309
|
self.with_raw_response = AsyncRelaxaiWithRawResponse(self)
|
|
302
310
|
self.with_streaming_response = AsyncRelaxaiWithStreamedResponse(self)
|
|
303
311
|
|
|
@@ -326,9 +334,9 @@ class AsyncRelaxai(AsyncAPIClient):
|
|
|
326
334
|
*,
|
|
327
335
|
api_key: str | None = None,
|
|
328
336
|
base_url: str | httpx.URL | None = None,
|
|
329
|
-
timeout: float | Timeout | None | NotGiven =
|
|
337
|
+
timeout: float | Timeout | None | NotGiven = not_given,
|
|
330
338
|
http_client: httpx.AsyncClient | None = None,
|
|
331
|
-
max_retries: int | NotGiven =
|
|
339
|
+
max_retries: int | NotGiven = not_given,
|
|
332
340
|
default_headers: Mapping[str, str] | None = None,
|
|
333
341
|
set_default_headers: Mapping[str, str] | None = None,
|
|
334
342
|
default_query: Mapping[str, object] | None = None,
|
|
@@ -380,7 +388,7 @@ class AsyncRelaxai(AsyncAPIClient):
|
|
|
380
388
|
extra_headers: Headers | None = None,
|
|
381
389
|
extra_query: Query | None = None,
|
|
382
390
|
extra_body: Body | None = None,
|
|
383
|
-
timeout: float | httpx.Timeout | None | NotGiven =
|
|
391
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
384
392
|
) -> str:
|
|
385
393
|
"""Check the health of the service."""
|
|
386
394
|
return await self.get(
|
|
@@ -430,6 +438,8 @@ class RelaxaiWithRawResponse:
|
|
|
430
438
|
self.chat = chat.ChatResourceWithRawResponse(client.chat)
|
|
431
439
|
self.embeddings = embeddings.EmbeddingsResourceWithRawResponse(client.embeddings)
|
|
432
440
|
self.models = models.ModelsResourceWithRawResponse(client.models)
|
|
441
|
+
self.tools = tools.ToolsResourceWithRawResponse(client.tools)
|
|
442
|
+
self.deep_research = deep_research.DeepResearchResourceWithRawResponse(client.deep_research)
|
|
433
443
|
|
|
434
444
|
self.health = to_raw_response_wrapper(
|
|
435
445
|
client.health,
|
|
@@ -441,6 +451,8 @@ class AsyncRelaxaiWithRawResponse:
|
|
|
441
451
|
self.chat = chat.AsyncChatResourceWithRawResponse(client.chat)
|
|
442
452
|
self.embeddings = embeddings.AsyncEmbeddingsResourceWithRawResponse(client.embeddings)
|
|
443
453
|
self.models = models.AsyncModelsResourceWithRawResponse(client.models)
|
|
454
|
+
self.tools = tools.AsyncToolsResourceWithRawResponse(client.tools)
|
|
455
|
+
self.deep_research = deep_research.AsyncDeepResearchResourceWithRawResponse(client.deep_research)
|
|
444
456
|
|
|
445
457
|
self.health = async_to_raw_response_wrapper(
|
|
446
458
|
client.health,
|
|
@@ -452,6 +464,8 @@ class RelaxaiWithStreamedResponse:
|
|
|
452
464
|
self.chat = chat.ChatResourceWithStreamingResponse(client.chat)
|
|
453
465
|
self.embeddings = embeddings.EmbeddingsResourceWithStreamingResponse(client.embeddings)
|
|
454
466
|
self.models = models.ModelsResourceWithStreamingResponse(client.models)
|
|
467
|
+
self.tools = tools.ToolsResourceWithStreamingResponse(client.tools)
|
|
468
|
+
self.deep_research = deep_research.DeepResearchResourceWithStreamingResponse(client.deep_research)
|
|
455
469
|
|
|
456
470
|
self.health = to_streamed_response_wrapper(
|
|
457
471
|
client.health,
|
|
@@ -463,6 +477,8 @@ class AsyncRelaxaiWithStreamedResponse:
|
|
|
463
477
|
self.chat = chat.AsyncChatResourceWithStreamingResponse(client.chat)
|
|
464
478
|
self.embeddings = embeddings.AsyncEmbeddingsResourceWithStreamingResponse(client.embeddings)
|
|
465
479
|
self.models = models.AsyncModelsResourceWithStreamingResponse(client.models)
|
|
480
|
+
self.tools = tools.AsyncToolsResourceWithStreamingResponse(client.tools)
|
|
481
|
+
self.deep_research = deep_research.AsyncDeepResearchResourceWithStreamingResponse(client.deep_research)
|
|
466
482
|
|
|
467
483
|
self.health = async_to_streamed_response_wrapper(
|
|
468
484
|
client.health,
|
relaxai/_compat.py
CHANGED
|
@@ -12,14 +12,13 @@ from ._types import IncEx, StrBytesIntFloat
|
|
|
12
12
|
_T = TypeVar("_T")
|
|
13
13
|
_ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)
|
|
14
14
|
|
|
15
|
-
# --------------- Pydantic v2 compatibility ---------------
|
|
15
|
+
# --------------- Pydantic v2, v3 compatibility ---------------
|
|
16
16
|
|
|
17
17
|
# Pyright incorrectly reports some of our functions as overriding a method when they don't
|
|
18
18
|
# pyright: reportIncompatibleMethodOverride=false
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
PYDANTIC_V1 = pydantic.VERSION.startswith("1.")
|
|
21
21
|
|
|
22
|
-
# v1 re-exports
|
|
23
22
|
if TYPE_CHECKING:
|
|
24
23
|
|
|
25
24
|
def parse_date(value: date | StrBytesIntFloat) -> date: # noqa: ARG001
|
|
@@ -44,90 +43,92 @@ if TYPE_CHECKING:
|
|
|
44
43
|
...
|
|
45
44
|
|
|
46
45
|
else:
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
# v1 re-exports
|
|
47
|
+
if PYDANTIC_V1:
|
|
48
|
+
from pydantic.typing import (
|
|
49
49
|
get_args as get_args,
|
|
50
50
|
is_union as is_union,
|
|
51
51
|
get_origin as get_origin,
|
|
52
52
|
is_typeddict as is_typeddict,
|
|
53
53
|
is_literal_type as is_literal_type,
|
|
54
54
|
)
|
|
55
|
-
from pydantic.
|
|
55
|
+
from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
|
|
56
56
|
else:
|
|
57
|
-
from
|
|
57
|
+
from ._utils import (
|
|
58
58
|
get_args as get_args,
|
|
59
59
|
is_union as is_union,
|
|
60
60
|
get_origin as get_origin,
|
|
61
|
+
parse_date as parse_date,
|
|
61
62
|
is_typeddict as is_typeddict,
|
|
63
|
+
parse_datetime as parse_datetime,
|
|
62
64
|
is_literal_type as is_literal_type,
|
|
63
65
|
)
|
|
64
|
-
from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
|
|
65
66
|
|
|
66
67
|
|
|
67
68
|
# refactored config
|
|
68
69
|
if TYPE_CHECKING:
|
|
69
70
|
from pydantic import ConfigDict as ConfigDict
|
|
70
71
|
else:
|
|
71
|
-
if
|
|
72
|
-
from pydantic import ConfigDict
|
|
73
|
-
else:
|
|
72
|
+
if PYDANTIC_V1:
|
|
74
73
|
# TODO: provide an error message here?
|
|
75
74
|
ConfigDict = None
|
|
75
|
+
else:
|
|
76
|
+
from pydantic import ConfigDict as ConfigDict
|
|
76
77
|
|
|
77
78
|
|
|
78
79
|
# renamed methods / properties
|
|
79
80
|
def parse_obj(model: type[_ModelT], value: object) -> _ModelT:
|
|
80
|
-
if
|
|
81
|
-
return model.model_validate(value)
|
|
82
|
-
else:
|
|
81
|
+
if PYDANTIC_V1:
|
|
83
82
|
return cast(_ModelT, model.parse_obj(value)) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
|
|
83
|
+
else:
|
|
84
|
+
return model.model_validate(value)
|
|
84
85
|
|
|
85
86
|
|
|
86
87
|
def field_is_required(field: FieldInfo) -> bool:
|
|
87
|
-
if
|
|
88
|
-
return field.
|
|
89
|
-
return field.
|
|
88
|
+
if PYDANTIC_V1:
|
|
89
|
+
return field.required # type: ignore
|
|
90
|
+
return field.is_required()
|
|
90
91
|
|
|
91
92
|
|
|
92
93
|
def field_get_default(field: FieldInfo) -> Any:
|
|
93
94
|
value = field.get_default()
|
|
94
|
-
if
|
|
95
|
-
from pydantic_core import PydanticUndefined
|
|
96
|
-
|
|
97
|
-
if value == PydanticUndefined:
|
|
98
|
-
return None
|
|
95
|
+
if PYDANTIC_V1:
|
|
99
96
|
return value
|
|
97
|
+
from pydantic_core import PydanticUndefined
|
|
98
|
+
|
|
99
|
+
if value == PydanticUndefined:
|
|
100
|
+
return None
|
|
100
101
|
return value
|
|
101
102
|
|
|
102
103
|
|
|
103
104
|
def field_outer_type(field: FieldInfo) -> Any:
|
|
104
|
-
if
|
|
105
|
-
return field.
|
|
106
|
-
return field.
|
|
105
|
+
if PYDANTIC_V1:
|
|
106
|
+
return field.outer_type_ # type: ignore
|
|
107
|
+
return field.annotation
|
|
107
108
|
|
|
108
109
|
|
|
109
110
|
def get_model_config(model: type[pydantic.BaseModel]) -> Any:
|
|
110
|
-
if
|
|
111
|
-
return model.
|
|
112
|
-
return model.
|
|
111
|
+
if PYDANTIC_V1:
|
|
112
|
+
return model.__config__ # type: ignore
|
|
113
|
+
return model.model_config
|
|
113
114
|
|
|
114
115
|
|
|
115
116
|
def get_model_fields(model: type[pydantic.BaseModel]) -> dict[str, FieldInfo]:
|
|
116
|
-
if
|
|
117
|
-
return model.
|
|
118
|
-
return model.
|
|
117
|
+
if PYDANTIC_V1:
|
|
118
|
+
return model.__fields__ # type: ignore
|
|
119
|
+
return model.model_fields
|
|
119
120
|
|
|
120
121
|
|
|
121
122
|
def model_copy(model: _ModelT, *, deep: bool = False) -> _ModelT:
|
|
122
|
-
if
|
|
123
|
-
return model.
|
|
124
|
-
return model.
|
|
123
|
+
if PYDANTIC_V1:
|
|
124
|
+
return model.copy(deep=deep) # type: ignore
|
|
125
|
+
return model.model_copy(deep=deep)
|
|
125
126
|
|
|
126
127
|
|
|
127
128
|
def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
|
|
128
|
-
if
|
|
129
|
-
return model.
|
|
130
|
-
return model.
|
|
129
|
+
if PYDANTIC_V1:
|
|
130
|
+
return model.json(indent=indent) # type: ignore
|
|
131
|
+
return model.model_dump_json(indent=indent)
|
|
131
132
|
|
|
132
133
|
|
|
133
134
|
def model_dump(
|
|
@@ -139,14 +140,14 @@ def model_dump(
|
|
|
139
140
|
warnings: bool = True,
|
|
140
141
|
mode: Literal["json", "python"] = "python",
|
|
141
142
|
) -> dict[str, Any]:
|
|
142
|
-
if
|
|
143
|
+
if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
|
|
143
144
|
return model.model_dump(
|
|
144
145
|
mode=mode,
|
|
145
146
|
exclude=exclude,
|
|
146
147
|
exclude_unset=exclude_unset,
|
|
147
148
|
exclude_defaults=exclude_defaults,
|
|
148
149
|
# warnings are not supported in Pydantic v1
|
|
149
|
-
warnings=
|
|
150
|
+
warnings=True if PYDANTIC_V1 else warnings,
|
|
150
151
|
)
|
|
151
152
|
return cast(
|
|
152
153
|
"dict[str, Any]",
|
|
@@ -159,9 +160,9 @@ def model_dump(
|
|
|
159
160
|
|
|
160
161
|
|
|
161
162
|
def model_parse(model: type[_ModelT], data: Any) -> _ModelT:
|
|
162
|
-
if
|
|
163
|
-
return model.
|
|
164
|
-
return model.
|
|
163
|
+
if PYDANTIC_V1:
|
|
164
|
+
return model.parse_obj(data) # pyright: ignore[reportDeprecated]
|
|
165
|
+
return model.model_validate(data)
|
|
165
166
|
|
|
166
167
|
|
|
167
168
|
# generic models
|
|
@@ -170,17 +171,16 @@ if TYPE_CHECKING:
|
|
|
170
171
|
class GenericModel(pydantic.BaseModel): ...
|
|
171
172
|
|
|
172
173
|
else:
|
|
173
|
-
if
|
|
174
|
+
if PYDANTIC_V1:
|
|
175
|
+
import pydantic.generics
|
|
176
|
+
|
|
177
|
+
class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
|
|
178
|
+
else:
|
|
174
179
|
# there no longer needs to be a distinction in v2 but
|
|
175
180
|
# we still have to create our own subclass to avoid
|
|
176
181
|
# inconsistent MRO ordering errors
|
|
177
182
|
class GenericModel(pydantic.BaseModel): ...
|
|
178
183
|
|
|
179
|
-
else:
|
|
180
|
-
import pydantic.generics
|
|
181
|
-
|
|
182
|
-
class GenericModel(pydantic.generics.GenericModel, pydantic.BaseModel): ...
|
|
183
|
-
|
|
184
184
|
|
|
185
185
|
# cached properties
|
|
186
186
|
if TYPE_CHECKING:
|