scale-gp-beta 0.1.0a29__py3-none-any.whl → 0.1.0a31__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.
- scale_gp_beta/_base_client.py +7 -4
- scale_gp_beta/_client.py +17 -8
- scale_gp_beta/_compat.py +48 -48
- scale_gp_beta/_files.py +4 -4
- scale_gp_beta/_models.py +63 -42
- scale_gp_beta/_types.py +35 -1
- scale_gp_beta/_utils/__init__.py +9 -2
- scale_gp_beta/_utils/_compat.py +45 -0
- scale_gp_beta/_utils/_datetime_parse.py +136 -0
- scale_gp_beta/_utils/_transform.py +11 -1
- scale_gp_beta/_utils/_typing.py +6 -1
- scale_gp_beta/_utils/_utils.py +0 -1
- scale_gp_beta/_version.py +1 -1
- scale_gp_beta/lib/CONTRIBUTING.MD +53 -0
- scale_gp_beta/lib/tracing/trace_queue_manager.py +14 -0
- scale_gp_beta/resources/__init__.py +20 -6
- scale_gp_beta/resources/chat/completions.py +22 -18
- scale_gp_beta/resources/completions.py +18 -18
- scale_gp_beta/resources/datasets.py +8 -8
- scale_gp_beta/resources/evaluations.py +35 -13
- scale_gp_beta/resources/responses.py +314 -0
- scale_gp_beta/resources/spans.py +25 -33
- scale_gp_beta/types/__init__.py +17 -0
- scale_gp_beta/types/chat/chat_completion.py +61 -6
- scale_gp_beta/types/chat/chat_completion_chunk.py +17 -1
- scale_gp_beta/types/chat/completion_create_params.py +5 -3
- scale_gp_beta/types/chat/completion_models_params.py +2 -0
- scale_gp_beta/types/chat/model_definition.py +6 -0
- scale_gp_beta/types/completion.py +8 -0
- scale_gp_beta/types/completion_create_params.py +5 -3
- scale_gp_beta/types/container.py +2 -8
- scale_gp_beta/types/container_param.py +2 -2
- scale_gp_beta/types/dataset.py +3 -1
- scale_gp_beta/types/dataset_create_params.py +4 -2
- scale_gp_beta/types/dataset_item.py +3 -1
- scale_gp_beta/types/dataset_list_params.py +3 -2
- scale_gp_beta/types/dataset_update_params.py +3 -2
- scale_gp_beta/types/evaluation.py +7 -8
- scale_gp_beta/types/evaluation_create_params.py +17 -6
- scale_gp_beta/types/evaluation_item.py +3 -1
- scale_gp_beta/types/evaluation_list_params.py +3 -1
- scale_gp_beta/types/evaluation_task.py +31 -55
- scale_gp_beta/types/evaluation_task_param.py +32 -4
- scale_gp_beta/types/evaluation_update_params.py +3 -2
- scale_gp_beta/types/file.py +3 -1
- scale_gp_beta/types/inference_model.py +7 -0
- scale_gp_beta/types/model_create_params.py +6 -4
- scale_gp_beta/types/model_update_params.py +6 -4
- scale_gp_beta/types/question.py +11 -10
- scale_gp_beta/types/question_create_params.py +4 -2
- scale_gp_beta/types/response.py +2852 -0
- scale_gp_beta/types/response_create_params.py +819 -0
- scale_gp_beta/types/response_create_response.py +20891 -0
- scale_gp_beta/types/shared/__init__.py +3 -0
- scale_gp_beta/types/shared/identity.py +16 -0
- scale_gp_beta/types/span.py +4 -2
- scale_gp_beta/types/span_search_params.py +10 -12
- {scale_gp_beta-0.1.0a29.dist-info → scale_gp_beta-0.1.0a31.dist-info}/METADATA +2 -3
- {scale_gp_beta-0.1.0a29.dist-info → scale_gp_beta-0.1.0a31.dist-info}/RECORD +61 -52
- {scale_gp_beta-0.1.0a29.dist-info → scale_gp_beta-0.1.0a31.dist-info}/WHEEL +0 -0
- {scale_gp_beta-0.1.0a29.dist-info → scale_gp_beta-0.1.0a31.dist-info}/licenses/LICENSE +0 -0
scale_gp_beta/_base_client.py
CHANGED
|
@@ -59,7 +59,7 @@ from ._types import (
|
|
|
59
59
|
ModelBuilderProtocol,
|
|
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,
|
|
@@ -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
|
|
@@ -532,7 +532,10 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
|
|
532
532
|
is_body_allowed = options.method.lower() != "get"
|
|
533
533
|
|
|
534
534
|
if is_body_allowed:
|
|
535
|
-
|
|
535
|
+
if isinstance(json_data, bytes):
|
|
536
|
+
kwargs["content"] = json_data
|
|
537
|
+
else:
|
|
538
|
+
kwargs["json"] = json_data if is_given(json_data) else None
|
|
536
539
|
kwargs["files"] = files
|
|
537
540
|
else:
|
|
538
541
|
headers.pop("Content-Type", None)
|
scale_gp_beta/_client.py
CHANGED
|
@@ -27,6 +27,7 @@ from .resources import (
|
|
|
27
27
|
datasets,
|
|
28
28
|
inference,
|
|
29
29
|
questions,
|
|
30
|
+
responses,
|
|
30
31
|
completions,
|
|
31
32
|
evaluations,
|
|
32
33
|
dataset_items,
|
|
@@ -61,6 +62,7 @@ ENVIRONMENTS: Dict[str, str] = {
|
|
|
61
62
|
|
|
62
63
|
|
|
63
64
|
class SGPClient(SyncAPIClient):
|
|
65
|
+
responses: responses.ResponsesResource
|
|
64
66
|
completions: completions.CompletionsResource
|
|
65
67
|
chat: chat.ChatResource
|
|
66
68
|
inference: inference.InferenceResource
|
|
@@ -68,8 +70,8 @@ class SGPClient(SyncAPIClient):
|
|
|
68
70
|
files: files.FilesResource
|
|
69
71
|
models: models.ModelsResource
|
|
70
72
|
datasets: datasets.DatasetsResource
|
|
71
|
-
evaluations: evaluations.EvaluationsResource
|
|
72
73
|
dataset_items: dataset_items.DatasetItemsResource
|
|
74
|
+
evaluations: evaluations.EvaluationsResource
|
|
73
75
|
evaluation_items: evaluation_items.EvaluationItemsResource
|
|
74
76
|
spans: spans.SpansResource
|
|
75
77
|
with_raw_response: SGPClientWithRawResponse
|
|
@@ -165,6 +167,7 @@ class SGPClient(SyncAPIClient):
|
|
|
165
167
|
_strict_response_validation=_strict_response_validation,
|
|
166
168
|
)
|
|
167
169
|
|
|
170
|
+
self.responses = responses.ResponsesResource(self)
|
|
168
171
|
self.completions = completions.CompletionsResource(self)
|
|
169
172
|
self.chat = chat.ChatResource(self)
|
|
170
173
|
self.inference = inference.InferenceResource(self)
|
|
@@ -172,8 +175,8 @@ class SGPClient(SyncAPIClient):
|
|
|
172
175
|
self.files = files.FilesResource(self)
|
|
173
176
|
self.models = models.ModelsResource(self)
|
|
174
177
|
self.datasets = datasets.DatasetsResource(self)
|
|
175
|
-
self.evaluations = evaluations.EvaluationsResource(self)
|
|
176
178
|
self.dataset_items = dataset_items.DatasetItemsResource(self)
|
|
179
|
+
self.evaluations = evaluations.EvaluationsResource(self)
|
|
177
180
|
self.evaluation_items = evaluation_items.EvaluationItemsResource(self)
|
|
178
181
|
self.spans = spans.SpansResource(self)
|
|
179
182
|
self.with_raw_response = SGPClientWithRawResponse(self)
|
|
@@ -290,6 +293,7 @@ class SGPClient(SyncAPIClient):
|
|
|
290
293
|
|
|
291
294
|
|
|
292
295
|
class AsyncSGPClient(AsyncAPIClient):
|
|
296
|
+
responses: responses.AsyncResponsesResource
|
|
293
297
|
completions: completions.AsyncCompletionsResource
|
|
294
298
|
chat: chat.AsyncChatResource
|
|
295
299
|
inference: inference.AsyncInferenceResource
|
|
@@ -297,8 +301,8 @@ class AsyncSGPClient(AsyncAPIClient):
|
|
|
297
301
|
files: files.AsyncFilesResource
|
|
298
302
|
models: models.AsyncModelsResource
|
|
299
303
|
datasets: datasets.AsyncDatasetsResource
|
|
300
|
-
evaluations: evaluations.AsyncEvaluationsResource
|
|
301
304
|
dataset_items: dataset_items.AsyncDatasetItemsResource
|
|
305
|
+
evaluations: evaluations.AsyncEvaluationsResource
|
|
302
306
|
evaluation_items: evaluation_items.AsyncEvaluationItemsResource
|
|
303
307
|
spans: spans.AsyncSpansResource
|
|
304
308
|
with_raw_response: AsyncSGPClientWithRawResponse
|
|
@@ -394,6 +398,7 @@ class AsyncSGPClient(AsyncAPIClient):
|
|
|
394
398
|
_strict_response_validation=_strict_response_validation,
|
|
395
399
|
)
|
|
396
400
|
|
|
401
|
+
self.responses = responses.AsyncResponsesResource(self)
|
|
397
402
|
self.completions = completions.AsyncCompletionsResource(self)
|
|
398
403
|
self.chat = chat.AsyncChatResource(self)
|
|
399
404
|
self.inference = inference.AsyncInferenceResource(self)
|
|
@@ -401,8 +406,8 @@ class AsyncSGPClient(AsyncAPIClient):
|
|
|
401
406
|
self.files = files.AsyncFilesResource(self)
|
|
402
407
|
self.models = models.AsyncModelsResource(self)
|
|
403
408
|
self.datasets = datasets.AsyncDatasetsResource(self)
|
|
404
|
-
self.evaluations = evaluations.AsyncEvaluationsResource(self)
|
|
405
409
|
self.dataset_items = dataset_items.AsyncDatasetItemsResource(self)
|
|
410
|
+
self.evaluations = evaluations.AsyncEvaluationsResource(self)
|
|
406
411
|
self.evaluation_items = evaluation_items.AsyncEvaluationItemsResource(self)
|
|
407
412
|
self.spans = spans.AsyncSpansResource(self)
|
|
408
413
|
self.with_raw_response = AsyncSGPClientWithRawResponse(self)
|
|
@@ -520,6 +525,7 @@ class AsyncSGPClient(AsyncAPIClient):
|
|
|
520
525
|
|
|
521
526
|
class SGPClientWithRawResponse:
|
|
522
527
|
def __init__(self, client: SGPClient) -> None:
|
|
528
|
+
self.responses = responses.ResponsesResourceWithRawResponse(client.responses)
|
|
523
529
|
self.completions = completions.CompletionsResourceWithRawResponse(client.completions)
|
|
524
530
|
self.chat = chat.ChatResourceWithRawResponse(client.chat)
|
|
525
531
|
self.inference = inference.InferenceResourceWithRawResponse(client.inference)
|
|
@@ -527,14 +533,15 @@ class SGPClientWithRawResponse:
|
|
|
527
533
|
self.files = files.FilesResourceWithRawResponse(client.files)
|
|
528
534
|
self.models = models.ModelsResourceWithRawResponse(client.models)
|
|
529
535
|
self.datasets = datasets.DatasetsResourceWithRawResponse(client.datasets)
|
|
530
|
-
self.evaluations = evaluations.EvaluationsResourceWithRawResponse(client.evaluations)
|
|
531
536
|
self.dataset_items = dataset_items.DatasetItemsResourceWithRawResponse(client.dataset_items)
|
|
537
|
+
self.evaluations = evaluations.EvaluationsResourceWithRawResponse(client.evaluations)
|
|
532
538
|
self.evaluation_items = evaluation_items.EvaluationItemsResourceWithRawResponse(client.evaluation_items)
|
|
533
539
|
self.spans = spans.SpansResourceWithRawResponse(client.spans)
|
|
534
540
|
|
|
535
541
|
|
|
536
542
|
class AsyncSGPClientWithRawResponse:
|
|
537
543
|
def __init__(self, client: AsyncSGPClient) -> None:
|
|
544
|
+
self.responses = responses.AsyncResponsesResourceWithRawResponse(client.responses)
|
|
538
545
|
self.completions = completions.AsyncCompletionsResourceWithRawResponse(client.completions)
|
|
539
546
|
self.chat = chat.AsyncChatResourceWithRawResponse(client.chat)
|
|
540
547
|
self.inference = inference.AsyncInferenceResourceWithRawResponse(client.inference)
|
|
@@ -542,14 +549,15 @@ class AsyncSGPClientWithRawResponse:
|
|
|
542
549
|
self.files = files.AsyncFilesResourceWithRawResponse(client.files)
|
|
543
550
|
self.models = models.AsyncModelsResourceWithRawResponse(client.models)
|
|
544
551
|
self.datasets = datasets.AsyncDatasetsResourceWithRawResponse(client.datasets)
|
|
545
|
-
self.evaluations = evaluations.AsyncEvaluationsResourceWithRawResponse(client.evaluations)
|
|
546
552
|
self.dataset_items = dataset_items.AsyncDatasetItemsResourceWithRawResponse(client.dataset_items)
|
|
553
|
+
self.evaluations = evaluations.AsyncEvaluationsResourceWithRawResponse(client.evaluations)
|
|
547
554
|
self.evaluation_items = evaluation_items.AsyncEvaluationItemsResourceWithRawResponse(client.evaluation_items)
|
|
548
555
|
self.spans = spans.AsyncSpansResourceWithRawResponse(client.spans)
|
|
549
556
|
|
|
550
557
|
|
|
551
558
|
class SGPClientWithStreamedResponse:
|
|
552
559
|
def __init__(self, client: SGPClient) -> None:
|
|
560
|
+
self.responses = responses.ResponsesResourceWithStreamingResponse(client.responses)
|
|
553
561
|
self.completions = completions.CompletionsResourceWithStreamingResponse(client.completions)
|
|
554
562
|
self.chat = chat.ChatResourceWithStreamingResponse(client.chat)
|
|
555
563
|
self.inference = inference.InferenceResourceWithStreamingResponse(client.inference)
|
|
@@ -557,14 +565,15 @@ class SGPClientWithStreamedResponse:
|
|
|
557
565
|
self.files = files.FilesResourceWithStreamingResponse(client.files)
|
|
558
566
|
self.models = models.ModelsResourceWithStreamingResponse(client.models)
|
|
559
567
|
self.datasets = datasets.DatasetsResourceWithStreamingResponse(client.datasets)
|
|
560
|
-
self.evaluations = evaluations.EvaluationsResourceWithStreamingResponse(client.evaluations)
|
|
561
568
|
self.dataset_items = dataset_items.DatasetItemsResourceWithStreamingResponse(client.dataset_items)
|
|
569
|
+
self.evaluations = evaluations.EvaluationsResourceWithStreamingResponse(client.evaluations)
|
|
562
570
|
self.evaluation_items = evaluation_items.EvaluationItemsResourceWithStreamingResponse(client.evaluation_items)
|
|
563
571
|
self.spans = spans.SpansResourceWithStreamingResponse(client.spans)
|
|
564
572
|
|
|
565
573
|
|
|
566
574
|
class AsyncSGPClientWithStreamedResponse:
|
|
567
575
|
def __init__(self, client: AsyncSGPClient) -> None:
|
|
576
|
+
self.responses = responses.AsyncResponsesResourceWithStreamingResponse(client.responses)
|
|
568
577
|
self.completions = completions.AsyncCompletionsResourceWithStreamingResponse(client.completions)
|
|
569
578
|
self.chat = chat.AsyncChatResourceWithStreamingResponse(client.chat)
|
|
570
579
|
self.inference = inference.AsyncInferenceResourceWithStreamingResponse(client.inference)
|
|
@@ -572,8 +581,8 @@ class AsyncSGPClientWithStreamedResponse:
|
|
|
572
581
|
self.files = files.AsyncFilesResourceWithStreamingResponse(client.files)
|
|
573
582
|
self.models = models.AsyncModelsResourceWithStreamingResponse(client.models)
|
|
574
583
|
self.datasets = datasets.AsyncDatasetsResourceWithStreamingResponse(client.datasets)
|
|
575
|
-
self.evaluations = evaluations.AsyncEvaluationsResourceWithStreamingResponse(client.evaluations)
|
|
576
584
|
self.dataset_items = dataset_items.AsyncDatasetItemsResourceWithStreamingResponse(client.dataset_items)
|
|
585
|
+
self.evaluations = evaluations.AsyncEvaluationsResourceWithStreamingResponse(client.evaluations)
|
|
577
586
|
self.evaluation_items = evaluation_items.AsyncEvaluationItemsResourceWithStreamingResponse(
|
|
578
587
|
client.evaluation_items
|
|
579
588
|
)
|
scale_gp_beta/_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:
|
scale_gp_beta/_files.py
CHANGED
|
@@ -69,12 +69,12 @@ def _transform_file(file: FileTypes) -> HttpxFileTypes:
|
|
|
69
69
|
return file
|
|
70
70
|
|
|
71
71
|
if is_tuple_t(file):
|
|
72
|
-
return (file[0],
|
|
72
|
+
return (file[0], read_file_content(file[1]), *file[2:])
|
|
73
73
|
|
|
74
74
|
raise TypeError(f"Expected file types input to be a FileContent type or to be a tuple")
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
def
|
|
77
|
+
def read_file_content(file: FileContent) -> HttpxFileContent:
|
|
78
78
|
if isinstance(file, os.PathLike):
|
|
79
79
|
return pathlib.Path(file).read_bytes()
|
|
80
80
|
return file
|
|
@@ -111,12 +111,12 @@ async def _async_transform_file(file: FileTypes) -> HttpxFileTypes:
|
|
|
111
111
|
return file
|
|
112
112
|
|
|
113
113
|
if is_tuple_t(file):
|
|
114
|
-
return (file[0], await
|
|
114
|
+
return (file[0], await async_read_file_content(file[1]), *file[2:])
|
|
115
115
|
|
|
116
116
|
raise TypeError(f"Expected file types input to be a FileContent type or to be a tuple")
|
|
117
117
|
|
|
118
118
|
|
|
119
|
-
async def
|
|
119
|
+
async def async_read_file_content(file: FileContent) -> HttpxFileContent:
|
|
120
120
|
if isinstance(file, os.PathLike):
|
|
121
121
|
return await anyio.Path(file).read_bytes()
|
|
122
122
|
|
scale_gp_beta/_models.py
CHANGED
|
@@ -50,7 +50,7 @@ from ._utils import (
|
|
|
50
50
|
strip_annotated_type,
|
|
51
51
|
)
|
|
52
52
|
from ._compat import (
|
|
53
|
-
|
|
53
|
+
PYDANTIC_V1,
|
|
54
54
|
ConfigDict,
|
|
55
55
|
GenericModel as BaseGenericModel,
|
|
56
56
|
get_args,
|
|
@@ -81,11 +81,7 @@ class _ConfigProtocol(Protocol):
|
|
|
81
81
|
|
|
82
82
|
|
|
83
83
|
class BaseModel(pydantic.BaseModel):
|
|
84
|
-
if
|
|
85
|
-
model_config: ClassVar[ConfigDict] = ConfigDict(
|
|
86
|
-
extra="allow", defer_build=coerce_boolean(os.environ.get("DEFER_PYDANTIC_BUILD", "true"))
|
|
87
|
-
)
|
|
88
|
-
else:
|
|
84
|
+
if PYDANTIC_V1:
|
|
89
85
|
|
|
90
86
|
@property
|
|
91
87
|
@override
|
|
@@ -95,6 +91,10 @@ class BaseModel(pydantic.BaseModel):
|
|
|
95
91
|
|
|
96
92
|
class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
|
|
97
93
|
extra: Any = pydantic.Extra.allow # type: ignore
|
|
94
|
+
else:
|
|
95
|
+
model_config: ClassVar[ConfigDict] = ConfigDict(
|
|
96
|
+
extra="allow", defer_build=coerce_boolean(os.environ.get("DEFER_PYDANTIC_BUILD", "true"))
|
|
97
|
+
)
|
|
98
98
|
|
|
99
99
|
def to_dict(
|
|
100
100
|
self,
|
|
@@ -208,28 +208,32 @@ class BaseModel(pydantic.BaseModel):
|
|
|
208
208
|
else:
|
|
209
209
|
fields_values[name] = field_get_default(field)
|
|
210
210
|
|
|
211
|
+
extra_field_type = _get_extra_fields_type(__cls)
|
|
212
|
+
|
|
211
213
|
_extra = {}
|
|
212
214
|
for key, value in values.items():
|
|
213
215
|
if key not in model_fields:
|
|
214
|
-
if
|
|
215
|
-
|
|
216
|
-
|
|
216
|
+
parsed = construct_type(value=value, type_=extra_field_type) if extra_field_type is not None else value
|
|
217
|
+
|
|
218
|
+
if PYDANTIC_V1:
|
|
217
219
|
_fields_set.add(key)
|
|
218
|
-
fields_values[key] =
|
|
220
|
+
fields_values[key] = parsed
|
|
221
|
+
else:
|
|
222
|
+
_extra[key] = parsed
|
|
219
223
|
|
|
220
224
|
object.__setattr__(m, "__dict__", fields_values)
|
|
221
225
|
|
|
222
|
-
if
|
|
223
|
-
# these properties are copied from Pydantic's `model_construct()` method
|
|
224
|
-
object.__setattr__(m, "__pydantic_private__", None)
|
|
225
|
-
object.__setattr__(m, "__pydantic_extra__", _extra)
|
|
226
|
-
object.__setattr__(m, "__pydantic_fields_set__", _fields_set)
|
|
227
|
-
else:
|
|
226
|
+
if PYDANTIC_V1:
|
|
228
227
|
# init_private_attributes() does not exist in v2
|
|
229
228
|
m._init_private_attributes() # type: ignore
|
|
230
229
|
|
|
231
230
|
# copied from Pydantic v1's `construct()` method
|
|
232
231
|
object.__setattr__(m, "__fields_set__", _fields_set)
|
|
232
|
+
else:
|
|
233
|
+
# these properties are copied from Pydantic's `model_construct()` method
|
|
234
|
+
object.__setattr__(m, "__pydantic_private__", None)
|
|
235
|
+
object.__setattr__(m, "__pydantic_extra__", _extra)
|
|
236
|
+
object.__setattr__(m, "__pydantic_fields_set__", _fields_set)
|
|
233
237
|
|
|
234
238
|
return m
|
|
235
239
|
|
|
@@ -239,7 +243,7 @@ class BaseModel(pydantic.BaseModel):
|
|
|
239
243
|
# although not in practice
|
|
240
244
|
model_construct = construct
|
|
241
245
|
|
|
242
|
-
if
|
|
246
|
+
if PYDANTIC_V1:
|
|
243
247
|
# we define aliases for some of the new pydantic v2 methods so
|
|
244
248
|
# that we can just document these methods without having to specify
|
|
245
249
|
# a specific pydantic version as some users may not know which
|
|
@@ -300,7 +304,7 @@ class BaseModel(pydantic.BaseModel):
|
|
|
300
304
|
exclude_none=exclude_none,
|
|
301
305
|
)
|
|
302
306
|
|
|
303
|
-
return cast(dict[str, Any], json_safe(dumped)) if mode == "json" else dumped
|
|
307
|
+
return cast("dict[str, Any]", json_safe(dumped)) if mode == "json" else dumped
|
|
304
308
|
|
|
305
309
|
@override
|
|
306
310
|
def model_dump_json(
|
|
@@ -359,10 +363,10 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
|
|
|
359
363
|
if value is None:
|
|
360
364
|
return field_get_default(field)
|
|
361
365
|
|
|
362
|
-
if
|
|
363
|
-
type_ = field.annotation
|
|
364
|
-
else:
|
|
366
|
+
if PYDANTIC_V1:
|
|
365
367
|
type_ = cast(type, field.outer_type_) # type: ignore
|
|
368
|
+
else:
|
|
369
|
+
type_ = field.annotation # type: ignore
|
|
366
370
|
|
|
367
371
|
if type_ is None:
|
|
368
372
|
raise RuntimeError(f"Unexpected field type is None for {key}")
|
|
@@ -370,6 +374,23 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
|
|
|
370
374
|
return construct_type(value=value, type_=type_, metadata=getattr(field, "metadata", None))
|
|
371
375
|
|
|
372
376
|
|
|
377
|
+
def _get_extra_fields_type(cls: type[pydantic.BaseModel]) -> type | None:
|
|
378
|
+
if PYDANTIC_V1:
|
|
379
|
+
# TODO
|
|
380
|
+
return None
|
|
381
|
+
|
|
382
|
+
schema = cls.__pydantic_core_schema__
|
|
383
|
+
if schema["type"] == "model":
|
|
384
|
+
fields = schema["schema"]
|
|
385
|
+
if fields["type"] == "model-fields":
|
|
386
|
+
extras = fields.get("extras_schema")
|
|
387
|
+
if extras and "cls" in extras:
|
|
388
|
+
# mypy can't narrow the type
|
|
389
|
+
return extras["cls"] # type: ignore[no-any-return]
|
|
390
|
+
|
|
391
|
+
return None
|
|
392
|
+
|
|
393
|
+
|
|
373
394
|
def is_basemodel(type_: type) -> bool:
|
|
374
395
|
"""Returns whether or not the given type is either a `BaseModel` or a union of `BaseModel`"""
|
|
375
396
|
if is_union(type_):
|
|
@@ -439,7 +460,7 @@ def construct_type(*, value: object, type_: object, metadata: Optional[List[Any]
|
|
|
439
460
|
type_ = type_.__value__ # type: ignore[unreachable]
|
|
440
461
|
|
|
441
462
|
# unwrap `Annotated[T, ...]` -> `T`
|
|
442
|
-
if metadata is not None:
|
|
463
|
+
if metadata is not None and len(metadata) > 0:
|
|
443
464
|
meta: tuple[Any, ...] = tuple(metadata)
|
|
444
465
|
elif is_annotated_type(type_):
|
|
445
466
|
meta = get_args(type_)[1:]
|
|
@@ -607,30 +628,30 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
|
|
|
607
628
|
for variant in get_args(union):
|
|
608
629
|
variant = strip_annotated_type(variant)
|
|
609
630
|
if is_basemodel_type(variant):
|
|
610
|
-
if
|
|
611
|
-
|
|
612
|
-
if not
|
|
631
|
+
if PYDANTIC_V1:
|
|
632
|
+
field_info = cast("dict[str, FieldInfo]", variant.__fields__).get(discriminator_field_name) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
|
|
633
|
+
if not field_info:
|
|
613
634
|
continue
|
|
614
635
|
|
|
615
636
|
# Note: if one variant defines an alias then they all should
|
|
616
|
-
discriminator_alias =
|
|
617
|
-
|
|
618
|
-
field_schema = field["schema"]
|
|
637
|
+
discriminator_alias = field_info.alias
|
|
619
638
|
|
|
620
|
-
if
|
|
621
|
-
for entry in
|
|
639
|
+
if (annotation := getattr(field_info, "annotation", None)) and is_literal_type(annotation):
|
|
640
|
+
for entry in get_args(annotation):
|
|
622
641
|
if isinstance(entry, str):
|
|
623
642
|
mapping[entry] = variant
|
|
624
643
|
else:
|
|
625
|
-
|
|
626
|
-
if not
|
|
644
|
+
field = _extract_field_schema_pv2(variant, discriminator_field_name)
|
|
645
|
+
if not field:
|
|
627
646
|
continue
|
|
628
647
|
|
|
629
648
|
# Note: if one variant defines an alias then they all should
|
|
630
|
-
discriminator_alias =
|
|
649
|
+
discriminator_alias = field.get("serialization_alias")
|
|
631
650
|
|
|
632
|
-
|
|
633
|
-
|
|
651
|
+
field_schema = field["schema"]
|
|
652
|
+
|
|
653
|
+
if field_schema["type"] == "literal":
|
|
654
|
+
for entry in cast("LiteralSchema", field_schema)["expected"]:
|
|
634
655
|
if isinstance(entry, str):
|
|
635
656
|
mapping[entry] = variant
|
|
636
657
|
|
|
@@ -693,7 +714,7 @@ else:
|
|
|
693
714
|
pass
|
|
694
715
|
|
|
695
716
|
|
|
696
|
-
if
|
|
717
|
+
if not PYDANTIC_V1:
|
|
697
718
|
from pydantic import TypeAdapter as _TypeAdapter
|
|
698
719
|
|
|
699
720
|
_CachedTypeAdapter = cast("TypeAdapter[object]", lru_cache(maxsize=None)(_TypeAdapter))
|
|
@@ -761,12 +782,12 @@ class FinalRequestOptions(pydantic.BaseModel):
|
|
|
761
782
|
json_data: Union[Body, None] = None
|
|
762
783
|
extra_json: Union[AnyMapping, None] = None
|
|
763
784
|
|
|
764
|
-
if
|
|
765
|
-
model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
|
|
766
|
-
else:
|
|
785
|
+
if PYDANTIC_V1:
|
|
767
786
|
|
|
768
787
|
class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
|
|
769
788
|
arbitrary_types_allowed: bool = True
|
|
789
|
+
else:
|
|
790
|
+
model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
|
|
770
791
|
|
|
771
792
|
def get_max_retries(self, max_retries: int) -> int:
|
|
772
793
|
if isinstance(self.max_retries, NotGiven):
|
|
@@ -799,9 +820,9 @@ class FinalRequestOptions(pydantic.BaseModel):
|
|
|
799
820
|
key: strip_not_given(value)
|
|
800
821
|
for key, value in values.items()
|
|
801
822
|
}
|
|
802
|
-
if
|
|
803
|
-
return super().
|
|
804
|
-
return
|
|
823
|
+
if PYDANTIC_V1:
|
|
824
|
+
return cast(FinalRequestOptions, super().construct(_fields_set, **kwargs)) # pyright: ignore[reportDeprecated]
|
|
825
|
+
return super().model_construct(_fields_set, **kwargs)
|
|
805
826
|
|
|
806
827
|
if not TYPE_CHECKING:
|
|
807
828
|
# type checkers incorrectly complain about this assignment
|
scale_gp_beta/_types.py
CHANGED
|
@@ -13,10 +13,21 @@ from typing import (
|
|
|
13
13
|
Mapping,
|
|
14
14
|
TypeVar,
|
|
15
15
|
Callable,
|
|
16
|
+
Iterator,
|
|
16
17
|
Optional,
|
|
17
18
|
Sequence,
|
|
18
19
|
)
|
|
19
|
-
from typing_extensions import
|
|
20
|
+
from typing_extensions import (
|
|
21
|
+
Set,
|
|
22
|
+
Literal,
|
|
23
|
+
Protocol,
|
|
24
|
+
TypeAlias,
|
|
25
|
+
TypedDict,
|
|
26
|
+
SupportsIndex,
|
|
27
|
+
overload,
|
|
28
|
+
override,
|
|
29
|
+
runtime_checkable,
|
|
30
|
+
)
|
|
20
31
|
|
|
21
32
|
import httpx
|
|
22
33
|
import pydantic
|
|
@@ -217,3 +228,26 @@ class _GenericAlias(Protocol):
|
|
|
217
228
|
class HttpxSendArgs(TypedDict, total=False):
|
|
218
229
|
auth: httpx.Auth
|
|
219
230
|
follow_redirects: bool
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
_T_co = TypeVar("_T_co", covariant=True)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
if TYPE_CHECKING:
|
|
237
|
+
# This works because str.__contains__ does not accept object (either in typeshed or at runtime)
|
|
238
|
+
# https://github.com/hauntsaninja/useful_types/blob/5e9710f3875107d068e7679fd7fec9cfab0eff3b/useful_types/__init__.py#L285
|
|
239
|
+
class SequenceNotStr(Protocol[_T_co]):
|
|
240
|
+
@overload
|
|
241
|
+
def __getitem__(self, index: SupportsIndex, /) -> _T_co: ...
|
|
242
|
+
@overload
|
|
243
|
+
def __getitem__(self, index: slice, /) -> Sequence[_T_co]: ...
|
|
244
|
+
def __contains__(self, value: object, /) -> bool: ...
|
|
245
|
+
def __len__(self) -> int: ...
|
|
246
|
+
def __iter__(self) -> Iterator[_T_co]: ...
|
|
247
|
+
def index(self, value: Any, start: int = 0, stop: int = ..., /) -> int: ...
|
|
248
|
+
def count(self, value: Any, /) -> int: ...
|
|
249
|
+
def __reversed__(self) -> Iterator[_T_co]: ...
|
|
250
|
+
else:
|
|
251
|
+
# just point this to a normal `Sequence` at runtime to avoid having to special case
|
|
252
|
+
# deserializing our custom sequence type
|
|
253
|
+
SequenceNotStr = Sequence
|