|
|
|
@ -69,6 +69,7 @@ from langchain_core.runnables.utils import (
|
|
|
|
|
accepts_config,
|
|
|
|
|
accepts_context,
|
|
|
|
|
accepts_run_manager,
|
|
|
|
|
adapt_first_streaming_chunk,
|
|
|
|
|
create_model,
|
|
|
|
|
gather_with_concurrency,
|
|
|
|
|
get_function_first_arg_dict_keys,
|
|
|
|
@ -1207,7 +1208,7 @@ class Runnable(Generic[Input, Output], ABC):
|
|
|
|
|
|
|
|
|
|
for chunk in input:
|
|
|
|
|
if not got_first_val:
|
|
|
|
|
final = _adapt_first_streaming_chunk(chunk) # type: ignore
|
|
|
|
|
final = adapt_first_streaming_chunk(chunk) # type: ignore
|
|
|
|
|
got_first_val = True
|
|
|
|
|
else:
|
|
|
|
|
# Make a best effort to gather, for any type that supports `+`
|
|
|
|
@ -1240,7 +1241,7 @@ class Runnable(Generic[Input, Output], ABC):
|
|
|
|
|
|
|
|
|
|
async for chunk in input:
|
|
|
|
|
if not got_first_val:
|
|
|
|
|
final = _adapt_first_streaming_chunk(chunk) # type: ignore
|
|
|
|
|
final = adapt_first_streaming_chunk(chunk) # type: ignore
|
|
|
|
|
got_first_val = True
|
|
|
|
|
else:
|
|
|
|
|
# Make a best effort to gather, for any type that supports `+`
|
|
|
|
@ -3731,7 +3732,7 @@ class RunnableLambda(Runnable[Input, Output]):
|
|
|
|
|
final: Optional[Input] = None
|
|
|
|
|
for ichunk in input:
|
|
|
|
|
if final is None:
|
|
|
|
|
final = _adapt_first_streaming_chunk(ichunk) # type: ignore
|
|
|
|
|
final = adapt_first_streaming_chunk(ichunk) # type: ignore
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
final = final + ichunk # type: ignore[operator]
|
|
|
|
@ -3815,7 +3816,7 @@ class RunnableLambda(Runnable[Input, Output]):
|
|
|
|
|
final: Optional[Input] = None
|
|
|
|
|
async for ichunk in input:
|
|
|
|
|
if final is None:
|
|
|
|
|
final = _adapt_first_streaming_chunk(ichunk)
|
|
|
|
|
final = adapt_first_streaming_chunk(ichunk)
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
final = final + ichunk # type: ignore[operator]
|
|
|
|
@ -4727,11 +4728,3 @@ def chain(
|
|
|
|
|
yield chunk
|
|
|
|
|
"""
|
|
|
|
|
return RunnableLambda(func)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _adapt_first_streaming_chunk(chunk: Any) -> Any:
|
|
|
|
|
"""This might transform the first chunk of a stream into an AddableDict."""
|
|
|
|
|
if isinstance(chunk, dict) and not isinstance(chunk, AddableDict):
|
|
|
|
|
return AddableDict(chunk)
|
|
|
|
|
else:
|
|
|
|
|
return chunk
|
|
|
|
|