This commit is contained in:
Erick Friis 2025-01-06 12:29:37 -08:00
parent acddfc772e
commit 1a14c394c1
6 changed files with 686 additions and 79 deletions

View File

@ -73,3 +73,29 @@ help:
@echo 'tests - run unit tests' @echo 'tests - run unit tests'
@echo 'test TEST_FILE=<test_file> - run all tests in file' @echo 'test TEST_FILE=<test_file> - run all tests in file'
@echo 'test_watch - run unit tests in watch mode' @echo 'test_watch - run unit tests in watch mode'
##########
# CUSTOM #
##########
bench-imports:
time poetry run python -c "from typing import Any"
time poetry run python -c "from typing import Any"
time poetry run python -c "from langchain_core import __version__"
time poetry run python -c "from langchain_core.tools import tool"
time poetry run python -c "from langchain_core.messages import AIMessage"
time poetry run python -c "from langchain_core.documents import Document"
time poetry run python -c "from langchain_core._api import deprecated"
time poetry run python -c "from langchain_core._api import beta"
time poetry run python -c "from langchain_core.callbacks import BaseCallbackHandler"
time poetry run python -c "from langchain_core.document_loaders import BaseLoader"
time poetry run python -c "from langchain_core.embeddings import Embeddings"
time poetry run python -c "from langchain_core.language_models import BaseChatModel"
time poetry run python -c "from langchain_core.language_models import BaseLLM"
time poetry run python -c "from langchain_core.load import loads"
time poetry run python -c "from langchain_core.output_parsers import BaseOutputParser"
time poetry run python -c "from langchain_core.prompts import ChatPromptTemplate"
time poetry run python -c "from langchain_core.runnables import RunnableSerializable"
time poetry run python -c "from langchain_core.tools import BaseTool"
time poetry run python -c "from langchain_core.tracers import BaseTracer"
time poetry run python -c "from langchain_core.vectorstores import VectorStore"

1
libs/core/it.py Normal file
View File

@ -0,0 +1 @@
from langchain_core.tools import tool

View File

