0
0
LangChainframework~10 mins

Parallel execution with RunnableParallel in LangChain - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a RunnableParallel instance with two runnables.

LangChain
from langchain.schema.runnable import Runnable
from langchain.schema.runnable.parallel import RunnableParallel

runnable1 = Runnable()
runnable2 = Runnable()
parallel = RunnableParallel([1])
Drag options to blanks, or click blank then click option'
Arunnable1, runnable2
Brunnable1=runnable1, runnable2=runnable2
C(runnable1, runnable2)
D{runnable1, runnable2}
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets for list syntax.
Passing runnables separated by commas without keyword names.
2fill in blank
medium

Complete the code to run the RunnableParallel instance with input 'data'.

LangChain
result = parallel.[1]('data')
Drag options to blanks, or click blank then click option'
Aexecute
Brun
Cinvoke
Dinvoke_async
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' or 'execute' which are not methods of RunnableParallel.
Using 'invoke_async' which is for asynchronous calls.
3fill in blank
hard

Fix the error in the code to run RunnableParallel asynchronously.

LangChain
import asyncio

async def main():
    result = await parallel.[1]('input')
    print(result)

asyncio.run(main())
Drag options to blanks, or click blank then click option'
Aainvoke
Brun
Cexecute_async
Dasync_run
Attempts:
3 left
💡 Hint
Common Mistakes
Using synchronous methods with await causing errors.
Using method names that do not exist in RunnableParallel.
4fill in blank
hard

Fill both blanks to create a RunnableParallel that runs two different runnables and run it synchronously.

LangChain
r1 = Runnable()
r2 = Runnable()
parallel = RunnableParallel([1]=r1, [2]=r2)
output = parallel.[3]('test input')
Drag options to blanks, or click blank then click option'
Ar1
Br2
Cinvoke
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Passing runnables without kwarg syntax or with wrong syntax.
Using 'execute' which is not a RunnableParallel method.
5fill in blank
hard

Fill all three blanks to create a RunnableParallel, run it asynchronously, and print the result.

LangChain
import asyncio

r1 = Runnable()
r2 = Runnable()
parallel = RunnableParallel([1]=r1, [2]=r2)

async def main():
    result = await parallel.[3]('async input')
    print(result)

asyncio.run(main())
Drag options to blanks, or click blank then click option'
Ar1
Br2
Cainvoke
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using synchronous invoke method with await causing errors.
Passing runnables without kwarg syntax.