Skip to content

Commit

Permalink
fix(community): file system chat history (#7357)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied authored Dec 14, 2024
1 parent 1e85e43 commit 3dfaa37
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
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();
});

0 comments on commit 3dfaa37

Please sign in to comment.