From fc4e08d692cfc1cda944c041bb0fa2a6e9c6c723 Mon Sep 17 00:00:00 2001 From: rawathemant246 Date: Sun, 19 Jan 2025 23:02:16 +0530 Subject: [PATCH] Fix: Updated pyproject.toml and added Google-style docstrings to ModelLaboratory --- libs/langchain/langchain/model_laboratory.py | 27 +++++++++++++++----- pyproject.toml | 6 +++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/libs/langchain/langchain/model_laboratory.py b/libs/langchain/langchain/model_laboratory.py index 114994535d8a8..914721470cebb 100644 --- a/libs/langchain/langchain/model_laboratory.py +++ b/libs/langchain/langchain/model_laboratory.py @@ -13,13 +13,23 @@ 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 @@ def __init__(self, chains: Sequence[Chain], names: Optional[List[str]] = None): 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 0466cad3b8ed8..fab1f2eaf6405 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.