07. EnumOutputParser
EnumOutputParser
Let's find out how to use the Enum output parser!
Copy
from langchain.output_parsers.enum import EnumOutputParserenumUsing moduleColorsDefine the class.ColorsClassEnumInheritance,RED,GREEN,BLUEIt 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,
ChatOpenAIThe model, parser is connected to form a processing chain.
Copy
chain.invokeUse the function to request information about the "sky".
Copy
Copy
Check the results.
Last updated