Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Simplify Output Parsers #367

Merged
merged 1 commit into from
Apr 8, 2024
Merged

refactor!: Simplify Output Parsers #367

merged 1 commit into from
Apr 8, 2024

Conversation

davidmigloz
Copy link
Owner

@davidmigloz davidmigloz commented Apr 8, 2024

Relates to #266

The BaseOutputParser class has been reworked. Before it was strongly coupled to LLMs/ChatModels and they could not be used with other types of Runnables. You couldn't pass options to the parser either.

Now the BaseOutputParser takes 3 generic parameters:

  • ParserInput (extends Object?): the type of the input to the parser.
  • CallOptions (extends OutputParserOptions): the type of the options to pass to the parser.
  • ParserOutput (extends Object?): the type of the output of the parser.

Migration guide

StringOutputParser

You now have to specify in input type in the generic parameter of StringOutputParser.

If you were using a StringOutputParser with an llm (e.g. OpenAI):

Before:

const outputParser = StringOutputParser<String>();

After:

const outputParser = StringOutputParser<LLMResult>();

If you were using a StringOutputParser with a Chat Model (e.g. ChatOpenAI):

Before:

const outputParser = StringOutputParser<AIChatMessage>();

After:

const outputParser = StringOutputParser<ChatResult>();

If you were using a StringOutputParser defined inside the chain, the generic type will still be inferred automatically:

final chain = promptTemplate.pipe(model).pipe(StringOutputParser());

@davidmigloz davidmigloz self-assigned this Apr 8, 2024
@davidmigloz davidmigloz mentioned this pull request Apr 8, 2024
16 tasks
@davidmigloz davidmigloz added t:enhancement New feature or request c:output-parsers Output parsers. c:lcel LangChain Expression Language labels Apr 8, 2024
@davidmigloz davidmigloz added this to the v0.5.0 milestone Apr 8, 2024
@davidmigloz davidmigloz merged commit f24b705 into main Apr 8, 2024
1 check passed
@davidmigloz davidmigloz deleted the output-parsers branch April 8, 2024 07:01
KennethKnudsen97 pushed a commit to KennethKnudsen97/langchain_dart that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c:lcel LangChain Expression Language c:output-parsers Output parsers. t:enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant