Skip to content

Commit 5f6999e

Browse files
committed
Add comments for the validation aliases
1 parent 8d20b12 commit 5f6999e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

pydantic_ai_slim/pydantic_ai/messages.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ class ModelResponse:
10161016

10171017
provider_details: Annotated[
10181018
dict[str, Any] | None,
1019+
# `vendor_details` is deprecated, but we still want to support deserializing model responses stored in a DB before the name was changed
10191020
pydantic.Field(validation_alias=pydantic.AliasChoices('provider_details', 'vendor_details')),
10201021
] = None
10211022
"""Additional provider-specific details in a serializable format.
@@ -1025,7 +1026,9 @@ class ModelResponse:
10251026
"""
10261027

10271028
provider_response_id: Annotated[
1028-
str | None, pydantic.Field(validation_alias=pydantic.AliasChoices('provider_response_id', 'vendor_id'))
1029+
str | None,
1030+
# `vendor_id` is deprecated, but we still want to support deserializing model responses stored in a DB before the name was changed
1031+
pydantic.Field(validation_alias=pydantic.AliasChoices('provider_response_id', 'vendor_id')),
10291032
] = None
10301033
"""request ID as specified by the model provider. This can be used to track the specific request to the model."""
10311034

pydantic_ai_slim/pydantic_ai/usage.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@
1616

1717
@dataclass(repr=False, kw_only=True)
1818
class UsageBase:
19-
input_tokens: Annotated[int, Field(validation_alias=AliasChoices('input_tokens', 'request_tokens'))] = 0
19+
input_tokens: Annotated[
20+
int,
21+
# `request_tokens` is deprecated, but we still want to support deserializing model responses stored in a DB before the name was changed
22+
Field(validation_alias=AliasChoices('input_tokens', 'request_tokens')),
23+
] = 0
2024
"""Number of input/prompt tokens."""
2125

2226
cache_write_tokens: int = 0
2327
"""Number of tokens written to the cache."""
2428
cache_read_tokens: int = 0
2529
"""Number of tokens read from the cache."""
2630

27-
output_tokens: Annotated[int, Field(validation_alias=AliasChoices('output_tokens', 'response_tokens'))] = 0
31+
output_tokens: Annotated[
32+
int,
33+
# `response_tokens` is deprecated, but we still want to support deserializing model responses stored in a DB before the name was changed
34+
Field(validation_alias=AliasChoices('output_tokens', 'response_tokens')),
35+
] = 0
2836
"""Number of output/completion tokens."""
2937

3038
input_audio_tokens: int = 0
@@ -34,7 +42,11 @@ class UsageBase:
3442
output_audio_tokens: int = 0
3543
"""Number of audio output tokens."""
3644

37-
details: Annotated[dict[str, int], BeforeValidator(lambda d: d or {})] = dataclasses.field(default_factory=dict)
45+
details: Annotated[
46+
dict[str, int],
47+
# `details` can not be `None` any longer, but we still want to support deserializing model responses stored in a DB before this was changed
48+
BeforeValidator(lambda d: d or {}),
49+
] = dataclasses.field(default_factory=dict)
3850
"""Any extra details returned by the model."""
3951

4052
@property

0 commit comments

Comments
 (0)