Home / File/ base.py — langchain Source File

base.py — langchain Source File

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

Entity Profile

Dependency Diagram

graph LR
  96d74b59_b5c3_f0b1_5bd5_4f6a29e34b2b["base.py"]
  7025b240_fdc3_cf68_b72f_f41dac94566b["json"]
  96d74b59_b5c3_f0b1_5bd5_4f6a29e34b2b --> 7025b240_fdc3_cf68_b72f_f41dac94566b
  2a7f66a7_8738_3d47_375b_70fcaa6ac169["logging"]
  96d74b59_b5c3_f0b1_5bd5_4f6a29e34b2b --> 2a7f66a7_8738_3d47_375b_70fcaa6ac169
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  96d74b59_b5c3_f0b1_5bd5_4f6a29e34b2b --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  7aaf52d4_ee88_411e_980e_bc4beeeb30ad["operator"]
  96d74b59_b5c3_f0b1_5bd5_4f6a29e34b2b --> 7aaf52d4_ee88_411e_980e_bc4beeeb30ad
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  96d74b59_b5c3_f0b1_5bd5_4f6a29e34b2b --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  78c5ca66_f675_3ca1_fdb7_d5a994dcf4bf["langchain_core.utils.json"]
  96d74b59_b5c3_f0b1_5bd5_4f6a29e34b2b --> 78c5ca66_f675_3ca1_fdb7_d5a994dcf4bf
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  96d74b59_b5c3_f0b1_5bd5_4f6a29e34b2b --> 91721f45_4909_e489_8c1f_084f8bd87145
  538b302b_528d_b6e6_cf56_04147780d18b["langchain_classic.evaluation.schema"]
  96d74b59_b5c3_f0b1_5bd5_4f6a29e34b2b --> 538b302b_528d_b6e6_cf56_04147780d18b
  style 96d74b59_b5c3_f0b1_5bd5_4f6a29e34b2b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Evaluators for parsing strings."""

import json
import logging
from collections.abc import Callable
from operator import eq
from typing import Any, cast

from langchain_core.utils.json import parse_json_markdown
from typing_extensions import override

from langchain_classic.evaluation.schema import StringEvaluator

_logger = logging.getLogger(__name__)


class JsonValidityEvaluator(StringEvaluator):
    """Evaluate whether the prediction is valid JSON.

    This evaluator checks if the prediction is a valid JSON string. It does not
        require any input or reference.

    Attributes:
        requires_input: Whether this evaluator requires an input
            string. Always False.
        requires_reference: Whether this evaluator requires a
            reference string. Always False.
        evaluation_name: The name of the evaluation metric.
            Always "json".

    Examples:
        >>> evaluator = JsonValidityEvaluator()
        >>> prediction = '{"name": "John", "age": 30, "city": "New York"}'
        >>> evaluator.evaluate(prediction)
        {'score': 1}

        >>> prediction = '{"name": "John", "age": 30, "city": "New York",}'
        >>> evaluator.evaluate(prediction)
        {'score': 0, 'reasoning': 'Expecting property name enclosed in double quotes'}
    """

    def __init__(self, **_: Any) -> None:
        """Initialize the JsonValidityEvaluator."""
        super().__init__()

    @property
    @override
    def requires_input(self) -> bool:
        return False

    @property
    @override
    def requires_reference(self) -> bool:
        return False

    @property
    @override
    def evaluation_name(self) -> str:
        return "json_validity"

// ... (122 more lines)

Subdomains

Dependencies

  • collections.abc
  • json
  • langchain_classic.evaluation.schema
  • langchain_core.utils.json
  • logging
  • operator
  • typing
  • typing_extensions

Frequently Asked Questions

What does base.py do?
base.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What does base.py depend on?
base.py imports 8 module(s): collections.abc, json, langchain_classic.evaluation.schema, langchain_core.utils.json, logging, operator, typing, typing_extensions.
Where is base.py in the architecture?
base.py is located at libs/langchain/langchain_classic/evaluation/parsing/base.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain/langchain_classic/evaluation/parsing).

Analyze Your Own Codebase

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

Try Supermodel Free