Store chat message history using a local JSON file.
For demo and development purposes only.
Example
constmodel = newChatOpenAI({ model:"gpt-3.5-turbo", temperature:0, }); constprompt = ChatPromptTemplate.fromMessages([ [ "system", "You are a helpful assistant. Answer all questions to the best of your ability.", ], ["placeholder", "chat_history"], ["human", "{input}"], ]);
constchain = prompt.pipe(model).pipe(newStringOutputParser()); constchainWithHistory = newRunnableWithMessageHistory({ runnable:chain, inputMessagesKey:"input", historyMessagesKey:"chat_history", getMessageHistory:async (sessionId) => { constchatHistory = newFileSystemChatMessageHistory({ sessionId:sessionId, userId:"userId", // Optional }) returnchatHistory; }, }); awaitchainWithHistory.invoke( { input:"What did I just say my name was?" }, { configurable: { sessionId:"session-id" } } );
Store chat message history using a local JSON file. For demo and development purposes only.
Example