test_base_transform_output_parser() — langchain Function Reference
Architecture documentation for the test_base_transform_output_parser() function in test_base_parsers.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD ca5fabf7_107e_cdd5_a7a6_2f608c56533a["test_base_transform_output_parser()"] c9530b99_1055_3d8a_4f5c_857ce24f7e3c["test_base_parsers.py"] ca5fabf7_107e_cdd5_a7a6_2f608c56533a -->|defined in| c9530b99_1055_3d8a_4f5c_857ce24f7e3c 403c3c38_5523_1f6d_f2cd_c4cdf6daf266["parse()"] ca5fabf7_107e_cdd5_a7a6_2f608c56533a -->|calls| 403c3c38_5523_1f6d_f2cd_c4cdf6daf266 25fd0a7f_3c3d_d9f7_0cbd_520068021510["parse_result()"] ca5fabf7_107e_cdd5_a7a6_2f608c56533a -->|calls| 25fd0a7f_3c3d_d9f7_0cbd_520068021510 style ca5fabf7_107e_cdd5_a7a6_2f608c56533a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/output_parsers/test_base_parsers.py lines 53–93
def test_base_transform_output_parser() -> None:
"""Test base transform output parser."""
class StrInvertCase(BaseTransformOutputParser[str]):
"""An example parser that inverts the case of the characters in the message."""
def parse(self, text: str) -> str:
"""Parse a single string into a specific format."""
raise NotImplementedError
@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()
model = GenericFakeChatModel(messages=iter([AIMessage(content="hello world")]))
chain = model | StrInvertCase()
# inputs to models are ignored, response is hard-coded in model definition
chunks = list(chain.stream(""))
assert chunks == ["HELLO", " ", "WORLD"]
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does test_base_transform_output_parser() do?
test_base_transform_output_parser() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/output_parsers/test_base_parsers.py.
Where is test_base_transform_output_parser() defined?
test_base_transform_output_parser() is defined in libs/core/tests/unit_tests/output_parsers/test_base_parsers.py at line 53.
What does test_base_transform_output_parser() call?
test_base_transform_output_parser() calls 2 function(s): parse, parse_result.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free