LCEL is a powerful feature of LangChain that allows for more flexible and composable chain construction.
These properties provide a comprehensive set of tools for working with LCEL chains in various scenarios.
The async versions (ainvoke
, astream
, abatch
, astream_log
) are particularly useful in applications that need to maintain responsiveness while processing, such as web servers or applications with user interfaces.
Here’s a brief summary of when we might use each:
- Use
invoke
andainvoke
for simple, one-off executions of your chain. - Use
stream
andastream
when you need to process or display results incrementally. - Use
batch
andabatch
when you have multiple inputs to process efficiently. - Use
astream_log
when you need detailed visibility into the chain's execution process.
Let’s dive into each of these properties:
1. invoke
- Purpose: Synchronously executes the chain or component.
- Usage: Used when you want to run the chain and wait for the result before proceeding.
- Example:
result = my_chain.invoke({"input": "Hello, world!"})
print(result)
2. ainvoke
- Purpose: Asynchronously executes the chain or component.
- Usage: Used when you…