initial commit

This commit is contained in:
2026-05-11 12:36:20 +05:30
commit 384cbe8019
15377 changed files with 2360544 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
"""Utility functions for LangChain.
These functions do not depend on any other LangChain module.
"""
from typing import TYPE_CHECKING, Any
from langchain_core.utils import (
comma_list,
get_from_dict_or_env,
get_from_env,
stringify_dict,
stringify_value,
)
from langchain_core.utils.formatting import StrictFormatter, formatter
from langchain_core.utils.input import (
get_bolded_text,
get_color_mapping,
get_colored_text,
print_text,
)
from langchain_core.utils.utils import (
check_package_version,
convert_to_secret_str,
get_pydantic_field_names,
guard_import,
mock_now,
raise_for_status_with_text,
xor_args,
)
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.utils.math import (
cosine_similarity,
cosine_similarity_top_k,
)
# Not deprecated right now because we will likely need to move these functions
# back into langchain (as long as we're OK with the dependency on numpy).
_MODULE_LOOKUP = {
"cosine_similarity": "langchain_community.utils.math",
"cosine_similarity_top_k": "langchain_community.utils.math",
}
_import_attribute = create_importer(__package__, module_lookup=_MODULE_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"StrictFormatter",
"check_package_version",
"comma_list",
"convert_to_secret_str",
"cosine_similarity",
"cosine_similarity_top_k",
"formatter",
"get_bolded_text",
"get_color_mapping",
"get_colored_text",
"get_from_dict_or_env",
"get_from_env",
"get_pydantic_field_names",
"guard_import",
"mock_now",
"print_text",
"raise_for_status_with_text",
"stringify_dict",
"stringify_value",
"xor_args",
]

View File

@@ -0,0 +1,3 @@
from langchain_core.utils.aiter import NoLock, Tee, py_anext
__all__ = ["NoLock", "Tee", "py_anext"]

View File

@@ -0,0 +1,3 @@
from langchain_core.utils.env import get_from_dict_or_env, get_from_env
__all__ = ["get_from_dict_or_env", "get_from_env"]

View File

@@ -0,0 +1,36 @@
from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.utils.ernie_functions import (
FunctionDescription,
ToolDescription,
convert_pydantic_to_ernie_function,
convert_pydantic_to_ernie_tool,
)
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {
"FunctionDescription": "langchain_community.utils.ernie_functions",
"ToolDescription": "langchain_community.utils.ernie_functions",
"convert_pydantic_to_ernie_function": "langchain_community.utils.ernie_functions",
"convert_pydantic_to_ernie_tool": "langchain_community.utils.ernie_functions",
}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"FunctionDescription",
"ToolDescription",
"convert_pydantic_to_ernie_function",
"convert_pydantic_to_ernie_tool",
]

View File

@@ -0,0 +1,3 @@
from langchain_core.utils.formatting import StrictFormatter
__all__ = ["StrictFormatter"]

View File

@@ -0,0 +1,19 @@
from langchain_core.utils.html import (
DEFAULT_LINK_REGEX,
PREFIXES_TO_IGNORE,
PREFIXES_TO_IGNORE_REGEX,
SUFFIXES_TO_IGNORE,
SUFFIXES_TO_IGNORE_REGEX,
extract_sub_links,
find_all_links,
)
__all__ = [
"DEFAULT_LINK_REGEX",
"PREFIXES_TO_IGNORE",
"PREFIXES_TO_IGNORE_REGEX",
"SUFFIXES_TO_IGNORE",
"SUFFIXES_TO_IGNORE_REGEX",
"extract_sub_links",
"find_all_links",
]

View File

@@ -0,0 +1,8 @@
from langchain_core.utils.input import (
get_bolded_text,
get_color_mapping,
get_colored_text,
print_text,
)
__all__ = ["get_bolded_text", "get_color_mapping", "get_colored_text", "print_text"]

View File

@@ -0,0 +1,3 @@
from langchain_core.utils.iter import NoLock, Tee, batch_iterate, tee_peer
__all__ = ["NoLock", "Tee", "batch_iterate", "tee_peer"]

View File

@@ -0,0 +1,11 @@
from langchain_core.utils.json_schema import (
_dereference_refs_helper,
_retrieve_ref,
dereference_refs,
)
__all__ = [
"_dereference_refs_helper",
"_retrieve_ref",
"dereference_refs",
]

View File

@@ -0,0 +1,32 @@
from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.utils.math import (
cosine_similarity,
cosine_similarity_top_k,
)
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
# Not marked as deprecated since we may want to move the functionality
# into langchain as long as we're OK with numpy as the dependency.
_MODULE_LOOKUP = {
"cosine_similarity": "langchain_community.utils.math",
"cosine_similarity_top_k": "langchain_community.utils.math",
}
_import_attribute = create_importer(__package__, module_lookup=_MODULE_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"cosine_similarity",
"cosine_similarity_top_k",
]

View File

@@ -0,0 +1,23 @@
from typing import TYPE_CHECKING, Any
from langchain_classic._api import create_importer
if TYPE_CHECKING:
from langchain_community.utils.openai import is_openai_v1
# Create a way to dynamically look up deprecated imports.
# Used to consolidate logic for raising deprecation warnings and
# handling optional imports.
DEPRECATED_LOOKUP = {"is_openai_v1": "langchain_community.utils.openai"}
_import_attribute = create_importer(__package__, deprecated_lookups=DEPRECATED_LOOKUP)
def __getattr__(name: str) -> Any:
"""Look up attributes dynamically."""
return _import_attribute(name)
__all__ = [
"is_openai_v1",
]

View File

@@ -0,0 +1,14 @@
from langchain_core.utils.function_calling import FunctionDescription, ToolDescription
from langchain_core.utils.function_calling import (
convert_to_openai_function as convert_pydantic_to_openai_function,
)
from langchain_core.utils.function_calling import (
convert_to_openai_tool as convert_pydantic_to_openai_tool,
)
__all__ = [
"FunctionDescription",
"ToolDescription",
"convert_pydantic_to_openai_function",
"convert_pydantic_to_openai_tool",
]

View File

@@ -0,0 +1,13 @@
from langchain_core.utils.pydantic import PYDANTIC_VERSION
def get_pydantic_major_version() -> int:
"""Get the major version of Pydantic.
Returns:
The major version of Pydantic.
"""
return PYDANTIC_VERSION.major
__all__ = ["get_pydantic_major_version"]

View File

@@ -0,0 +1,3 @@
from langchain_core.utils.strings import comma_list, stringify_dict, stringify_value
__all__ = ["comma_list", "stringify_dict", "stringify_value"]

View File

@@ -0,0 +1,21 @@
from langchain_core.utils.utils import (
build_extra_kwargs,
check_package_version,
convert_to_secret_str,
get_pydantic_field_names,
guard_import,
mock_now,
raise_for_status_with_text,
xor_args,
)
__all__ = [
"build_extra_kwargs",
"check_package_version",
"convert_to_secret_str",
"get_pydantic_field_names",
"guard_import",
"mock_now",
"raise_for_status_with_text",
"xor_args",
]