Home / File/ __init__.py — langchain Source File

__init__.py — langchain Source File

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

File python PromptManagement ExampleSelection 10 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  33324901_b8f2_4f93_9580_5f5cecfd15b5["__init__.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  33324901_b8f2_4f93_9580_5f5cecfd15b5 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  923d222e_e249_1c30_4cfe_3c907f050b78["langchain_core._import_utils"]
  33324901_b8f2_4f93_9580_5f5cecfd15b5 --> 923d222e_e249_1c30_4cfe_3c907f050b78
  8c01ac33_5694_26d8_6f82_8267af524e4e["langchain_core.prompts.base"]
  33324901_b8f2_4f93_9580_5f5cecfd15b5 --> 8c01ac33_5694_26d8_6f82_8267af524e4e
  e45722a2_0136_a972_1f58_7b5987500404["langchain_core.prompts.chat"]
  33324901_b8f2_4f93_9580_5f5cecfd15b5 --> e45722a2_0136_a972_1f58_7b5987500404
  de8c88fa_966e_67e6_53fe_64406853c45a["langchain_core.prompts.dict"]
  33324901_b8f2_4f93_9580_5f5cecfd15b5 --> de8c88fa_966e_67e6_53fe_64406853c45a
  4fa023ed_e78b_1291_b37f_a81c605fc08d["langchain_core.prompts.few_shot"]
  33324901_b8f2_4f93_9580_5f5cecfd15b5 --> 4fa023ed_e78b_1291_b37f_a81c605fc08d
  c97a0dce_925d_55ec_7e9c_82a22379554a["langchain_core.prompts.few_shot_with_templates"]
  33324901_b8f2_4f93_9580_5f5cecfd15b5 --> c97a0dce_925d_55ec_7e9c_82a22379554a
  2a05822d_373f_590f_ce0e_57ccb68dc8b0["langchain_core.prompts.loading"]
  33324901_b8f2_4f93_9580_5f5cecfd15b5 --> 2a05822d_373f_590f_ce0e_57ccb68dc8b0
  c17bcf07_a2ef_b992_448f_5088d46a1e79["langchain_core.prompts.prompt"]
  33324901_b8f2_4f93_9580_5f5cecfd15b5 --> c17bcf07_a2ef_b992_448f_5088d46a1e79
  e10bb307_3784_1031_cf6b_680e7c362c93["langchain_core.prompts.string"]
  33324901_b8f2_4f93_9580_5f5cecfd15b5 --> e10bb307_3784_1031_cf6b_680e7c362c93
  style 33324901_b8f2_4f93_9580_5f5cecfd15b5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""A prompt is the input to the model.

Prompt is often constructed from multiple components and prompt values. Prompt classes
and functions make constructing and working with prompts easy.
"""

from typing import TYPE_CHECKING

from langchain_core._import_utils import import_attr

if TYPE_CHECKING:
    from langchain_core.prompts.base import (
        BasePromptTemplate,
        aformat_document,
        format_document,
    )
    from langchain_core.prompts.chat import (
        AIMessagePromptTemplate,
        BaseChatPromptTemplate,
        ChatMessagePromptTemplate,
        ChatPromptTemplate,
        HumanMessagePromptTemplate,
        MessagesPlaceholder,
        SystemMessagePromptTemplate,
    )
    from langchain_core.prompts.dict import DictPromptTemplate
    from langchain_core.prompts.few_shot import (
        FewShotChatMessagePromptTemplate,
        FewShotPromptTemplate,
    )
    from langchain_core.prompts.few_shot_with_templates import (
        FewShotPromptWithTemplates,
    )
    from langchain_core.prompts.loading import load_prompt
    from langchain_core.prompts.prompt import PromptTemplate
    from langchain_core.prompts.string import (
        StringPromptTemplate,
        check_valid_template,
        get_template_variables,
        jinja2_formatter,
        validate_jinja2,
    )

__all__ = (
    "AIMessagePromptTemplate",
    "BaseChatPromptTemplate",
    "BasePromptTemplate",
    "ChatMessagePromptTemplate",
    "ChatPromptTemplate",
    "DictPromptTemplate",
    "FewShotChatMessagePromptTemplate",
    "FewShotPromptTemplate",
    "FewShotPromptWithTemplates",
    "HumanMessagePromptTemplate",
    "MessagesPlaceholder",
    "PromptTemplate",
    "StringPromptTemplate",
    "SystemMessagePromptTemplate",
    "aformat_document",
    "check_valid_template",
    "format_document",
    "get_template_variables",
    "jinja2_formatter",
    "load_prompt",
    "validate_jinja2",
)

_dynamic_imports = {
    "BasePromptTemplate": "base",
    "format_document": "base",
    "aformat_document": "base",
    "AIMessagePromptTemplate": "chat",
    "BaseChatPromptTemplate": "chat",
    "ChatMessagePromptTemplate": "chat",
    "ChatPromptTemplate": "chat",
    "DictPromptTemplate": "dict",
    "HumanMessagePromptTemplate": "chat",
    "MessagesPlaceholder": "chat",
    "SystemMessagePromptTemplate": "chat",
    "FewShotChatMessagePromptTemplate": "few_shot",
    "FewShotPromptTemplate": "few_shot",
    "FewShotPromptWithTemplates": "few_shot_with_templates",
    "load_prompt": "loading",
    "PromptTemplate": "prompt",
    "StringPromptTemplate": "string",
    "check_valid_template": "string",
    "get_template_variables": "string",
    "jinja2_formatter": "string",
    "validate_jinja2": "string",
}


def __getattr__(attr_name: str) -> object:
    module_name = _dynamic_imports.get(attr_name)
    result = import_attr(attr_name, module_name, __spec__.parent)
    globals()[attr_name] = result
    return result


def __dir__() -> list[str]:
    return list(__all__)

Subdomains

Dependencies

  • langchain_core._import_utils
  • langchain_core.prompts.base
  • langchain_core.prompts.chat
  • langchain_core.prompts.dict
  • langchain_core.prompts.few_shot
  • langchain_core.prompts.few_shot_with_templates
  • langchain_core.prompts.loading
  • langchain_core.prompts.prompt
  • langchain_core.prompts.string
  • typing

Frequently Asked Questions

What does __init__.py do?
__init__.py is a source file in the langchain codebase, written in python. It belongs to the PromptManagement domain, ExampleSelection subdomain.
What functions are defined in __init__.py?
__init__.py defines 3 function(s): __dir__, __getattr__, langchain_core.
What does __init__.py depend on?
__init__.py imports 10 module(s): langchain_core._import_utils, langchain_core.prompts.base, langchain_core.prompts.chat, langchain_core.prompts.dict, langchain_core.prompts.few_shot, langchain_core.prompts.few_shot_with_templates, langchain_core.prompts.loading, langchain_core.prompts.prompt, and 2 more.
Where is __init__.py in the architecture?
__init__.py is located at libs/core/langchain_core/prompts/__init__.py (domain: PromptManagement, subdomain: ExampleSelection, directory: libs/core/langchain_core/prompts).

Analyze Your Own Codebase

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

Try Supermodel Free