Skip to content

Commit dc14217

Browse files
committed
langchain: Add ruff rules D except D1
1 parent 2104cf0 commit dc14217

File tree

139 files changed

+762
-703
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

+762
-703
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(
@@ -235,9 +235,10 @@ def __iter__(self: AgentExecutorIterator) -> Iterator[AddableDict]:
235235
yield self._stop(run_manager)
236236

237237
async def __aiter__(self) -> AsyncIterator[AddableDict]:
238-
"""
238+
"""Create an async iterator for the AgentExecutor.
239+
239240
N.B. __aiter__ must be a normal method, so need to initialize async run manager
240-
on first __anext__ call where we can await it
241+
on first __anext__ call where we can await it.
241242
"""
242243
logger.debug("Initialising AgentExecutorIterator (async)")
243244
self.reset()
@@ -319,7 +320,8 @@ def _process_next_step_output(
319320
next_step_output: Union[AgentFinish, list[tuple[AgentAction, str]]],
320321
run_manager: CallbackManagerForChainRun,
321322
) -> AddableDict:
322-
"""
323+
"""Process the output of the next step.
324+
323325
Process the output of the next step,
324326
handling AgentFinish and tool return cases.
325327
"""
@@ -347,7 +349,8 @@ async def _aprocess_next_step_output(
347349
next_step_output: Union[AgentFinish, list[tuple[AgentAction, str]]],
348350
run_manager: AsyncCallbackManagerForChainRun,
349351
) -> AddableDict:
350-
"""
352+
"""Process the output of the next async step.
353+
351354
Process the output of the next async step,
352355
handling AgentFinish and tool return cases.
353356
"""
@@ -371,7 +374,8 @@ async def _aprocess_next_step_output(
371374
return AddableDict(intermediate_step=next_step_output)
372375

373376
def _stop(self, run_manager: CallbackManagerForChainRun) -> AddableDict:
374-
"""
377+
"""Stop the iterator.
378+
375379
Stop the iterator and raise a StopIteration exception with the stopped response.
376380
"""
377381
logger.warning("Stopping agent prematurely due to triggering stop condition")
@@ -384,7 +388,8 @@ def _stop(self, run_manager: CallbackManagerForChainRun) -> AddableDict:
384388
return self._return(output, run_manager=run_manager)
385389

386390
async def _astop(self, run_manager: AsyncCallbackManagerForChainRun) -> AddableDict:
387-
"""
391+
"""Stop the async iterator.
392+
388393
Stop the async iterator and raise a StopAsyncIteration exception with
389394
the stopped response.
390395
"""
@@ -401,9 +406,7 @@ def _return(
401406
output: AgentFinish,
402407
run_manager: CallbackManagerForChainRun,
403408
) -> AddableDict:
404-
"""
405-
Return the final output of the iterator.
406-
"""
409+
"""Return the final output of the iterator."""
407410
returned_output = self.agent_executor._return(
408411
output,
409412
self.intermediate_steps,
@@ -418,9 +421,7 @@ async def _areturn(
418421
output: AgentFinish,
419422
run_manager: AsyncCallbackManagerForChainRun,
420423
) -> AddableDict:
421-
"""
422-
Return the final output of the async iterator.
423-
"""
424+
"""Return the final output of the async iterator."""
424425
returned_output = await self.agent_executor._areturn(
425426
output,
426427
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)