Stream HelpersLangChainStream
LangChainStream
LangChainStream is part of the legacy LangChain integration. It is recommended to use the LangChain Adapter instead.
Helps with the integration of LangChain. It is compatible with useChat and useCompletion.
Import
import { LangChainStream } from "ai"
API Signature
Parameters
callbacks?:
AIStreamCallbacksAndOptions
An object containing callback functions to handle the start, each token, and completion of the AI response. In the absence of this parameter, default behavior is implemented.
AIStreamCallbacksAndOptions
onStart:
() => Promise<void>
An optional function that is called at the start of the stream processing.
onCompletion:
(completion: string) => Promise<void>
An optional function that is called for every completion. It's passed the completion as a string.
onFinal:
(completion: string) => Promise<void>
An optional function that is called once when the stream is closed with the final completion message.
onToken:
(token: string) => Promise<void>
An optional function that is called for each token in the stream. It's passed the token as a string.
Returns
stream:
ReadableStream
This is the readable stream that can be piped into another stream. This stream contains the results of the LangChain process.
handlers:
LangChainCallbacks
This object contains handlers that can be used to handle certain callbacks provided by LangChain.