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

import { ChatOpenAI } from "langchain/chat_models/openai";
import { StringOutputParser } from "langchain/schema/output_parser";

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: