Home / File/ test_combining_parser.py — langchain Source File

test_combining_parser.py — langchain Source File

Architecture documentation for test_combining_parser.py, a python file in the langchain codebase. 4 imports, 0 dependents.

File python CoreAbstractions MessageSchema 4 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  8f950b29_46bc_0e2b_1f60_07fe30573f7c["test_combining_parser.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  8f950b29_46bc_0e2b_1f60_07fe30573f7c --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  98d419b2_a9fc_1a33_bb85_9d02469fb780["langchain_classic.output_parsers.combining"]
  8f950b29_46bc_0e2b_1f60_07fe30573f7c --> 98d419b2_a9fc_1a33_bb85_9d02469fb780
  e7ae90d2_7c36_40aa_f905_386f8e995321["langchain_classic.output_parsers.regex"]
  8f950b29_46bc_0e2b_1f60_07fe30573f7c --> e7ae90d2_7c36_40aa_f905_386f8e995321
  6710b5d5_8c76_290b_dc8f_3711ae8df10c["langchain_classic.output_parsers.structured"]
  8f950b29_46bc_0e2b_1f60_07fe30573f7c --> 6710b5d5_8c76_290b_dc8f_3711ae8df10c
  style 8f950b29_46bc_0e2b_1f60_07fe30573f7c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test in memory docstore."""

from typing import Any

from langchain_classic.output_parsers.combining import CombiningOutputParser
from langchain_classic.output_parsers.regex import RegexParser
from langchain_classic.output_parsers.structured import (
    ResponseSchema,
    StructuredOutputParser,
)

DEF_EXPECTED_RESULT = {
    "answer": "Paris",
    "source": "https://en.wikipedia.org/wiki/France",
    "confidence": "A",
    "explanation": "Paris is the capital of France according to Wikipedia.",
}

DEF_README = """```json
{
    "answer": "Paris",
    "source": "https://en.wikipedia.org/wiki/France"
}
```

//Confidence: A, Explanation: Paris is the capital of France according to Wikipedia."""


def test_combining_dict_result() -> None:
    """Test combining result."""
    parsers = [
        StructuredOutputParser(
            response_schemas=[
                ResponseSchema(
                    name="answer",
                    description="answer to the user's question",
                ),
                ResponseSchema(
                    name="source",
                    description="source used to answer the user's question",
                ),
            ],
        ),
        RegexParser(
            regex=r"Confidence: (A|B|C), Explanation: (.*)",
            output_keys=["confidence", "explanation"],
            default_output_key="noConfidence",
        ),
    ]
    combining_parser = CombiningOutputParser(parsers=parsers)
    result_dict = combining_parser.parse(DEF_README)
    assert result_dict == DEF_EXPECTED_RESULT


def test_combining_output_parser_output_type() -> None:
    """Test combining output parser output type is Dict[str, Any]."""
    parsers = [
        StructuredOutputParser(
            response_schemas=[
                ResponseSchema(
                    name="answer",
                    description="answer to the user's question",
                ),
                ResponseSchema(
                    name="source",
                    description="source used to answer the user's question",
                ),
            ],
        ),
        RegexParser(
            regex=r"Confidence: (A|B|C), Explanation: (.*)",
            output_keys=["confidence", "explanation"],
            default_output_key="noConfidence",
        ),
    ]
    combining_parser = CombiningOutputParser(parsers=parsers)
    assert combining_parser.OutputType == dict[str, Any]

Subdomains

Dependencies

  • langchain_classic.output_parsers.combining
  • langchain_classic.output_parsers.regex
  • langchain_classic.output_parsers.structured
  • typing

Frequently Asked Questions

What does test_combining_parser.py do?
test_combining_parser.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_combining_parser.py?
test_combining_parser.py defines 2 function(s): test_combining_dict_result, test_combining_output_parser_output_type.
What does test_combining_parser.py depend on?
test_combining_parser.py imports 4 module(s): langchain_classic.output_parsers.combining, langchain_classic.output_parsers.regex, langchain_classic.output_parsers.structured, typing.
Where is test_combining_parser.py in the architecture?
test_combining_parser.py is located at libs/langchain/tests/unit_tests/output_parsers/test_combining_parser.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/langchain/tests/unit_tests/output_parsers).

Analyze Your Own Codebase

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

Try Supermodel Free