From 359fb8fa3ae0b0904dbb36f998cd2339ea0aec0f Mon Sep 17 00:00:00 2001 From: Taras Tsugrii Date: Wed, 31 May 2023 17:10:43 -0500 Subject: [PATCH] Replace list comprehension with generator. (#5526) # Replace list comprehension with generator. Since these strings can be fairly long, it's best to not construct unnecessary temporary list just to pass it to `join`. Generators produce items one-by-one and even though they are slightly more expensive than lists in terms of CPU they are much more memory-friendly and slightly more readable. --- langchain/output_parsers/combining.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/langchain/output_parsers/combining.py b/langchain/output_parsers/combining.py index 23599fa7..9a100c14 100644 --- a/langchain/output_parsers/combining.py +++ b/langchain/output_parsers/combining.py @@ -35,10 +35,8 @@ class CombiningOutputParser(BaseOutputParser): initial = f"For your first output: {self.parsers[0].get_format_instructions()}" subsequent = "\n".join( - [ - f"Complete that output fully. Then produce another output, separated by two newline characters: {p.get_format_instructions()}" # noqa: E501 - for p in self.parsers[1:] - ] + f"Complete that output fully. Then produce another output, separated by two newline characters: {p.get_format_instructions()}" # noqa: E501 + for p in self.parsers[1:] ) return f"{initial}\n{subsequent}"