Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Possible mistake in property's docstring of ConversationBufferWindowMemory #18080

Closed
2 tasks done
lgabs opened this issue Feb 25, 2024 · 3 comments
Closed
2 tasks done
Labels
🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder Ɑ: memory Related to memory module

Comments

@lgabs
Copy link
Contributor

lgabs commented Feb 25, 2024

Checklist

  • I added a very descriptive title to this issue.
  • I included a link to the documentation page I am referring to (if applicable).

Issue with current documentation:

Readiing ConversationBufferWindowMemory class, it seems that the property buffer returns self.buffer_as_messages if self.return_messages is True, otherwise it returns self.buffer_as_str.

@property
def buffer(self) -> Union[str, List[BaseMessage]]:
"""String buffer of memory."""
return self.buffer_as_messages if self.return_messages else self.buffer_as_str

However, the docstrings of these properties buffer_as_str and return_messages seem inverted when they say True and False respectively:

@property
def buffer_as_str(self) -> str:
"""Exposes the buffer as a string in case return_messages is True."""
messages = self.chat_memory.messages[-self.k * 2 :] if self.k > 0 else []
return get_buffer_string(
messages,
human_prefix=self.human_prefix,
ai_prefix=self.ai_prefix,
)

@property
def buffer_as_messages(self) -> List[BaseMessage]:
"""Exposes the buffer as a list of messages in case return_messages is False."""
return self.chat_memory.messages[-self.k * 2 :] if self.k > 0 else []

Idea or request for content:

No response

@dosubot dosubot bot added Ɑ: memory Related to memory module 🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder labels Feb 25, 2024
@keenborder786
Copy link
Contributor

@lgabs nice catch ,created a PR for the fix.

eyurtsev pushed a commit that referenced this issue Feb 26, 2024
@eyurtsev
Copy link
Collaborator

Merged

@lgabs
Copy link
Contributor Author

lgabs commented Feb 26, 2024

@keenborder786 am I mistaken or there is still a change to make in buffer_as_messages?

https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/memory/buffer_window.py#L22-L36

I've updated this in this new PR: #18136

hwchase17 pushed a commit that referenced this issue Feb 26, 2024
al1p pushed a commit to al1p/langchain that referenced this issue Feb 27, 2024
al1p pushed a commit to al1p/langchain that referenced this issue Feb 27, 2024
haydeniw pushed a commit to haydeniw/langchain that referenced this issue Feb 27, 2024
haydeniw pushed a commit to haydeniw/langchain that referenced this issue Feb 27, 2024
gkorland pushed a commit to FalkorDB/langchain that referenced this issue Mar 30, 2024
gkorland pushed a commit to FalkorDB/langchain that referenced this issue Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:docs Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder Ɑ: memory Related to memory module
Projects
None yet
Development

No branches or pull requests

3 participants