Home / Function/ from_run_and_data_type() — langchain Function Reference

from_run_and_data_type() — langchain Function Reference

Architecture documentation for the from_run_and_data_type() function in string_run_evaluator.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  a9615765_7463_0bdd_480f_312e89300d9b["from_run_and_data_type()"]
  96e174c1_4107_a88b_8d98_3f22e5d7fb20["StringRunEvaluatorChain"]
  a9615765_7463_0bdd_480f_312e89300d9b -->|defined in| 96e174c1_4107_a88b_8d98_3f22e5d7fb20
  style a9615765_7463_0bdd_480f_312e89300d9b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/smith/evaluation/string_run_evaluator.py lines 406–477

    def from_run_and_data_type(
        cls,
        evaluator: StringEvaluator,
        run_type: str,
        data_type: DataType,
        input_key: str | None = None,
        prediction_key: str | None = None,
        reference_key: str | None = None,
        tags: list[str] | None = None,
    ) -> StringRunEvaluatorChain:
        """Create a StringRunEvaluatorChain.

        Create a StringRunEvaluatorChain from an evaluator and the run and dataset
        types.

        This method provides an easy way to instantiate a StringRunEvaluatorChain, by
        taking an evaluator and information about the type of run and the data.
        The method supports LLM and chain runs.

        Args:
            evaluator: The string evaluator to use.
            run_type: The type of run being evaluated.
                Supported types are LLM and Chain.
            data_type: The type of dataset used in the run.
            input_key: The key used to map the input from the run.
            prediction_key: The key used to map the prediction from the run.
            reference_key: The key used to map the reference from the dataset.
            tags: List of tags to attach to the evaluation chain.

        Returns:
            The instantiated evaluation chain.

        Raises:
            ValueError: If the run type is not supported, or if the evaluator requires a
                reference from the dataset but the reference key is not provided.

        """
        # Configure how run inputs/predictions are passed to the evaluator
        if run_type == "llm":
            run_mapper: StringRunMapper = LLMStringRunMapper()
        elif run_type == "chain":
            run_mapper = ChainStringRunMapper(
                input_key=input_key,
                prediction_key=prediction_key,
            )
        else:
            msg = f"Unsupported run type {run_type}. Expected one of 'llm' or 'chain'."
            raise ValueError(msg)

        # Configure how example rows are fed as a reference string to the evaluator
        if (
            reference_key is not None
            or data_type in (DataType.llm, DataType.chat)
            or evaluator.requires_reference
        ):
            example_mapper = StringExampleMapper(reference_key=reference_key)
        elif evaluator.requires_reference:
            msg = (  # type: ignore[unreachable]
                f"Evaluator {evaluator.evaluation_name} requires a reference"
                " example from the dataset. Please specify the reference key from"
                " amongst the dataset outputs keys."
            )
            raise ValueError(msg)
        else:
            example_mapper = None
        return cls(
            name=evaluator.evaluation_name,
            run_mapper=run_mapper,
            example_mapper=example_mapper,
            string_evaluator=evaluator,
            tags=tags,
        )

Domain

Subdomains

Frequently Asked Questions

What does from_run_and_data_type() do?
from_run_and_data_type() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/smith/evaluation/string_run_evaluator.py.
Where is from_run_and_data_type() defined?
from_run_and_data_type() is defined in libs/langchain/langchain_classic/smith/evaluation/string_run_evaluator.py at line 406.

Analyze Your Own Codebase

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

Try Supermodel Free