Wiki: https://wikidocs.net/book/14314
Github: https://github.com/teddylee777/langchain-kr
LangChain also provides asynchronous methods. Async functions are prefixed with "a".
Async Functions
# Call the 'ainvoke' method on the async chain object to process the 'NVDA' topic.
my_process = chain.ainvoke({"topic": "NVDA"})
# Wait until the asynchronously processed process completes.
await my_process
Runnable Interface https://python.langchain.com/v0.1/docs/expression_language/interface/
RunnableParallel
from langchain_core.runnables import RunnableParallel
# Create a RunnableParallel instance. This instance can run multiple Runnable instances in parallel.
runnable = RunnableParallel(
# Pass a RunnablePassthrough instance as the 'passed' keyword argument. This passes the input data through as-is.
passed=RunnablePassthrough(),
# Use RunnablePassthrough.assign as the 'extra' keyword argument, assigning the 'mult' lambda function. This function multiplies the value of the 'num' key in the input dictionary by 3.
extra=RunnablePassthrough.assign(mult=lambda x: x["num"] * 3),
# Pass a lambda function as the 'modified' keyword argument. This function adds 1 to the value of the 'num' key in the input dictionary.
modified=lambda x: x["num"] + 1,
)
# Call the invoke method on the runnable instance with {'num': 1} dictionary as input.
runnable.invoke({"num": 1})
# Result
# {'passed': {'num': 1}, 'extra': {'num': 1, 'mult': 3}, 'modified': 2}
Quiz
Q1: What is the main topic covered in "ch01 LangChain Notes"?
ch01 LangChain Notes
Q2: What is Async Functions?
Runnable Interface https://python.langchain.com/v0.1/docs/expression_language/interface/