test_base_generation_parser() — langchain Function Reference
Architecture documentation for the test_base_generation_parser() function in test_base_parsers.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6777a403_618b_6329_886e_6bb4224e04fe["test_base_generation_parser()"] c9530b99_1055_3d8a_4f5c_857ce24f7e3c["test_base_parsers.py"] 6777a403_618b_6329_886e_6bb4224e04fe -->|defined in| c9530b99_1055_3d8a_4f5c_857ce24f7e3c 25fd0a7f_3c3d_d9f7_0cbd_520068021510["parse_result()"] 6777a403_618b_6329_886e_6bb4224e04fe -->|calls| 25fd0a7f_3c3d_d9f7_0cbd_520068021510 style 6777a403_618b_6329_886e_6bb4224e04fe fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/output_parsers/test_base_parsers.py lines 15–50
def test_base_generation_parser() -> None:
"""Test Base Generation Output Parser."""
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()
model = GenericFakeChatModel(messages=iter([AIMessage(content="hEllo")]))
chain = model | StrInvertCase()
assert chain.invoke("") == "HeLLO"
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does test_base_generation_parser() do?
test_base_generation_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_generation_parser() defined?
test_base_generation_parser() is defined in libs/core/tests/unit_tests/output_parsers/test_base_parsers.py at line 15.
What does test_base_generation_parser() call?
test_base_generation_parser() calls 1 function(s): parse_result.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free