Skip to main content

String output parser

The StringOutputParser takes language model output (either an entire response or as a stream) and converts it into a string. This is useful for standardizing chat model and LLM output.

This output parser can act as a transform stream and work with streamed response chunks from a model.

Usage

npm install @langchain/openai
import { ChatOpenAI } from "@langchain/openai";
import { StringOutputParser } from "@langchain/core/output_parsers";

const parser = new StringOutputParser();

const model = new ChatOpenAI({ temperature: 0 });

const stream = await model.pipe(parser).stream("Hello there!");

for await (const chunk of stream) {
console.log(chunk);
}

/*
Hello
!
How
can
I
assist
you
today
?
*/

API Reference:


Help us out by providing feedback on this documentation page: