pydantic-ai-slim 0.0.20__py3-none-any.whl → 0.0.22__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/_agent_graph.py +770 -0
- pydantic_ai/_parts_manager.py +1 -1
- pydantic_ai/_result.py +3 -7
- pydantic_ai/_utils.py +1 -56
- pydantic_ai/agent.py +192 -560
- pydantic_ai/messages.py +21 -46
- pydantic_ai/models/__init__.py +104 -57
- pydantic_ai/models/anthropic.py +17 -10
- pydantic_ai/models/cohere.py +37 -25
- pydantic_ai/models/gemini.py +27 -7
- pydantic_ai/models/groq.py +19 -17
- pydantic_ai/models/mistral.py +22 -23
- pydantic_ai/models/openai.py +25 -12
- pydantic_ai/models/test.py +37 -22
- pydantic_ai/result.py +1 -1
- pydantic_ai/settings.py +46 -1
- pydantic_ai/tools.py +11 -8
- {pydantic_ai_slim-0.0.20.dist-info → pydantic_ai_slim-0.0.22.dist-info}/METADATA +2 -3
- pydantic_ai_slim-0.0.22.dist-info/RECORD +30 -0
- pydantic_ai/models/ollama.py +0 -123
- pydantic_ai_slim-0.0.20.dist-info/RECORD +0 -30
- {pydantic_ai_slim-0.0.20.dist-info → pydantic_ai_slim-0.0.22.dist-info}/WHEEL +0 -0
pydantic_ai/_parts_manager.py
CHANGED
|
@@ -221,7 +221,7 @@ class ModelResponsePartsManager:
|
|
|
221
221
|
ModelResponseStreamEvent: A `PartStartEvent` indicating that a new tool call part
|
|
222
222
|
has been added to the manager, or replaced an existing part.
|
|
223
223
|
"""
|
|
224
|
-
new_part = ToolCallPart
|
|
224
|
+
new_part = ToolCallPart(tool_name=tool_name, args=args, tool_call_id=tool_call_id)
|
|
225
225
|
if vendor_part_id is None:
|
|
226
226
|
# vendor_part_id is None, so we unconditionally append a new ToolCallPart to the end of the list
|
|
227
227
|
new_part_index = len(self._parts)
|
pydantic_ai/_result.py
CHANGED
|
@@ -201,14 +201,10 @@ class ResultTool(Generic[ResultDataT]):
|
|
|
201
201
|
"""
|
|
202
202
|
try:
|
|
203
203
|
pyd_allow_partial: Literal['off', 'trailing-strings'] = 'trailing-strings' if allow_partial else 'off'
|
|
204
|
-
if isinstance(tool_call.args,
|
|
205
|
-
result = self.type_adapter.validate_json(
|
|
206
|
-
tool_call.args.args_json or '', experimental_allow_partial=pyd_allow_partial
|
|
207
|
-
)
|
|
204
|
+
if isinstance(tool_call.args, str):
|
|
205
|
+
result = self.type_adapter.validate_json(tool_call.args, experimental_allow_partial=pyd_allow_partial)
|
|
208
206
|
else:
|
|
209
|
-
result = self.type_adapter.validate_python(
|
|
210
|
-
tool_call.args.args_dict, experimental_allow_partial=pyd_allow_partial
|
|
211
|
-
)
|
|
207
|
+
result = self.type_adapter.validate_python(tool_call.args, experimental_allow_partial=pyd_allow_partial)
|
|
212
208
|
except ValidationError as e:
|
|
213
209
|
if wrap_validation_errors:
|
|
214
210
|
m = _messages.RetryPromptPart(
|
pydantic_ai/_utils.py
CHANGED
|
@@ -8,7 +8,7 @@ from dataclasses import dataclass, is_dataclass
|
|
|
8
8
|
from datetime import datetime, timezone
|
|
9
9
|
from functools import partial
|
|
10
10
|
from types import GenericAlias
|
|
11
|
-
from typing import TYPE_CHECKING, Any, Callable, Generic, TypeVar, Union
|
|
11
|
+
from typing import TYPE_CHECKING, Any, Callable, Generic, TypeVar, Union
|
|
12
12
|
|
|
13
13
|
from pydantic import BaseModel
|
|
14
14
|
from pydantic.json_schema import JsonSchemaValue
|
|
@@ -79,61 +79,6 @@ def is_set(t_or_unset: T | Unset) -> TypeGuard[T]:
|
|
|
79
79
|
return t_or_unset is not UNSET
|
|
80
80
|
|
|
81
81
|
|
|
82
|
-
Left = TypeVar('Left')
|
|
83
|
-
Right = TypeVar('Right')
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
class Either(Generic[Left, Right]):
|
|
87
|
-
"""Two member Union that records which member was set, this is analogous to Rust enums with two variants.
|
|
88
|
-
|
|
89
|
-
Usage:
|
|
90
|
-
|
|
91
|
-
```python
|
|
92
|
-
if left_thing := either.left:
|
|
93
|
-
use_left(left_thing.value)
|
|
94
|
-
else:
|
|
95
|
-
use_right(either.right)
|
|
96
|
-
```
|
|
97
|
-
"""
|
|
98
|
-
|
|
99
|
-
__slots__ = '_left', '_right'
|
|
100
|
-
|
|
101
|
-
@overload
|
|
102
|
-
def __init__(self, *, left: Left) -> None: ...
|
|
103
|
-
|
|
104
|
-
@overload
|
|
105
|
-
def __init__(self, *, right: Right) -> None: ...
|
|
106
|
-
|
|
107
|
-
def __init__(self, left: Left | Unset = UNSET, right: Right | Unset = UNSET) -> None:
|
|
108
|
-
if left is not UNSET:
|
|
109
|
-
assert right is UNSET, '`Either` must receive exactly one argument - `left` or `right`'
|
|
110
|
-
self._left: Option[Left] = Some(cast(Left, left))
|
|
111
|
-
else:
|
|
112
|
-
assert right is not UNSET, '`Either` must receive exactly one argument - `left` or `right`'
|
|
113
|
-
self._left = None
|
|
114
|
-
self._right = cast(Right, right)
|
|
115
|
-
|
|
116
|
-
@property
|
|
117
|
-
def left(self) -> Option[Left]:
|
|
118
|
-
return self._left
|
|
119
|
-
|
|
120
|
-
@property
|
|
121
|
-
def right(self) -> Right:
|
|
122
|
-
return self._right
|
|
123
|
-
|
|
124
|
-
def is_left(self) -> bool:
|
|
125
|
-
return self._left is not None
|
|
126
|
-
|
|
127
|
-
def whichever(self) -> Left | Right:
|
|
128
|
-
return self._left.value if self._left is not None else self.right
|
|
129
|
-
|
|
130
|
-
def __repr__(self):
|
|
131
|
-
if left := self._left:
|
|
132
|
-
return f'Either(left={left.value!r})'
|
|
133
|
-
else:
|
|
134
|
-
return f'Either(right={self.right!r})'
|
|
135
|
-
|
|
136
|
-
|
|
137
82
|
@asynccontextmanager
|
|
138
83
|
async def group_by_temporal(
|
|
139
84
|
aiterable: AsyncIterable[T], soft_max_interval: float | None
|