Skip to content

Commit

Permalink
Fix: Updated pyproject.toml and added Google-style docstrings to Mode…
Browse files Browse the repository at this point in the history
…lLaboratory
  • Loading branch information
rawathemant246 committed Jan 19, 2025
1 parent e9abe58 commit fc4e08d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
27 changes: 20 additions & 7 deletions libs/langchain/langchain/model_laboratory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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}")
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fc4e08d

Please sign in to comment.