diff --git a/libs/experimental/langchain_experimental/agents/__init__.py b/libs/experimental/langchain_experimental/agents/__init__.py index 57affee471b..fc1e4ef8978 100644 --- a/libs/experimental/langchain_experimental/agents/__init__.py +++ b/libs/experimental/langchain_experimental/agents/__init__.py @@ -1,3 +1,12 @@ +"""**Agent** is a class that uses an LLM to choose +a sequence of actions to take. + +In Chains, a sequence of actions is hardcoded. In Agents, +a language model is used as a reasoning engine to determine which actions +to take and in which order. + +Agents select and use **Tools** and **Toolkits** for actions. +""" # noqa: E501 from langchain_experimental.agents.agent_toolkits import ( create_csv_agent, create_pandas_dataframe_agent, diff --git a/libs/experimental/langchain_experimental/autonomous_agents/__init__.py b/libs/experimental/langchain_experimental/autonomous_agents/__init__.py index 080a6d5a99f..15ce2cb68d6 100644 --- a/libs/experimental/langchain_experimental/autonomous_agents/__init__.py +++ b/libs/experimental/langchain_experimental/autonomous_agents/__init__.py @@ -1,3 +1,15 @@ +"""**Autonomous agents** in the Langchain experimental package include +[AutoGPT](https://github.com/Significant-Gravitas/AutoGPT), +[BabyAGI](https://github.com/yoheinakajima/babyagi), +and [HuggingGPT](https://arxiv.org/abs/2303.17580) agents that +interact with language models autonomously. + +These agents have specific functionalities like memory management, +task creation, execution chains, and response generation. + +They differ from ordinary agents by their autonomous decision-making capabilities, +memory handling, and specialized functionalities for tasks and response. +""" from langchain_experimental.autonomous_agents.autogpt.agent import AutoGPT from langchain_experimental.autonomous_agents.baby_agi.baby_agi import BabyAGI from langchain_experimental.autonomous_agents.hugginggpt.hugginggpt import HuggingGPT diff --git a/libs/experimental/langchain_experimental/comprehend_moderation/__init__.py b/libs/experimental/langchain_experimental/comprehend_moderation/__init__.py index 4a265438f19..a8193b083ff 100644 --- a/libs/experimental/langchain_experimental/comprehend_moderation/__init__.py +++ b/libs/experimental/langchain_experimental/comprehend_moderation/__init__.py @@ -1,3 +1,23 @@ +""" +**Comprehend Moderation** is used to detect and handle `Personally Identifiable Information (PII)`, +`toxicity`, and `prompt safety` in text. + +The Langchain experimental package includes the **AmazonComprehendModerationChain** class +for the comprehend moderation tasks. It is based on `Amazon Comprehend` service. +This class can be configured with specific moderation settings like PII labels, redaction, +toxicity thresholds, and prompt safety thresholds. + +See more at https://aws.amazon.com/comprehend/ + +`Amazon Comprehend` service is used by several other classes: +- **ComprehendToxicity** class is used to check the toxicity of text prompts using + `AWS Comprehend service` and take actions based on the configuration +- **ComprehendPromptSafety** class is used to validate the safety of given prompt + text, raising an error if unsafe content is detected based on the specified threshold +- **ComprehendPII** class is designed to handle + `Personally Identifiable Information (PII)` moderation tasks, + detecting and managing PII entities in text inputs +""" # noqa: E501 from langchain_experimental.comprehend_moderation.amazon_comprehend_moderation import ( AmazonComprehendModerationChain, ) diff --git a/libs/experimental/langchain_experimental/cpal/__init__.py b/libs/experimental/langchain_experimental/cpal/__init__.py index e69de29bb2d..5bbca549593 100644 --- a/libs/experimental/langchain_experimental/cpal/__init__.py +++ b/libs/experimental/langchain_experimental/cpal/__init__.py @@ -0,0 +1,17 @@ +""" +**Causal program-aided language (CPAL)** is a concept implemented in LangChain as +a chain for causal modeling and narrative decomposition. + +CPAL improves upon the program-aided language (**PAL**) by incorporating +causal structure to prevent hallucination in language models, +particularly when dealing with complex narratives and math +problems with nested dependencies. + +CPAL involves translating causal narratives into a stack of operations, +setting hypothetical conditions for causal models, and decomposing +narratives into story elements. + +It allows for the creation of causal chains that define the relationships +between different elements in a narrative, enabling the modeling and analysis +of causal relationships within a given context. +""" diff --git a/libs/experimental/langchain_experimental/data_anonymizer/__init__.py b/libs/experimental/langchain_experimental/data_anonymizer/__init__.py index f43d6d98df5..1e57f743452 100644 --- a/libs/experimental/langchain_experimental/data_anonymizer/__init__.py +++ b/libs/experimental/langchain_experimental/data_anonymizer/__init__.py @@ -1,4 +1,13 @@ -"""Data anonymizer package""" +"""**Data anonymizer** contains both Anonymizers and Deanonymizers. +It uses the [Microsoft Presidio](https://microsoft.github.io/presidio/) library. + +**Anonymizers** are used to replace a `Personally Identifiable Information (PII)` +entity text with some other +value by applying a certain operator (e.g. replace, mask, redact, encrypt). + +**Deanonymizers** are used to revert the anonymization operation +(e.g. to decrypt an encrypted text). +""" from langchain_experimental.data_anonymizer.presidio import ( PresidioAnonymizer, PresidioReversibleAnonymizer, diff --git a/libs/experimental/langchain_experimental/fallacy_removal/__init__.py b/libs/experimental/langchain_experimental/fallacy_removal/__init__.py index 804990be4b6..2ce9701be6b 100644 --- a/libs/experimental/langchain_experimental/fallacy_removal/__init__.py +++ b/libs/experimental/langchain_experimental/fallacy_removal/__init__.py @@ -1,4 +1,7 @@ -"""The Chain runs a self-review of logical fallacies as determined by this paper \ -categorizing and defining logical fallacies https://arxiv.org/pdf/2212.07425.pdf. \ -Modeled after Constitutional AI and in same format, but applying logical \ -fallacies as generalized rules to remove in output""" +"""**Fallacy Removal** Chain runs a self-review of logical fallacies +as determined by paper +[Robust and Explainable Identification of Logical Fallacies in Natural +Language Arguments](https://arxiv.org/pdf/2212.07425.pdf). +It is modeled after `Constitutional AI` and in the same format, but applying logical +fallacies as generalized rules to remove them in output. +""" diff --git a/libs/experimental/langchain_experimental/generative_agents/__init__.py b/libs/experimental/langchain_experimental/generative_agents/__init__.py index 5012c512aac..532c1e70206 100644 --- a/libs/experimental/langchain_experimental/generative_agents/__init__.py +++ b/libs/experimental/langchain_experimental/generative_agents/__init__.py @@ -1,4 +1,4 @@ -"""Generative Agents primitives.""" +"""**Generative Agent** primitives.""" from langchain_experimental.generative_agents.generative_agent import GenerativeAgent from langchain_experimental.generative_agents.memory import GenerativeAgentMemory diff --git a/libs/experimental/langchain_experimental/graph_transformers/__init__.py b/libs/experimental/langchain_experimental/graph_transformers/__init__.py index 19d50bba6b5..ada53d24038 100644 --- a/libs/experimental/langchain_experimental/graph_transformers/__init__.py +++ b/libs/experimental/langchain_experimental/graph_transformers/__init__.py @@ -1,3 +1,4 @@ +"""**Graph Transformers** transform Documents into Graph Documents.""" from langchain_experimental.graph_transformers.diffbot import DiffbotGraphTransformer from langchain_experimental.graph_transformers.llm import LLMGraphTransformer diff --git a/libs/experimental/langchain_experimental/graph_transformers/llm.py b/libs/experimental/langchain_experimental/graph_transformers/llm.py index 0d0888f84be..34ff03a0099 100644 --- a/libs/experimental/langchain_experimental/graph_transformers/llm.py +++ b/libs/experimental/langchain_experimental/graph_transformers/llm.py @@ -143,24 +143,26 @@ def map_to_base_relationship(rel: Any) -> Relationship: class LLMGraphTransformer: - """ - A class designed to transform documents into graph-based documents using a LLM. + """Transform documents into graph-based documents using a LLM. + It allows specifying constraints on the types of nodes and relationships to include in the output graph. The class doesn't support neither extract and node or relationship properties Args: llm (BaseLanguageModel): An instance of a language model supporting structured - output. allowed_nodes (List[str], optional): Specifies which node types are - allowed in the graph. Defaults to an empty list, allowing all node types. + output. + allowed_nodes (List[str], optional): Specifies which node types are + allowed in the graph. Defaults to an empty list, allowing all node types. allowed_relationships (List[str], optional): Specifies which relationship types - are allowed in the graph. Defaults to an empty list, allowing all relationship - types. - prompt (Optional[ChatPromptTemplate], optional): The prompt to pass to the to - the LLM with additional instructions. + are allowed in the graph. Defaults to an empty list, allowing all relationship + types. + prompt (Optional[ChatPromptTemplate], optional): The prompt to pass to + the LLM with additional instructions. strict_mode (bool, optional): Determines whether the transformer should apply - filtering to strictly adhere to `allowed_nodes` and `allowed_relationships`. - Defaults to True. + filtering to strictly adhere to `allowed_nodes` and `allowed_relationships`. + Defaults to True. + Example: .. code-block:: python from langchain_experimental.graph_transformers import LLMGraphTransformer diff --git a/libs/experimental/langchain_experimental/llm_bash/__init__.py b/libs/experimental/langchain_experimental/llm_bash/__init__.py index e1e848a1a8f..cab96624b0d 100644 --- a/libs/experimental/langchain_experimental/llm_bash/__init__.py +++ b/libs/experimental/langchain_experimental/llm_bash/__init__.py @@ -1 +1,2 @@ -"""Chain that interprets a prompt and executes bash code to perform bash operations.""" +"""**LLM bash** is a chain that uses LLM to interpret a prompt and +executes **bash** code.""" diff --git a/libs/experimental/langchain_experimental/llm_symbolic_math/__init__.py b/libs/experimental/langchain_experimental/llm_symbolic_math/__init__.py index d6cde9105ad..a6c24bc0d3d 100644 --- a/libs/experimental/langchain_experimental/llm_symbolic_math/__init__.py +++ b/libs/experimental/langchain_experimental/llm_symbolic_math/__init__.py @@ -1,4 +1,4 @@ -"""Chain that interprets a prompt and executes python code to do math. +"""Chain that interprets a prompt and **executes python code to do math**. -Heavily borrowed from llm_math, wrapper for SymPy +Heavily borrowed from `llm_math`, uses the [SymPy](https://www.sympy.org/) package. """ diff --git a/libs/experimental/langchain_experimental/llms/__init__.py b/libs/experimental/langchain_experimental/llms/__init__.py index a45d1baab65..6825f1c9d74 100644 --- a/libs/experimental/langchain_experimental/llms/__init__.py +++ b/libs/experimental/langchain_experimental/llms/__init__.py @@ -1,5 +1,6 @@ -"""Experimental LLM wrappers.""" - +"""Experimental **LLM** classes provide +access to the large language model (**LLM**) APIs and services. +""" from langchain_experimental.llms.jsonformer_decoder import JsonFormer from langchain_experimental.llms.llamaapi import ChatLlamaAPI from langchain_experimental.llms.lmformatenforcer_decoder import LMFormatEnforcer diff --git a/libs/experimental/langchain_experimental/open_clip/__init__.py b/libs/experimental/langchain_experimental/open_clip/__init__.py index fdf91875404..ebf9afc60b1 100644 --- a/libs/experimental/langchain_experimental/open_clip/__init__.py +++ b/libs/experimental/langchain_experimental/open_clip/__init__.py @@ -1,3 +1,11 @@ +"""**OpenCLIP Embeddings** model. + +OpenCLIP is a multimodal model that can encode text and images into a shared space. + +See this paper for more details: https://arxiv.org/abs/2103.00020 +and [this repository](https://github.com/mlfoundations/open_clip) for details. + +""" from .open_clip import OpenCLIPEmbeddings __all__ = ["OpenCLIPEmbeddings"] diff --git a/libs/experimental/langchain_experimental/pal_chain/__init__.py b/libs/experimental/langchain_experimental/pal_chain/__init__.py index ed25c20a5ff..bba4e717f43 100644 --- a/libs/experimental/langchain_experimental/pal_chain/__init__.py +++ b/libs/experimental/langchain_experimental/pal_chain/__init__.py @@ -1,10 +1,9 @@ -"""Implements Program-Aided Language Models. +"""**PAL Chain** implements **Program-Aided Language** Models. -As in https://arxiv.org/pdf/2211.10435.pdf. +See the paper: https://arxiv.org/pdf/2211.10435.pdf. -This is vulnerable to arbitrary code execution: -https://github.com/langchain-ai/langchain/issues/5872 -""" +This chain is vulnerable to [arbitrary code execution](https://github.com/langchain-ai/langchain/issues/5872). +""" # noqa: E501 from langchain_experimental.pal_chain.base import PALChain __all__ = ["PALChain"] diff --git a/libs/experimental/langchain_experimental/plan_and_execute/__init__.py b/libs/experimental/langchain_experimental/plan_and_execute/__init__.py index e5cd8b934dd..3cd4626294a 100644 --- a/libs/experimental/langchain_experimental/plan_and_execute/__init__.py +++ b/libs/experimental/langchain_experimental/plan_and_execute/__init__.py @@ -1,3 +1,7 @@ +"""**Plan-and-execute agents** are planning tasks with a language model (LLM) and +executing them with a separate agent. + +""" from langchain_experimental.plan_and_execute.agent_executor import PlanAndExecute from langchain_experimental.plan_and_execute.executors.agent_executor import ( load_agent_executor, diff --git a/libs/experimental/langchain_experimental/prompt_injection_identifier/__init__.py b/libs/experimental/langchain_experimental/prompt_injection_identifier/__init__.py index 69f4248067e..aba9151fc1a 100644 --- a/libs/experimental/langchain_experimental/prompt_injection_identifier/__init__.py +++ b/libs/experimental/langchain_experimental/prompt_injection_identifier/__init__.py @@ -1,4 +1,7 @@ -"""HuggingFace Security toolkit.""" +"""**HuggingFace Injection Identifier** is a tool that uses +[HuggingFace Prompt Injection model](https://huggingface.co/deepset/deberta-v3-base-injection) +to detect prompt injection attacks. +""" from langchain_experimental.prompt_injection_identifier.hugging_face_identifier import ( HuggingFaceInjectionIdentifier, diff --git a/libs/experimental/langchain_experimental/prompt_injection_identifier/hugging_face_identifier.py b/libs/experimental/langchain_experimental/prompt_injection_identifier/hugging_face_identifier.py index 4f830d2c7f5..a2868477611 100644 --- a/libs/experimental/langchain_experimental/prompt_injection_identifier/hugging_face_identifier.py +++ b/libs/experimental/langchain_experimental/prompt_injection_identifier/hugging_face_identifier.py @@ -50,7 +50,7 @@ def _model_default_factory( class HuggingFaceInjectionIdentifier(BaseTool): - """Tool that uses HuggingFace Prompt Injection to + """Tool that uses HuggingFace Prompt Injection model to detect prompt injection attacks.""" name: str = "hugging_face_injection_identifier" diff --git a/libs/experimental/langchain_experimental/prompts/__init__.py b/libs/experimental/langchain_experimental/prompts/__init__.py index 2bde8c4df1f..f26c3fa5ad2 100644 --- a/libs/experimental/langchain_experimental/prompts/__init__.py +++ b/libs/experimental/langchain_experimental/prompts/__init__.py @@ -1,3 +1,5 @@ +"""Unified method for **loading a prompt** from LangChainHub or local file system. +""" from langchain_experimental.prompts.load import load_prompt __all__ = ["load_prompt"] diff --git a/libs/experimental/langchain_experimental/recommenders/__init__.py b/libs/experimental/langchain_experimental/recommenders/__init__.py index ec06f554189..1c05b72faf9 100644 --- a/libs/experimental/langchain_experimental/recommenders/__init__.py +++ b/libs/experimental/langchain_experimental/recommenders/__init__.py @@ -1,4 +1,9 @@ -"""Amazon Personalize primitives.""" +"""**Amazon Personalize** primitives. + +[Amazon Personalize](https://docs.aws.amazon.com/personalize/latest/dg/what-is-personalize.html) +is a fully managed machine learning service that uses your data to generate +item recommendations for your users. +""" # noqa: E501 from langchain_experimental.recommenders.amazon_personalize import AmazonPersonalize from langchain_experimental.recommenders.amazon_personalize_chain import ( AmazonPersonalizeChain, diff --git a/libs/experimental/langchain_experimental/recommenders/amazon_personalize.py b/libs/experimental/langchain_experimental/recommenders/amazon_personalize.py index 9b73f2e0876..6f24bc02c84 100644 --- a/libs/experimental/langchain_experimental/recommenders/amazon_personalize.py +++ b/libs/experimental/langchain_experimental/recommenders/amazon_personalize.py @@ -2,8 +2,9 @@ from typing import Any, List, Mapping, Optional, Sequence class AmazonPersonalize: - """Amazon Personalize Runtime wrapper for executing real-time operations: - https://docs.aws.amazon.com/personalize/latest/dg/API_Operations_Amazon_Personalize_Runtime.html + """Amazon Personalize Runtime wrapper for executing real-time operations. + + See [this link for more details](https://docs.aws.amazon.com/personalize/latest/dg/API_Operations_Amazon_Personalize_Runtime.html). Args: campaign_arn: str, Optional: The Amazon Resource Name (ARN) of the campaign diff --git a/libs/experimental/langchain_experimental/retrievers/__init__.py b/libs/experimental/langchain_experimental/retrievers/__init__.py index e69de29bb2d..0f8ca9cb81f 100644 --- a/libs/experimental/langchain_experimental/retrievers/__init__.py +++ b/libs/experimental/langchain_experimental/retrievers/__init__.py @@ -0,0 +1,5 @@ +"""**Retriever** class returns Documents given a text **query**. + +It is more general than a vector store. A retriever does not need to be able to +store documents, only to return (or retrieve) it. +""" diff --git a/libs/experimental/langchain_experimental/rl_chain/__init__.py b/libs/experimental/langchain_experimental/rl_chain/__init__.py index ca558dd6f39..d2fb52fcd7e 100644 --- a/libs/experimental/langchain_experimental/rl_chain/__init__.py +++ b/libs/experimental/langchain_experimental/rl_chain/__init__.py @@ -1,3 +1,12 @@ +""" +**RL (Reinforcement Learning) Chain** leverages the `Vowpal Wabbit (VW)` models +for reinforcement learning with a context, with the goal of modifying +the prompt before the LLM call. + +[Vowpal Wabbit](https://vowpalwabbit.org/) provides fast, efficient, +and flexible online machine learning techniques for reinforcement learning, +supervised learning, and more. +""" import logging from langchain_experimental.rl_chain.base import ( diff --git a/libs/experimental/langchain_experimental/smart_llm/__init__.py b/libs/experimental/langchain_experimental/smart_llm/__init__.py index d1f83aab61b..3e83d6c76e1 100644 --- a/libs/experimental/langchain_experimental/smart_llm/__init__.py +++ b/libs/experimental/langchain_experimental/smart_llm/__init__.py @@ -1,13 +1,13 @@ -"""Chain for applying self-critique using the SmartGPT workflow. +"""**SmartGPT** chain is applying self-critique using the `SmartGPT` workflow. See details at https://youtu.be/wVzuvf9D9BU The workflow performs these 3 steps: -1. **Ideate**: Pass the user prompt to an ideation LLM n_ideas times, +1. **Ideate**: Pass the user prompt to an `Ideation LLM` n_ideas times, each result is an "idea" -2. **Critique**: Pass the ideas to a critique LLM which looks for flaws in the ideas +2. **Critique**: Pass the ideas to a `Critique LLM` which looks for flaws in the ideas & picks the best one -3. **Resolve**: Pass the critique to a resolver LLM which improves upon the best idea +3. **Resolve**: Pass the critique to a `Resolver LLM` which improves upon the best idea & outputs only the (improved version of) the best output In total, the SmartGPT workflow will use n_ideas+2 LLM calls diff --git a/libs/experimental/langchain_experimental/sql/__init__.py b/libs/experimental/langchain_experimental/sql/__init__.py index d14f9a0dea0..05d4ecb1bde 100644 --- a/libs/experimental/langchain_experimental/sql/__init__.py +++ b/libs/experimental/langchain_experimental/sql/__init__.py @@ -1,4 +1,4 @@ -"""Chain for interacting with SQL Database.""" +"""**SQL Chain** interacts with `SQL` Database.""" from langchain_experimental.sql.base import SQLDatabaseChain, SQLDatabaseSequentialChain __all__ = ["SQLDatabaseChain", "SQLDatabaseSequentialChain"] diff --git a/libs/experimental/langchain_experimental/synthetic_data/__init__.py b/libs/experimental/langchain_experimental/synthetic_data/__init__.py index c5762a341c5..ba1621a9d26 100644 --- a/libs/experimental/langchain_experimental/synthetic_data/__init__.py +++ b/libs/experimental/langchain_experimental/synthetic_data/__init__.py @@ -1,3 +1,4 @@ +"""Generate **synthetic data** using LLM and few-shot template.""" from typing import Any, Dict, List, Optional from langchain.chains.base import Chain diff --git a/libs/experimental/langchain_experimental/tabular_synthetic_data/__init__.py b/libs/experimental/langchain_experimental/tabular_synthetic_data/__init__.py index e69de29bb2d..d26ccf38f8e 100644 --- a/libs/experimental/langchain_experimental/tabular_synthetic_data/__init__.py +++ b/libs/experimental/langchain_experimental/tabular_synthetic_data/__init__.py @@ -0,0 +1 @@ +"""Generate **tabular synthetic data** using LLM and few-shot template.""" diff --git a/libs/experimental/langchain_experimental/text_splitter.py b/libs/experimental/langchain_experimental/text_splitter.py index a522f72c057..d53049e2326 100644 --- a/libs/experimental/langchain_experimental/text_splitter.py +++ b/libs/experimental/langchain_experimental/text_splitter.py @@ -1,3 +1,4 @@ +"""Experimental **text splitter** based on semantic similarity.""" import copy import re from typing import Any, Dict, Iterable, List, Literal, Optional, Sequence, Tuple, cast diff --git a/libs/experimental/langchain_experimental/tools/__init__.py b/libs/experimental/langchain_experimental/tools/__init__.py index 1d6b868d11c..b3a746178b9 100644 --- a/libs/experimental/langchain_experimental/tools/__init__.py +++ b/libs/experimental/langchain_experimental/tools/__init__.py @@ -1,3 +1,4 @@ +"""Experimental **Python REPL** tools.""" from langchain_experimental.tools.python.tool import PythonAstREPLTool, PythonREPLTool __all__ = ["PythonREPLTool", "PythonAstREPLTool"] diff --git a/libs/experimental/langchain_experimental/tot/__init__.py b/libs/experimental/langchain_experimental/tot/__init__.py index c20812ccd5b..9bd0639197c 100644 --- a/libs/experimental/langchain_experimental/tot/__init__.py +++ b/libs/experimental/langchain_experimental/tot/__init__.py @@ -1,7 +1,5 @@ -"""Implementation of a Tree of Thought (ToT) chain based on the paper -"Large Language Model Guided Tree-of-Thought" - -https://arxiv.org/pdf/2305.08291.pdf +"""Implementation of a **Tree of Thought (ToT)** chain based on the paper +[Large Language Model Guided Tree-of-Thought](https://arxiv.org/pdf/2305.08291.pdf). The Tree of Thought (ToT) chain uses a tree structure to explore the space of possible solutions to a problem. diff --git a/libs/experimental/langchain_experimental/utilities/__init__.py b/libs/experimental/langchain_experimental/utilities/__init__.py index d3aae0240d2..4b7a4d5721e 100644 --- a/libs/experimental/langchain_experimental/utilities/__init__.py +++ b/libs/experimental/langchain_experimental/utilities/__init__.py @@ -1,3 +1,4 @@ +"""Utility that simulates a standalone **Python REPL**.""" from langchain_experimental.utilities.python import PythonREPL __all__ = ["PythonREPL"]