langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
93.11k stars 14.97k forks source link

In the astream_log() method, you cannot use the bind method with RunnableLambda. #17241

Closed eyurtsev closed 2 months ago

eyurtsev commented 8 months ago

Discussed in https://github.com/langchain-ai/langchain/discussions/16446

Originally posted by **jason1315** January 23, 2024 In my project, I need to implement the following logic. Here is a simple: ```python import asyncio from langchain_core.runnables import * from lang_chain.llm.llms import llm def _test(_dict): print("value:", _dict) return _dict @chain def my_method(_dict, **keywords): print(keywords) return RunnablePassthrough.assign(key=lambda x: keywords.get("i")) | RunnableLambda(_test) if name == 'main': loop = asyncio.new_event_loop() my_list = ["1", "2", "3", " 4", "5"] head = RunnablePassthrough() for i in my_list: head = head | my_method.bind(i=i) stream = head.invoke({}) # # async def __stream(stream1): # async for i in stream1: # print(i) # # loop.run_until_complete(__stream(stream)) ``` When I use the .invoke({}) method, it outputs the following results correctly: ```text {'i': '1'} value: {'key': '1'} {'i': '2'} value: {'key': '2'} {'i': '3'} value: {'key': '3'} {'i': ' 4'} value: {'key': ' 4'} {'i': '5'} value: {'key': '5'} ``` But if I use the astream_log({}) method, it throws an error: ```text File "F:\py3.11\Lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: RunnableLambda._atransform..func() got an unexpected keyword argument 'i' ``` Why is it designed like this? Do I need to implement a runnable similar to the model if I want to achieve the above logic?
UtkarshaGupte commented 6 months ago

@baskaryan - Is this issue fixed by PR ?