Home / File/ base.py — langchain Source File

base.py — langchain Source File

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

File python CoreAbstractions RunnableInterface 13 imports 4 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  36d37670_e012_f502_4b19_b9823ce99006["base.py"]
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  36d37670_e012_f502_4b19_b9823ce99006 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  36d37670_e012_f502_4b19_b9823ce99006 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  c89186be_3766_27dd_efaa_6092bf0ccc74["urllib.parse"]
  36d37670_e012_f502_4b19_b9823ce99006 --> c89186be_3766_27dd_efaa_6092bf0ccc74
  b19a8b7e_fbee_95b1_65b8_509a1ed3cad7["langchain_core._api"]
  36d37670_e012_f502_4b19_b9823ce99006 --> b19a8b7e_fbee_95b1_65b8_509a1ed3cad7
  f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"]
  36d37670_e012_f502_4b19_b9823ce99006 --> f3bc7443_c889_119d_0744_aacc3620d8d2
  ba43b74d_3099_7e1c_aac3_cf594720469e["langchain_core.language_models"]
  36d37670_e012_f502_4b19_b9823ce99006 --> ba43b74d_3099_7e1c_aac3_cf594720469e
  e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"]
  36d37670_e012_f502_4b19_b9823ce99006 --> e6b4f61e_7b98_6666_3641_26b069517d4a
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  36d37670_e012_f502_4b19_b9823ce99006 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  36d37670_e012_f502_4b19_b9823ce99006 --> 91721f45_4909_e489_8c1f_084f8bd87145
  bd84d84b_5a28_c8ba_98e6_0525a5ba860d["langchain_classic.chains.api.prompt"]
  36d37670_e012_f502_4b19_b9823ce99006 --> bd84d84b_5a28_c8ba_98e6_0525a5ba860d
  01158a5b_b299_f45d_92e9_2a7433a1a91a["langchain_classic.chains.base"]
  36d37670_e012_f502_4b19_b9823ce99006 --> 01158a5b_b299_f45d_92e9_2a7433a1a91a
  31974615_0d58_bd26_13f1_776e0a9d1413["langchain_classic.chains.llm"]
  36d37670_e012_f502_4b19_b9823ce99006 --> 31974615_0d58_bd26_13f1_776e0a9d1413
  8d455231_a1b2_0d85_21aa_32322ecec980["langchain_community.utilities.requests"]
  36d37670_e012_f502_4b19_b9823ce99006 --> 8d455231_a1b2_0d85_21aa_32322ecec980
  style 36d37670_e012_f502_4b19_b9823ce99006 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Chain that makes API calls and summarizes the responses to answer a question."""

from __future__ import annotations

from collections.abc import Sequence
from typing import Any
from urllib.parse import urlparse

from langchain_core._api import deprecated
from langchain_core.callbacks import (
    AsyncCallbackManagerForChainRun,
    CallbackManagerForChainRun,
)
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts import BasePromptTemplate
from pydantic import Field, model_validator
from typing_extensions import Self

from langchain_classic.chains.api.prompt import API_RESPONSE_PROMPT, API_URL_PROMPT
from langchain_classic.chains.base import Chain
from langchain_classic.chains.llm import LLMChain


def _extract_scheme_and_domain(url: str) -> tuple[str, str]:
    """Extract the scheme + domain from a given URL.

    Args:
        url: The input URL.

    Returns:
        A 2-tuple of scheme and domain
    """
    parsed_uri = urlparse(url)
    return parsed_uri.scheme, parsed_uri.netloc


def _check_in_allowed_domain(url: str, limit_to_domains: Sequence[str]) -> bool:
    """Check if a URL is in the allowed domains.

    Args:
        url: The input URL.
        limit_to_domains: The allowed domains.

    Returns:
        `True` if the URL is in the allowed domains, `False` otherwise.
    """
    scheme, domain = _extract_scheme_and_domain(url)

    for allowed_domain in limit_to_domains:
        allowed_scheme, allowed_domain_ = _extract_scheme_and_domain(allowed_domain)
        if scheme == allowed_scheme and domain == allowed_domain_:
            return True
    return False


try:
    from langchain_community.utilities.requests import TextRequestsWrapper

    @deprecated(
        since="0.2.13",
// ... (340 more lines)

Subdomains

Classes

Dependencies

  • collections.abc
  • langchain_classic.chains.api.prompt
  • langchain_classic.chains.base
  • langchain_classic.chains.llm
  • langchain_community.utilities.requests
  • langchain_core._api
  • langchain_core.callbacks
  • langchain_core.language_models
  • langchain_core.prompts
  • pydantic
  • typing
  • typing_extensions
  • urllib.parse

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, RunnableInterface subdomain.
What functions are defined in base.py?
base.py defines 4 function(s): APIChain, _check_in_allowed_domain, _extract_scheme_and_domain, langchain_community.
What does base.py depend on?
base.py imports 13 module(s): collections.abc, langchain_classic.chains.api.prompt, langchain_classic.chains.base, langchain_classic.chains.llm, langchain_community.utilities.requests, langchain_core._api, langchain_core.callbacks, langchain_core.language_models, and 5 more.
Where is base.py in the architecture?
base.py is located at libs/langchain/langchain_classic/chains/api/base.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/langchain_classic/chains/api).

Analyze Your Own Codebase

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

Try Supermodel Free