Skip to content

The agent engineering platform.

docs: community docstring updates (#21040)

Leonid Ganeline85094cbb3a41
diff --git a/libs/community/langchain_community/callbacks/aim_callback.py b/libs/community/langchain_community/callbacks/aim_callback.py
index 46d7987c54..02debd8c8d 100644
--- a/libs/community/langchain_community/callbacks/aim_callback.py
+++ b/libs/community/langchain_community/callbacks/aim_callback.py
@@ -20,7 +20,7 @@ def import_aim() -> Any:
class BaseMetadataCallbackHandler:
- """This class handles the metadata and associated function states for callbacks.
+ """Callback handler for the metadata and associated function states for callbacks.
Attributes:
step (int): The current step.
diff --git a/libs/community/langchain_community/callbacks/uptrain_callback.py b/libs/community/langchain_community/callbacks/uptrain_callback.py
index fd08fd02c5..5e89592dec 100644
--- a/libs/community/langchain_community/callbacks/uptrain_callback.py
+++ b/libs/community/langchain_community/callbacks/uptrain_callback.py
@@ -74,6 +74,7 @@ logger.addHandler(handler)
def import_uptrain() -> Any:
+ """Import the `uptrain` package."""
try:
import uptrain
except ImportError as e:
diff --git a/libs/community/langchain_community/callbacks/utils.py b/libs/community/langchain_community/callbacks/utils.py
index b83bace601..5f8b82a127 100644
--- a/libs/community/langchain_community/callbacks/utils.py
+++ b/libs/community/langchain_community/callbacks/utils.py
@@ -65,7 +65,7 @@ def _flatten_dict(
def flatten_dict(
nested_dict: Dict[str, Any], parent_key: str = "", sep: str = "_"
) -> Dict[str, Any]:
- """Flattens a nested dictionary into a flat dictionary.
+ """Flatten a nested dictionary into a flat dictionary.
Parameters:
nested_dict (dict): The nested dictionary to flatten.
@@ -108,7 +108,7 @@ def load_json(json_path: Union[str, Path]) -> str:
class BaseMetadataCallbackHandler:
- """This class handles the metadata and associated function states for callbacks.
+ """Handle the metadata and associated function states for callbacks.
Attributes:
step (int): The current step.
diff --git a/libs/community/langchain_community/chat_message_histories/zep.py b/libs/community/langchain_community/chat_message_histories/zep.py
index c3a2a820d8..cd2e056af4 100644
--- a/libs/community/langchain_community/chat_message_histories/zep.py
+++ b/libs/community/langchain_community/chat_message_histories/zep.py
@@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
class SearchScope(str, Enum):
- """Which documents to search. Messages or Summaries?"""
+ """Scope for the document search. Messages or Summaries?"""
messages = "messages"
"""Search chat history messages."""
diff --git a/libs/community/langchain_community/chat_models/mlx.py b/libs/community/langchain_community/chat_models/mlx.py
index 4613f3d826..1bd9f740d7 100644
--- a/libs/community/langchain_community/chat_models/mlx.py
+++ b/libs/community/langchain_community/chat_models/mlx.py
@@ -27,8 +27,7 @@ DEFAULT_SYSTEM_PROMPT = """You are a helpful, respectful, and honest assistant."
class ChatMLX(BaseChatModel):
- """
- Wrapper for using MLX LLM's as ChatModels.
+ """MLX chat models.
Works with `MLXPipeline` LLM.
diff --git a/libs/community/langchain_community/document_loaders/doc_intelligence.py b/libs/community/langchain_community/document_loaders/doc_intelligence.py
index f4965e1767..68a3eb44bd 100644
--- a/libs/community/langchain_community/document_loaders/doc_intelligence.py
+++ b/libs/community/langchain_community/document_loaders/doc_intelligence.py
@@ -10,7 +10,7 @@ from langchain_community.document_loaders.parsers import (
class AzureAIDocumentIntelligenceLoader(BaseLoader):
- """Loads a PDF with Azure Document Intelligence"""
+ """Load a PDF with Azure Document Intelligence."""
def __init__(
self,
diff --git a/libs/community/langchain_community/document_loaders/parsers/docai.py b/libs/community/langchain_community/document_loaders/parsers/docai.py
index bb7a502db2..b5861de54c 100644
--- a/libs/community/langchain_community/document_loaders/parsers/docai.py
+++ b/libs/community/langchain_community/document_loaders/parsers/docai.py
@@ -28,7 +28,7 @@ logger = logging.getLogger(__name__)
@dataclass
class DocAIParsingResults:
- """A dataclass to store Document AI parsing results."""
+ """Dataclass to store Document AI parsing results."""
source_path: str
parsed_path: str
diff --git a/libs/community/langchain_community/document_loaders/parsers/html/bs4.py b/libs/community/langchain_community/document_loaders/parsers/html/bs4.py
index 6863b6d106..d00af499dc 100644
--- a/libs/community/langchain_community/document_loaders/parsers/html/bs4.py
+++ b/libs/community/langchain_community/document_loaders/parsers/html/bs4.py
@@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
class BS4HTMLParser(BaseBlobParser):
- """Pparse HTML files using `Beautiful Soup`."""
+ """Parse HTML files using `Beautiful Soup`."""
def __init__(
self,
diff --git a/libs/community/langchain_community/document_loaders/pdf.py b/libs/community/langchain_community/document_loaders/pdf.py
index 31267217ad..0f3d2110b7 100644
--- a/libs/community/langchain_community/document_loaders/pdf.py
+++ b/libs/community/langchain_community/document_loaders/pdf.py
@@ -731,7 +731,7 @@ class AmazonTextractPDFLoader(BasePDFLoader):
class DocumentIntelligenceLoader(BasePDFLoader):
- """Loads a PDF with Azure Document Intelligence"""
+ """Load a PDF with Azure Document Intelligence"""
def __init__(
self,
diff --git a/libs/community/langchain_community/document_loaders/url_playwright.py b/libs/community/langchain_community/document_loaders/url_playwright.py
index 016626086c..c35942f1c9 100644
--- a/libs/community/langchain_community/document_loaders/url_playwright.py
+++ b/libs/community/langchain_community/document_loaders/url_playwright.py
@@ -57,7 +57,7 @@ class PlaywrightEvaluator(ABC):
class UnstructuredHtmlEvaluator(PlaywrightEvaluator):
- """Evaluates the page HTML content using the `unstructured` library."""
+ """Evaluate the page HTML content using the `unstructured` library."""
def __init__(self, remove_selectors: Optional[List[str]] = None):
"""Initialize UnstructuredHtmlEvaluator."""
diff --git a/libs/community/langchain_community/embeddings/infinity.py b/libs/community/langchain_community/embeddings/infinity.py
index f0a01fc75e..f5068e64f6 100644
--- a/libs/community/langchain_community/embeddings/infinity.py
+++ b/libs/community/langchain_community/embeddings/infinity.py
@@ -15,11 +15,13 @@ __all__ = ["InfinityEmbeddings"]
class InfinityEmbeddings(BaseModel, Embeddings):
- """Embedding models for self-hosted https://github.com/michaelfeil/infinity
- This should also work for text-embeddings-inference and other
+ """Self-hosted embedding models for `infinity` package.
+
+ See https://github.com/michaelfeil/infinity
+ This also works for text-embeddings-inference and other
self-hosted openai-compatible servers.
- Infinity is a class to interact with Embedding Models on https://github.com/michaelfeil/infinity
+ Infinity is a package to interact with Embedding Models on https://github.com/michaelfeil/infinity
Example:
@@ -115,7 +117,9 @@ class InfinityEmbeddings(BaseModel, Embeddings):
class TinyAsyncOpenAIInfinityEmbeddingClient: #: :meta private:
- """A helper tool to embed Infinity. Not part of Langchain's stable API,
+ """Helper tool to embed Infinity.
+
+ It is not a part of Langchain's stable API,
direct use discouraged.
Example:
diff --git a/libs/community/langchain_community/embeddings/premai.py b/libs/community/langchain_community/embeddings/premai.py
index e811b1bae4..9f2585c3ed 100644
--- a/libs/community/langchain_community/embeddings/premai.py
+++ b/libs/community/langchain_community/embeddings/premai.py
@@ -72,6 +72,15 @@ def create_prem_retry_decorator(
*,
max_retries: int = 1,
) -> Callable[[Any], Any]:
+ """Create a retry decorator for PremAIEmbeddings.
+
+ Args:
+ embedder (PremAIEmbeddings): The PremAIEmbeddings instance
+ max_retries (int): The maximum number of retries
+
+ Returns:
+ Callable[[Any], Any]: The retry decorator
+ """
import premai.models
errors = [
diff --git a/libs/community/langchain_community/embeddings/sparkllm.py b/libs/community/langchain_community/embeddings/sparkllm.py
index 7e80b11896..44a6b9a7fd 100644
--- a/libs/community/langchain_community/embeddings/sparkllm.py
+++ b/libs/community/langchain_community/embeddings/sparkllm.py
@@ -187,5 +187,7 @@ class SparkLLMTextEmbeddings(BaseModel, Embeddings):
class AssembleHeaderException(Exception):
+ """Exception raised for errors in the header assembly."""
+
def __init__(self, msg: str) -> None:
self.message = msg
diff --git a/libs/community/langchain_community/embeddings/titan_takeoff.py b/libs/community/langchain_community/embeddings/titan_takeoff.py
index dc09e22936..81966c6739 100644
--- a/libs/community/langchain_community/embeddings/titan_takeoff.py
+++ b/libs/community/langchain_community/embeddings/titan_takeoff.py
@@ -6,22 +6,24 @@ from langchain_core.pydantic_v1 import BaseModel
class TakeoffEmbeddingException(Exception):
- """Exceptions experienced with interfacing with Takeoff Embedding Wrapper"""
+ """Custom exception for interfacing with Takeoff Embedding class."""
class MissingConsumerGroup(TakeoffEmbeddingException):
"""Exception raised when no consumer group is provided on initialization of
- TitanTakeoffEmbed or in embed request"""
+ TitanTakeoffEmbed or in embed request."""
class Device(str, Enum):
- """The device to use for inference, cuda or cpu"""
+ """Device to use for inference, cuda or cpu."""
cuda = "cuda"
cpu = "cpu"
class ReaderConfig(BaseModel):
+ """Configuration for the reader to be deployed in Takeoff."""
+
class Config:
protected_namespaces = ()
@@ -36,10 +38,9 @@ class ReaderConfig(BaseModel):
class TitanTakeoffEmbed(Embeddings):
- """Titan Takeoff Embed is a wrapper to interface with Takeoff Inference API
- for embedding models
+ """Interface with Takeoff Inference API for embedding models.
- You can use this wrapper to send embedding requests and to deploy embedding
+ Use it to send embedding requests and to deploy embedding
readers with Takeoff.
Examples:
diff --git a/libs/community/langchain_community/graphs/graph_store.py b/libs/community/langchain_community/graphs/graph_store.py
index 0618eae48d..73a07c7de5 100644
--- a/libs/community/langchain_community/graphs/graph_store.py
+++ b/libs/community/langchain_community/graphs/graph_store.py
@@ -5,18 +5,18 @@ from langchain_community.graphs.graph_document import GraphDocument
class GraphStore:
- """An abstract class wrapper for graph operations."""
+ """Abstract class for graph operations."""
@property
@abstractmethod
def get_schema(self) -> str:
- """Returns the schema of the Graph database"""
+ """Return the schema of the Graph database"""
pass
@property
@abstractmethod
def get_structured_schema(self) -> Dict[str, Any]:
- """Returns the schema of the Graph database"""
+ """Return the schema of the Graph database"""
pass
@abstractmethod
@@ -26,7 +26,7 @@ class GraphStore:
@abstractmethod
def refresh_schema(self) -> None:
- """Refreshes the graph schema information."""
+ """Refresh the graph schema information."""
pass
@abstractmethod
diff --git a/libs/community/langchain_community/graphs/gremlin_graph.py b/libs/community/langchain_community/graphs/gremlin_graph.py
index 7cabd8e1cd..934ccb3f53 100644
--- a/libs/community/langchain_community/graphs/gremlin_graph.py
+++ b/libs/community/langchain_community/graphs/gremlin_graph.py
@@ -10,6 +10,7 @@ from langchain_community.graphs.graph_store import GraphStore
class GremlinGraph(GraphStore):
"""Gremlin wrapper for graph operations.
+
Parameters:
url (Optional[str]): The URL of the Gremlin database server or env GREMLIN_URI
username (Optional[str]): The collection-identifier like '/dbs/database/colls/graph'
diff --git a/libs/community/langchain_community/graphs/neptune_graph.py b/libs/community/langchain_community/graphs/neptune_graph.py
index 05d840bae8..a6eb71ad69 100644
--- a/libs/community/langchain_community/graphs/neptune_graph.py
+++ b/libs/community/langchain_community/graphs/neptune_graph.py
@@ -22,9 +22,11 @@ class NeptuneQueryException(Exception):
class BaseNeptuneGraph(ABC):
+ """Abstract base class for Neptune"""
+
@property
def get_schema(self) -> str:
- """Returns the schema of the Neptune database"""
+ """Return the schema of the Neptune database"""
return self.schema
@abstractmethod
diff --git a/libs/community/langchain_community/llms/baichuan.py b/libs/community/langchain_community/llms/baichuan.py
index 293c95d2c8..2f897b2c6d 100644
--- a/libs/community/langchain_community/llms/baichuan.py
+++ b/libs/community/langchain_community/llms/baichuan.py
@@ -17,7 +17,7 @@ logger = logging.getLogger(__name__)
class BaichuanLLM(LLM):
# TODO: Adding streaming support.
- """Wrapper around Baichuan large language models."""
+ """Baichuan large language models."""
model: str = "Baichuan2-Turbo-192k"
"""
diff --git a/libs/community/langchain_community/llms/minimax.py b/libs/community/langchain_community/llms/minimax.py
index a2375b7445..ea38c36fb4 100644
--- a/libs/community/langchain_community/llms/minimax.py
+++ b/libs/community/langchain_community/llms/minimax.py
@@ -23,7 +23,7 @@ logger = logging.getLogger(__name__)
class _MinimaxEndpointClient(BaseModel):
- """An API client that talks to a Minimax llm endpoint."""
+ """API client for the Minimax LLM endpoint."""
host: str
group_id: str
@@ -117,7 +117,8 @@ class MinimaxCommon(BaseModel):
class Minimax(MinimaxCommon, LLM):
- """Wrapper around Minimax large language models.
+ """Minimax large language models.
+
To use, you should have the environment variable
``MINIMAX_API_KEY`` and ``MINIMAX_GROUP_ID`` set with your API key,
or pass them as a named parameter to the constructor.
diff --git a/libs/community/langchain_community/llms/titan_takeoff.py b/libs/community/langchain_community/llms/titan_takeoff.py
index e5b38e77dd..6df0d0a37e 100644
--- a/libs/community/langchain_community/llms/titan_takeoff.py
+++ b/libs/community/langchain_community/llms/titan_takeoff.py
@@ -17,6 +17,8 @@ class Device(str, Enum):
class ReaderConfig(BaseModel):
+ """Configuration for the reader to be deployed in Titan Takeoff API."""
+
class Config:
protected_namespaces = ()
diff --git a/libs/community/langchain_community/tools/e2b_data_analysis/unparse.py b/libs/community/langchain_community/tools/e2b_data_analysis/unparse.py
index 0090596e37..b924f92733 100644
--- a/libs/community/langchain_community/tools/e2b_data_analysis/unparse.py
+++ b/libs/community/langchain_community/tools/e2b_data_analysis/unparse.py
@@ -27,7 +27,7 @@ def interleave(inter, f, seq):
class Unparser:
- """Methods in this class recursively traverse an AST and
+ """Traverse an AST and
output source code for the abstract syntax; original formatting
is disregarded."""
diff --git a/libs/community/langchain_community/utilities/cassandra.py b/libs/community/langchain_community/utilities/cassandra.py
index c871ece440..cd58850896 100644
--- a/libs/community/langchain_community/utilities/cassandra.py
+++ b/libs/community/langchain_community/utilities/cassandra.py
@@ -11,6 +11,16 @@ if TYPE_CHECKING:
async def wrapped_response_future(
func: Callable[..., ResponseFuture], *args: Any, **kwargs: Any
) -> Any:
+ """Wrap a Cassandra response future in an asyncio future.
+
+ Args:
+ func: The Cassandra function to call.
+ *args: The arguments to pass to the Cassandra function.
+ **kwargs: The keyword arguments to pass to the Cassandra function.
+
+ Returns:
+ The result of the Cassandra function.
+ """
loop = asyncio.get_event_loop()
asyncio_future = loop.create_future()
response_future = func(*args, **kwargs)
diff --git a/libs/community/langchain_community/utilities/clickup.py b/libs/community/langchain_community/utilities/clickup.py
index e13deef894..5d82a00416 100644
--- a/libs/community/langchain_community/utilities/clickup.py
+++ b/libs/community/langchain_community/utilities/clickup.py
@@ -196,12 +196,15 @@ def extract_dict_elements_from_component_fields(
def load_query(
query: str, fault_tolerant: bool = False
) -> Tuple[Optional[Dict], Optional[str]]:
- """Attempts to parse a JSON string and return the parsed object.
+ """Parse a JSON string and return the parsed object.
If parsing fails, returns an error message.
:param query: The JSON string to parse.
:return: A tuple containing the parsed object or None and an error message or None.
+
+ Exceptions:
+ json.JSONDecodeError: If the input is not a valid JSON string.
"""
try:
return json.loads(query), None
diff --git a/libs/community/langchain_community/utilities/passio_nutrition_ai.py b/libs/community/langchain_community/utilities/passio_nutrition_ai.py
index 5be284d301..0e3a8cb8dd 100644
--- a/libs/community/langchain_community/utilities/passio_nutrition_ai.py
+++ b/libs/community/langchain_community/utilities/passio_nutrition_ai.py
@@ -9,6 +9,8 @@ from langchain_core.utils import get_from_dict_or_env
class NoDiskStorage:
+ """Mixin to prevent storing on disk."""
+
@final
def __getstate__(self) -> None:
raise AttributeError("Do not store on disk.")
@@ -46,11 +48,12 @@ except ImportError:
def is_http_retryable(rsp: requests.Response) -> bool:
+ """Check if a HTTP response is retryable."""
return bool(rsp) and rsp.status_code in [408, 425, 429, 500, 502, 503, 504]
class ManagedPassioLifeAuth(NoDiskStorage):
- """Manages the token for the NutritionAI API."""
+ """Manage the token for the NutritionAI API."""
_access_token_expiry: Optional[datetime]
diff --git a/libs/community/langchain_community/utilities/pebblo.py b/libs/community/langchain_community/utilities/pebblo.py
index d94ba80985..4c82c63bec 100644
--- a/libs/community/langchain_community/utilities/pebblo.py
+++ b/libs/community/langchain_community/utilities/pebblo.py
@@ -192,7 +192,7 @@ def get_loader_type(loader: str) -> str:
def get_loader_full_path(loader: BaseLoader) -> str:
"""Return an absolute source path of source of loader based on the
- keys present in Document object from loader.
+ keys present in Document.
Args:
loader (BaseLoader): Langchain document loader, derived from Baseloader.
diff --git a/libs/community/langchain_community/utilities/powerbi.py b/libs/community/langchain_community/utilities/powerbi.py
index 8821993626..93d4886796 100644
--- a/libs/community/langchain_community/utilities/powerbi.py
+++ b/libs/community/langchain_community/utilities/powerbi.py
@@ -251,7 +251,7 @@ def json_to_md(
json_contents: List[Dict[str, Union[str, int, float]]],
table_name: Optional[str] = None,
) -> str:
- """Converts a JSON object to a markdown table."""
+ """Convert a JSON object to a markdown table."""
if len(json_contents) == 0:
return ""
output_md = ""
diff --git a/libs/community/langchain_community/vectorstores/cassandra.py b/libs/community/langchain_community/vectorstores/cassandra.py
index 603c33cf94..9656f56339 100644
--- a/libs/community/langchain_community/vectorstores/cassandra.py
+++ b/libs/community/langchain_community/vectorstores/cassandra.py
@@ -35,7 +35,7 @@ _NOT_SET = object()
class Cassandra(VectorStore):
- """Wrapper around Apache Cassandra(R) for vector-store workloads.
+ """Apache Cassandra(R) for vector-store workloads.
To use it, you need a recent installation of the `cassio` library
and a Cassandra cluster / Astra DB instance supporting vector capabilities.
diff --git a/libs/community/langchain_community/vectorstores/lancedb.py b/libs/community/langchain_community/vectorstores/lancedb.py
index e591fc7666..2d2f859b76 100644
--- a/libs/community/langchain_community/vectorstores/lancedb.py
+++ b/libs/community/langchain_community/vectorstores/lancedb.py
@@ -11,6 +11,8 @@ from langchain_core.vectorstores import VectorStore
def import_lancedb() -> Any:
+ """Import lancedb package."""
+
try:
import lancedb
except ImportError as e:
diff --git a/libs/community/langchain_community/vectorstores/tencentvectordb.py b/libs/community/langchain_community/vectorstores/tencentvectordb.py
index d9c070f177..48e18ca6c0 100644
--- a/libs/community/langchain_community/vectorstores/tencentvectordb.py
+++ b/libs/community/langchain_community/vectorstores/tencentvectordb.py
@@ -109,6 +109,15 @@ class MetaField(BaseModel):
def translate_filter(
lc_filter: str, allowed_fields: Optional[Sequence[str]] = None
) -> str:
+ """Translate LangChain filter to Tencent VectorDB filter.
+
+ Args:
+ lc_filter (str): LangChain filter.
+ allowed_fields (Optional[Sequence[str]]): Allowed fields for filter.
+
+ Returns:
+ str: Translated filter.
+ """
from langchain.chains.query_constructor.base import fix_filter_directive
from langchain.chains.query_constructor.parser import get_parser
from langchain.retrievers.self_query.tencentvectordb import (