07. EnumOutputParser

EnumOutputParser

Let's find out how to use the Enum output parser!

Copy

from langchain.output_parsers.enum import EnumOutputParser
  • enum Using module Colors Define the class.

  • Colors Class Enum Inheritance, RED , GREEN , BLUE It has three color values.

Copy

from enum import Enum


class Colors(Enum):
    RED = "RED"
    GREEN = "GREEN"
    BLUE = "BLUE"

Copy

# EnumOutputParser create immediately
parser = EnumOutputParser(enum=Colors)
  • People's information at the prompt ( {person} ) And parsing instructions ( {instructions} ).

  • parser.get_format_instructions() Call the function to get the parsing instructions.

  • prompt, ChatOpenAI The model, parser is connected to form a processing chain.

Copy

  • chain.invoke Use the function to request information about the "sky".

Copy

Copy

Check the results.

Last updated