test_regex_dict.py — langchain Source File
Architecture documentation for test_regex_dict.py, a python file in the langchain codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 608785ad_0df1_2e0f_0223_6ec903eb602f["test_regex_dict.py"] c7c7628d_2902_2e42_061c_ef7a34011dc8["langchain_classic.output_parsers.regex_dict"] 608785ad_0df1_2e0f_0223_6ec903eb602f --> c7c7628d_2902_2e42_061c_ef7a34011dc8 style 608785ad_0df1_2e0f_0223_6ec903eb602f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Test in memory docstore."""
from langchain_classic.output_parsers.regex_dict import RegexDictParser
DEF_EXPECTED_RESULT = {"action": "Search", "action_input": "How to use this class?"}
DEF_OUTPUT_KEY_TO_FORMAT = {"action": "Action", "action_input": "Action Input"}
DEF_README = """We have just received a new result from the LLM, and our next step is
to filter and read its format using regular expressions to identify specific fields,
such as:
- Action: Search
- Action Input: How to use this class?
- Additional Fields: "N/A"
To assist us in this task, we use the regex_dict class. This class allows us to send a
dictionary containing an output key and the expected format, which in turn enables us to
retrieve the result of the matching formats and extract specific information from it.
To exclude irrelevant information from our return dictionary, we can instruct the LLM to
use a specific command that notifies us when it doesn't know the answer. We call this
variable the "no_update_value", and for our current case, we set it to "N/A". Therefore,
we expect the result to only contain the following fields:
{
{key = action, value = search}
{key = action_input, value = "How to use this class?"}.
}"""
def test_regex_dict_result() -> None:
"""Test regex dict result."""
regex_dict_parser = RegexDictParser(
output_key_to_format=DEF_OUTPUT_KEY_TO_FORMAT,
no_update_value="N/A",
)
result_dict = regex_dict_parser.parse(DEF_README)
print("parse_result:", result_dict) # noqa: T201
assert result_dict == DEF_EXPECTED_RESULT
def test_regex_dict_output_type() -> None:
"""Test regex dict output type."""
regex_dict_parser = RegexDictParser(
output_key_to_format=DEF_OUTPUT_KEY_TO_FORMAT,
no_update_value="N/A",
)
assert regex_dict_parser.OutputType == dict[str, str]
Domain
Subdomains
Dependencies
- langchain_classic.output_parsers.regex_dict
Source
Frequently Asked Questions
What does test_regex_dict.py do?
test_regex_dict.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_regex_dict.py?
test_regex_dict.py defines 2 function(s): test_regex_dict_output_type, test_regex_dict_result.
What does test_regex_dict.py depend on?
test_regex_dict.py imports 1 module(s): langchain_classic.output_parsers.regex_dict.
Where is test_regex_dict.py in the architecture?
test_regex_dict.py is located at libs/langchain/tests/unit_tests/output_parsers/test_regex_dict.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