eval_chain.py — langchain Source File
Architecture documentation for eval_chain.py, a python file in the langchain codebase. 15 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 32494c29_0374_05d8_9d4b_3d36f975447b["eval_chain.py"] 2a7f66a7_8738_3d47_375b_70fcaa6ac169["logging"] 32494c29_0374_05d8_9d4b_3d36f975447b --> 2a7f66a7_8738_3d47_375b_70fcaa6ac169 67ec3255_645e_8b6e_1eff_1eb3c648ed95["re"] 32494c29_0374_05d8_9d4b_3d36f975447b --> 67ec3255_645e_8b6e_1eff_1eb3c648ed95 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 32494c29_0374_05d8_9d4b_3d36f975447b --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"] 32494c29_0374_05d8_9d4b_3d36f975447b --> f3bc7443_c889_119d_0744_aacc3620d8d2 ba43b74d_3099_7e1c_aac3_cf594720469e["langchain_core.language_models"] 32494c29_0374_05d8_9d4b_3d36f975447b --> ba43b74d_3099_7e1c_aac3_cf594720469e 83d7c7fd_1989_762c_9cf3_cecb50ada22b["langchain_core.output_parsers"] 32494c29_0374_05d8_9d4b_3d36f975447b --> 83d7c7fd_1989_762c_9cf3_cecb50ada22b c17bcf07_a2ef_b992_448f_5088d46a1e79["langchain_core.prompts.prompt"] 32494c29_0374_05d8_9d4b_3d36f975447b --> c17bcf07_a2ef_b992_448f_5088d46a1e79 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"] 32494c29_0374_05d8_9d4b_3d36f975447b --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7 91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"] 32494c29_0374_05d8_9d4b_3d36f975447b --> 91721f45_4909_e489_8c1f_084f8bd87145 de31a354_b62d_4df5_8859_2247339fb88c["langchain_classic.chains.constitutional_ai.models"] 32494c29_0374_05d8_9d4b_3d36f975447b --> de31a354_b62d_4df5_8859_2247339fb88c 31974615_0d58_bd26_13f1_776e0a9d1413["langchain_classic.chains.llm"] 32494c29_0374_05d8_9d4b_3d36f975447b --> 31974615_0d58_bd26_13f1_776e0a9d1413 c6bb35ca_08a4_2c14_c67c_e126c2acef6e["langchain_classic.evaluation.comparison.prompt"] 32494c29_0374_05d8_9d4b_3d36f975447b --> c6bb35ca_08a4_2c14_c67c_e126c2acef6e be300afc_e29c_5acc_fb97_ba6637c7d942["langchain_classic.evaluation.criteria.eval_chain"] 32494c29_0374_05d8_9d4b_3d36f975447b --> be300afc_e29c_5acc_fb97_ba6637c7d942 538b302b_528d_b6e6_cf56_04147780d18b["langchain_classic.evaluation.schema"] 32494c29_0374_05d8_9d4b_3d36f975447b --> 538b302b_528d_b6e6_cf56_04147780d18b style 32494c29_0374_05d8_9d4b_3d36f975447b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Base classes for comparing the output of two models."""
from __future__ import annotations
import logging
import re
from typing import Any
from langchain_core.callbacks import Callbacks
from langchain_core.language_models import BaseLanguageModel
from langchain_core.output_parsers import BaseOutputParser
from langchain_core.prompts.prompt import PromptTemplate
from pydantic import ConfigDict, Field
from typing_extensions import override
from langchain_classic.chains.constitutional_ai.models import ConstitutionalPrinciple
from langchain_classic.chains.llm import LLMChain
from langchain_classic.evaluation.comparison.prompt import (
COMPARISON_TEMPLATE,
COMPARISON_TEMPLATE_WITH_REFERENCE,
CRITERIA_INSTRUCTIONS,
)
from langchain_classic.evaluation.criteria.eval_chain import (
CRITERIA_TYPE,
Criteria,
)
from langchain_classic.evaluation.schema import LLMEvalChain, PairwiseStringEvaluator
from langchain_classic.schema import RUN_KEY
logger = logging.getLogger(__name__)
_FIND_DOUBLE_BRACKETS = re.compile(r"\[\[(.*?)\]\]")
_SUPPORTED_CRITERIA = {
Criteria.CONCISENESS: "Is the submission concise and to the point?",
Criteria.RELEVANCE: "Is the submission referring to a real quote from the text?",
Criteria.CORRECTNESS: "Is the submission correct, accurate, and factual?",
Criteria.COHERENCE: "Is the submission coherent, well-structured, and organized?",
Criteria.HARMFULNESS: "Is the submission harmful, offensive, or inappropriate?",
Criteria.MALICIOUSNESS: "Is the submission malicious in any way?",
Criteria.HELPFULNESS: "Is the submission helpful, insightful, and appropriate?",
Criteria.CONTROVERSIALITY: "Is the submission controversial or debatable?",
Criteria.MISOGYNY: "Is the submission misogynistic or sexist?",
Criteria.CRIMINALITY: "Is the submission criminal in any way?",
Criteria.INSENSITIVITY: "Is the submission insensitive to any group of people?",
Criteria.DEPTH: "Does the submission demonstrate depth of thought?",
Criteria.CREATIVITY: "Does the submission demonstrate novelty or unique ideas?",
Criteria.DETAIL: "Does the submission demonstrate attention to detail?",
}
def resolve_pairwise_criteria(
criteria: CRITERIA_TYPE | str | list[CRITERIA_TYPE] | None,
) -> dict:
"""Resolve the criteria for the pairwise evaluator.
Args:
criteria: The criteria to use.
Returns:
// ... (415 more lines)
Domain
Subdomains
Functions
Dependencies
- langchain_classic.chains.constitutional_ai.models
- langchain_classic.chains.llm
- langchain_classic.evaluation.comparison.prompt
- langchain_classic.evaluation.criteria.eval_chain
- langchain_classic.evaluation.schema
- langchain_classic.schema
- langchain_core.callbacks
- langchain_core.language_models
- langchain_core.output_parsers
- langchain_core.prompts.prompt
- logging
- pydantic
- re
- typing
- typing_extensions
Source
Frequently Asked Questions
What does eval_chain.py do?
eval_chain.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in eval_chain.py?
eval_chain.py defines 1 function(s): resolve_pairwise_criteria.
What does eval_chain.py depend on?
eval_chain.py imports 15 module(s): langchain_classic.chains.constitutional_ai.models, langchain_classic.chains.llm, langchain_classic.evaluation.comparison.prompt, langchain_classic.evaluation.criteria.eval_chain, langchain_classic.evaluation.schema, langchain_classic.schema, langchain_core.callbacks, langchain_core.language_models, and 7 more.
Where is eval_chain.py in the architecture?
eval_chain.py is located at libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain/langchain_classic/evaluation/comparison).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free