mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 15:19:33 +00:00
Patch forward ref bug (#12508)
Currently this gives a bug: ``` from langchain.schema.runnable import RunnableLambda bound = RunnableLambda(lambda x: x).with_config({"callbacks": []}) # ConfigError: field "callbacks" not yet prepared so type is still a ForwardRef, you might need to call RunnableConfig.update_forward_refs(). ``` Rather than deal with cyclic imports and extra load time, etc., I think it makes sense to just have a separate Callbacks definition here that is a relaxed typehint.
This commit is contained in:
parent
36204c2baf
commit
a830b809f3
@ -32,6 +32,10 @@ if TYPE_CHECKING:
|
||||
CallbackManager,
|
||||
CallbackManagerForChainRun,
|
||||
)
|
||||
else:
|
||||
# Pydantic validates through typed dicts, but
|
||||
# the callbacks need forward refs updated
|
||||
Callbacks = Optional[Union[List, Any]]
|
||||
|
||||
|
||||
class EmptyDict(TypedDict, total=False):
|
||||
|
@ -60,7 +60,11 @@ from langchain.schema.runnable import (
|
||||
RunnableSequence,
|
||||
RunnableWithFallbacks,
|
||||
)
|
||||
from langchain.schema.runnable.base import ConfigurableField, RunnableGenerator
|
||||
from langchain.schema.runnable.base import (
|
||||
ConfigurableField,
|
||||
RunnableBinding,
|
||||
RunnableGenerator,
|
||||
)
|
||||
from langchain.schema.runnable.utils import (
|
||||
ConfigurableFieldMultiOption,
|
||||
ConfigurableFieldSingleOption,
|
||||
@ -3999,3 +4003,11 @@ async def test_runnable_gen_transform() -> None:
|
||||
|
||||
assert list(chain.stream(3)) == [1, 2, 3]
|
||||
assert [p async for p in achain.astream(4)] == [1, 2, 3, 4]
|
||||
|
||||
|
||||
def test_with_config_callbacks() -> None:
|
||||
result = RunnableLambda(lambda x: x).with_config({"callbacks": []})
|
||||
# Bugfix from version 0.0.325
|
||||
# ConfigError: field "callbacks" not yet prepared so type is still a ForwardRef,
|
||||
# you might need to call RunnableConfig.update_forward_refs().
|
||||
assert isinstance(result, RunnableBinding)
|
||||
|
Loading…
Reference in New Issue
Block a user