Skip to content

The agent engineering platform.

Add Google-style docstring linting and update pyproject.toml (#29303)

Hemant Rawat6c52378992f1
diff --git a/libs/langchain/langchain/model_laboratory.py b/libs/langchain/langchain/model_laboratory.py
index 114994535d..914721470c 100644
--- a/libs/langchain/langchain/model_laboratory.py
+++ b/libs/langchain/langchain/model_laboratory.py
@@ -13,13 +13,23 @@ from langchain.chains.llm import LLMChain
class ModelLaboratory:
- """Experiment with different models."""
+ """A utility to experiment with and compare the performance of different models."""
def __init__(self, chains: Sequence[Chain], names: Optional[List[str]] = None):
- """Initialize with chains to experiment with.
+ """Initialize the ModelLaboratory with chains to experiment with.
Args:
- chains: list of chains to experiment with.
+ chains (Sequence[Chain]): A sequence of chains to experiment with.
+ Each chain must have exactly one input and one output variable.
+ names (Optional[List[str]]): Optional list of names corresponding to each chain.
+ If provided, its length must match the number of chains.
+
+
+ Raises:
+ ValueError: If any chain is not an instance of `Chain`.
+ ValueError: If a chain does not have exactly one input variable.
+ ValueError: If a chain does not have exactly one output variable.
+ ValueError: If the length of `names` does not match the number of chains.
"""
for chain in chains:
if not isinstance(chain, Chain):
@@ -50,12 +60,15 @@ class ModelLaboratory:
def from_llms(
cls, llms: List[BaseLLM], prompt: Optional[PromptTemplate] = None
) -> ModelLaboratory:
- """Initialize with LLMs to experiment with and optional prompt.
+ """Initialize the ModelLaboratory with LLMs and an optional prompt.
Args:
- llms: list of LLMs to experiment with
- prompt: Optional prompt to use to prompt the LLMs. Defaults to None.
- If a prompt was provided, it should only have one input variable.
+ llms (List[BaseLLM]): A list of LLMs to experiment with.
+ prompt (Optional[PromptTemplate]): An optional prompt to use with the LLMs.
+ If provided, the prompt must contain exactly one input variable.
+
+ Returns:
+ ModelLaboratory: An instance of `ModelLaboratory` initialized with LLMs.
"""
if prompt is None:
prompt = PromptTemplate(input_variables=["_input"], template="{_input}")
diff --git a/pyproject.toml b/pyproject.toml
index 0466cad3b8..fab1f2eaf6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -68,13 +68,19 @@ extend-exclude = [
"docs/docs/expression_language/why.ipynb", # TODO: look into why linter errors
]
+[tool.ruff.lint]
+select = ["D"]
+pydocstyle = { convention = "google" }
+
[tool.ruff.lint.per-file-ignores]
"**/{cookbook,docs}/*" = [
"E402", # allow imports to appear anywhere in docs
"F401", # allow "imported but unused" example code
"F811", # allow re-importing the same module, so that cells can stay independent
"F841", # allow assignments to variables that are never read -- it's example code
+
]
+"!libs/langchain/langchain/model_laboratory.py"=["D"]
# These files were failing the listed rules at the time ruff was adopted for notebooks.
# Don't require them to change at once, though we should look into them eventually.