Complete the code to create a RunnablePassthrough that returns the input as output.
from langchain_core.runnables import RunnablePassthrough passthrough = RunnablePassthrough() result = passthrough.invoke([1]) print(result)
The RunnablePassthrough returns exactly what it receives. Passing a string like 'Hello World' will print the same string.
Complete the code to create a RunnableLambda that doubles the input number.
from langchain_core.runnables import RunnableLambda runnable = RunnableLambda(lambda x: x [1] 2) result = runnable.invoke(5) print(result)
The lambda multiplies the input by 2 to double it. Using '*' performs multiplication.
Fix the error in the RunnableLambda that should return the input string in uppercase.
runnable = RunnableLambda(lambda x: x.[1]()) result = runnable.invoke('hello') print(result)
The 'upper()' method converts a string to uppercase. This fixes the error to produce 'HELLO'.
Fill both blanks to create a RunnableLambda that returns the length of the input string if it is longer than 3 characters.
runnable = RunnableLambda(lambda x: len(x) if len(x) [1] 3 else [2]) print(runnable.invoke('test'))
The lambda checks if the input length is greater than 3 and returns its length; otherwise, it returns None.
Fill all three blanks to create a RunnableLambda that returns a dictionary with the input string as key and its uppercase as value if the string length is at least 4.
runnable = RunnableLambda(lambda x: [1] if len(x) [2] 4 else [3]) print(runnable.invoke('code'))
The lambda returns a dictionary with the input and its uppercase if length is 4 or more; otherwise, it returns an empty dictionary.