Skip to content

Commit e16df3b

Browse files
authored
support Pydantic v2.10 (#79)
1 parent 1afaead commit e16df3b

File tree

5 files changed

+107
-107
lines changed

5 files changed

+107
-107
lines changed

docs/install.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ pip/uv-add pydantic-ai
99

1010
It requires Python 3.9+.
1111

12-
!!! note "Use `--prerelease=allow` with uv"
13-
Until Pydantic v2.10 is released (very soon), you'll need to use `--prerelease=allow` with `uv` to install PydanticAI.
14-
1512
## Use with Pydantic Logfire
1613

1714
PydanticAI has an excellent (but completely optional) integration with [Pydantic Logfire](https://pydantic.dev/logfire) to help you view and understand agent runs.

pydantic_ai/_result.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import types
66
from collections.abc import Awaitable
77
from dataclasses import dataclass, field
8-
from typing import Any, Callable, Generic, Union, cast, get_args, get_origin
8+
from typing import Any, Callable, Generic, Literal, Union, cast, get_args, get_origin
99

1010
from pydantic import TypeAdapter, ValidationError
1111
from typing_extensions import Self, TypeAliasType, TypedDict
@@ -184,13 +184,14 @@ def validate(
184184
Either the validated result data (left) or a retry message (right).
185185
"""
186186
try:
187+
pyd_allow_partial: Literal['off', 'trailing-strings'] = 'trailing-strings' if allow_partial else 'off'
187188
if isinstance(tool_call.args, messages.ArgsJson):
188189
result = self.type_adapter.validate_json(
189-
tool_call.args.args_json or '', experimental_allow_partial=allow_partial
190+
tool_call.args.args_json or '', experimental_allow_partial=pyd_allow_partial
190191
)
191192
else:
192193
result = self.type_adapter.validate_python(
193-
tool_call.args.args_object, experimental_allow_partial=allow_partial
194+
tool_call.args.args_object, experimental_allow_partial=pyd_allow_partial
194195
)
195196
except ValidationError as e:
196197
if wrap_validation_errors:

pydantic_ai/models/gemini.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ async def _process_streamed_response(http_response: HTTPResponse) -> EitherStrea
213213
async for chunk in aiter_bytes:
214214
content.extend(chunk)
215215
responses = _gemini_streamed_response_ta.validate_json(
216-
content, # type: ignore # see https://github.com/pydantic/pydantic/pull/10802
217-
experimental_allow_partial=True,
216+
content,
217+
experimental_allow_partial='trailing-strings',
218218
)
219219
if responses:
220220
last = responses[-1]
@@ -279,7 +279,9 @@ def get(self, *, final: bool = False) -> Iterable[str]:
279279
all_items = pydantic_core.from_json(self._json_content, allow_partial=True)
280280
new_items = all_items[self._position : -1]
281281
self._position = len(all_items) - 1
282-
new_responses = _gemini_streamed_response_ta.validate_python(new_items, experimental_allow_partial=True)
282+
new_responses = _gemini_streamed_response_ta.validate_python(
283+
new_items, experimental_allow_partial='trailing-strings'
284+
)
283285
for r in new_responses:
284286
self._cost += _metadata_as_cost(r['usage_metadata'])
285287
parts = r['candidates'][0]['content']['parts']
@@ -321,8 +323,8 @@ def get(self, *, final: bool = False) -> ModelStructuredResponse:
321323
separate parts.
322324
"""
323325
responses = _gemini_streamed_response_ta.validate_json(
324-
self._content, # type: ignore # see https://github.com/pydantic/pydantic/pull/10802
325-
experimental_allow_partial=not final,
326+
self._content,
327+
experimental_allow_partial='off' if final else 'trailing-strings',
326328
)
327329
combined_parts: list[_GeminiFunctionCallPart] = []
328330
self._cost = result.Cost()

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "pydantic-ai"
7-
version = "0.0.4"
7+
version = "0.0.5"
88
description = "Agent Framework / shim to use Pydantic with LLMs"
99
authors = [
1010
{ name = "Samuel Colvin", email = "[email protected]" },
@@ -39,7 +39,7 @@ dependencies = [
3939
"httpx>=0.27.2",
4040
"logfire-api>=1.2.0",
4141
"openai>=1.54.3",
42-
"pydantic>=2.10.0b1",
42+
"pydantic>=2.10",
4343
]
4444

4545
[project.optional-dependencies]

0 commit comments

Comments
 (0)