mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 15:43:54 +00:00
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.
This commit is contained in:
parent
4c8aad0d1b
commit
359fb8fa3a
@ -35,10 +35,8 @@ class CombiningOutputParser(BaseOutputParser):
|
|||||||
|
|
||||||
initial = f"For your first output: {self.parsers[0].get_format_instructions()}"
|
initial = f"For your first output: {self.parsers[0].get_format_instructions()}"
|
||||||
subsequent = "\n".join(
|
subsequent = "\n".join(
|
||||||
[
|
|
||||||
f"Complete that output fully. Then produce another output, separated by two newline characters: {p.get_format_instructions()}" # noqa: E501
|
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:]
|
for p in self.parsers[1:]
|
||||||
]
|
|
||||||
)
|
)
|
||||||
return f"{initial}\n{subsequent}"
|
return f"{initial}\n{subsequent}"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user