01. RunnablePasstrough
RunnablePassthrough Is the role of passing data. This class invoke() Through the method Returns the entered data as it is To.
This can be used to pass the data to the next level of the piprain without changing it.
RunnablePassthrough can be useful in the following scenarios.
If you don't need to convert or modify data
If you need to cross certain steps in the pipline
When data flow needs to be monitored for debugging or testing purposes
This class Runnable Interface implemented, so different Runnable It can be used in the pipeline with objects.
Copy
# Configuration file for managing API keys as environment variables
from dotenv import load_dotenv
# Load API key information
load_dotenv()Copy
True Copy
# Set up LangSmith tracking. https://smith.langchain.com
# !pip install langchain-teddynote
from langchain_teddynote import logging
# Enter a project name.
logging.langsmith("LCEL-Advanced")Copy
Data transfer
RunnablePassthrough You can pass it as it is without changing the input, or you can pass it by adding additional keys.
Generally RunnableParallel Used in conjunction with and used to assign data to new keys in the map.
RunnablePassthrough() When called alone, it simply takes input and passes it as it is.
RunnablePasstrough called with assign RunnablePassthrough.assign(...) ) Receives input and adds additional factors passed to the assign function.
RunnableParallelUsing class Define actionable actions in parallel To.passedIn propertiesRunnablePassthroughAssign an instance to return the input as it is.extraIn propertiesRunnablePassthrough.assign()Defines the task of assigning the "num" value of the input multiplied by 3 to the "mult" key using a method.modifiedThe attribute defines the task of adding 1 to the "num" value of the input using the lambda function.runnable.invoke()By calling the method{"num": 1}Run parallel operations with input.
Copy
Copy
Copy
Copy
In the example above passed tall RunnablePassthrough() It was called with, it is simply {'num': 1} Pass.
In the second line, along with the lambda function multiplying the numeric value by 3 RunnablePastshrough.assign Used. in this case, extra to the original value mult Added key {'num': 1, 'mult': 3} Set to.
Finally, modified I used a key to set the third key on the map, which used the lambda function to set a single value plus 1 for num, and as a result modified The value of the key 2 It has been.
Finder example
In the example below RunnablePassthrough You can look at the usage cases you use.
Copy
Copy
Copy
Copy
Copy
Last updated