Home / Class/ StrInvertCase Class — langchain Architecture

StrInvertCase Class — langchain Architecture

Architecture documentation for the StrInvertCase class in test_base_parsers.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  9521b311_e9e2_a1c2_b324_bd7449374ca5["StrInvertCase"]
  2bdc4d81_5592_3e8d_1079_4eb50790f1d0["ChatGeneration"]
  9521b311_e9e2_a1c2_b324_bd7449374ca5 -->|extends| 2bdc4d81_5592_3e8d_1079_4eb50790f1d0
  c9530b99_1055_3d8a_4f5c_857ce24f7e3c["test_base_parsers.py"]
  9521b311_e9e2_a1c2_b324_bd7449374ca5 -->|defined in| c9530b99_1055_3d8a_4f5c_857ce24f7e3c
  25fd0a7f_3c3d_d9f7_0cbd_520068021510["parse_result()"]
  9521b311_e9e2_a1c2_b324_bd7449374ca5 -->|method| 25fd0a7f_3c3d_d9f7_0cbd_520068021510
  403c3c38_5523_1f6d_f2cd_c4cdf6daf266["parse()"]
  9521b311_e9e2_a1c2_b324_bd7449374ca5 -->|method| 403c3c38_5523_1f6d_f2cd_c4cdf6daf266

Relationship Graph

Source Code

libs/core/tests/unit_tests/output_parsers/test_base_parsers.py lines 18–46

    class StrInvertCase(BaseGenerationOutputParser[str]):
        """An example parser that inverts the case of the characters in the message."""

        @override
        def parse_result(
            self, result: list[Generation], *, partial: bool = False
        ) -> str:
            """Parse a list of model Generations into a specific format.

            Args:
                result: A list of `Generation` to be parsed. The Generations are assumed
                    to be different candidate outputs for a single model input.
                    Many parsers assume that only a single generation is passed it in.
                    We will assert for that
                partial: Whether to allow partial results. This is used for parsers
                         that support streaming
            """
            if len(result) != 1:
                msg = "This output parser can only be used with a single generation."
                raise NotImplementedError(msg)
            generation = result[0]
            if not isinstance(generation, ChatGeneration):
                # Say that this one only works with chat generations
                msg = "This output parser can only be used with a chat generation."
                raise OutputParserException(msg)

            content = generation.message.content
            assert isinstance(content, str)
            return content.swapcase()

Extends

Frequently Asked Questions

What is the StrInvertCase class?
StrInvertCase is a class in the langchain codebase, defined in libs/core/tests/unit_tests/output_parsers/test_base_parsers.py.
Where is StrInvertCase defined?
StrInvertCase is defined in libs/core/tests/unit_tests/output_parsers/test_base_parsers.py at line 18.
What does StrInvertCase extend?
StrInvertCase extends ChatGeneration.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free