mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-18 17:11:25 +00:00
Add Google-style docstring linting and update pyproject.toml (#29303)
### Description: This PR introduces Google-style docstring linting for the ModelLaboratory class in libs/langchain/langchain/model_laboratory.py. It also updates the pyproject.toml file to comply with the latest Ruff configuration standards (deprecating top-level lint settings in favor of lint). ### Changes include: - [x] Added detailed Google-style docstrings to all methods in ModelLaboratory. - [x] Updated pyproject.toml to move select and pydocstyle settings under the [tool.ruff.lint] section. - [x] Ensured all files pass Ruff linting. Issue: Closes #25154 ### Dependencies: No additional dependencies are required for this change. ### Checklist - [x] Files passes ruff linting. - [x] Docstrings conform to the Google-style convention. - [x] pyproject.toml updated to avoid deprecation warnings. - [x] My PR is ready to review, please review.
This commit is contained in:
parent
b5fbebb3c8
commit
6c52378992
@ -13,13 +13,23 @@ from langchain.chains.llm import LLMChain
|
|||||||
|
|
||||||
|
|
||||||
class ModelLaboratory:
|
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):
|
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:
|
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:
|
for chain in chains:
|
||||||
if not isinstance(chain, Chain):
|
if not isinstance(chain, Chain):
|
||||||
@ -50,12 +60,15 @@ class ModelLaboratory:
|
|||||||
def from_llms(
|
def from_llms(
|
||||||
cls, llms: List[BaseLLM], prompt: Optional[PromptTemplate] = None
|
cls, llms: List[BaseLLM], prompt: Optional[PromptTemplate] = None
|
||||||
) -> ModelLaboratory:
|
) -> ModelLaboratory:
|
||||||
"""Initialize with LLMs to experiment with and optional prompt.
|
"""Initialize the ModelLaboratory with LLMs and an optional prompt.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
llms: list of LLMs to experiment with
|
llms (List[BaseLLM]): A list of LLMs to experiment with.
|
||||||
prompt: Optional prompt to use to prompt the LLMs. Defaults to None.
|
prompt (Optional[PromptTemplate]): An optional prompt to use with the LLMs.
|
||||||
If a prompt was provided, it should only have one input variable.
|
If provided, the prompt must contain exactly one input variable.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
ModelLaboratory: An instance of `ModelLaboratory` initialized with LLMs.
|
||||||
"""
|
"""
|
||||||
if prompt is None:
|
if prompt is None:
|
||||||
prompt = PromptTemplate(input_variables=["_input"], template="{_input}")
|
prompt = PromptTemplate(input_variables=["_input"], template="{_input}")
|
||||||
|
@ -68,13 +68,19 @@ extend-exclude = [
|
|||||||
"docs/docs/expression_language/why.ipynb", # TODO: look into why linter errors
|
"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]
|
[tool.ruff.lint.per-file-ignores]
|
||||||
"**/{cookbook,docs}/*" = [
|
"**/{cookbook,docs}/*" = [
|
||||||
"E402", # allow imports to appear anywhere in docs
|
"E402", # allow imports to appear anywhere in docs
|
||||||
"F401", # allow "imported but unused" example code
|
"F401", # allow "imported but unused" example code
|
||||||
"F811", # allow re-importing the same module, so that cells can stay independent
|
"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
|
"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.
|
# 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.
|
# Don't require them to change at once, though we should look into them eventually.
|
||||||
|
Loading…
Reference in New Issue
Block a user