Skip to content

Commit 6158742

Browse files
committed
some fixes
1 parent f04683d commit 6158742

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pydantic_ai_slim/pydantic_ai/result.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from __future__ import annotations as _annotations
22

3-
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Iterator
3+
import inspect
4+
from collections.abc import AsyncIterator, Awaitable, Callable, Coroutine, Iterable, Iterator
45
from contextlib import asynccontextmanager
56
from copy import deepcopy
67
from dataclasses import dataclass, field, replace
78
from datetime import datetime
8-
from typing import TYPE_CHECKING, Generic, cast, overload
9+
from typing import TYPE_CHECKING, Any, Generic, cast, overload
910

1011
from pydantic import ValidationError
1112
from typing_extensions import TypeVar, deprecated
@@ -739,15 +740,14 @@ async def my_task():
739740

740741
def _async_to_sync(
741742
self,
742-
func: Callable[[StreamedRunResult[AgentDepsT, OutputDataT]], Awaitable[T]]
743-
| Callable[[StreamedRunResult[AgentDepsT, OutputDataT]], T],
743+
func: Callable[[StreamedRunResult[AgentDepsT, OutputDataT]], Coroutine[Any, Any, T] | T],
744744
) -> T:
745745
async def my_task():
746746
async with self._with_streamed_run_result() as result:
747-
if _utils.is_async_callable(func):
748-
return await func(result)
749-
else:
750-
return func(result)
747+
res = func(result)
748+
if inspect.isawaitable(res):
749+
res = await res
750+
return res
751751

752752
return _utils.get_event_loop().run_until_complete(my_task())
753753

tests/test_streaming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ async def ret_a(x: str) -> str:
190190
RunUsage(
191191
requests=2,
192192
input_tokens=103,
193-
output_tokens=5,
193+
output_tokens=11,
194194
tool_calls=1,
195195
)
196196
)

0 commit comments

Comments
 (0)