@ -6,6 +6,9 @@
BaseCallbackHandler --> <name>CallbackHandler # Example: AimCallbackHandler BaseCallbackHandler --> <name>CallbackHandler # Example: AimCallbackHandler
""" """
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from langchain_core.callbacks.base import ( from langchain_core.callbacks.base import (
AsyncCallbackHandler, AsyncCallbackHandler,
@ -44,6 +47,140 @@ from langchain_core.callbacks.manager import (
from langchain_core.callbacks.stdout import StdOutCallbackHandler from langchain_core.callbacks.stdout import StdOutCallbackHandler
from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
def __getattr__(name: str) -> Any:
if name == "dispatch_custom_event":
from langchain_core.callbacks.manager import dispatch_custom_event
return dispatch_custom_event
if name == "adispatch_custom_event":
from langchain_core.callbacks.manager import adispatch_custom_event
return adispatch_custom_event
if name == "RetrieverManagerMixin":
from langchain_core.callbacks.base import RetrieverManagerMixin
return RetrieverManagerMixin
if name == "LLMManagerMixin":
from langchain_core.callbacks.base import LLMManagerMixin
return LLMManagerMixin
if name == "ChainManagerMixin":
from langchain_core.callbacks.base import ChainManagerMixin
return ChainManagerMixin
if name == "ToolManagerMixin":
from langchain_core.callbacks.base import ToolManagerMixin
return ToolManagerMixin
if name == "Callbacks":
from langchain_core.callbacks.base import Callbacks
return Callbacks
if name == "CallbackManagerMixin":
from langchain_core.callbacks.base import CallbackManagerMixin
return CallbackManagerMixin
if name == "RunManagerMixin":
from langchain_core.callbacks.base import RunManagerMixin
return RunManagerMixin
if name == "BaseCallbackHandler":
from langchain_core.callbacks.base import BaseCallbackHandler
return BaseCallbackHandler
if name == "AsyncCallbackHandler":
from langchain_core.callbacks.base import AsyncCallbackHandler
return AsyncCallbackHandler
if name == "BaseCallbackManager":
from langchain_core.callbacks.manager import BaseCallbackManager
return BaseCallbackManager
if name == "BaseRunManager":
from langchain_core.callbacks.manager import BaseRunManager
return BaseRunManager
if name == "RunManager":
from langchain_core.callbacks.manager import RunManager
return RunManager
if name == "ParentRunManager":
from langchain_core.callbacks.manager import ParentRunManager
return ParentRunManager
if name == "AsyncRunManager":
from langchain_core.callbacks.manager import AsyncRunManager
return AsyncRunManager
if name == "AsyncParentRunManager":
from langchain_core.callbacks.manager import AsyncParentRunManager
return AsyncParentRunManager
if name == "CallbackManagerForLLMRun":
from langchain_core.callbacks.manager import CallbackManagerForLLMRun
return CallbackManagerForLLMRun
if name == "AsyncCallbackManagerForLLMRun":
from langchain_core.callbacks.manager import AsyncCallbackManagerForLLMRun
return AsyncCallbackManagerForLLMRun
if name == "CallbackManagerForChainRun":
from langchain_core.callbacks.manager import CallbackManagerForChainRun
return CallbackManagerForChainRun
if name == "AsyncCallbackManagerForChainRun":
from langchain_core.callbacks.manager import AsyncCallbackManagerForChainRun
return AsyncCallbackManagerForChainRun
if name == "CallbackManagerForToolRun":
from langchain_core.callbacks.manager import CallbackManagerForToolRun
return CallbackManagerForToolRun
if name == "AsyncCallbackManagerForToolRun":
from langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun
return AsyncCallbackManagerForToolRun
if name == "CallbackManagerForRetrieverRun":
from langchain_core.callbacks.manager import CallbackManagerForRetrieverRun
return CallbackManagerForRetrieverRun
if name == "AsyncCallbackManagerForRetrieverRun":
from langchain_core.callbacks.manager import AsyncCallbackManagerForRetrieverRun
return AsyncCallbackManagerForRetrieverRun
if name == "CallbackManager":
from langchain_core.callbacks.manager import CallbackManager
return CallbackManager
if name == "CallbackManagerForChainGroup":
from langchain_core.callbacks.manager import CallbackManagerForChainGroup
return CallbackManagerForChainGroup
if name == "AsyncCallbackManager":
from langchain_core.callbacks.manager import AsyncCallbackManager
return AsyncCallbackManager
if name == "AsyncCallbackManagerForChainGroup":
from langchain_core.callbacks.manager import AsyncCallbackManagerForChainGroup
return AsyncCallbackManagerForChainGroup
if name == "StdOutCallbackHandler":
from langchain_core.callbacks.stdout import StdOutCallbackHandler
return StdOutCallbackHandler
if name == "StreamingStdOutCallbackHandler":
from langchain_core.callbacks.streaming_stdout import (
StreamingStdOutCallbackHandler,
)
return StreamingStdOutCallbackHandler
if name == "FileCallbackHandler":
from langchain_core.callbacks.file import FileCallbackHandler
return FileCallbackHandler
msg = f"module {__name__} has no attribute {name}"
raise AttributeError(msg)
__all__ = [ __all__ = [
"dispatch_custom_event", "dispatch_custom_event",
"adispatch_custom_event", "adispatch_custom_event",

View File

@ -19,6 +19,11 @@ tool for the job.
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Any
from langchain_core.tools.base import ( from langchain_core.tools.base import (
FILTERED_ARGS as FILTERED_ARGS, FILTERED_ARGS as FILTERED_ARGS,
) )
@ -59,3 +64,99 @@ from langchain_core.tools.retriever import (
) )
from langchain_core.tools.simple import Tool as Tool from langchain_core.tools.simple import Tool as Tool
from langchain_core.tools.structured import StructuredTool as StructuredTool from langchain_core.tools.structured import StructuredTool as StructuredTool
def __getattr__(name: str) -> Any:
if name == "FILTERED_ARGS":
from langchain_core.tools.base import FILTERED_ARGS
return FILTERED_ARGS
if name == "BaseTool":
from langchain_core.tools.base import BaseTool
return BaseTool
if name == "BaseToolkit":
from langchain_core.tools.base import BaseToolkit
return BaseToolkit
if name == "InjectedToolArg":
from langchain_core.tools.base import InjectedToolArg
return InjectedToolArg
if name == "InjectedToolCallId":
from langchain_core.tools.base import InjectedToolCallId
return InjectedToolCallId
if name == "SchemaAnnotationError":
from langchain_core.tools.base import SchemaAnnotationError
return SchemaAnnotationError
if name == "ToolException":
from langchain_core.tools.base import ToolException
return ToolException
if name == "_get_runnable_config_param":
from langchain_core.tools.base import _get_runnable_config_param
return _get_runnable_config_param
if name == "create_schema_from_function":
from langchain_core.tools.base import create_schema_from_function
return create_schema_from_function
if name == "convert_runnable_to_tool":
from langchain_core.tools.convert import convert_runnable_to_tool
return convert_runnable_to_tool
if name == "tool":
from langchain_core.tools.convert import tool
return tool
if name == "ToolsRenderer":
from langchain_core.tools.render import ToolsRenderer
return ToolsRenderer
if name == "render_text_description":
from langchain_core.tools.render import render_text_description
return render_text_description
if name == "render_text_description_and_args":
from langchain_core.tools.render import render_text_description_and_args
return render_text_description_and_args
if name == "RetrieverInput":
from langchain_core.tools.retriever import RetrieverInput
return RetrieverInput
if name == "create_retriever_tool":
from langchain_core.tools.retriever import create_retriever_tool
return create_retriever_tool
if name == "Tool":
from langchain_core.tools.simple import Tool
return Tool
if name == "StructuredTool":
from langchain_core.tools.structured import StructuredTool
return StructuredTool
raise AttributeError(f"module {__name__} has no attribute {name}")
__all__ = [
"FILTERED_ARGS",
"BaseTool",
"BaseToolkit",
"InjectedToolArg",
"InjectedToolCallId",
"SchemaAnnotationError",
"ToolException",
"_get_runnable_config_param",
"create_schema_from_function",
"convert_runnable_to_tool",
"tool",
"ToolsRenderer",
"render_text_description",
"render_text_description_and_args",
"RetrieverInput",
"create_retriever_tool",
"Tool",
"StructuredTool",
]

View File

@ -8,11 +8,13 @@ import os
import warnings import warnings
from collections.abc import Sequence from collections.abc import Sequence
from importlib.metadata import version from importlib.metadata import version
from typing import Any, Callable, Optional, Union, overload from typing import TYPE_CHECKING, Any, Callable, Optional, Union, overload
from packaging.version import parse from packaging.version import parse
from pydantic import SecretStr from pydantic import SecretStr
from requests import HTTPError, Response
if TYPE_CHECKING:
from requests import Response
from langchain_core.utils.pydantic import ( from langchain_core.utils.pydantic import (
is_pydantic_v1_subclass, is_pydantic_v1_subclass,
@ -57,7 +59,7 @@ def xor_args(*arg_groups: tuple[str, ...]) -> Callable:
return decorator return decorator
def raise_for_status_with_text(response: Response) -> None: def raise_for_status_with_text(response: "Response") -> None:
"""Raise an error with the response text. """Raise an error with the response text.
Args: Args:
@ -66,6 +68,7 @@ def raise_for_status_with_text(response: Response) -> None:
Raises: Raises:
ValueError: If the response has an error status code. ValueError: If the response has an error status code.
""" """
from requests import HTTPError
try: try:
response.raise_for_status() response.raise_for_status()
except HTTPError as e: except HTTPError as e:

File diff suppressed because one or more lines are too long