07. Runnable

# .env Read a file and set it as an environment variable
from dotenv import load_dotenv

# load token information
load_dotenv()
True
# Set up LangSmith tracking. https://smith.langchain.com
# !pip install -qU langchain-teddynote
from langchain_teddynote import logging

# Enter a project name.
logging.langsmith("CH01-Basic")
Start tracking LangSmith.
[project name]
CH01-Basic

How to effectively convey data

  • RunnablePassthrough can be passed without changing the input or by adding additional keys.

  • RunnablePassthrough() When called alone, it simply takes input and passes it on as is.

  • RunnablePassthrough.assign(...) When called in this way, it takes input and adds any additional arguments passed to the assign function.

RunnablePassthrough

chain 을 invoke() When executing, the input data type must be a dictionary.

However, with the update of the langchain library, it is also possible to pass only the value if the template contains only one variable.

Below is an example using RunnablePassthrough.w

RunnablePassthrough is a runnable object, and a runnable object can be executed separately using the invoke() method.

Below is an example of constructing a chain with RunnablePassthrough.

다음은 RunnablePassthrough.assign() The results are compared with when using .

RunnablePassthrough.assign()

  • Merges the key/value pairs of the values ​​passed as input values ​​with the newly assigned key/value pairs.

RunnableParallel

Chain can also apply RunnableParallel.

RunnableLambda

You can map your own custom functions using RunnableLambda.

Use itemgetter to extract a specific key.

Last edited by : Sept. 5, 2024, 9:18 a.m.

Last updated