April 29, 2024, 10:45 p.m. | Olivier

DEV Community dev.to

If you got stuck like me for hours on how to use the new Vercel AI SDK with Langchain to stream, the trick is not to use the LangChainStream from Vercel's here https://sdk.vercel.ai/docs/api-reference/providers/langchain-stream


But to use the .stream with an outputparser here

https://sdk.vercel.ai/docs/guides/providers/langchain



let completion = ''

const transformStream = new TransformStream({
transform(chunk, controller) {
// accumulate the assistant answer aka completion
completion += new TextDecoder('utf-8').decode(chunk)
controller.enqueue(chunk)
},
flush(controller) {
console.log('completion', completion)
// do something like save history.. similar
// …

assistant chunk decode history langchain llm save something utf-8 vercel

Software Engineer for AI Training Data (School Specific)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Python)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Tier 2)

@ G2i Inc | Remote

Data Engineer

@ Lemon.io | Remote: Europe, LATAM, Canada, UK, Asia, Oceania

Artificial Intelligence – Bioinformatic Expert

@ University of Texas Medical Branch | Galveston, TX

Lead Developer (AI)

@ Cere Network | San Francisco, US