Skip to content

Commit cf6a996

Browse files
committed
langchain: Add ruff rules D except D1
1 parent 19fff8c commit cf6a996

File tree

139 files changed

+763
-702
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+763
-702
lines changed

libs/langchain/langchain/agents/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
**Agent** is a class that uses an LLM to choose a sequence of actions to take.
1+
"""**Agent** is a class that uses an LLM to choose a sequence of actions to take.
32
43
In Chains, a sequence of actions is hardcoded. In Agents,
54
a language model is used as a reasoning engine to determine which actions

libs/langchain/langchain/agents/agent.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ def save(self, file_path: Union[Path, str]) -> None:
363363

364364
def tool_run_logging_kwargs(self) -> builtins.dict:
365365
"""Return logging kwargs for tool run."""
366-
367366
return {}
368367

369368

@@ -1811,7 +1810,6 @@ async def astream(
18111810
Yields:
18121811
AddableDict: Addable dictionary.
18131812
"""
1814-
18151813
config = ensure_config(config)
18161814
iterator = AgentExecutorIterator(
18171815
self,

libs/langchain/langchain/agents/agent_iterator.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def __init__(
5555
include_run_info: bool = False,
5656
yield_actions: bool = False,
5757
):
58-
"""
58+
"""Initialize the AgentExecutorIterator.
59+
5960
Initialize the AgentExecutorIterator with the given AgentExecutor,
6061
inputs, and optional callbacks.
6162
@@ -129,7 +130,8 @@ def color_mapping(self) -> dict[str, str]:
129130
)
130131

131132
def reset(self) -> None:
132-
"""
133+
"""Reset the iterator to its initial state.
134+
133135
Reset the iterator to its initial state, clearing intermediate steps,
134136
iterations, and time elapsed.
135137
"""
@@ -141,9 +143,7 @@ def reset(self) -> None:
141143
self.start_time = time.time()
142144

143145
def update_iterations(self) -> None:
144-
"""
145-
Increment the number of iterations and update the time elapsed.
146-
"""
146+
"""Increment the number of iterations and update the time elapsed."""
147147
self.iterations += 1
148148
self.time_elapsed = time.time() - self.start_time
149149
logger.debug(
@@ -233,9 +233,10 @@ def __iter__(self: AgentExecutorIterator) -> Iterator[AddableDict]:
233233
yield self._stop(run_manager)
234234

235235
async def __aiter__(self) -> AsyncIterator[AddableDict]:
236-
"""
236+
"""Create an async iterator for the AgentExecutor.
237+
237238
N.B. __aiter__ must be a normal method, so need to initialize async run manager
238-
on first __anext__ call where we can await it
239+
on first __anext__ call where we can await it.
239240
"""
240241
logger.debug("Initialising AgentExecutorIterator (async)")
241242
self.reset()
@@ -317,7 +318,8 @@ def _process_next_step_output(
317318
next_step_output: Union[AgentFinish, list[tuple[AgentAction, str]]],
318319
run_manager: CallbackManagerForChainRun,
319320
) -> AddableDict:
320-
"""
321+
"""Process the output of the next step.
322+
321323
Process the output of the next step,
322324
handling AgentFinish and tool return cases.
323325
"""
@@ -345,7 +347,8 @@ async def _aprocess_next_step_output(
345347
next_step_output: Union[AgentFinish, list[tuple[AgentAction, str]]],
346348
run_manager: AsyncCallbackManagerForChainRun,
347349
) -> AddableDict:
348-
"""
350+
"""Process the output of the next async step.
351+
349352
Process the output of the next async step,
350353
handling AgentFinish and tool return cases.
351354
"""
@@ -369,7 +372,8 @@ async def _aprocess_next_step_output(
369372
return AddableDict(intermediate_step=next_step_output)
370373

371374
def _stop(self, run_manager: CallbackManagerForChainRun) -> AddableDict:
372-
"""
375+
"""Stop the iterator.
376+
373377
Stop the iterator and raise a StopIteration exception with the stopped response.
374378
"""
375379
logger.warning("Stopping agent prematurely due to triggering stop condition")
@@ -382,7 +386,8 @@ def _stop(self, run_manager: CallbackManagerForChainRun) -> AddableDict:
382386
return self._return(output, run_manager=run_manager)
383387

384388
async def _astop(self, run_manager: AsyncCallbackManagerForChainRun) -> AddableDict:
385-
"""
389+
"""Stop the async iterator.
390+
386391
Stop the async iterator and raise a StopAsyncIteration exception with
387392
the stopped response.
388393
"""
@@ -399,9 +404,7 @@ def _return(
399404
output: AgentFinish,
400405
run_manager: CallbackManagerForChainRun,
401406
) -> AddableDict:
402-
"""
403-
Return the final output of the iterator.
404-
"""
407+
"""Return the final output of the iterator."""
405408
returned_output = self.agent_executor._return(
406409
output,
407410
self.intermediate_steps,
@@ -416,9 +419,7 @@ async def _areturn(
416419
output: AgentFinish,
417420
run_manager: AsyncCallbackManagerForChainRun,
418421
) -> AddableDict:
419-
"""
420-
Return the final output of the async iterator.
421-
"""
422+
"""Return the final output of the async iterator."""
422423
returned_output = await self.agent_executor._areturn(
423424
output,
424425
self.intermediate_steps,

libs/langchain/langchain/agents/agent_toolkits/conversational_retrieval/openai_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def create_conversational_retrieval_agent(
5151
defaults to False.
5252
max_token_limit: The max number of tokens to keep around in memory.
5353
Defaults to 2000.
54+
**kwargs: Additional keyword arguments to pass to the AgentExecutor.
5455
5556
Returns:
5657
An agent executor initialized appropriately
5758
"""
58-
5959
if remember_intermediate_steps:
6060
memory: BaseMemory = AgentTokenBufferMemory(
6161
memory_key=memory_key,

libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
def __getattr__(name: str) -> Any:
88
"""Get attr name."""
9-
109
if name == "create_csv_agent":
1110
# Get directory of langchain package
1211
HERE = Path(__file__).parents[3]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""NASA Toolkit"""
1+
"""NASA Toolkit."""

libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
def __getattr__(name: str) -> Any:
88
"""Get attr name."""
9-
109
if name == "create_pandas_dataframe_agent":
1110
# Get directory of langchain package
1211
HERE = Path(__file__).parents[3]

libs/langchain/langchain/agents/agent_toolkits/python/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
def __getattr__(name: str) -> Any:
88
"""Get attr name."""
9-
109
if name == "create_python_agent":
1110
# Get directory of langchain package
1211
HERE = Path(__file__).parents[3]

libs/langchain/langchain/agents/agent_toolkits/spark/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
def __getattr__(name: str) -> Any:
88
"""Get attr name."""
9-
109
if name == "create_spark_dataframe_agent":
1110
# Get directory of langchain package
1211
HERE = Path(__file__).parents[3]

libs/langchain/langchain/agents/agent_toolkits/xorbits/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
def __getattr__(name: str) -> Any:
88
"""Get attr name."""
9-
109
if name == "create_xorbits_agent":
1110
# Get directory of langchain package
1211
HERE = Path(__file__).parents[3]

0 commit comments

Comments
 (0)