mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-24 20:12:11 +00:00
refactor(core): Use duck typing for _StreamingCallbackHandler
(#32535)
It's used in langgraph and maybe elsewhere, so would be preferable if it could just be duck-typed
This commit is contained in:
parent
d204f0dd55
commit
b470c79f1d
@ -1,15 +1,16 @@
|
|||||||
"""Internal tracers used for stream_log and astream events implementations."""
|
"""Internal tracers used for stream_log and astream events implementations."""
|
||||||
|
|
||||||
import abc
|
import typing
|
||||||
from collections.abc import AsyncIterator, Iterator
|
from collections.abc import AsyncIterator, Iterator
|
||||||
from typing import TypeVar
|
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = typing.TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
class _StreamingCallbackHandler(abc.ABC):
|
# THIS IS USED IN LANGGRAPH.
|
||||||
"""For internal use.
|
@typing.runtime_checkable
|
||||||
|
class _StreamingCallbackHandler(typing.Protocol[T]):
|
||||||
|
"""Types for streaming callback handlers.
|
||||||
|
|
||||||
This is a common mixin that the callback handlers
|
This is a common mixin that the callback handlers
|
||||||
for both astream events and astream log inherit from.
|
for both astream events and astream log inherit from.
|
||||||
@ -18,13 +19,11 @@ class _StreamingCallbackHandler(abc.ABC):
|
|||||||
to produce callbacks for intermediate results.
|
to produce callbacks for intermediate results.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def tap_output_aiter(
|
def tap_output_aiter(
|
||||||
self, run_id: UUID, output: AsyncIterator[T]
|
self, run_id: UUID, output: AsyncIterator[T]
|
||||||
) -> AsyncIterator[T]:
|
) -> AsyncIterator[T]:
|
||||||
"""Used for internal astream_log and astream events implementations."""
|
"""Used for internal astream_log and astream events implementations."""
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def tap_output_iter(self, run_id: UUID, output: Iterator[T]) -> Iterator[T]:
|
def tap_output_iter(self, run_id: UUID, output: Iterator[T]) -> Iterator[T]:
|
||||||
"""Used for internal astream_log and astream events implementations."""
|
"""Used for internal astream_log and astream events implementations."""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user