from langchain_core.runnables import RunnableLambda
def func(x):
return x + 5
= RunnableLambda(func)
runnable 2) runnable.invoke(
7
LangChain Expression Language: https://python.langchain.com/v0.2/docs/how_to/lcel_cheatsheet/
from langchain_core.runnables import RunnableLambda
def func(x):
return x + 5
= RunnableLambda(func)
runnable 2) runnable.invoke(
7
= RunnableLambda(lambda x: str(x + 1))
runnable 5) runnable.invoke(
'6'
= RunnableLambda(lambda x: str(x + 1))
runnable 7, 8, 9])
runnable.batch([# Async variant:
# await runnable.abatch([7, 8, 9])
['8', '9', '10']
def func(x):
for y in x:
yield str(y)
= RunnableLambda(func)
runnable for chunk in runnable.stream(range(5)):
print(chunk)
0
1
2
3
4
|
from langchain_core.runnables import RunnableLambda
= RunnableLambda(lambda x: x + 1)
runnable1 = RunnableLambda(lambda x: x * 2)
runnable2
= runnable1 | runnable2
chain
2) chain.invoke(
6
from langchain_core.runnables import RunnableLambda, RunnableParallel
= RunnableLambda(lambda x: x + 1)
runnable1 = RunnableLambda(lambda x: x * 2)
runnable2
= RunnableParallel(first=runnable1, second=runnable2)
chain chain
{
first: RunnableLambda(lambda x: x + 1),
second: RunnableLambda(lambda x: x * 2)
}
type(chain)
langchain_core.runnables.base.RunnableParallel
2) chain.invoke(
6