In this exercise, you will use the EnumOutputParser to implement the behavior explained in the following prompt. This prompt may or may not work as-is with the LLM of your choice. As a result, you will need to adjust it as part of the exercise.
Note : This prompt was optimized in LangChain/Exercise#7 :)
template_1 = """
what is the color of {object}.
Format instructions: {format_instructions}
"""
from langchain.output_parsers import EnumOutputParser
from enum import Enum
# Create a class with a set of options
class Colors(Enum):
RED = "red"
GREEN = "green"
BLUE = "blue"
WHITE = "white"
UNKNOWN = "others"
# Create the output parser
output_parser_enum = EnumOutputParser(enum=Colors)
The solution to the exercise is available in the notebook: