pydantic-ai-slim 0.0.13__py3-none-any.whl → 0.0.14__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.
Potentially problematic release.
This version of pydantic-ai-slim might be problematic. Click here for more details.
- pydantic_ai/__init__.py +12 -2
- pydantic_ai/_result.py +4 -7
- pydantic_ai/_system_prompt.py +2 -2
- pydantic_ai/agent.py +85 -75
- pydantic_ai/exceptions.py +20 -2
- pydantic_ai/messages.py +29 -7
- pydantic_ai/models/__init__.py +10 -9
- pydantic_ai/models/anthropic.py +12 -12
- pydantic_ai/models/function.py +16 -22
- pydantic_ai/models/gemini.py +16 -18
- pydantic_ai/models/groq.py +21 -23
- pydantic_ai/models/mistral.py +24 -36
- pydantic_ai/models/openai.py +21 -23
- pydantic_ai/models/test.py +23 -17
- pydantic_ai/result.py +63 -33
- pydantic_ai/settings.py +65 -0
- pydantic_ai/tools.py +24 -14
- {pydantic_ai_slim-0.0.13.dist-info → pydantic_ai_slim-0.0.14.dist-info}/METADATA +1 -1
- pydantic_ai_slim-0.0.14.dist-info/RECORD +26 -0
- pydantic_ai_slim-0.0.13.dist-info/RECORD +0 -26
- {pydantic_ai_slim-0.0.13.dist-info → pydantic_ai_slim-0.0.14.dist-info}/WHEEL +0 -0
pydantic_ai/tools.py
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
from __future__ import annotations as _annotations
|
|
2
2
|
|
|
3
|
+
import dataclasses
|
|
3
4
|
import inspect
|
|
4
5
|
from collections.abc import Awaitable
|
|
5
6
|
from dataclasses import dataclass, field
|
|
6
|
-
from typing import
|
|
7
|
+
from typing import Any, Callable, Generic, TypeVar, Union, cast
|
|
7
8
|
|
|
8
9
|
from pydantic import ValidationError
|
|
9
10
|
from pydantic_core import SchemaValidator
|
|
10
11
|
from typing_extensions import Concatenate, ParamSpec, TypeAlias
|
|
11
12
|
|
|
12
|
-
from . import _pydantic, _utils, messages as _messages
|
|
13
|
+
from . import _pydantic, _utils, messages as _messages, models
|
|
13
14
|
from .exceptions import ModelRetry, UnexpectedModelBehavior
|
|
14
15
|
|
|
15
|
-
if TYPE_CHECKING:
|
|
16
|
-
from .result import ResultData
|
|
17
|
-
else:
|
|
18
|
-
ResultData = Any
|
|
19
|
-
|
|
20
|
-
|
|
21
16
|
__all__ = (
|
|
22
17
|
'AgentDeps',
|
|
23
18
|
'RunContext',
|
|
@@ -37,7 +32,7 @@ AgentDeps = TypeVar('AgentDeps')
|
|
|
37
32
|
"""Type variable for agent dependencies."""
|
|
38
33
|
|
|
39
34
|
|
|
40
|
-
@dataclass
|
|
35
|
+
@dataclasses.dataclass
|
|
41
36
|
class RunContext(Generic[AgentDeps]):
|
|
42
37
|
"""Information about the current call."""
|
|
43
38
|
|
|
@@ -49,6 +44,19 @@ class RunContext(Generic[AgentDeps]):
|
|
|
49
44
|
"""Messages exchanged in the conversation so far."""
|
|
50
45
|
tool_name: str | None
|
|
51
46
|
"""Name of the tool being called."""
|
|
47
|
+
model: models.Model
|
|
48
|
+
"""The model used in this run."""
|
|
49
|
+
|
|
50
|
+
def replace_with(
|
|
51
|
+
self, retry: int | None = None, tool_name: str | None | _utils.Unset = _utils.UNSET
|
|
52
|
+
) -> RunContext[AgentDeps]:
|
|
53
|
+
# Create a new `RunContext` a new `retry` value and `tool_name`.
|
|
54
|
+
kwargs = {}
|
|
55
|
+
if retry is not None:
|
|
56
|
+
kwargs['retry'] = retry
|
|
57
|
+
if tool_name is not _utils.UNSET:
|
|
58
|
+
kwargs['tool_name'] = tool_name
|
|
59
|
+
return dataclasses.replace(self, **kwargs)
|
|
52
60
|
|
|
53
61
|
|
|
54
62
|
ToolParams = ParamSpec('ToolParams')
|
|
@@ -65,6 +73,8 @@ SystemPromptFunc = Union[
|
|
|
65
73
|
Usage `SystemPromptFunc[AgentDeps]`.
|
|
66
74
|
"""
|
|
67
75
|
|
|
76
|
+
ResultData = TypeVar('ResultData')
|
|
77
|
+
|
|
68
78
|
ResultValidatorFunc = Union[
|
|
69
79
|
Callable[[RunContext[AgentDeps], ResultData], ResultData],
|
|
70
80
|
Callable[[RunContext[AgentDeps], ResultData], Awaitable[ResultData]],
|
|
@@ -238,7 +248,7 @@ class Tool(Generic[AgentDeps]):
|
|
|
238
248
|
return tool_def
|
|
239
249
|
|
|
240
250
|
async def run(
|
|
241
|
-
self,
|
|
251
|
+
self, message: _messages.ToolCallPart, run_context: RunContext[AgentDeps]
|
|
242
252
|
) -> _messages.ModelRequestPart:
|
|
243
253
|
"""Run the tool function asynchronously."""
|
|
244
254
|
try:
|
|
@@ -249,7 +259,7 @@ class Tool(Generic[AgentDeps]):
|
|
|
249
259
|
except ValidationError as e:
|
|
250
260
|
return self._on_error(e, message)
|
|
251
261
|
|
|
252
|
-
args, kwargs = self._call_args(
|
|
262
|
+
args, kwargs = self._call_args(args_dict, message, run_context)
|
|
253
263
|
try:
|
|
254
264
|
if self._is_async:
|
|
255
265
|
function = cast(Callable[[Any], Awaitable[str]], self.function)
|
|
@@ -269,15 +279,15 @@ class Tool(Generic[AgentDeps]):
|
|
|
269
279
|
|
|
270
280
|
def _call_args(
|
|
271
281
|
self,
|
|
272
|
-
deps: AgentDeps,
|
|
273
282
|
args_dict: dict[str, Any],
|
|
274
283
|
message: _messages.ToolCallPart,
|
|
275
|
-
|
|
284
|
+
run_context: RunContext[AgentDeps],
|
|
276
285
|
) -> tuple[list[Any], dict[str, Any]]:
|
|
277
286
|
if self._single_arg_name:
|
|
278
287
|
args_dict = {self._single_arg_name: args_dict}
|
|
279
288
|
|
|
280
|
-
|
|
289
|
+
ctx = dataclasses.replace(run_context, retry=self.current_retry, tool_name=message.tool_name)
|
|
290
|
+
args = [ctx] if self.takes_ctx else []
|
|
281
291
|
for positional_field in self._positional_fields:
|
|
282
292
|
args.append(args_dict.pop(positional_field))
|
|
283
293
|
if self._var_positional_field:
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
pydantic_ai/__init__.py,sha256=a3ffrVF4eJyylreRa6LbTMF6RI7VIv96zHv2tCWo1kQ,439
|
|
2
|
+
pydantic_ai/_griffe.py,sha256=pRjCJ6B1hhx6k46XJgl9zF6aRYxRmqEZKFok8unp4Iw,3449
|
|
3
|
+
pydantic_ai/_pydantic.py,sha256=qXi5IsyiYOHeg_-qozCdxkfeqw2z0gBTjqgywBCiJWo,8125
|
|
4
|
+
pydantic_ai/_result.py,sha256=iL0oZXvuCEoa37EKGXkEhn90oB_950emKG-uXdlmssM,10317
|
|
5
|
+
pydantic_ai/_system_prompt.py,sha256=MZJWksIoS5GM3Au5lznlcQnC-h7eqwtE7oI5WFgRcOg,1090
|
|
6
|
+
pydantic_ai/_utils.py,sha256=skWNgm89US_x1EpxdRy5wCkghBrm1XgxFCiEh6wAkAo,8753
|
|
7
|
+
pydantic_ai/agent.py,sha256=6iOVgmoGw5wGd0W4ewFgOGJqTLmtJLyl5RLqt3dSegE,49574
|
|
8
|
+
pydantic_ai/exceptions.py,sha256=eGDKX6bGhgVxXBzu81Sk3iiAkXr0GUtgT7bD5Rxlqpg,2028
|
|
9
|
+
pydantic_ai/messages.py,sha256=ImbWY8Ft3mxInUQ08EmIWywf4nJBvTiJhmsECRYDkSQ,8968
|
|
10
|
+
pydantic_ai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
pydantic_ai/result.py,sha256=pE8YTCUDS0hXTplEJKSG3UnhMvwGNqaOU-9eC09K4y4,14735
|
|
12
|
+
pydantic_ai/settings.py,sha256=rSNqWYzBoIwC9wZCS2M_aEdCNAy5sOXbi5bXJAuqK08,4923
|
|
13
|
+
pydantic_ai/tools.py,sha256=9ZEhvgylv3pc0_JaahCJgJlFxubCWeEaCNqERl-I9B0,11982
|
|
14
|
+
pydantic_ai/models/__init__.py,sha256=XHt02IDQAircb-lEkIbIcuabSAIh5_UKnz2V1xN0Glw,10926
|
|
15
|
+
pydantic_ai/models/anthropic.py,sha256=EUZgmvT0jhMDbooBp_jfW0z2cM5jTMuAhVws1XKgaNs,13451
|
|
16
|
+
pydantic_ai/models/function.py,sha256=i7qkS_31aHrTbYVh6OzQ7Cwucz44F5PjT2EJK3GMphw,10573
|
|
17
|
+
pydantic_ai/models/gemini.py,sha256=8vdcW4izL9NUGFj6lcD9yIPaakCtsmHauTvKwlTzD14,28207
|
|
18
|
+
pydantic_ai/models/groq.py,sha256=ZoPkuWJrf78JPnTRfZhi7v0ETgxJKNN5dH8BLWagGGk,15770
|
|
19
|
+
pydantic_ai/models/mistral.py,sha256=xZMK2vNLDR4uw1XoAQs-3obeA6c39Q1Qhei8w1JMIow,26458
|
|
20
|
+
pydantic_ai/models/ollama.py,sha256=i3mMXkXu9xL6f4c52Eyx3j4aHKfYoloFondlGHPtkS4,3971
|
|
21
|
+
pydantic_ai/models/openai.py,sha256=qFFInL3NbgfGcsAWigxMP5mscp76hC-jJimHc9woU6Y,16518
|
|
22
|
+
pydantic_ai/models/test.py,sha256=pty5qaudHsSDvdE89HqMj-kmd4UMV9VJI2YGtdfOX1o,15960
|
|
23
|
+
pydantic_ai/models/vertexai.py,sha256=DBCBfpvpIhZaMG7cKvRl5rugCZqJqqEFm74uBc45weo,9259
|
|
24
|
+
pydantic_ai_slim-0.0.14.dist-info/METADATA,sha256=GgTCeoTiFNW1S0pSniLn7ILqGrLK8eaOkOG84aYE06M,2785
|
|
25
|
+
pydantic_ai_slim-0.0.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
26
|
+
pydantic_ai_slim-0.0.14.dist-info/RECORD,,
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
pydantic_ai/__init__.py,sha256=a29NqQz0JyW4BoCjcRh23fBBfwY17_n57moE4QrFWM4,324
|
|
2
|
-
pydantic_ai/_griffe.py,sha256=pRjCJ6B1hhx6k46XJgl9zF6aRYxRmqEZKFok8unp4Iw,3449
|
|
3
|
-
pydantic_ai/_pydantic.py,sha256=qXi5IsyiYOHeg_-qozCdxkfeqw2z0gBTjqgywBCiJWo,8125
|
|
4
|
-
pydantic_ai/_result.py,sha256=LycNJR_Whc9P7sz2uD-Ce5bs9kQBU6eYqQxCUDNiNxU,10453
|
|
5
|
-
pydantic_ai/_system_prompt.py,sha256=2Ui7fYAXxR_aZZLJdwMnOAecBOIbrKwx1yV4Qz523WQ,1089
|
|
6
|
-
pydantic_ai/_utils.py,sha256=skWNgm89US_x1EpxdRy5wCkghBrm1XgxFCiEh6wAkAo,8753
|
|
7
|
-
pydantic_ai/agent.py,sha256=sDQE20lQXyWO-SrodqSNlzzGwtaLNSkla6NgyJXPKTU,48568
|
|
8
|
-
pydantic_ai/exceptions.py,sha256=ko_47M0k6Rhg9mUC9P1cj7N4LCH6cC0pEsF65A2vL-U,1561
|
|
9
|
-
pydantic_ai/messages.py,sha256=Qa9H5kf9qeI1NqB-XgRjPJ-wwgVKvDZxqam7gnsLtrc,8106
|
|
10
|
-
pydantic_ai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
-
pydantic_ai/result.py,sha256=ZhaYArCiVl9JlrTllaeFIl2vU2foiIgpQYGby55G4cQ,13664
|
|
12
|
-
pydantic_ai/settings.py,sha256=3sUaDMVMBX9Pku4Bh7lpv6VizX1utenHd5kVIRJvHyY,1908
|
|
13
|
-
pydantic_ai/tools.py,sha256=hhhe5_ELeyYpaRoETMLjml83FAbMY7cpo5us7qwbOWg,11532
|
|
14
|
-
pydantic_ai/models/__init__.py,sha256=y1tkHgWjIGLhZX95dIeOXcljSiAiRGma2T55hNi8EwA,10897
|
|
15
|
-
pydantic_ai/models/anthropic.py,sha256=YBqiYjvOVqsSHPNT2Vt2aMaAAa8nMK57IMPONrtBCyc,13430
|
|
16
|
-
pydantic_ai/models/function.py,sha256=i54ce97lqmy1p7Vqc162EiF_72oA3khc7z2uBGZbuWg,10731
|
|
17
|
-
pydantic_ai/models/gemini.py,sha256=3oy0FVHLOP8SEOvpvoWtlUhRCJpddRj4-J_IPXaEkLE,28277
|
|
18
|
-
pydantic_ai/models/groq.py,sha256=dorqZk8xbZ4ZDzZothJoWbUkoD8TWHb6lftdkNDlsu0,15821
|
|
19
|
-
pydantic_ai/models/mistral.py,sha256=S0K73J5AGKwJc0UU0ifCrPmcxR2QMvVS6L1Cq19xDrk,26793
|
|
20
|
-
pydantic_ai/models/ollama.py,sha256=i3mMXkXu9xL6f4c52Eyx3j4aHKfYoloFondlGHPtkS4,3971
|
|
21
|
-
pydantic_ai/models/openai.py,sha256=fo3ocIOylD8YTuJMTJR1eXcRAQDGFKWFIYYrSOQS1C0,16569
|
|
22
|
-
pydantic_ai/models/test.py,sha256=mBQ0vJYjEMHv01A3yyHR2porkxekpmqIUBkK-W8d-L8,15530
|
|
23
|
-
pydantic_ai/models/vertexai.py,sha256=DBCBfpvpIhZaMG7cKvRl5rugCZqJqqEFm74uBc45weo,9259
|
|
24
|
-
pydantic_ai_slim-0.0.13.dist-info/METADATA,sha256=57JLefiQcRnSOVvkDHcik6wQ24FZ3HOmPrfCaBUe4X8,2785
|
|
25
|
-
pydantic_ai_slim-0.0.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
26
|
-
pydantic_ai_slim-0.0.13.dist-info/RECORD,,
|
|
File without changes
|