[docs]classEnumOutputParser(BaseOutputParser[Enum]):"""Parse an output that is one of a set of values."""enum:Type[Enum]"""The enum to parse. Its values must be strings."""
[docs]@pre_initdefraise_deprecation(cls,values:Dict)->Dict:enum=values["enum"]ifnotall(isinstance(e.value,str)foreinenum):raiseValueError("Enum values must be strings")returnvalues
[docs]defparse(self,response:str)->Enum:try:returnself.enum(response.strip())exceptValueError:raiseOutputParserException(f"Response '{response}' is not one of the "f"expected values: {self._valid_values}")
[docs]defget_format_instructions(self)->str:returnf"Select one of the following options: {', '.join(self._valid_values)}"