From 7cf2d2759d0112c4772dcb11d756e904f591a88d Mon Sep 17 00:00:00 2001 From: Leonid Ganeline Date: Thu, 11 Apr 2024 13:23:27 -0700 Subject: [PATCH] community[patch]: docstrings update (#20301) Added missed docstrings. Format docstings to the consistent form. --- .../agent_toolkits/connery/toolkit.py | 2 +- .../agent_toolkits/openapi/planner.py | 2 +- .../callbacks/flyte_callback.py | 2 +- .../callbacks/streamlit/mutable_expander.py | 8 ++++---- .../streamlit/streamlit_callback_handler.py | 2 +- .../chat_message_histories/sql.py | 2 +- .../langchain_community/chat_models/bedrock.py | 2 +- .../chat_models/huggingface.py | 3 +-- .../langchain_community/chat_models/litellm.py | 2 +- .../langchain_community/chat_models/minimax.py | 2 +- .../langchain_community/chat_models/moonshot.py | 2 +- .../chat_models/pai_eas_endpoint.py | 2 +- .../langchain_community/chat_models/premai.py | 3 ++- .../langchain_community/chat_models/solar.py | 2 +- .../langchain_community/chat_models/sparkllm.py | 2 +- .../langchain_community/chat_models/tongyi.py | 2 ++ .../langchain_community/chat_models/yandex.py | 2 +- .../langchain_community/chat_models/zhipuai.py | 2 ++ .../langchain_community/docstore/arbitrary_fn.py | 2 +- .../langchain_community/docstore/wikipedia.py | 2 +- .../document_compressors/openvino_rerank.py | 2 ++ .../document_loaders/assemblyai.py | 5 ++--- .../document_loaders/bilibili.py | 2 +- .../long_context_reorder.py | 4 +++- .../nuclia_text_transform.py | 3 ++- .../embeddings/aleph_alpha.py | 2 +- .../langchain_community/embeddings/databricks.py | 2 +- .../embeddings/infinity_local.py | 4 +++- .../embeddings/javelin_ai_gateway.py | 3 +-- .../embeddings/mlflow_gateway.py | 3 +-- .../langchain_community/embeddings/nemo.py | 2 ++ .../langchain_community/graphs/networkx_graph.py | 2 +- .../langchain_community/indexes/base.py | 2 +- .../llms/cloudflare_workersai.py | 2 +- .../langchain_community/llms/databricks.py | 6 +++--- .../community/langchain_community/llms/edenai.py | 2 +- libs/community/langchain_community/llms/human.py | 4 +--- .../langchain_community/llms/ipex_llm.py | 2 +- libs/community/langchain_community/llms/konko.py | 2 +- .../langchain_community/llms/layerup_security.py | 10 ++++++++++ .../langchain_community/llms/loading.py | 1 + .../community/langchain_community/llms/mlflow.py | 2 +- .../llms/mlflow_ai_gateway.py | 3 +-- .../langchain_community/llms/moonshot.py | 2 ++ .../langchain_community/llms/opaqueprompts.py | 2 +- .../llms/promptlayer_openai.py | 2 +- .../llms/sagemaker_endpoint.py | 5 ++--- .../langchain_community/llms/sparkllm.py | 2 +- .../langchain_community/llms/titan_takeoff.py | 2 +- .../langchain_community/llms/vertexai.py | 6 +++--- .../langchain_community/retrievers/arcee.py | 2 +- .../langchain_community/retrievers/you.py | 3 ++- .../tools/cogniswitch/tool.py | 16 ++++++++-------- .../langchain_community/tools/connery/service.py | 4 ++-- .../langchain_community/tools/connery/tool.py | 4 +--- .../tools/office365/events_search.py | 2 +- .../tools/office365/messages_search.py | 4 ++-- .../tools/office365/send_message.py | 2 +- .../langchain_community/tools/office365/utils.py | 2 +- .../langchain_community/tools/you/tool.py | 4 +++- .../langchain_community/tools/zapier/tool.py | 11 ++++------- .../langchain_community/utilities/astradb.py | 2 ++ .../langchain_community/utilities/pebblo.py | 16 ++++++++-------- .../langchain_community/utilities/vertexai.py | 6 +++--- .../langchain_community/utilities/you.py | 4 ++-- .../langchain_community/utils/ernie_functions.py | 4 ++-- .../langchain_community/utils/google.py | 2 +- .../vectorstores/neo4j_vector.py | 16 +++++++++++++--- .../vectorstores/redis/filters.py | 8 ++++---- .../vectorstores/redis/schema.py | 2 +- .../langchain_community/vectorstores/sklearn.py | 6 +++--- .../vectorstores/sqlitevss.py | 3 ++- .../vectorstores/tidb_vector.py | 2 ++ .../langchain_community/vectorstores/vald.py | 2 +- .../langchain_community/vectorstores/vdms.py | 7 ++++--- .../langchain_community/vectorstores/vectara.py | 11 +++++++---- .../vectorstores/yellowbrick.py | 3 ++- 77 files changed, 162 insertions(+), 125 deletions(-) diff --git a/libs/community/langchain_community/agent_toolkits/connery/toolkit.py b/libs/community/langchain_community/agent_toolkits/connery/toolkit.py index 03bbbf62316..e1a84fd6c13 100644 --- a/libs/community/langchain_community/agent_toolkits/connery/toolkit.py +++ b/libs/community/langchain_community/agent_toolkits/connery/toolkit.py @@ -9,7 +9,7 @@ from langchain_community.tools.connery import ConneryService class ConneryToolkit(BaseToolkit): """ - A LangChain Toolkit with a list of Connery Actions as tools. + Toolkit with a list of Connery Actions as tools. """ tools: List[BaseTool] diff --git a/libs/community/langchain_community/agent_toolkits/openapi/planner.py b/libs/community/langchain_community/agent_toolkits/openapi/planner.py index 792a6dff660..281c8a49be1 100644 --- a/libs/community/langchain_community/agent_toolkits/openapi/planner.py +++ b/libs/community/langchain_community/agent_toolkits/openapi/planner.py @@ -348,7 +348,7 @@ def create_openapi_agent( allow_dangerous_requests: bool = False, **kwargs: Any, ) -> Any: - """Instantiate OpenAI API planner and controller for a given spec. + """Construct an OpenAI API planner and controller for a given spec. Inject credentials via requests_wrapper. diff --git a/libs/community/langchain_community/callbacks/flyte_callback.py b/libs/community/langchain_community/callbacks/flyte_callback.py index 9fd953443f2..3cd38f7eca9 100644 --- a/libs/community/langchain_community/callbacks/flyte_callback.py +++ b/libs/community/langchain_community/callbacks/flyte_callback.py @@ -91,7 +91,7 @@ def analyze_text( class FlyteCallbackHandler(BaseMetadataCallbackHandler, BaseCallbackHandler): - """This callback handler that is used within a Flyte task.""" + """Callback handler that is used within a Flyte task.""" def __init__(self) -> None: """Initialize callback handler.""" diff --git a/libs/community/langchain_community/callbacks/streamlit/mutable_expander.py b/libs/community/langchain_community/callbacks/streamlit/mutable_expander.py index 0bb73f571ad..9870e472242 100644 --- a/libs/community/langchain_community/callbacks/streamlit/mutable_expander.py +++ b/libs/community/langchain_community/callbacks/streamlit/mutable_expander.py @@ -9,14 +9,14 @@ if TYPE_CHECKING: class ChildType(Enum): - """The enumerator of the child type.""" + """Enumerator of the child type.""" MARKDOWN = "MARKDOWN" EXCEPTION = "EXCEPTION" class ChildRecord(NamedTuple): - """The child record as a NamedTuple.""" + """Child record as a NamedTuple.""" type: ChildType kwargs: Dict[str, Any] @@ -24,7 +24,7 @@ class ChildRecord(NamedTuple): class MutableExpander: - """A Streamlit expander that can be renamed and dynamically expanded/collapsed.""" + """Streamlit expander that can be renamed and dynamically expanded/collapsed.""" def __init__(self, parent_container: DeltaGenerator, label: str, expanded: bool): """Create a new MutableExpander. @@ -51,7 +51,7 @@ class MutableExpander: @property def label(self) -> str: - """The expander's label string.""" + """Expander's label string.""" return self._label @property diff --git a/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py b/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py index 89183fd5f46..0d065e95dd3 100644 --- a/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py +++ b/libs/community/langchain_community/callbacks/streamlit/streamlit_callback_handler.py @@ -40,7 +40,7 @@ class LLMThoughtState(Enum): class ToolRecord(NamedTuple): - """The tool record as a NamedTuple.""" + """Tool record as a NamedTuple.""" name: str input_str: str diff --git a/libs/community/langchain_community/chat_message_histories/sql.py b/libs/community/langchain_community/chat_message_histories/sql.py index f77deee61e7..01cafeb9bcd 100644 --- a/libs/community/langchain_community/chat_message_histories/sql.py +++ b/libs/community/langchain_community/chat_message_histories/sql.py @@ -21,7 +21,7 @@ logger = logging.getLogger(__name__) class BaseMessageConverter(ABC): - """Class that converts BaseMessage to the SQLAlchemy model.""" + """Convert BaseMessage to the SQLAlchemy model.""" @abstractmethod def from_sql_model(self, sql_message: Any) -> BaseMessage: diff --git a/libs/community/langchain_community/chat_models/bedrock.py b/libs/community/langchain_community/chat_models/bedrock.py index 587db5ee353..0555c9f2b02 100644 --- a/libs/community/langchain_community/chat_models/bedrock.py +++ b/libs/community/langchain_community/chat_models/bedrock.py @@ -196,7 +196,7 @@ _message_type_lookups = {"human": "user", "ai": "assistant"} class BedrockChat(BaseChatModel, BedrockBase): - """A chat model that uses the Bedrock API.""" + """Chat model that uses the Bedrock API.""" @property def _llm_type(self) -> str: diff --git a/libs/community/langchain_community/chat_models/huggingface.py b/libs/community/langchain_community/chat_models/huggingface.py index f459f58e1dd..598a8ebc49c 100644 --- a/libs/community/langchain_community/chat_models/huggingface.py +++ b/libs/community/langchain_community/chat_models/huggingface.py @@ -26,8 +26,7 @@ DEFAULT_SYSTEM_PROMPT = """You are a helpful, respectful, and honest assistant." class ChatHuggingFace(BaseChatModel): - """ - Wrapper for using Hugging Face LLM's as ChatModels. + """Hugging Face LLMs as ChatModels. Works with `HuggingFaceTextGenInference`, `HuggingFaceEndpoint`, and `HuggingFaceHub` LLMs. diff --git a/libs/community/langchain_community/chat_models/litellm.py b/libs/community/langchain_community/chat_models/litellm.py index b80fa2a6beb..2f980337807 100644 --- a/libs/community/langchain_community/chat_models/litellm.py +++ b/libs/community/langchain_community/chat_models/litellm.py @@ -161,7 +161,7 @@ def _convert_message_to_dict(message: BaseMessage) -> dict: class ChatLiteLLM(BaseChatModel): - """A chat model that uses the LiteLLM API.""" + """Chat model that uses the LiteLLM API.""" client: Any #: :meta private: model: str = "gpt-3.5-turbo" diff --git a/libs/community/langchain_community/chat_models/minimax.py b/libs/community/langchain_community/chat_models/minimax.py index 5a5c281d3b0..a315aa1f539 100644 --- a/libs/community/langchain_community/chat_models/minimax.py +++ b/libs/community/langchain_community/chat_models/minimax.py @@ -37,7 +37,7 @@ def _parse_chat_history(history: List[BaseMessage]) -> List: class MiniMaxChat(MinimaxCommon, BaseChatModel): - """Wrapper around Minimax large language models. + """MiniMax large language models. To use, you should have the environment variable ``MINIMAX_GROUP_ID`` and ``MINIMAX_API_KEY`` set with your API token, or pass it as a named parameter to diff --git a/libs/community/langchain_community/chat_models/moonshot.py b/libs/community/langchain_community/chat_models/moonshot.py index 8df9ab612ac..202a62d8ea1 100644 --- a/libs/community/langchain_community/chat_models/moonshot.py +++ b/libs/community/langchain_community/chat_models/moonshot.py @@ -9,7 +9,7 @@ from langchain_community.llms.moonshot import MOONSHOT_SERVICE_URL_BASE, Moonsho class MoonshotChat(MoonshotCommon, ChatOpenAI): # type: ignore[misc] - """Wrapper around Moonshot large language models. + """Moonshot large language models. To use, you should have the ``openai`` python package installed, and the environment variable ``MOONSHOT_API_KEY`` set with your API key. diff --git a/libs/community/langchain_community/chat_models/pai_eas_endpoint.py b/libs/community/langchain_community/chat_models/pai_eas_endpoint.py index c0257d4d364..e438ad25ee0 100644 --- a/libs/community/langchain_community/chat_models/pai_eas_endpoint.py +++ b/libs/community/langchain_community/chat_models/pai_eas_endpoint.py @@ -26,7 +26,7 @@ logger = logging.getLogger(__name__) class PaiEasChatEndpoint(BaseChatModel): - """Eas LLM Service chat model API. + """Alibaba Cloud PAI-EAS LLM Service chat model API. To use, must have a deployed eas chat llm service on AliCloud. One can set the environment variable ``eas_service_url`` and ``eas_service_token`` set with your eas diff --git a/libs/community/langchain_community/chat_models/premai.py b/libs/community/langchain_community/chat_models/premai.py index b0e9c83cf38..b509b8bf7db 100644 --- a/libs/community/langchain_community/chat_models/premai.py +++ b/libs/community/langchain_community/chat_models/premai.py @@ -159,7 +159,7 @@ def _messages_to_prompt_dict( class ChatPremAI(BaseChatModel, BaseModel): - """Use any LLM provider with Prem and Langchain. + """PremAI Chat models. To use, you will need to have an API key. You can find your existing API Key or generate a new one here: https://app.premai.io/api_keys/ @@ -357,6 +357,7 @@ def create_prem_retry_decorator( max_retries: int = 1, run_manager: Optional[Union[CallbackManagerForLLMRun]] = None, ) -> Callable[[Any], Any]: + """Create a retry decorator for PremAI API errors.""" import premai.models errors = [ diff --git a/libs/community/langchain_community/chat_models/solar.py b/libs/community/langchain_community/chat_models/solar.py index b5f64c37a16..dd466468fb8 100644 --- a/libs/community/langchain_community/chat_models/solar.py +++ b/libs/community/langchain_community/chat_models/solar.py @@ -10,7 +10,7 @@ from langchain_community.llms.solar import SOLAR_SERVICE_URL_BASE, SolarCommon class SolarChat(SolarCommon, ChatOpenAI): # type: ignore[misc] - """Wrapper around Solar large language models. + """Solar large language models. To use, you should have the ``openai`` python package installed, and the environment variable ``SOLAR_API_KEY`` set with your API key. diff --git a/libs/community/langchain_community/chat_models/sparkllm.py b/libs/community/langchain_community/chat_models/sparkllm.py index 9305b0ce378..e3b36bed9bf 100644 --- a/libs/community/langchain_community/chat_models/sparkllm.py +++ b/libs/community/langchain_community/chat_models/sparkllm.py @@ -89,7 +89,7 @@ def _convert_delta_to_message_chunk( class ChatSparkLLM(BaseChatModel): - """Wrapper around iFlyTek's Spark large language model. + """iFlyTek Spark large language model. To use, you should pass `app_id`, `api_key`, `api_secret` as a named parameter to the constructor OR set environment diff --git a/libs/community/langchain_community/chat_models/tongyi.py b/libs/community/langchain_community/chat_models/tongyi.py index 937d4311932..fe3c2c1d41d 100644 --- a/libs/community/langchain_community/chat_models/tongyi.py +++ b/libs/community/langchain_community/chat_models/tongyi.py @@ -61,6 +61,7 @@ logger = logging.getLogger(__name__) def convert_dict_to_message( _dict: Mapping[str, Any], is_chunk: bool = False ) -> Union[BaseMessage, BaseMessageChunk]: + """Convert a dict to a message.""" role = _dict["role"] content = _dict["content"] if role == "user": @@ -88,6 +89,7 @@ def convert_dict_to_message( def convert_message_chunk_to_message(message_chunk: BaseMessageChunk) -> BaseMessage: + """Convert a message chunk to a message.""" if isinstance(message_chunk, HumanMessageChunk): return HumanMessage(content=message_chunk.content) elif isinstance(message_chunk, AIMessageChunk): diff --git a/libs/community/langchain_community/chat_models/yandex.py b/libs/community/langchain_community/chat_models/yandex.py index 61ae77a4713..424de6f8cf0 100644 --- a/libs/community/langchain_community/chat_models/yandex.py +++ b/libs/community/langchain_community/chat_models/yandex.py @@ -53,7 +53,7 @@ def _parse_chat_history(history: List[BaseMessage]) -> List[Dict[str, str]]: class ChatYandexGPT(_BaseYandexGPT, BaseChatModel): - """Wrapper around YandexGPT large language models. + """YandexGPT large language models. There are two authentication options for the service account with the ``ai.languageModels.user`` role: diff --git a/libs/community/langchain_community/chat_models/zhipuai.py b/libs/community/langchain_community/chat_models/zhipuai.py index 23c9904b666..f367eb01c49 100644 --- a/libs/community/langchain_community/chat_models/zhipuai.py +++ b/libs/community/langchain_community/chat_models/zhipuai.py @@ -42,6 +42,7 @@ ZHIPUAI_API_BASE = "https://open.bigmodel.cn/api/paas/v4/chat/completions" @contextmanager def connect_sse(client: Any, method: str, url: str, **kwargs: Any) -> Iterator: + """Connect to a server-sent event stream.""" from httpx_sse import EventSource with client.stream(method, url, **kwargs) as response: @@ -52,6 +53,7 @@ def connect_sse(client: Any, method: str, url: str, **kwargs: Any) -> Iterator: async def aconnect_sse( client: Any, method: str, url: str, **kwargs: Any ) -> AsyncIterator: + """Async connect to a server-sent event stream.""" from httpx_sse import EventSource async with client.stream(method, url, **kwargs) as response: diff --git a/libs/community/langchain_community/docstore/arbitrary_fn.py b/libs/community/langchain_community/docstore/arbitrary_fn.py index 6495d37b5eb..a2eba5ddafd 100644 --- a/libs/community/langchain_community/docstore/arbitrary_fn.py +++ b/libs/community/langchain_community/docstore/arbitrary_fn.py @@ -6,7 +6,7 @@ from langchain_community.docstore.base import Docstore class DocstoreFn(Docstore): - """Langchain Docstore via arbitrary lookup function. + """Docstore via arbitrary lookup function. This is useful when: * it's expensive to construct an InMemoryDocstore/dict diff --git a/libs/community/langchain_community/docstore/wikipedia.py b/libs/community/langchain_community/docstore/wikipedia.py index cc7b6ae20e9..5f09b3e0c00 100644 --- a/libs/community/langchain_community/docstore/wikipedia.py +++ b/libs/community/langchain_community/docstore/wikipedia.py @@ -9,7 +9,7 @@ from langchain_community.docstore.base import Docstore class Wikipedia(Docstore): - """Wrapper around wikipedia API.""" + """Wikipedia API.""" def __init__(self) -> None: """Check that wikipedia package is installed.""" diff --git a/libs/community/langchain_community/document_compressors/openvino_rerank.py b/libs/community/langchain_community/document_compressors/openvino_rerank.py index 8917c53cb12..182b1c159ac 100644 --- a/libs/community/langchain_community/document_compressors/openvino_rerank.py +++ b/libs/community/langchain_community/document_compressors/openvino_rerank.py @@ -9,6 +9,8 @@ from langchain_core.pydantic_v1 import Field class RerankRequest: + """Request for reranking.""" + def __init__(self, query: Any = None, passages: Any = None): self.query = query self.passages = passages if passages is not None else [] diff --git a/libs/community/langchain_community/document_loaders/assemblyai.py b/libs/community/langchain_community/document_loaders/assemblyai.py index 32ec943bdf6..b7713d33bf4 100644 --- a/libs/community/langchain_community/document_loaders/assemblyai.py +++ b/libs/community/langchain_community/document_loaders/assemblyai.py @@ -29,8 +29,7 @@ class TranscriptFormat(Enum): class AssemblyAIAudioTranscriptLoader(BaseLoader): - """ - Loader for AssemblyAI audio transcripts. + """Load AssemblyAI audio transcripts. It uses the AssemblyAI API to transcribe audio files and loads the transcribed text into one or more Documents, @@ -110,7 +109,7 @@ class AssemblyAIAudioTranscriptLoader(BaseLoader): class AssemblyAIAudioLoaderById(BaseLoader): """ - Loader for AssemblyAI audio transcripts. + Load AssemblyAI audio transcripts. It uses the AssemblyAI API to get an existing transcription and loads the transcribed text into one or more Documents, diff --git a/libs/community/langchain_community/document_loaders/bilibili.py b/libs/community/langchain_community/document_loaders/bilibili.py index 4757ee3c797..192311f59da 100644 --- a/libs/community/langchain_community/document_loaders/bilibili.py +++ b/libs/community/langchain_community/document_loaders/bilibili.py @@ -15,7 +15,7 @@ AV_PATTERN = re.compile(r"av[0-9]+") class BiliBiliLoader(BaseLoader): """ - Loader for fetching transcripts from BiliBili videos. + Load fetching transcripts from BiliBili videos. """ def __init__( diff --git a/libs/community/langchain_community/document_transformers/long_context_reorder.py b/libs/community/langchain_community/document_transformers/long_context_reorder.py index 32eda6b4826..a047c2d1435 100644 --- a/libs/community/langchain_community/document_transformers/long_context_reorder.py +++ b/libs/community/langchain_community/document_transformers/long_context_reorder.py @@ -21,7 +21,9 @@ def _litm_reordering(documents: List[Document]) -> List[Document]: class LongContextReorder(BaseDocumentTransformer, BaseModel): - """Lost in the middle: + """Reorder long context. + + Lost in the middle: Performance degrades when models must access relevant information in the middle of long contexts. See: https://arxiv.org/abs//2307.03172""" diff --git a/libs/community/langchain_community/document_transformers/nuclia_text_transform.py b/libs/community/langchain_community/document_transformers/nuclia_text_transform.py index ed62f527e1c..47ef5709f6c 100644 --- a/libs/community/langchain_community/document_transformers/nuclia_text_transform.py +++ b/libs/community/langchain_community/document_transformers/nuclia_text_transform.py @@ -9,7 +9,8 @@ from langchain_community.tools.nuclia.tool import NucliaUnderstandingAPI class NucliaTextTransformer(BaseDocumentTransformer): - """ + """Nuclia Text Transformer. + The Nuclia Understanding API splits into paragraphs and sentences, identifies entities, provides a summary of the text and generates embeddings for all sentences. diff --git a/libs/community/langchain_community/embeddings/aleph_alpha.py b/libs/community/langchain_community/embeddings/aleph_alpha.py index 41f970673fd..24f6f9ebf2c 100644 --- a/libs/community/langchain_community/embeddings/aleph_alpha.py +++ b/libs/community/langchain_community/embeddings/aleph_alpha.py @@ -183,7 +183,7 @@ class AlephAlphaAsymmetricSemanticEmbedding(BaseModel, Embeddings): class AlephAlphaSymmetricSemanticEmbedding(AlephAlphaAsymmetricSemanticEmbedding): - """The symmetric version of the Aleph Alpha's semantic embeddings. + """Symmetric version of the Aleph Alpha's semantic embeddings. The main difference is that here, both the documents and queries are embedded with a SemanticRepresentation.Symmetric diff --git a/libs/community/langchain_community/embeddings/databricks.py b/libs/community/langchain_community/embeddings/databricks.py index ce4a7e856bd..8ea3867fa42 100644 --- a/libs/community/langchain_community/embeddings/databricks.py +++ b/libs/community/langchain_community/embeddings/databricks.py @@ -12,7 +12,7 @@ def _chunk(texts: List[str], size: int) -> Iterator[List[str]]: class DatabricksEmbeddings(MlflowEmbeddings): - """Wrapper around embeddings LLMs in Databricks. + """Databricks embeddings. To use, you should have the ``mlflow`` python package installed. For more information, see https://mlflow.org/docs/latest/llms/deployments. diff --git a/libs/community/langchain_community/embeddings/infinity_local.py b/libs/community/langchain_community/embeddings/infinity_local.py index a4f0d513ec5..3b94f716327 100644 --- a/libs/community/langchain_community/embeddings/infinity_local.py +++ b/libs/community/langchain_community/embeddings/infinity_local.py @@ -13,7 +13,9 @@ logger = getLogger(__name__) class InfinityEmbeddingsLocal(BaseModel, Embeddings): - """Optimized Embedding models https://github.com/michaelfeil/infinity + """Optimized Infinity embedding models. + + https://github.com/michaelfeil/infinity This class deploys a local Infinity instance to embed text. The class requires async usage. diff --git a/libs/community/langchain_community/embeddings/javelin_ai_gateway.py b/libs/community/langchain_community/embeddings/javelin_ai_gateway.py index 6ee376097e9..61baac869da 100644 --- a/libs/community/langchain_community/embeddings/javelin_ai_gateway.py +++ b/libs/community/langchain_community/embeddings/javelin_ai_gateway.py @@ -12,8 +12,7 @@ def _chunk(texts: List[str], size: int) -> Iterator[List[str]]: class JavelinAIGatewayEmbeddings(Embeddings, BaseModel): - """ - Wrapper around embeddings LLMs in the Javelin AI Gateway. + """Javelin AI Gateway embeddings. To use, you should have the ``javelin_sdk`` python package installed. For more information, see https://docs.getjavelin.io diff --git a/libs/community/langchain_community/embeddings/mlflow_gateway.py b/libs/community/langchain_community/embeddings/mlflow_gateway.py index ad54761cbe2..6e2fad408a3 100644 --- a/libs/community/langchain_community/embeddings/mlflow_gateway.py +++ b/libs/community/langchain_community/embeddings/mlflow_gateway.py @@ -13,8 +13,7 @@ def _chunk(texts: List[str], size: int) -> Iterator[List[str]]: class MlflowAIGatewayEmbeddings(Embeddings, BaseModel): - """ - Wrapper around embeddings LLMs in the MLflow AI Gateway. + """MLflow AI Gateway embeddings. To use, you should have the ``mlflow[gateway]`` python package installed. For more information, see https://mlflow.org/docs/latest/gateway/index.html. diff --git a/libs/community/langchain_community/embeddings/nemo.py b/libs/community/langchain_community/embeddings/nemo.py index 7ae0ab5da63..f0c33c67969 100644 --- a/libs/community/langchain_community/embeddings/nemo.py +++ b/libs/community/langchain_community/embeddings/nemo.py @@ -42,6 +42,8 @@ def is_endpoint_live(url: str, headers: Optional[dict], payload: Any) -> bool: class NeMoEmbeddings(BaseModel, Embeddings): + """NeMo embedding models.""" + batch_size: int = 16 model: str = "NV-Embed-QA-003" api_endpoint_url: str = "http://localhost:8088/v1/embeddings" diff --git a/libs/community/langchain_community/graphs/networkx_graph.py b/libs/community/langchain_community/graphs/networkx_graph.py index 7cafed62536..59c26479860 100644 --- a/libs/community/langchain_community/graphs/networkx_graph.py +++ b/libs/community/langchain_community/graphs/networkx_graph.py @@ -7,7 +7,7 @@ KG_TRIPLE_DELIMITER = "<|>" class KnowledgeTriple(NamedTuple): - """A triple in the graph.""" + """Knowledge triple in the graph.""" subject: str predicate: str diff --git a/libs/community/langchain_community/indexes/base.py b/libs/community/langchain_community/indexes/base.py index 46ef5bf2efa..97805d91e7d 100644 --- a/libs/community/langchain_community/indexes/base.py +++ b/libs/community/langchain_community/indexes/base.py @@ -8,7 +8,7 @@ NAMESPACE_UUID = uuid.UUID(int=1984) class RecordManager(ABC): - """An abstract base class representing the interface for a record manager.""" + """Abstract base class for a record manager.""" def __init__( self, diff --git a/libs/community/langchain_community/llms/cloudflare_workersai.py b/libs/community/langchain_community/llms/cloudflare_workersai.py index 840acdbdb81..54b41418c42 100644 --- a/libs/community/langchain_community/llms/cloudflare_workersai.py +++ b/libs/community/langchain_community/llms/cloudflare_workersai.py @@ -11,7 +11,7 @@ logger = logging.getLogger(__name__) class CloudflareWorkersAI(LLM): - """Langchain LLM class to help to access Cloudflare Workers AI service. + """Cloudflare Workers AI service. To use, you must provide an API token and account ID to access Cloudflare Workers AI, and diff --git a/libs/community/langchain_community/llms/databricks.py b/libs/community/langchain_community/llms/databricks.py index 715530f7a72..0debf87353a 100644 --- a/libs/community/langchain_community/llms/databricks.py +++ b/libs/community/langchain_community/llms/databricks.py @@ -161,7 +161,7 @@ class _DatabricksClusterDriverProxyClient(_DatabricksClientBase): def get_repl_context() -> Any: - """Gets the notebook REPL context if running inside a Databricks notebook. + """Get the notebook REPL context if running inside a Databricks notebook. Returns None otherwise. """ try: @@ -175,7 +175,7 @@ def get_repl_context() -> Any: def get_default_host() -> str: - """Gets the default Databricks workspace hostname. + """Get the default Databricks workspace hostname. Raises an error if the hostname cannot be automatically determined. """ host = os.getenv("DATABRICKS_HOST") @@ -195,7 +195,7 @@ def get_default_host() -> str: def get_default_api_token() -> str: - """Gets the default Databricks personal access token. + """Get the default Databricks personal access token. Raises an error if the token cannot be automatically determined. """ if api_token := os.getenv("DATABRICKS_TOKEN"): diff --git a/libs/community/langchain_community/llms/edenai.py b/libs/community/langchain_community/llms/edenai.py index fd1842d72a5..e397aa7a2aa 100644 --- a/libs/community/langchain_community/llms/edenai.py +++ b/libs/community/langchain_community/llms/edenai.py @@ -18,7 +18,7 @@ logger = logging.getLogger(__name__) class EdenAI(LLM): - """Wrapper around edenai models. + """EdenAI models. To use, you should have the environment variable ``EDENAI_API_KEY`` set with your API token. diff --git a/libs/community/langchain_community/llms/human.py b/libs/community/langchain_community/llms/human.py index ae1e627f30e..39473c0ee1e 100644 --- a/libs/community/langchain_community/llms/human.py +++ b/libs/community/langchain_community/llms/human.py @@ -33,9 +33,7 @@ def _collect_user_input( class HumanInputLLM(LLM): - """ - It returns user input as the response. - """ + """User input as the response.""" input_func: Callable = Field(default_factory=lambda: _collect_user_input) prompt_func: Callable[[str], None] = Field(default_factory=lambda: _display_prompt) diff --git a/libs/community/langchain_community/llms/ipex_llm.py b/libs/community/langchain_community/llms/ipex_llm.py index af847786d97..ed037701806 100644 --- a/libs/community/langchain_community/llms/ipex_llm.py +++ b/libs/community/langchain_community/llms/ipex_llm.py @@ -12,7 +12,7 @@ logger = logging.getLogger(__name__) class IpexLLM(LLM): - """Wrapper around the IpexLLM model + """IpexLLM model. Example: .. code-block:: python diff --git a/libs/community/langchain_community/llms/konko.py b/libs/community/langchain_community/llms/konko.py index 7bcd471d4e0..97ac3fdc8a4 100644 --- a/libs/community/langchain_community/llms/konko.py +++ b/libs/community/langchain_community/llms/konko.py @@ -16,7 +16,7 @@ logger = logging.getLogger(__name__) class Konko(LLM): - """Wrapper around Konko AI models. + """Konko AI models. To use, you'll need an API key. This can be passed in as init param ``konko_api_key`` or set as environment variable ``KONKO_API_KEY``. diff --git a/libs/community/langchain_community/llms/layerup_security.py b/libs/community/langchain_community/llms/layerup_security.py index 6faf14e1e39..2a383cd2eeb 100644 --- a/libs/community/langchain_community/llms/layerup_security.py +++ b/libs/community/langchain_community/llms/layerup_security.py @@ -9,6 +9,14 @@ logger = logging.getLogger(__name__) def default_guardrail_violation_handler(violation: dict) -> str: + """Default guardrail violation handler. + + Args: + violation (dict): The violation dictionary. + + Returns: + str: The canned response. + """ if violation.get("canned_response"): return violation["canned_response"] guardrail_name = ( @@ -22,6 +30,8 @@ def default_guardrail_violation_handler(violation: dict) -> str: class LayerupSecurity(LLM): + """Layerup Security LLM service.""" + llm: LLM layerup_api_key: str layerup_api_base_url: str = "https://api.uselayerup.com/v1" diff --git a/libs/community/langchain_community/llms/loading.py b/libs/community/langchain_community/llms/loading.py index 83a459265ed..05025b8e7a0 100644 --- a/libs/community/langchain_community/llms/loading.py +++ b/libs/community/langchain_community/llms/loading.py @@ -34,6 +34,7 @@ def load_llm_from_config(config: dict, **kwargs: Any) -> BaseLLM: def load_llm(file: Union[str, Path], **kwargs: Any) -> BaseLLM: + """Load LLM from a file.""" # Convert file to Path object. if isinstance(file, str): file_path = Path(file) diff --git a/libs/community/langchain_community/llms/mlflow.py b/libs/community/langchain_community/llms/mlflow.py index ff2817de8a8..9b27ed57d87 100644 --- a/libs/community/langchain_community/llms/mlflow.py +++ b/libs/community/langchain_community/llms/mlflow.py @@ -9,7 +9,7 @@ from langchain_core.pydantic_v1 import Field, PrivateAttr class Mlflow(LLM): - """Wrapper around completions LLMs in MLflow. + """MLflow LLM service. To use, you should have the `mlflow[genai]` python package installed. For more information, see https://mlflow.org/docs/latest/llms/deployments. diff --git a/libs/community/langchain_community/llms/mlflow_ai_gateway.py b/libs/community/langchain_community/llms/mlflow_ai_gateway.py index 776307a6bd3..1909b8901a6 100644 --- a/libs/community/langchain_community/llms/mlflow_ai_gateway.py +++ b/libs/community/langchain_community/llms/mlflow_ai_gateway.py @@ -21,8 +21,7 @@ class Params(BaseModel, extra=Extra.allow): # type: ignore[call-arg] class MlflowAIGateway(LLM): - """ - Wrapper around completions LLMs in the MLflow AI Gateway. + """MLflow AI Gateway LLMs. To use, you should have the ``mlflow[gateway]`` python package installed. For more information, see https://mlflow.org/docs/latest/gateway/index.html. diff --git a/libs/community/langchain_community/llms/moonshot.py b/libs/community/langchain_community/llms/moonshot.py index 7fa5db33d13..d72659f1266 100644 --- a/libs/community/langchain_community/llms/moonshot.py +++ b/libs/community/langchain_community/llms/moonshot.py @@ -31,6 +31,8 @@ class _MoonshotClient(BaseModel): class MoonshotCommon(BaseModel): + """Common parameters for Moonshot LLMs.""" + _client: _MoonshotClient base_url: str = MOONSHOT_SERVICE_URL_BASE moonshot_api_key: Optional[SecretStr] = Field(default=None, alias="api_key") diff --git a/libs/community/langchain_community/llms/opaqueprompts.py b/libs/community/langchain_community/llms/opaqueprompts.py index 34f14c515c1..9be25d4d236 100644 --- a/libs/community/langchain_community/llms/opaqueprompts.py +++ b/libs/community/langchain_community/llms/opaqueprompts.py @@ -11,7 +11,7 @@ logger = logging.getLogger(__name__) class OpaquePrompts(LLM): - """An LLM wrapper that uses OpaquePrompts to sanitize prompts. + """LLM that uses OpaquePrompts to sanitize prompts. Wraps another LLM and sanitizes prompts before passing it to the LLM, then de-sanitizes the response. diff --git a/libs/community/langchain_community/llms/promptlayer_openai.py b/libs/community/langchain_community/llms/promptlayer_openai.py index cb904476e8b..15456a73996 100644 --- a/libs/community/langchain_community/llms/promptlayer_openai.py +++ b/libs/community/langchain_community/llms/promptlayer_openai.py @@ -124,7 +124,7 @@ class PromptLayerOpenAI(OpenAI): class PromptLayerOpenAIChat(OpenAIChat): - """Wrapper around OpenAI large language models. + """PromptLayer OpenAI large language models. To use, you should have the ``openai`` and ``promptlayer`` python package installed, and the environment variable ``OPENAI_API_KEY`` diff --git a/libs/community/langchain_community/llms/sagemaker_endpoint.py b/libs/community/langchain_community/llms/sagemaker_endpoint.py index 7ca76fc411b..7027a3ffa56 100644 --- a/libs/community/langchain_community/llms/sagemaker_endpoint.py +++ b/libs/community/langchain_community/llms/sagemaker_endpoint.py @@ -15,8 +15,7 @@ OUTPUT_TYPE = TypeVar("OUTPUT_TYPE", bound=Union[str, List[List[float]], Iterato class LineIterator: - """ - A helper class for parsing the byte stream input. + """Parse the byte stream input. The output of the model will be in the following format: @@ -74,7 +73,7 @@ class LineIterator: class ContentHandlerBase(Generic[INPUT_TYPE, OUTPUT_TYPE]): - """A handler class to transform input from LLM to a + """Handler class to transform input from LLM to a format that SageMaker endpoint expects. Similarly, the class handles transforming output from the diff --git a/libs/community/langchain_community/llms/sparkllm.py b/libs/community/langchain_community/llms/sparkllm.py index e7596929c98..467952f35cb 100644 --- a/libs/community/langchain_community/llms/sparkllm.py +++ b/libs/community/langchain_community/llms/sparkllm.py @@ -24,7 +24,7 @@ logger = logging.getLogger(__name__) class SparkLLM(LLM): - """Wrapper around iFlyTek's Spark large language model. + """iFlyTek Spark large language model. To use, you should pass `app_id`, `api_key`, `api_secret` as a named parameter to the constructor OR set environment diff --git a/libs/community/langchain_community/llms/titan_takeoff.py b/libs/community/langchain_community/llms/titan_takeoff.py index 9140aa0bc3a..b2007ccdea2 100644 --- a/libs/community/langchain_community/llms/titan_takeoff.py +++ b/libs/community/langchain_community/llms/titan_takeoff.py @@ -10,7 +10,7 @@ from langchain_community.llms.utils import enforce_stop_tokens class TitanTakeoff(LLM): - """Wrapper around Titan Takeoff APIs.""" + """Titan Takeoff API LLMs.""" base_url: str = "http://localhost:8000" """Specifies the baseURL to use for the Titan Takeoff API. diff --git a/libs/community/langchain_community/llms/vertexai.py b/libs/community/langchain_community/llms/vertexai.py index b93cdbafb7f..b8ba8c54f28 100644 --- a/libs/community/langchain_community/llms/vertexai.py +++ b/libs/community/langchain_community/llms/vertexai.py @@ -40,12 +40,12 @@ stream_completion_with_retry = None def is_codey_model(model_name: str) -> bool: - """Returns True if the model name is a Codey model.""" + """Return True if the model name is a Codey model.""" return "code" in model_name def is_gemini_model(model_name: str) -> bool: - """Returns True if the model name is a Gemini model.""" + """Return True if the model name is a Gemini model.""" return model_name is not None and "gemini" in model_name @@ -397,7 +397,7 @@ class VertexAI(_VertexAICommon, BaseLLM): alternative_import="langchain_google_vertexai.VertexAIModelGarden", ) class VertexAIModelGarden(_VertexAIBase, BaseLLM): - """Large language models served from Vertex AI Model Garden.""" + """Vertex AI Model Garden large language models.""" client: "PredictionServiceClient" = None #: :meta private: async_client: "PredictionServiceAsyncClient" = None #: :meta private: diff --git a/libs/community/langchain_community/retrievers/arcee.py b/libs/community/langchain_community/retrievers/arcee.py index dbe4449fd9a..b7e645c9343 100644 --- a/libs/community/langchain_community/retrievers/arcee.py +++ b/libs/community/langchain_community/retrievers/arcee.py @@ -10,7 +10,7 @@ from langchain_community.utilities.arcee import ArceeWrapper, DALMFilter class ArceeRetriever(BaseRetriever): - """Retriever for Arcee's Domain Adapted Language Models (DALMs). + """Arcee Domain Adapted Language Models (DALMs) retriever. To use, set the ``ARCEE_API_KEY`` environment variable with your Arcee API key, or pass ``arcee_api_key`` as a named parameter. diff --git a/libs/community/langchain_community/retrievers/you.py b/libs/community/langchain_community/retrievers/you.py index 5d3b19e4302..8ce080545af 100644 --- a/libs/community/langchain_community/retrievers/you.py +++ b/libs/community/langchain_community/retrievers/you.py @@ -11,7 +11,8 @@ from langchain_community.utilities import YouSearchAPIWrapper class YouRetriever(BaseRetriever, YouSearchAPIWrapper): - """`You` retriever that uses You.com's search API. + """You.com Search API retriever. + It wraps results() to get_relevant_documents It uses all YouSearchAPIWrapper arguments without any change. """ diff --git a/libs/community/langchain_community/tools/cogniswitch/tool.py b/libs/community/langchain_community/tools/cogniswitch/tool.py index e2878e6ed54..514b3b97b16 100644 --- a/libs/community/langchain_community/tools/cogniswitch/tool.py +++ b/libs/community/langchain_community/tools/cogniswitch/tool.py @@ -8,8 +8,8 @@ from langchain_core.tools import BaseTool class CogniswitchKnowledgeRequest(BaseTool): - """ - A tool for interacting with the Cogniswitch service to answer questions. + """Tool that uses the Cogniswitch service to answer questions. + name: str = "cogniswitch_knowledge_request" description: str = ( "A wrapper around cogniswitch service to answer the question @@ -81,9 +81,9 @@ class CogniswitchKnowledgeRequest(BaseTool): class CogniswitchKnowledgeStatus(BaseTool): - """ - A cogniswitch tool for interacting with the Cogniswitch services to know the + """Tool that uses the Cogniswitch services to get the status of the document or url uploaded. + name: str = "cogniswitch_knowledge_status" description: str = ( "A wrapper around cogniswitch services to know the status of @@ -181,8 +181,8 @@ class CogniswitchKnowledgeStatus(BaseTool): class CogniswitchKnowledgeSourceFile(BaseTool): - """ - A cogniswitch tool for interacting with the Cogniswitch services to store data. + """Tool that uses the Cogniswitch services to store data from file. + name: str = "cogniswitch_knowledge_source_file" description: str = ( "This calls the CogniSwitch services to analyze & store data from a file. @@ -294,8 +294,8 @@ class CogniswitchKnowledgeSourceFile(BaseTool): class CogniswitchKnowledgeSourceURL(BaseTool): - """ - A cogniswitch tool for interacting with the Cogniswitch services to store data. + """Tool that uses the Cogniswitch services to store data from a URL. + name: str = "cogniswitch_knowledge_source_url" description: str = ( "This calls the CogniSwitch services to analyze & store data from a url. diff --git a/libs/community/langchain_community/tools/connery/service.py b/libs/community/langchain_community/tools/connery/service.py index decc9a440f5..b8606a9317a 100644 --- a/libs/community/langchain_community/tools/connery/service.py +++ b/libs/community/langchain_community/tools/connery/service.py @@ -10,8 +10,8 @@ from langchain_community.tools.connery.tool import ConneryAction class ConneryService(BaseModel): - """ - A service for interacting with the Connery Runner API. + """Service for interacting with the Connery Runner API. + It gets the list of available actions from the Connery Runner, wraps them in ConneryAction Tools and returns them to the user. It also provides a method for running the actions. diff --git a/libs/community/langchain_community/tools/connery/tool.py b/libs/community/langchain_community/tools/connery/tool.py index 359a4dd75e1..51138714e26 100644 --- a/libs/community/langchain_community/tools/connery/tool.py +++ b/libs/community/langchain_community/tools/connery/tool.py @@ -13,9 +13,7 @@ from langchain_community.tools.connery.models import Action, Parameter class ConneryAction(BaseTool): - """ - A LangChain Tool wrapping a Connery Action. - """ + """Connery Action tool.""" name: str description: str diff --git a/libs/community/langchain_community/tools/office365/events_search.py b/libs/community/langchain_community/tools/office365/events_search.py index 8cb16f7a299..f74927e507b 100644 --- a/libs/community/langchain_community/tools/office365/events_search.py +++ b/libs/community/langchain_community/tools/office365/events_search.py @@ -54,7 +54,7 @@ class SearchEventsInput(BaseModel): class O365SearchEvents(O365BaseTool): - """Class for searching calendar events in Office 365 + """Search calendar events in Office 365. Free, but setup is required """ diff --git a/libs/community/langchain_community/tools/office365/messages_search.py b/libs/community/langchain_community/tools/office365/messages_search.py index ad26e42de4e..3b12b2a15ab 100644 --- a/libs/community/langchain_community/tools/office365/messages_search.py +++ b/libs/community/langchain_community/tools/office365/messages_search.py @@ -53,9 +53,9 @@ class SearchEmailsInput(BaseModel): class O365SearchEmails(O365BaseTool): - """Class for searching email messages in Office 365 + """Search email messages in Office 365. - Free, but setup is required + Free, but setup is required. """ name: str = "messages_search" diff --git a/libs/community/langchain_community/tools/office365/send_message.py b/libs/community/langchain_community/tools/office365/send_message.py index cd7abef976b..828e9e4fa61 100644 --- a/libs/community/langchain_community/tools/office365/send_message.py +++ b/libs/community/langchain_community/tools/office365/send_message.py @@ -32,7 +32,7 @@ class SendMessageSchema(BaseModel): class O365SendMessage(O365BaseTool): - """Tool for sending an email in Office 365.""" + """Send an email in Office 365.""" name: str = "send_email" description: str = ( diff --git a/libs/community/langchain_community/tools/office365/utils.py b/libs/community/langchain_community/tools/office365/utils.py index f13c10dde1c..168fe1ccb45 100644 --- a/libs/community/langchain_community/tools/office365/utils.py +++ b/libs/community/langchain_community/tools/office365/utils.py @@ -36,7 +36,7 @@ def clean_body(body: str) -> str: def authenticate() -> Account: - """Authenticate using the Microsoft Grah API""" + """Authenticate using the Microsoft Graph API""" try: from O365 import Account except ImportError as e: diff --git a/libs/community/langchain_community/tools/you/tool.py b/libs/community/langchain_community/tools/you/tool.py index 75e18a1b623..75b06bd0139 100644 --- a/libs/community/langchain_community/tools/you/tool.py +++ b/libs/community/langchain_community/tools/you/tool.py @@ -12,11 +12,13 @@ from langchain_community.utilities.you import YouSearchAPIWrapper class YouInput(BaseModel): + """Input schema for the you.com tool.""" + query: str = Field(description="should be a search query") class YouSearchTool(BaseTool): - """Tool that searches the you.com API""" + """Tool that searches the you.com API.""" name = "you_search" description = ( diff --git a/libs/community/langchain_community/tools/zapier/tool.py b/libs/community/langchain_community/tools/zapier/tool.py index 3d5f3955546..22a25b13a97 100644 --- a/libs/community/langchain_community/tools/zapier/tool.py +++ b/libs/community/langchain_community/tools/zapier/tool.py @@ -82,8 +82,9 @@ from langchain_community.utilities.zapier import ZapierNLAWrapper class ZapierNLARunAction(BaseTool): - """ - Args: + """Tool to run a specific action from the user's exposed actions. + + Params: action_id: a specific action ID (from list actions) of the action to execute (the set api_key must be associated with the action owner) instructions: a natural language instruction string for using the action @@ -167,11 +168,7 @@ ZapierNLARunAction.__doc__ = ( class ZapierNLAListActions(BaseTool): - """ - Args: - None - - """ + """Tool to list all exposed actions for the user.""" name: str = "ZapierNLA_list_actions" description: str = BASE_ZAPIER_TOOL_PROMPT + ( diff --git a/libs/community/langchain_community/utilities/astradb.py b/libs/community/langchain_community/utilities/astradb.py index c113d660792..1df76730498 100644 --- a/libs/community/langchain_community/utilities/astradb.py +++ b/libs/community/langchain_community/utilities/astradb.py @@ -14,6 +14,8 @@ if TYPE_CHECKING: class SetupMode(Enum): + """Setup mode for AstraDBEnvironment as enumerator.""" + SYNC = 1 ASYNC = 2 OFF = 3 diff --git a/libs/community/langchain_community/utilities/pebblo.py b/libs/community/langchain_community/utilities/pebblo.py index 5319b17400a..da65a5835dd 100644 --- a/libs/community/langchain_community/utilities/pebblo.py +++ b/libs/community/langchain_community/utilities/pebblo.py @@ -62,7 +62,7 @@ logger = logging.getLogger(__name__) class Runtime(BaseModel): - """This class represents a Runtime. + """Pebblo Runtime. Args: type (Optional[str]): Runtime type. Defaults to "" @@ -90,7 +90,7 @@ class Runtime(BaseModel): class Framework(BaseModel): - """This class represents a Framework instance. + """Pebblo Framework instance. Args: name (str): Name of the Framework. @@ -102,7 +102,7 @@ class Framework(BaseModel): class App(BaseModel): - """This class represents an AI application. + """Pebblo AI application. Args: name (str): Name of the app. @@ -124,7 +124,7 @@ class App(BaseModel): class Doc(BaseModel): - """This class represents a pebblo document. + """Pebblo document. Args: name (str): Name of app originating this document. @@ -148,8 +148,8 @@ class Doc(BaseModel): def get_full_path(path: str) -> str: - """Return absolute local path for a local file/directory, - for network related path, return as is. + """Return an absolute local path for a local file/directory, + for a network related path, return as is. Args: path (str): Relative path to be resolved. @@ -184,7 +184,7 @@ def get_loader_type(loader: str) -> str: def get_loader_full_path(loader: BaseLoader) -> str: - """Return absolute source path of source of loader based on the + """Return an absolute source path of source of loader based on the keys present in Document object from loader. Args: @@ -266,7 +266,7 @@ def get_runtime() -> Tuple[Framework, Runtime]: def get_ip() -> str: - """Fetch local runtime ip address + """Fetch local runtime ip address. Returns: str: IP address diff --git a/libs/community/langchain_community/utilities/vertexai.py b/libs/community/langchain_community/utilities/vertexai.py index 1dc1f14b3f8..6a8023b36ca 100644 --- a/libs/community/langchain_community/utilities/vertexai.py +++ b/libs/community/langchain_community/utilities/vertexai.py @@ -22,7 +22,7 @@ def create_retry_decorator( Union[AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun] ] = None, ) -> Callable[[Any], Any]: - """Creates a retry decorator for Vertex / Palm LLMs.""" + """Create a retry decorator for Vertex / Palm LLMs.""" import google.api_core errors = [ @@ -82,7 +82,7 @@ def init_vertexai( def get_client_info(module: Optional[str] = None) -> "ClientInfo": - r"""Returns a custom user agent header. + r"""Return a custom user agent header. Args: module (Optional[str]): @@ -109,7 +109,7 @@ def get_client_info(module: Optional[str] = None) -> "ClientInfo": def load_image_from_gcs(path: str, project: Optional[str] = None) -> "Image": - """Loads im Image from GCS.""" + """Load an image from Google Cloud Storage.""" try: from google.cloud import storage except ImportError: diff --git a/libs/community/langchain_community/utilities/you.py b/libs/community/langchain_community/utilities/you.py index 119b79bc0ed..b74841c868b 100644 --- a/libs/community/langchain_community/utilities/you.py +++ b/libs/community/langchain_community/utilities/you.py @@ -29,7 +29,7 @@ class YouHit(YouHitMetadata): class YouAPIOutput(BaseModel): - """The output from you.com api""" + """Output from you.com API.""" hits: List[YouHit] = Field( description="A list of dictionaries containing the results" @@ -37,7 +37,7 @@ class YouAPIOutput(BaseModel): class YouDocument(BaseModel): - """The output of parsing one snippet""" + """Output of parsing one snippet.""" page_content: str = Field(description="One snippet of text") metadata: YouHitMetadata diff --git a/libs/community/langchain_community/utils/ernie_functions.py b/libs/community/langchain_community/utils/ernie_functions.py index 7fa3580bce4..4166de1bfd3 100644 --- a/libs/community/langchain_community/utils/ernie_functions.py +++ b/libs/community/langchain_community/utils/ernie_functions.py @@ -28,7 +28,7 @@ def convert_pydantic_to_ernie_function( name: Optional[str] = None, description: Optional[str] = None, ) -> FunctionDescription: - """Converts a Pydantic model to a function description for the Ernie API.""" + """Convert a Pydantic model to a function description for the Ernie API.""" schema = dereference_refs(model.schema()) schema.pop("definitions", None) return { @@ -44,7 +44,7 @@ def convert_pydantic_to_ernie_tool( name: Optional[str] = None, description: Optional[str] = None, ) -> ToolDescription: - """Converts a Pydantic model to a function description for the Ernie API.""" + """Convert a Pydantic model to a function description for the Ernie API.""" function = convert_pydantic_to_ernie_function( model, name=name, description=description ) diff --git a/libs/community/langchain_community/utils/google.py b/libs/community/langchain_community/utils/google.py index 4e68512296b..18028c65001 100644 --- a/libs/community/langchain_community/utils/google.py +++ b/libs/community/langchain_community/utils/google.py @@ -5,7 +5,7 @@ from typing import Any, Optional def get_client_info(module: Optional[str] = None) -> Any: - r"""Returns a custom user agent header. + r"""Return a custom user agent header. Args: module (Optional[str]): diff --git a/libs/community/langchain_community/vectorstores/neo4j_vector.py b/libs/community/langchain_community/vectorstores/neo4j_vector.py index 4fd6cee51d6..8cb51d7f2b9 100644 --- a/libs/community/langchain_community/vectorstores/neo4j_vector.py +++ b/libs/community/langchain_community/vectorstores/neo4j_vector.py @@ -139,7 +139,7 @@ def remove_lucene_chars(text: str) -> str: def dict_to_yaml_str(input_dict: Dict, indent: int = 0) -> str: """ - Converts a dictionary to a YAML-like string without using external libraries. + Convert a dictionary to a YAML-like string without using external libraries. Parameters: - input_dict (dict): The dictionary to convert. @@ -165,6 +165,8 @@ def dict_to_yaml_str(input_dict: Dict, indent: int = 0) -> str: def combine_queries( input_queries: List[Tuple[str, Dict[str, Any]]], operator: str ) -> Tuple[str, Dict[str, Any]]: + """Combine multiple queries with an operator.""" + # Initialize variables to hold the combined query and parameters combined_query: str = "" combined_params: Dict = {} @@ -197,8 +199,7 @@ def combine_queries( def collect_params( input_data: List[Tuple[str, Dict[str, str]]], ) -> Tuple[List[str], Dict[str, Any]]: - """ - Transform the input data into the desired format. + """Transform the input data into the desired format. Args: - input_data (list of tuples): Input data to transform. @@ -324,6 +325,15 @@ def _handle_field_filter( def construct_metadata_filter(filter: Dict[str, Any]) -> Tuple[str, Dict]: + """Construct a metadata filter. + + Args: + filter: A dictionary representing the filter condition. + + Returns: + Tuple[str, Dict] + """ + if isinstance(filter, dict): if len(filter) == 1: # The only operators allowed at the top level are $AND and $OR diff --git a/libs/community/langchain_community/vectorstores/redis/filters.py b/libs/community/langchain_community/vectorstores/redis/filters.py index 8ec492ee2cb..09a58bd281d 100644 --- a/libs/community/langchain_community/vectorstores/redis/filters.py +++ b/libs/community/langchain_community/vectorstores/redis/filters.py @@ -100,7 +100,7 @@ def check_operator_misuse(func: Callable) -> Callable: class RedisTag(RedisFilterField): - """A RedisFilterField representing a tag in a Redis index.""" + """RedisFilterField representing a tag in a Redis index.""" OPERATORS: Dict[RedisFilterOperator, str] = { RedisFilterOperator.EQ: "==", @@ -192,7 +192,7 @@ class RedisTag(RedisFilterField): class RedisNum(RedisFilterField): - """A RedisFilterField representing a numeric field in a Redis index.""" + """RedisFilterField representing a numeric field in a Redis index.""" OPERATORS: Dict[RedisFilterOperator, str] = { RedisFilterOperator.EQ: "==", @@ -311,7 +311,7 @@ class RedisNum(RedisFilterField): class RedisText(RedisFilterField): - """A RedisFilterField representing a text field in a Redis index.""" + """RedisFilterField representing a text field in a Redis index.""" OPERATORS: Dict[RedisFilterOperator, str] = { RedisFilterOperator.EQ: "==", @@ -381,7 +381,7 @@ class RedisText(RedisFilterField): class RedisFilterExpression: - """A logical expression of RedisFilterFields. + """Logical expression of RedisFilterFields. RedisFilterExpressions can be combined using the & and | operators to create complex logical expressions that evaluate to the Redis Query language. diff --git a/libs/community/langchain_community/vectorstores/redis/schema.py b/libs/community/langchain_community/vectorstores/redis/schema.py index 8269b71f699..5b8618797eb 100644 --- a/libs/community/langchain_community/vectorstores/redis/schema.py +++ b/libs/community/langchain_community/vectorstores/redis/schema.py @@ -285,7 +285,7 @@ class RedisModel(BaseModel): def read_schema( index_schema: Optional[Union[Dict[str, List[Any]], str, os.PathLike]], ) -> Dict[str, Any]: - """Reads in the index schema from a dict or yaml file. + """Read in the index schema from a dict or yaml file. Check if it is a dict and return RedisModel otherwise, check if it's a path and read in the file assuming it's a yaml file and return a RedisModel diff --git a/libs/community/langchain_community/vectorstores/sklearn.py b/libs/community/langchain_community/vectorstores/sklearn.py index 685e2e28e4e..8194e31db61 100644 --- a/libs/community/langchain_community/vectorstores/sklearn.py +++ b/libs/community/langchain_community/vectorstores/sklearn.py @@ -42,7 +42,7 @@ class BaseSerializer(ABC): class JsonSerializer(BaseSerializer): - """Serializes data in json using the json package from python standard library.""" + """Serialize data in JSON using the json package from python standard library.""" @classmethod def extension(cls) -> str: @@ -58,7 +58,7 @@ class JsonSerializer(BaseSerializer): class BsonSerializer(BaseSerializer): - """Serializes data in binary json using the `bson` python package.""" + """Serialize data in Binary JSON using the `bson` python package.""" def __init__(self, persist_path: str) -> None: super().__init__(persist_path) @@ -78,7 +78,7 @@ class BsonSerializer(BaseSerializer): class ParquetSerializer(BaseSerializer): - """Serializes data in `Apache Parquet` format using the `pyarrow` package.""" + """Serialize data in `Apache Parquet` format using the `pyarrow` package.""" def __init__(self, persist_path: str) -> None: super().__init__(persist_path) diff --git a/libs/community/langchain_community/vectorstores/sqlitevss.py b/libs/community/langchain_community/vectorstores/sqlitevss.py index 60551d02066..3ea9f427700 100644 --- a/libs/community/langchain_community/vectorstores/sqlitevss.py +++ b/libs/community/langchain_community/vectorstores/sqlitevss.py @@ -24,7 +24,8 @@ logger = logging.getLogger(__name__) class SQLiteVSS(VectorStore): - """Wrapper around SQLite with vss extension as a vector database. + """SQLite with VSS extension as a vector database. + To use, you should have the ``sqlite-vss`` python package installed. Example: .. code-block:: python diff --git a/libs/community/langchain_community/vectorstores/tidb_vector.py b/libs/community/langchain_community/vectorstores/tidb_vector.py index 958ba7f52db..e98d3bb6c41 100644 --- a/libs/community/langchain_community/vectorstores/tidb_vector.py +++ b/libs/community/langchain_community/vectorstores/tidb_vector.py @@ -10,6 +10,8 @@ DEFAULT_TiDB_VECTOR_TABLE_NAME = "langchain_vector" class TiDBVectorStore(VectorStore): + """TiDB Vector Store.""" + def __init__( self, connection_string: str, diff --git a/libs/community/langchain_community/vectorstores/vald.py b/libs/community/langchain_community/vectorstores/vald.py index 6b6abae4e92..31102ce0f75 100644 --- a/libs/community/langchain_community/vectorstores/vald.py +++ b/libs/community/langchain_community/vectorstores/vald.py @@ -12,7 +12,7 @@ from langchain_community.vectorstores.utils import maximal_marginal_relevance class Vald(VectorStore): - """Wrapper around Vald vector database. + """Vald vector database. To use, you should have the ``vald-client-python`` python package installed. diff --git a/libs/community/langchain_community/vectorstores/vdms.py b/libs/community/langchain_community/vectorstores/vdms.py index d07c57469b0..52de71201b5 100644 --- a/libs/community/langchain_community/vectorstores/vdms.py +++ b/libs/community/langchain_community/vectorstores/vdms.py @@ -77,8 +77,7 @@ def _len_check_if_sized(x: Any, y: Any, x_name: str, y_name: str) -> None: def VDMS_Client(host: str = "localhost", port: int = 55555) -> vdms.vdms: - """ - Wrapper to initiate and connect a VDMS client to a VDMS server + """VDMS client for the VDMS server. Args: host: IP or hostname of VDMS server @@ -98,7 +97,7 @@ def VDMS_Client(host: str = "localhost", port: int = 55555) -> vdms.vdms: class VDMS(VectorStore): - """Wrapper around Intel Lab's VDMS for vector-store workloads. + """Intel Lab's VDMS for vector-store workloads. To use, you should have both: - the ``vdms`` python package installed @@ -1534,6 +1533,8 @@ def _check_descriptor_exists_by_id( def embedding2bytes(embedding: Union[List[float], None]) -> Union[bytes, None]: + """Convert embedding to bytes.""" + blob = None if embedding is not None: emb = np.array(embedding, dtype="float32") diff --git a/libs/community/langchain_community/vectorstores/vectara.py b/libs/community/langchain_community/vectorstores/vectara.py index edebc3f4133..2c66d38f84f 100644 --- a/libs/community/langchain_community/vectorstores/vectara.py +++ b/libs/community/langchain_community/vectorstores/vectara.py @@ -18,7 +18,8 @@ logger = logging.getLogger(__name__) @dataclass class SummaryConfig: - """ + """Configuration for summary generation. + is_enabled: True if summary is enabled, False otherwise max_results: maximum number of results to summarize response_lang: requested language for the summary @@ -34,7 +35,8 @@ class SummaryConfig: @dataclass class MMRConfig: - """ + """Configuration for Maximal Marginal Relevance (MMR) search. + is_enabled: True if MMR is enabled, False otherwise mmr_k: number of results to fetch for MMR, defaults to 50 diversity_bias: number between 0 and 1 that determines the degree @@ -53,7 +55,8 @@ class MMRConfig: @dataclass class VectaraQueryConfig: - """ + """Configuration for Vectara query. + k: Number of Documents to return. Defaults to 10. lambda_val: lexical match parameter for hybrid search. filter Dictionary of argument(s) to filter on metadata. For example a @@ -566,7 +569,7 @@ class Vectara(VectorStore): class VectaraRetriever(VectorStoreRetriever): - """Retriever class for `Vectara`.""" + """Retriever for `Vectara`.""" vectorstore: Vectara """Vectara vectorstore.""" diff --git a/libs/community/langchain_community/vectorstores/yellowbrick.py b/libs/community/langchain_community/vectorstores/yellowbrick.py index d7f1a159f3e..e3e5504346a 100644 --- a/libs/community/langchain_community/vectorstores/yellowbrick.py +++ b/libs/community/langchain_community/vectorstores/yellowbrick.py @@ -23,7 +23,8 @@ logger = logging.getLogger(__name__) class Yellowbrick(VectorStore): - """Wrapper around Yellowbrick as a vector database. + """Yellowbrick as a vector database. + Example: .. code-block:: python from langchain_community.vectorstores import Yellowbrick