mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-05 20:58:25 +00:00
core: Add ruff rules TC (#29268)
See https://docs.astral.sh/ruff/rules/#flake8-type-checking-tc Some fixes done for TC001,TC002 and TC003 but these rules are excluded since they don't play well with Pydantic. --------- Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
parent
9cd20080fc
commit
b3885c124f
@ -3,13 +3,14 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from collections.abc import Sequence
|
|
||||||
from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union
|
from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
from tenacity import RetryCallState
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from tenacity import RetryCallState
|
||||||
|
|
||||||
from langchain_core.agents import AgentAction, AgentFinish
|
from langchain_core.agents import AgentAction, AgentFinish
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
from langchain_core.messages import BaseMessage
|
from langchain_core.messages import BaseMessage
|
||||||
|
@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, Optional, TextIO, cast
|
from typing import TYPE_CHECKING, Any, Optional, TextIO, cast
|
||||||
|
|
||||||
from langchain_core.agents import AgentAction, AgentFinish
|
|
||||||
from langchain_core.callbacks import BaseCallbackHandler
|
from langchain_core.callbacks import BaseCallbackHandler
|
||||||
from langchain_core.utils.input import print_text
|
from langchain_core.utils.input import print_text
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langchain_core.agents import AgentAction, AgentFinish
|
||||||
|
|
||||||
|
|
||||||
class FileCallbackHandler(BaseCallbackHandler):
|
class FileCallbackHandler(BaseCallbackHandler):
|
||||||
"""Callback Handler that writes to a file.
|
"""Callback Handler that writes to a file.
|
||||||
|
@ -5,7 +5,6 @@ import functools
|
|||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import AsyncGenerator, Coroutine, Generator, Sequence
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from contextlib import asynccontextmanager, contextmanager
|
from contextlib import asynccontextmanager, contextmanager
|
||||||
from contextvars import copy_context
|
from contextvars import copy_context
|
||||||
@ -21,7 +20,6 @@ from typing import (
|
|||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from langsmith.run_helpers import get_tracing_context
|
from langsmith.run_helpers import get_tracing_context
|
||||||
from tenacity import RetryCallState
|
|
||||||
|
|
||||||
from langchain_core.callbacks.base import (
|
from langchain_core.callbacks.base import (
|
||||||
BaseCallbackHandler,
|
BaseCallbackHandler,
|
||||||
@ -39,6 +37,10 @@ from langchain_core.tracers.schemas import Run
|
|||||||
from langchain_core.utils.env import env_var_is_set
|
from langchain_core.utils.env import env_var_is_set
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import AsyncGenerator, Coroutine, Generator, Sequence
|
||||||
|
|
||||||
|
from tenacity import RetryCallState
|
||||||
|
|
||||||
from langchain_core.agents import AgentAction, AgentFinish
|
from langchain_core.agents import AgentAction, AgentFinish
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk, LLMResult
|
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk, LLMResult
|
||||||
|
@ -17,8 +17,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Sequence
|
from typing import TYPE_CHECKING, Union
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
@ -29,6 +28,9 @@ from langchain_core.messages import (
|
|||||||
get_buffer_string,
|
get_buffer_string,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
|
||||||
class BaseChatMessageHistory(ABC):
|
class BaseChatMessageHistory(ABC):
|
||||||
"""Abstract base class for storing chat message history.
|
"""Abstract base class for storing chat message history.
|
||||||
|
@ -3,16 +3,17 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import AsyncIterator, Iterator
|
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from langchain_core.documents import Document
|
|
||||||
from langchain_core.runnables import run_in_executor
|
from langchain_core.runnables import run_in_executor
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import AsyncIterator, Iterator
|
||||||
|
|
||||||
from langchain_text_splitters import TextSplitter
|
from langchain_text_splitters import TextSplitter
|
||||||
|
|
||||||
from langchain_core.documents.base import Blob
|
from langchain_core.documents import Document
|
||||||
|
from langchain_core.documents.base import Blob
|
||||||
|
|
||||||
|
|
||||||
class BaseLoader(ABC): # noqa: B024
|
class BaseLoader(ABC): # noqa: B024
|
||||||
|
@ -8,12 +8,15 @@ In addition, content loading code should provide a lazy loading interface by def
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Iterable
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
# Re-export Blob and PathLike for backwards compatibility
|
# Re-export Blob and PathLike for backwards compatibility
|
||||||
from langchain_core.documents.base import Blob as Blob
|
from langchain_core.documents.base import Blob as Blob
|
||||||
from langchain_core.documents.base import PathLike as PathLike
|
from langchain_core.documents.base import PathLike as PathLike
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Iterable
|
||||||
|
|
||||||
|
|
||||||
class BlobLoader(ABC):
|
class BlobLoader(ABC):
|
||||||
"""Abstract interface for blob loaders implementation.
|
"""Abstract interface for blob loaders implementation.
|
||||||
|
@ -2,15 +2,17 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import mimetypes
|
import mimetypes
|
||||||
from collections.abc import Generator
|
|
||||||
from io import BufferedReader, BytesIO
|
from io import BufferedReader, BytesIO
|
||||||
from pathlib import PurePath
|
from pathlib import PurePath
|
||||||
from typing import Any, Literal, Optional, Union, cast
|
from typing import TYPE_CHECKING, Any, Literal, Optional, Union, cast
|
||||||
|
|
||||||
from pydantic import ConfigDict, Field, field_validator, model_validator
|
from pydantic import ConfigDict, Field, field_validator, model_validator
|
||||||
|
|
||||||
from langchain_core.load.serializable import Serializable
|
from langchain_core.load.serializable import Serializable
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Generator
|
||||||
|
|
||||||
PathLike = Union[str, PurePath]
|
PathLike = Union[str, PurePath]
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Sequence
|
from typing import TYPE_CHECKING, Optional
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from langchain_core.callbacks import Callbacks
|
|
||||||
from langchain_core.documents import Document
|
|
||||||
from langchain_core.runnables import run_in_executor
|
from langchain_core.runnables import run_in_executor
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
from langchain_core.callbacks import Callbacks
|
||||||
|
from langchain_core.documents import Document
|
||||||
|
|
||||||
|
|
||||||
class BaseDocumentCompressor(BaseModel, ABC):
|
class BaseDocumentCompressor(BaseModel, ABC):
|
||||||
"""Base class for document compressors.
|
"""Base class for document compressors.
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Sequence
|
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from langchain_core.runnables.config import run_in_executor
|
from langchain_core.runnables.config import run_in_executor
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,11 +7,11 @@ from typing import TYPE_CHECKING, Any, Optional
|
|||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
from langchain_core.documents import Document
|
|
||||||
from langchain_core.example_selectors.base import BaseExampleSelector
|
from langchain_core.example_selectors.base import BaseExampleSelector
|
||||||
from langchain_core.vectorstores import VectorStore
|
from langchain_core.vectorstores import VectorStore
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from langchain_core.documents import Document
|
||||||
from langchain_core.embeddings import Embeddings
|
from langchain_core.embeddings import Embeddings
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,14 +3,17 @@ from __future__ import annotations
|
|||||||
import abc
|
import abc
|
||||||
import time
|
import time
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Sequence
|
from typing import TYPE_CHECKING, Any, Optional, TypedDict
|
||||||
from typing import Any, Optional, TypedDict
|
|
||||||
|
|
||||||
from langchain_core._api import beta
|
from langchain_core._api import beta
|
||||||
from langchain_core.documents import Document
|
|
||||||
from langchain_core.retrievers import BaseRetriever
|
from langchain_core.retrievers import BaseRetriever
|
||||||
from langchain_core.runnables import run_in_executor
|
from langchain_core.runnables import run_in_executor
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
from langchain_core.documents import Document
|
||||||
|
|
||||||
|
|
||||||
class RecordManager(ABC):
|
class RecordManager(ABC):
|
||||||
"""Abstract base class representing the interface for a record manager.
|
"""Abstract base class representing the interface for a record manager.
|
||||||
|
@ -4,7 +4,6 @@ import asyncio
|
|||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import typing
|
import typing
|
||||||
import uuid
|
|
||||||
import warnings
|
import warnings
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import AsyncIterator, Iterator, Sequence
|
from collections.abc import AsyncIterator, Iterator, Sequence
|
||||||
@ -70,6 +69,8 @@ from langchain_core.utils.function_calling import convert_to_openai_tool
|
|||||||
from langchain_core.utils.pydantic import TypeBaseModel, is_basemodel_subclass
|
from langchain_core.utils.pydantic import TypeBaseModel, is_basemodel_subclass
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
import uuid
|
||||||
|
|
||||||
from langchain_core.output_parsers.base import OutputParserLike
|
from langchain_core.output_parsers.base import OutputParserLike
|
||||||
from langchain_core.runnables import Runnable, RunnableConfig
|
from langchain_core.runnables import Runnable, RunnableConfig
|
||||||
from langchain_core.tools import BaseTool
|
from langchain_core.tools import BaseTool
|
||||||
|
@ -7,12 +7,12 @@ import functools
|
|||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
|
||||||
import warnings
|
import warnings
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import AsyncIterator, Iterator, Sequence
|
from collections.abc import AsyncIterator, Iterator, Sequence
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
Optional,
|
Optional,
|
||||||
@ -61,6 +61,9 @@ from langchain_core.prompt_values import ChatPromptValue, PromptValue, StringPro
|
|||||||
from langchain_core.runnables import RunnableConfig, ensure_config, get_config_list
|
from langchain_core.runnables import RunnableConfig, ensure_config, get_config_list
|
||||||
from langchain_core.runnables.config import run_in_executor
|
from langchain_core.runnables.config import run_in_executor
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
import uuid
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Sequence
|
|
||||||
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
||||||
|
|
||||||
from pydantic import ConfigDict, Field, field_validator
|
from pydantic import ConfigDict, Field, field_validator
|
||||||
@ -11,6 +10,8 @@ from langchain_core.utils._merge import merge_dicts, merge_lists
|
|||||||
from langchain_core.utils.interactive_env import is_interactive_env
|
from langchain_core.utils.interactive_env import is_interactive_env
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
from langchain_core.prompts.chat import ChatPromptTemplate
|
from langchain_core.prompts.chat import ChatPromptTemplate
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,14 +4,16 @@ import csv
|
|||||||
import re
|
import re
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from collections.abc import AsyncIterator, Iterator
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
from typing import TYPE_CHECKING, TypeVar, Union
|
||||||
from typing import Optional as Optional
|
from typing import Optional as Optional
|
||||||
from typing import TypeVar, Union
|
|
||||||
|
|
||||||
from langchain_core.messages import BaseMessage
|
from langchain_core.messages import BaseMessage
|
||||||
from langchain_core.output_parsers.transform import BaseTransformOutputParser
|
from langchain_core.output_parsers.transform import BaseTransformOutputParser
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import AsyncIterator, Iterator
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import AsyncIterator, Iterator
|
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
@ -19,6 +18,8 @@ from langchain_core.outputs import (
|
|||||||
from langchain_core.runnables.config import run_in_executor
|
from langchain_core.runnables.config import run_in_executor
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import AsyncIterator, Iterator
|
||||||
|
|
||||||
from langchain_core.runnables import RunnableConfig
|
from langchain_core.runnables import RunnableConfig
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Literal, Union
|
from typing import TYPE_CHECKING, Literal, Union
|
||||||
|
|
||||||
from pydantic import model_validator
|
from pydantic import model_validator
|
||||||
from typing_extensions import Self
|
|
||||||
|
|
||||||
from langchain_core.messages import BaseMessage, BaseMessageChunk
|
from langchain_core.messages import BaseMessage, BaseMessageChunk
|
||||||
from langchain_core.outputs.generation import Generation
|
from langchain_core.outputs.generation import Generation
|
||||||
from langchain_core.utils._merge import merge_dicts
|
from langchain_core.utils._merge import merge_dicts
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing_extensions import Self
|
||||||
|
|
||||||
|
|
||||||
class ChatGeneration(Generation):
|
class ChatGeneration(Generation):
|
||||||
"""A single chat generation output.
|
"""A single chat generation output.
|
||||||
|
@ -3,9 +3,8 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Sequence
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Annotated,
|
Annotated,
|
||||||
Any,
|
Any,
|
||||||
Optional,
|
Optional,
|
||||||
@ -47,6 +46,10 @@ from langchain_core.prompts.string import (
|
|||||||
from langchain_core.utils import get_colored_text
|
from langchain_core.utils import get_colored_text
|
||||||
from langchain_core.utils.interactive_env import is_interactive_env
|
from langchain_core.utils.interactive_env import is_interactive_env
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class BaseMessagePromptTemplate(Serializable, ABC):
|
class BaseMessagePromptTemplate(Serializable, ABC):
|
||||||
"""Base class for message prompt templates."""
|
"""Base class for message prompt templates."""
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
from typing import TYPE_CHECKING, Any, Literal, Optional, Union
|
||||||
from typing import Any, Literal, Optional, Union
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@ -11,7 +10,6 @@ from pydantic import (
|
|||||||
Field,
|
Field,
|
||||||
model_validator,
|
model_validator,
|
||||||
)
|
)
|
||||||
from typing_extensions import Self
|
|
||||||
|
|
||||||
from langchain_core.example_selectors import BaseExampleSelector
|
from langchain_core.example_selectors import BaseExampleSelector
|
||||||
from langchain_core.messages import BaseMessage, get_buffer_string
|
from langchain_core.messages import BaseMessage, get_buffer_string
|
||||||
@ -27,6 +25,11 @@ from langchain_core.prompts.string import (
|
|||||||
get_template_variables,
|
get_template_variables,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
|
|
||||||
|
|
||||||
class _FewShotPromptTemplateMixin(BaseModel):
|
class _FewShotPromptTemplateMixin(BaseModel):
|
||||||
"""Prompt template that contains few shot examples."""
|
"""Prompt template that contains few shot examples."""
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
from pathlib import Path
|
from typing import TYPE_CHECKING, Any, Optional, Union
|
||||||
from typing import Any, Optional, Union
|
|
||||||
|
|
||||||
from pydantic import BaseModel, model_validator
|
from pydantic import BaseModel, model_validator
|
||||||
|
|
||||||
@ -16,7 +15,11 @@ from langchain_core.prompts.string import (
|
|||||||
get_template_variables,
|
get_template_variables,
|
||||||
mustache_schema,
|
mustache_schema,
|
||||||
)
|
)
|
||||||
from langchain_core.runnables.config import RunnableConfig
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from langchain_core.runnables.config import RunnableConfig
|
||||||
|
|
||||||
|
|
||||||
class PromptTemplate(StringPromptTemplate):
|
class PromptTemplate(StringPromptTemplate):
|
||||||
|
@ -60,7 +60,6 @@ from langchain_core.runnables.config import (
|
|||||||
run_in_executor,
|
run_in_executor,
|
||||||
)
|
)
|
||||||
from langchain_core.runnables.graph import Graph
|
from langchain_core.runnables.graph import Graph
|
||||||
from langchain_core.runnables.schema import StreamEvent
|
|
||||||
from langchain_core.runnables.utils import (
|
from langchain_core.runnables.utils import (
|
||||||
AddableDict,
|
AddableDict,
|
||||||
AnyConfigurableField,
|
AnyConfigurableField,
|
||||||
@ -94,6 +93,7 @@ if TYPE_CHECKING:
|
|||||||
from langchain_core.runnables.fallbacks import (
|
from langchain_core.runnables.fallbacks import (
|
||||||
RunnableWithFallbacks as RunnableWithFallbacksT,
|
RunnableWithFallbacks as RunnableWithFallbacksT,
|
||||||
)
|
)
|
||||||
|
from langchain_core.runnables.schema import StreamEvent
|
||||||
from langchain_core.tools import BaseTool
|
from langchain_core.tools import BaseTool
|
||||||
from langchain_core.tracers.log_stream import (
|
from langchain_core.tracers.log_stream import (
|
||||||
RunLog,
|
RunLog,
|
||||||
|
@ -7,6 +7,7 @@ from collections.abc import AsyncIterator, Iterator, Sequence
|
|||||||
from collections.abc import Mapping as Mapping
|
from collections.abc import Mapping as Mapping
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
Optional,
|
Optional,
|
||||||
@ -26,7 +27,6 @@ from langchain_core.runnables.config import (
|
|||||||
get_executor_for_config,
|
get_executor_for_config,
|
||||||
merge_configs,
|
merge_configs,
|
||||||
)
|
)
|
||||||
from langchain_core.runnables.graph import Graph
|
|
||||||
from langchain_core.runnables.utils import (
|
from langchain_core.runnables.utils import (
|
||||||
AnyConfigurableField,
|
AnyConfigurableField,
|
||||||
ConfigurableField,
|
ConfigurableField,
|
||||||
@ -39,6 +39,9 @@ from langchain_core.runnables.utils import (
|
|||||||
get_unique_config_specs,
|
get_unique_config_specs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langchain_core.runnables.graph import Graph
|
||||||
|
|
||||||
|
|
||||||
class DynamicRunnable(RunnableSerializable[Input, Output]):
|
class DynamicRunnable(RunnableSerializable[Input, Output]):
|
||||||
"""Serializable Runnable that can be dynamically configured.
|
"""Serializable Runnable that can be dynamically configured.
|
||||||
|
@ -2,7 +2,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from collections.abc import Sequence
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import (
|
from typing import (
|
||||||
@ -18,11 +17,13 @@ from typing import (
|
|||||||
)
|
)
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
from langchain_core.utils.pydantic import _IgnoreUnserializable, is_basemodel_subclass
|
from langchain_core.utils.pydantic import _IgnoreUnserializable, is_basemodel_subclass
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from langchain_core.runnables.base import Runnable as RunnableType
|
from langchain_core.runnables.base import Runnable as RunnableType
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
import asyncio
|
import asyncio
|
||||||
import inspect
|
import inspect
|
||||||
import threading
|
import threading
|
||||||
from collections.abc import AsyncIterator, Awaitable, Iterator, Mapping
|
from collections.abc import Awaitable
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
@ -32,7 +32,6 @@ from langchain_core.runnables.config import (
|
|||||||
get_executor_for_config,
|
get_executor_for_config,
|
||||||
patch_config,
|
patch_config,
|
||||||
)
|
)
|
||||||
from langchain_core.runnables.graph import Graph
|
|
||||||
from langchain_core.runnables.utils import (
|
from langchain_core.runnables.utils import (
|
||||||
AddableDict,
|
AddableDict,
|
||||||
ConfigurableFieldSpec,
|
ConfigurableFieldSpec,
|
||||||
@ -42,10 +41,13 @@ from langchain_core.utils.iter import safetee
|
|||||||
from langchain_core.utils.pydantic import create_model_v2
|
from langchain_core.utils.pydantic import create_model_v2
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import AsyncIterator, Iterator, Mapping
|
||||||
|
|
||||||
from langchain_core.callbacks.manager import (
|
from langchain_core.callbacks.manager import (
|
||||||
AsyncCallbackManagerForChainRun,
|
AsyncCallbackManagerForChainRun,
|
||||||
CallbackManagerForChainRun,
|
CallbackManagerForChainRun,
|
||||||
)
|
)
|
||||||
|
from langchain_core.runnables.graph import Graph
|
||||||
|
|
||||||
|
|
||||||
def identity(x: Other) -> Other:
|
def identity(x: Other) -> Other:
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import AsyncIterator, Iterator, Mapping
|
from collections.abc import Mapping
|
||||||
from itertools import starmap
|
from itertools import starmap
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
Optional,
|
Optional,
|
||||||
@ -31,6 +32,9 @@ from langchain_core.runnables.utils import (
|
|||||||
get_unique_config_specs,
|
get_unique_config_specs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import AsyncIterator, Iterator
|
||||||
|
|
||||||
|
|
||||||
class RouterInput(TypedDict):
|
class RouterInput(TypedDict):
|
||||||
"""Router input.
|
"""Router input.
|
||||||
|
@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Sequence
|
from typing import TYPE_CHECKING, Any, Literal, Union
|
||||||
from typing import Any, Literal, Union
|
|
||||||
|
|
||||||
from typing_extensions import NotRequired, TypedDict
|
from typing_extensions import NotRequired, TypedDict
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
|
||||||
class EventData(TypedDict, total=False):
|
class EventData(TypedDict, total=False):
|
||||||
"""Data associated with a streaming event."""
|
"""Data associated with a streaming event."""
|
||||||
|
@ -6,19 +6,11 @@ import ast
|
|||||||
import asyncio
|
import asyncio
|
||||||
import inspect
|
import inspect
|
||||||
import textwrap
|
import textwrap
|
||||||
from collections.abc import (
|
|
||||||
AsyncIterable,
|
|
||||||
AsyncIterator,
|
|
||||||
Awaitable,
|
|
||||||
Coroutine,
|
|
||||||
Iterable,
|
|
||||||
Mapping,
|
|
||||||
Sequence,
|
|
||||||
)
|
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from inspect import signature
|
from inspect import signature
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
NamedTuple,
|
NamedTuple,
|
||||||
@ -30,11 +22,22 @@ from typing import (
|
|||||||
|
|
||||||
from typing_extensions import TypeGuard, override
|
from typing_extensions import TypeGuard, override
|
||||||
|
|
||||||
from langchain_core.runnables.schema import StreamEvent
|
|
||||||
|
|
||||||
# Re-export create-model for backwards compatibility
|
# Re-export create-model for backwards compatibility
|
||||||
from langchain_core.utils.pydantic import create_model as create_model
|
from langchain_core.utils.pydantic import create_model as create_model
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import (
|
||||||
|
AsyncIterable,
|
||||||
|
AsyncIterator,
|
||||||
|
Awaitable,
|
||||||
|
Coroutine,
|
||||||
|
Iterable,
|
||||||
|
Mapping,
|
||||||
|
Sequence,
|
||||||
|
)
|
||||||
|
|
||||||
|
from langchain_core.runnables.schema import StreamEvent
|
||||||
|
|
||||||
Input = TypeVar("Input", contravariant=True)
|
Input = TypeVar("Input", contravariant=True)
|
||||||
# Output type should implement __concat__, as eg str, list, dict do
|
# Output type should implement __concat__, as eg str, list, dict do
|
||||||
Output = TypeVar("Output", covariant=True)
|
Output = TypeVar("Output", covariant=True)
|
||||||
|
@ -3,12 +3,14 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Sequence
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Optional, Union
|
from typing import TYPE_CHECKING, Any, Optional, Union
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
|
||||||
class Visitor(ABC):
|
class Visitor(ABC):
|
||||||
"""Defines interface for IR translation using a visitor pattern."""
|
"""Defines interface for IR translation using a visitor pattern."""
|
||||||
|
@ -4,13 +4,12 @@ import asyncio
|
|||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import uuid
|
|
||||||
import warnings
|
import warnings
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Sequence
|
|
||||||
from contextvars import copy_context
|
from contextvars import copy_context
|
||||||
from inspect import signature
|
from inspect import signature
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Annotated,
|
Annotated,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
@ -68,6 +67,10 @@ from langchain_core.utils.pydantic import (
|
|||||||
is_pydantic_v2_subclass,
|
is_pydantic_v2_subclass,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
import uuid
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
FILTERED_ARGS = ("run_manager", "callbacks")
|
FILTERED_ARGS = ("run_manager", "callbacks")
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Literal, Optional, Union
|
from typing import TYPE_CHECKING, Literal, Optional, Union
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from langchain_core.callbacks import Callbacks
|
|
||||||
from langchain_core.documents import Document
|
|
||||||
from langchain_core.prompts import (
|
from langchain_core.prompts import (
|
||||||
BasePromptTemplate,
|
BasePromptTemplate,
|
||||||
PromptTemplate,
|
PromptTemplate,
|
||||||
aformat_document,
|
aformat_document,
|
||||||
format_document,
|
format_document,
|
||||||
)
|
)
|
||||||
from langchain_core.retrievers import BaseRetriever
|
|
||||||
from langchain_core.tools.simple import Tool
|
from langchain_core.tools.simple import Tool
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langchain_core.callbacks import Callbacks
|
||||||
|
from langchain_core.documents import Document
|
||||||
|
from langchain_core.retrievers import BaseRetriever
|
||||||
|
|
||||||
|
|
||||||
class RetrieverInput(BaseModel):
|
class RetrieverInput(BaseModel):
|
||||||
"""Input to the retriever."""
|
"""Input to the retriever."""
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
from collections.abc import Awaitable
|
from collections.abc import Awaitable
|
||||||
from inspect import signature
|
from inspect import signature
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
Optional,
|
Optional,
|
||||||
@ -13,7 +14,6 @@ from langchain_core.callbacks import (
|
|||||||
AsyncCallbackManagerForToolRun,
|
AsyncCallbackManagerForToolRun,
|
||||||
CallbackManagerForToolRun,
|
CallbackManagerForToolRun,
|
||||||
)
|
)
|
||||||
from langchain_core.messages import ToolCall
|
|
||||||
from langchain_core.runnables import RunnableConfig, run_in_executor
|
from langchain_core.runnables import RunnableConfig, run_in_executor
|
||||||
from langchain_core.tools.base import (
|
from langchain_core.tools.base import (
|
||||||
ArgsSchema,
|
ArgsSchema,
|
||||||
@ -22,6 +22,9 @@ from langchain_core.tools.base import (
|
|||||||
_get_runnable_config_param,
|
_get_runnable_config_param,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langchain_core.messages import ToolCall
|
||||||
|
|
||||||
|
|
||||||
class Tool(BaseTool):
|
class Tool(BaseTool):
|
||||||
"""Tool that takes in function or coroutine directly."""
|
"""Tool that takes in function or coroutine directly."""
|
||||||
|
@ -4,6 +4,7 @@ import textwrap
|
|||||||
from collections.abc import Awaitable
|
from collections.abc import Awaitable
|
||||||
from inspect import signature
|
from inspect import signature
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Annotated,
|
Annotated,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
@ -18,7 +19,6 @@ from langchain_core.callbacks import (
|
|||||||
AsyncCallbackManagerForToolRun,
|
AsyncCallbackManagerForToolRun,
|
||||||
CallbackManagerForToolRun,
|
CallbackManagerForToolRun,
|
||||||
)
|
)
|
||||||
from langchain_core.messages import ToolCall
|
|
||||||
from langchain_core.runnables import RunnableConfig, run_in_executor
|
from langchain_core.runnables import RunnableConfig, run_in_executor
|
||||||
from langchain_core.tools.base import (
|
from langchain_core.tools.base import (
|
||||||
FILTERED_ARGS,
|
FILTERED_ARGS,
|
||||||
@ -29,6 +29,9 @@ from langchain_core.tools.base import (
|
|||||||
)
|
)
|
||||||
from langchain_core.utils.pydantic import is_basemodel_subclass
|
from langchain_core.utils.pydantic import is_basemodel_subclass
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langchain_core.messages import ToolCall
|
||||||
|
|
||||||
|
|
||||||
class StructuredTool(BaseTool):
|
class StructuredTool(BaseTool):
|
||||||
"""Tool that can operate on any number of inputs."""
|
"""Tool that can operate on any number of inputs."""
|
||||||
|
@ -5,26 +5,27 @@ from __future__ import annotations
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Sequence
|
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Optional,
|
Optional,
|
||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
from tenacity import RetryCallState
|
|
||||||
|
|
||||||
from langchain_core.callbacks.base import AsyncCallbackHandler, BaseCallbackHandler
|
from langchain_core.callbacks.base import AsyncCallbackHandler, BaseCallbackHandler
|
||||||
from langchain_core.exceptions import TracerException # noqa
|
from langchain_core.exceptions import TracerException # noqa
|
||||||
from langchain_core.messages import BaseMessage
|
|
||||||
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk, LLMResult
|
|
||||||
from langchain_core.tracers.core import _TracerCore
|
from langchain_core.tracers.core import _TracerCore
|
||||||
from langchain_core.tracers.schemas import Run
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from tenacity import RetryCallState
|
||||||
|
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
|
from langchain_core.messages import BaseMessage
|
||||||
|
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk, LLMResult
|
||||||
|
from langchain_core.tracers.schemas import Run
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Generator
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from contextvars import ContextVar
|
from contextvars import ContextVar
|
||||||
from typing import (
|
from typing import (
|
||||||
@ -18,13 +17,15 @@ from langsmith import utils as ls_utils
|
|||||||
|
|
||||||
from langchain_core.tracers.langchain import LangChainTracer
|
from langchain_core.tracers.langchain import LangChainTracer
|
||||||
from langchain_core.tracers.run_collector import RunCollectorCallbackHandler
|
from langchain_core.tracers.run_collector import RunCollectorCallbackHandler
|
||||||
from langchain_core.tracers.schemas import TracerSessionV1
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Generator
|
||||||
|
|
||||||
from langsmith import Client as LangSmithClient
|
from langsmith import Client as LangSmithClient
|
||||||
|
|
||||||
from langchain_core.callbacks.base import BaseCallbackHandler, Callbacks
|
from langchain_core.callbacks.base import BaseCallbackHandler, Callbacks
|
||||||
from langchain_core.callbacks.manager import AsyncCallbackManager, CallbackManager
|
from langchain_core.callbacks.manager import AsyncCallbackManager, CallbackManager
|
||||||
|
from langchain_core.tracers.schemas import TracerSessionV1
|
||||||
|
|
||||||
# for backwards partial compatibility if this is imported by users but unused
|
# for backwards partial compatibility if this is imported by users but unused
|
||||||
tracing_callback_var: Any = None
|
tracing_callback_var: Any = None
|
||||||
|
@ -6,7 +6,6 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Coroutine, Sequence
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
@ -16,13 +15,9 @@ from typing import (
|
|||||||
Union,
|
Union,
|
||||||
cast,
|
cast,
|
||||||
)
|
)
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
from tenacity import RetryCallState
|
|
||||||
|
|
||||||
from langchain_core.exceptions import TracerException
|
from langchain_core.exceptions import TracerException
|
||||||
from langchain_core.load import dumpd
|
from langchain_core.load import dumpd
|
||||||
from langchain_core.messages import BaseMessage
|
|
||||||
from langchain_core.outputs import (
|
from langchain_core.outputs import (
|
||||||
ChatGeneration,
|
ChatGeneration,
|
||||||
ChatGenerationChunk,
|
ChatGenerationChunk,
|
||||||
@ -32,7 +27,13 @@ from langchain_core.outputs import (
|
|||||||
from langchain_core.tracers.schemas import Run
|
from langchain_core.tracers.schemas import Run
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Coroutine, Sequence
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from tenacity import RetryCallState
|
||||||
|
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
|
from langchain_core.messages import BaseMessage
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -5,9 +5,8 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import weakref
|
import weakref
|
||||||
from collections.abc import Sequence
|
|
||||||
from concurrent.futures import Future, ThreadPoolExecutor, wait
|
from concurrent.futures import Future, ThreadPoolExecutor, wait
|
||||||
from typing import Any, Optional, Union, cast
|
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
import langsmith
|
import langsmith
|
||||||
@ -17,7 +16,11 @@ from langchain_core.tracers import langchain as langchain_tracer
|
|||||||
from langchain_core.tracers.base import BaseTracer
|
from langchain_core.tracers.base import BaseTracer
|
||||||
from langchain_core.tracers.context import tracing_v2_enabled
|
from langchain_core.tracers.context import tracing_v2_enabled
|
||||||
from langchain_core.tracers.langchain import _get_executor
|
from langchain_core.tracers.langchain import _get_executor
|
||||||
from langchain_core.tracers.schemas import Run
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
from langchain_core.tracers.schemas import Run
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
|||||||
import asyncio
|
import asyncio
|
||||||
import contextlib
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
from collections.abc import AsyncIterator, Iterator, Sequence
|
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
@ -37,13 +36,15 @@ from langchain_core.runnables.utils import (
|
|||||||
_RootEventFilter,
|
_RootEventFilter,
|
||||||
)
|
)
|
||||||
from langchain_core.tracers._streaming import _StreamingCallbackHandler
|
from langchain_core.tracers._streaming import _StreamingCallbackHandler
|
||||||
from langchain_core.tracers.log_stream import LogEntry
|
|
||||||
from langchain_core.tracers.memory_stream import _MemoryStream
|
from langchain_core.tracers.memory_stream import _MemoryStream
|
||||||
from langchain_core.utils.aiter import aclosing, py_anext
|
from langchain_core.utils.aiter import aclosing, py_anext
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import AsyncIterator, Iterator, Sequence
|
||||||
|
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
from langchain_core.runnables import Runnable, RunnableConfig
|
from langchain_core.runnables import Runnable, RunnableConfig
|
||||||
|
from langchain_core.tracers.log_stream import LogEntry
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -22,12 +22,12 @@ from tenacity import (
|
|||||||
|
|
||||||
from langchain_core.env import get_runtime_environment
|
from langchain_core.env import get_runtime_environment
|
||||||
from langchain_core.load import dumpd
|
from langchain_core.load import dumpd
|
||||||
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk
|
|
||||||
from langchain_core.tracers.base import BaseTracer
|
from langchain_core.tracers.base import BaseTracer
|
||||||
from langchain_core.tracers.schemas import Run
|
from langchain_core.tracers.schemas import Run
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from langchain_core.messages import BaseMessage
|
from langchain_core.messages import BaseMessage
|
||||||
|
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
_LOGGED = set()
|
_LOGGED = set()
|
||||||
|
@ -5,8 +5,8 @@ import contextlib
|
|||||||
import copy
|
import copy
|
||||||
import threading
|
import threading
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from collections.abc import AsyncIterator, Iterator, Sequence
|
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Literal,
|
Literal,
|
||||||
Optional,
|
Optional,
|
||||||
@ -14,7 +14,6 @@ from typing import (
|
|||||||
Union,
|
Union,
|
||||||
overload,
|
overload,
|
||||||
)
|
)
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
import jsonpatch # type: ignore[import]
|
import jsonpatch # type: ignore[import]
|
||||||
from typing_extensions import NotRequired, TypedDict
|
from typing_extensions import NotRequired, TypedDict
|
||||||
@ -23,11 +22,16 @@ from langchain_core.load import dumps
|
|||||||
from langchain_core.load.load import load
|
from langchain_core.load.load import load
|
||||||
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk
|
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk
|
||||||
from langchain_core.runnables import Runnable, RunnableConfig, ensure_config
|
from langchain_core.runnables import Runnable, RunnableConfig, ensure_config
|
||||||
from langchain_core.runnables.utils import Input, Output
|
|
||||||
from langchain_core.tracers._streaming import _StreamingCallbackHandler
|
from langchain_core.tracers._streaming import _StreamingCallbackHandler
|
||||||
from langchain_core.tracers.base import BaseTracer
|
from langchain_core.tracers.base import BaseTracer
|
||||||
from langchain_core.tracers.memory_stream import _MemoryStream
|
from langchain_core.tracers.memory_stream import _MemoryStream
|
||||||
from langchain_core.tracers.schemas import Run
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import AsyncIterator, Iterator, Sequence
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from langchain_core.runnables.utils import Input, Output
|
||||||
|
from langchain_core.tracers.schemas import Run
|
||||||
|
|
||||||
|
|
||||||
class LogEntry(TypedDict):
|
class LogEntry(TypedDict):
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from collections.abc import Awaitable
|
from collections.abc import Awaitable
|
||||||
from typing import Callable, Optional, Union
|
from typing import TYPE_CHECKING, Callable, Optional, Union
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
from langchain_core.runnables.config import (
|
from langchain_core.runnables.config import (
|
||||||
RunnableConfig,
|
RunnableConfig,
|
||||||
@ -10,6 +9,9 @@ from langchain_core.runnables.config import (
|
|||||||
from langchain_core.tracers.base import AsyncBaseTracer, BaseTracer
|
from langchain_core.tracers.base import AsyncBaseTracer, BaseTracer
|
||||||
from langchain_core.tracers.schemas import Run
|
from langchain_core.tracers.schemas import Run
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
Listener = Union[Callable[[Run], None], Callable[[Run, RunnableConfig], None]]
|
Listener = Union[Callable[[Run], None], Callable[[Run, RunnableConfig], None]]
|
||||||
AsyncListener = Union[
|
AsyncListener = Union[
|
||||||
Callable[[Run], Awaitable[None]], Callable[[Run, RunnableConfig], Awaitable[None]]
|
Callable[[Run], Awaitable[None]], Callable[[Run, RunnableConfig], Awaitable[None]]
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Sequence
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from typing import Any, Optional
|
from typing import TYPE_CHECKING, Any, Optional
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
|
||||||
def _retrieve_ref(path: str, schema: dict) -> dict:
|
def _retrieve_ref(path: str, schema: dict) -> dict:
|
||||||
|
@ -8,6 +8,7 @@ import logging
|
|||||||
from collections.abc import Iterator, Mapping, Sequence
|
from collections.abc import Iterator, Mapping, Sequence
|
||||||
from types import MappingProxyType
|
from types import MappingProxyType
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Literal,
|
Literal,
|
||||||
Optional,
|
Optional,
|
||||||
@ -15,7 +16,8 @@ from typing import (
|
|||||||
cast,
|
cast,
|
||||||
)
|
)
|
||||||
|
|
||||||
from typing_extensions import TypeAlias
|
if TYPE_CHECKING:
|
||||||
|
from typing_extensions import TypeAlias
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ from contextlib import nullcontext
|
|||||||
from functools import lru_cache, wraps
|
from functools import lru_cache, wraps
|
||||||
from types import GenericAlias
|
from types import GenericAlias
|
||||||
from typing import (
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
Optional,
|
Optional,
|
||||||
@ -29,13 +30,16 @@ from pydantic import (
|
|||||||
from pydantic import (
|
from pydantic import (
|
||||||
create_model as _create_model_base,
|
create_model as _create_model_base,
|
||||||
)
|
)
|
||||||
|
from pydantic.fields import FieldInfo as FieldInfoV2
|
||||||
from pydantic.json_schema import (
|
from pydantic.json_schema import (
|
||||||
DEFAULT_REF_TEMPLATE,
|
DEFAULT_REF_TEMPLATE,
|
||||||
GenerateJsonSchema,
|
GenerateJsonSchema,
|
||||||
JsonSchemaMode,
|
JsonSchemaMode,
|
||||||
JsonSchemaValue,
|
JsonSchemaValue,
|
||||||
)
|
)
|
||||||
from pydantic_core import core_schema
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from pydantic_core import core_schema
|
||||||
|
|
||||||
|
|
||||||
def get_pydantic_major_version() -> int:
|
def get_pydantic_major_version() -> int:
|
||||||
@ -71,8 +75,8 @@ elif PYDANTIC_MAJOR_VERSION == 2:
|
|||||||
from pydantic.v1.fields import FieldInfo as FieldInfoV1 # type: ignore[assignment]
|
from pydantic.v1.fields import FieldInfo as FieldInfoV1 # type: ignore[assignment]
|
||||||
|
|
||||||
# Union type needs to be last assignment to PydanticBaseModel to make mypy happy.
|
# Union type needs to be last assignment to PydanticBaseModel to make mypy happy.
|
||||||
PydanticBaseModel = Union[BaseModel, pydantic.BaseModel] # type: ignore
|
PydanticBaseModel = Union[BaseModel, pydantic.BaseModel] # type: ignore[assignment,misc]
|
||||||
TypeBaseModel = Union[type[BaseModel], type[pydantic.BaseModel]] # type: ignore
|
TypeBaseModel = Union[type[BaseModel], type[pydantic.BaseModel]] # type: ignore[misc]
|
||||||
else:
|
else:
|
||||||
msg = f"Unsupported Pydantic version: {PYDANTIC_MAJOR_VERSION}"
|
msg = f"Unsupported Pydantic version: {PYDANTIC_MAJOR_VERSION}"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
@ -357,7 +361,6 @@ def _create_subset_model(
|
|||||||
|
|
||||||
if PYDANTIC_MAJOR_VERSION == 2:
|
if PYDANTIC_MAJOR_VERSION == 2:
|
||||||
from pydantic import BaseModel as BaseModelV2
|
from pydantic import BaseModel as BaseModelV2
|
||||||
from pydantic.fields import FieldInfo as FieldInfoV2
|
|
||||||
from pydantic.v1 import BaseModel as BaseModelV1
|
from pydantic.v1 import BaseModel as BaseModelV1
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
|
@ -25,7 +25,6 @@ import logging
|
|||||||
import math
|
import math
|
||||||
import warnings
|
import warnings
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Collection, Iterable, Iterator, Sequence
|
|
||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
@ -43,6 +42,8 @@ from langchain_core.retrievers import BaseRetriever, LangSmithRetrieverParams
|
|||||||
from langchain_core.runnables.config import run_in_executor
|
from langchain_core.runnables.config import run_in_executor
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Collection, Iterable, Iterator, Sequence
|
||||||
|
|
||||||
from langchain_core.callbacks.manager import (
|
from langchain_core.callbacks.manager import (
|
||||||
AsyncCallbackManagerForRetrieverRun,
|
AsyncCallbackManagerForRetrieverRun,
|
||||||
CallbackManagerForRetrieverRun,
|
CallbackManagerForRetrieverRun,
|
||||||
|
@ -2,7 +2,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
from collections.abc import Iterator, Sequence
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
@ -13,13 +12,15 @@ from typing import (
|
|||||||
|
|
||||||
from langchain_core._api import deprecated
|
from langchain_core._api import deprecated
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
from langchain_core.embeddings import Embeddings
|
|
||||||
from langchain_core.load import dumpd, load
|
from langchain_core.load import dumpd, load
|
||||||
from langchain_core.vectorstores import VectorStore
|
from langchain_core.vectorstores import VectorStore
|
||||||
from langchain_core.vectorstores.utils import _cosine_similarity as cosine_similarity
|
from langchain_core.vectorstores.utils import _cosine_similarity as cosine_similarity
|
||||||
from langchain_core.vectorstores.utils import maximal_marginal_relevance
|
from langchain_core.vectorstores.utils import maximal_marginal_relevance
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Iterator, Sequence
|
||||||
|
|
||||||
|
from langchain_core.embeddings import Embeddings
|
||||||
from langchain_core.indexing import UpsertResponse
|
from langchain_core.indexing import UpsertResponse
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,8 +77,9 @@ target-version = "py39"
|
|||||||
|
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
select = [ "ANN", "ASYNC", "B", "C4", "COM", "DJ", "E", "EM", "EXE", "F", "FLY", "FURB", "I", "ICN", "INT", "LOG", "N", "NPY", "PD", "PIE", "Q", "RSE", "S", "SIM", "SLOT", "T10", "T201", "TID", "TRY", "UP", "W", "YTT",]
|
select = [ "ANN", "ASYNC", "B", "C4", "COM", "DJ", "E", "EM", "EXE", "F", "FLY", "FURB", "I", "ICN", "INT", "LOG", "N", "NPY", "PD", "PIE", "Q", "RSE", "S", "SIM", "SLOT", "T10", "T201", "TC", "TID", "TRY", "UP", "W", "YTT",]
|
||||||
ignore = [ "ANN401", "COM812", "UP007", "S110", "S112",]
|
ignore = [ "ANN401", "COM812", "UP007", "S110", "S112", "TC001", "TC002", "TC003"]
|
||||||
|
flake8-type-checking.runtime-evaluated-base-classes = ["pydantic.BaseModel","langchain_core.load.serializable.Serializable","langchain_core.runnables.base.RunnableSerializable"]
|
||||||
flake8-annotations.allow-star-arg-any = true
|
flake8-annotations.allow-star-arg-any = true
|
||||||
flake8-annotations.mypy-init-return = true
|
flake8-annotations.mypy-init-return = true
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
from collections.abc import AsyncIterator, Iterator
|
from collections.abc import AsyncIterator, Iterator
|
||||||
from typing import Any, Literal, Optional, Union
|
from typing import TYPE_CHECKING, Any, Literal, Optional, Union
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -30,6 +30,9 @@ from tests.unit_tests.fake.callbacks import (
|
|||||||
)
|
)
|
||||||
from tests.unit_tests.stubs import _any_id_ai_message, _any_id_ai_message_chunk
|
from tests.unit_tests.stubs import _any_id_ai_message, _any_id_ai_message_chunk
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langchain_core.outputs.llm_result import LLMResult
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def messages() -> list:
|
def messages() -> list:
|
||||||
|
@ -7,8 +7,7 @@ the relevant methods.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
from collections.abc import Iterable, Sequence
|
from typing import TYPE_CHECKING, Any, Optional
|
||||||
from typing import Any, Optional
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -16,6 +15,9 @@ from langchain_core.documents import Document
|
|||||||
from langchain_core.embeddings import Embeddings, FakeEmbeddings
|
from langchain_core.embeddings import Embeddings, FakeEmbeddings
|
||||||
from langchain_core.vectorstores import VectorStore
|
from langchain_core.vectorstores import VectorStore
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Iterable, Sequence
|
||||||
|
|
||||||
|
|
||||||
class CustomAddTextsVectorstore(VectorStore):
|
class CustomAddTextsVectorstore(VectorStore):
|
||||||
"""A vectorstore that only implements add texts."""
|
"""A vectorstore that only implements add texts."""
|
||||||
|
Loading…
Reference in New Issue
Block a user