mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-04 12:39:32 +00:00
Fixed k=0 bug on ConversationBufferWindowMemory (#2796)
Updated the "load_memory_variables" function of the ConversationBufferWindowMemory to support a window size of 0 (k=0). Previous behavior would return the full memory instead of an empty array.
This commit is contained in:
@@ -28,11 +28,10 @@ class ConversationBufferWindowMemory(BaseChatMemory):
|
|||||||
def load_memory_variables(self, inputs: Dict[str, Any]) -> Dict[str, str]:
|
def load_memory_variables(self, inputs: Dict[str, Any]) -> Dict[str, str]:
|
||||||
"""Return history buffer."""
|
"""Return history buffer."""
|
||||||
|
|
||||||
if self.return_messages:
|
buffer: Any = self.buffer[-self.k * 2 :] if self.k > 0 else []
|
||||||
buffer: Any = self.buffer[-self.k * 2 :]
|
if not self.return_messages:
|
||||||
else:
|
|
||||||
buffer = get_buffer_string(
|
buffer = get_buffer_string(
|
||||||
self.buffer[-self.k * 2 :],
|
buffer,
|
||||||
human_prefix=self.human_prefix,
|
human_prefix=self.human_prefix,
|
||||||
ai_prefix=self.ai_prefix,
|
ai_prefix=self.ai_prefix,
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user