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

fix(community): file system chat history #7357

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/core_docs/docs/integrations/memory/file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ hide_table_of_contents: true

import CodeBlock from "@theme/CodeBlock";

# File Chat Message History
# File System Chat Message History

The `FileChatMessageHistory` uses a JSON file to store chat message history. For longer-term persistence across chat sessions, you can swap out the default in-memory `chatHistory` that backs chat memory classes like `BufferMemory`.
The `FileSystemChatMessageHistory` uses a JSON file to store chat message history. For longer-term persistence across chat sessions, you can swap out the default in-memory `chatHistory` that backs chat memory classes like `BufferMemory`.

## Setup

Expand Down
2 changes: 1 addition & 1 deletion examples/src/memory/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ const sessions = await chatHistory.getAllSessions();
console.log(sessions);
/*
[
{ sessionId: 'langchain-test-session', context: { title: "Introducing Jim" } }
{ id: 'langchain-test-session', context: { title: "Introducing Jim" } }
]
*/
4 changes: 2 additions & 2 deletions libs/langchain-community/src/stores/message/file_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ export class FileSystemChatMessageHistory extends BaseListChatMessageHistory {
async getAllSessions(): Promise<FileChatSession[]> {
await this.init();
const userSessions = store[this.userId]
? Object.values(store[this.userId]).map((session) => ({
id: session.id,
? Object.entries(store[this.userId]).map(([id, session]) => ({
id,
context: session.context,
}))
: [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,7 @@ test("FileSystemChatMessageHistory set context and get all sessions", async () =

expect(sessions.length).toBe(2);
expect(sessions[0].context).toEqual(context1);
expect(sessions[0].id).toBeDefined();
expect(sessions[1].context).toEqual(context2);
expect(sessions[1].id).toBeDefined();
});
Loading