-
Notifications
You must be signed in to change notification settings - Fork 16.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runnables: Add .map() method #9445
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
04cd3a0
to
0f2abc4
Compare
7eab95c
to
bba4ddc
Compare
@@ -208,6 +208,12 @@ def bind(self, **kwargs: Any) -> Runnable[Input, Output]: | |||
""" | |||
return RunnableBinding(bound=self, kwargs=kwargs) | |||
|
|||
def each(self) -> Runnable[List[Input], List[Output]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better name for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of looks like .map
to me?
def lc_namespace(self) -> List[str]: | ||
return self.__class__.__module__.split(".")[:-1] | ||
|
||
def each(self) -> RunnableEach[Input, Output]: # type: ignore[override] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mypy isn't super smart here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to return Runnable[List[Input], List[Output]]
wouldn't this preserve the correct interface?
Otherwise, could you leave a comment in the code explaining the need for this type ignore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is Mypy wants this to be Runnable[List[List[Input]], List[List[Output]]]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I think mypy is correct here:
Runnable.map
has a signature of-> Runnable[List[Input], List[Output]]
.RunnableEach[I, O]
is aRunnable[List[I], List[O]]
.- That means that in order to subtype
Runnable
,RunnableEach[I, O].map
has to be-> Runnable[List[List[I]], List[List[O]]]
.
I think this might cause further issues in downstream code, both inside langchain and in downstream packages that depend on it.
It feels like RunnableEach
shouldn't be Runnable
, and perhaps there's a missing abstraction that should sit underneath both of them?
68535ef
to
fcb0fbe
Compare
def lc_namespace(self) -> List[str]: | ||
return self.__class__.__module__.split(".")[:-1] | ||
|
||
def each(self) -> RunnableEach[Input, Output]: # type: ignore[override] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to return Runnable[List[Input], List[Output]]
wouldn't this preserve the correct interface?
Otherwise, could you leave a comment in the code explaining the need for this type ignore?
libs/langchain/tests/unit_tests/schema/runnable/test_runnable.py
Outdated
Show resolved
Hide resolved
bba4ddc
to
937e27f
Compare
fcb0fbe
to
db4b256
Compare
345dc6e
to
ab9f7b5
Compare
ab9f7b5
to
882b97c
Compare
No description provided.