4
4
import dataclasses
5
5
import hashlib
6
6
from collections import defaultdict , deque
7
- from collections .abc import AsyncIterator , Awaitable , Iterator , Sequence
7
+ from collections .abc import AsyncIterator , Awaitable , Callable , Iterator , Sequence
8
8
from contextlib import asynccontextmanager , contextmanager
9
9
from contextvars import ContextVar
10
10
from dataclasses import field
11
- from typing import TYPE_CHECKING , Any , Callable , Generic , Literal , Union , cast
11
+ from typing import TYPE_CHECKING , Any , Generic , Literal , TypeGuard , Union , cast
12
12
13
13
from opentelemetry .trace import Tracer
14
- from typing_extensions import TypeGuard , TypeVar , assert_never
14
+ from typing_extensions import TypeVar , assert_never
15
15
16
16
from pydantic_ai ._function_schema import _takes_ctx as is_takes_ctx # type: ignore
17
17
from pydantic_ai ._tool_manager import ToolManager
59
59
_HistoryProcessorAsyncWithCtx = Callable [
60
60
[RunContext [DepsT ], list [_messages .ModelMessage ]], Awaitable [list [_messages .ModelMessage ]]
61
61
]
62
- HistoryProcessor = Union [
63
- _HistoryProcessorSync ,
64
- _HistoryProcessorAsync ,
65
- _HistoryProcessorSyncWithCtx [DepsT ],
66
- _HistoryProcessorAsyncWithCtx [DepsT ],
67
- ]
62
+ HistoryProcessor = (
63
+ _HistoryProcessorSync
64
+ | _HistoryProcessorAsync
65
+ | _HistoryProcessorSyncWithCtx [DepsT ]
66
+ | _HistoryProcessorAsyncWithCtx [DepsT ]
67
+ )
68
68
"""A function that processes a list of model messages and returns a list of model messages.
69
69
70
70
Can optionally accept a `RunContext` as a parameter.
@@ -736,15 +736,15 @@ async def _call_function_tool(
736
736
737
737
if isinstance (tool_result , _messages .ToolReturn ):
738
738
if (
739
- isinstance (tool_result .return_value , _messages .MultiModalContentTypes )
739
+ isinstance (tool_result .return_value , _messages .MultiModalContent )
740
740
or isinstance (tool_result .return_value , list )
741
741
and any (
742
- isinstance (content , _messages .MultiModalContentTypes )
742
+ isinstance (content , _messages .MultiModalContent )
743
743
for content in tool_result .return_value # type: ignore
744
744
)
745
745
):
746
746
raise exceptions .UserError (
747
- f'The `return_value` of tool { tool_call .tool_name !r} contains invalid nested `MultiModalContentTypes ` objects. '
747
+ f'The `return_value` of tool { tool_call .tool_name !r} contains invalid nested `MultiModalContent ` objects. '
748
748
f'Please use `content` instead.'
749
749
)
750
750
@@ -765,7 +765,7 @@ def process_content(content: Any) -> Any:
765
765
f'The return value of tool { tool_call .tool_name !r} contains invalid nested `ToolReturn` objects. '
766
766
f'`ToolReturn` should be used directly.'
767
767
)
768
- elif isinstance (content , _messages .MultiModalContentTypes ):
768
+ elif isinstance (content , _messages .MultiModalContent ):
769
769
if isinstance (content , _messages .BinaryContent ):
770
770
identifier = content .identifier or multi_modal_content_identifier (content .data )
771
771
else :
0 commit comments