From 3dfaa37e702af82647d0ab518c192da98b08c368 Mon Sep 17 00:00:00 2001 From: Yohan Lasorsa Date: Sat, 14 Dec 2024 04:53:16 +0100 Subject: [PATCH] fix(community): file system chat history (#7357) --- docs/core_docs/docs/integrations/memory/file.mdx | 4 ++-- examples/src/memory/file.ts | 2 +- libs/langchain-community/src/stores/message/file_system.ts | 4 ++-- .../src/stores/tests/file_chat_history.int.test.ts | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/core_docs/docs/integrations/memory/file.mdx b/docs/core_docs/docs/integrations/memory/file.mdx index d485be9d29c6..25a41fef2415 100644 --- a/docs/core_docs/docs/integrations/memory/file.mdx +++ b/docs/core_docs/docs/integrations/memory/file.mdx @@ -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 diff --git a/examples/src/memory/file.ts b/examples/src/memory/file.ts index 5728ec3af26d..e8791f5fbcf3 100644 --- a/examples/src/memory/file.ts +++ b/examples/src/memory/file.ts @@ -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" } } ] */ diff --git a/libs/langchain-community/src/stores/message/file_system.ts b/libs/langchain-community/src/stores/message/file_system.ts index f81af5f7a4ef..0e49b5ee95dd 100644 --- a/libs/langchain-community/src/stores/message/file_system.ts +++ b/libs/langchain-community/src/stores/message/file_system.ts @@ -189,8 +189,8 @@ export class FileSystemChatMessageHistory extends BaseListChatMessageHistory { async getAllSessions(): Promise { 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, })) : []; diff --git a/libs/langchain-community/src/stores/tests/file_chat_history.int.test.ts b/libs/langchain-community/src/stores/tests/file_chat_history.int.test.ts index 1610bcbee0e1..0229caa30fe1 100644 --- a/libs/langchain-community/src/stores/tests/file_chat_history.int.test.ts +++ b/libs/langchain-community/src/stores/tests/file_chat_history.int.test.ts @@ -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(); });