class AzureCosmsosDBNoSQLChatMessageHistoryconst model = new ChatOpenAI({
model: "gpt-3.5-turbo",
temperature: 0,
});
const prompt = ChatPromptTemplate.fromMessages([
[
"system",
"You are a helpful assistant. Answer all questions to the best of your ability.",
],
new MessagesPlaceholder("chat_history"),
["human", "{input}"],
]);
const chain = prompt.pipe(model).pipe(new StringOutputParser());
const chainWithHistory = new RunnableWithMessageHistory({
runnable: chain,
inputMessagesKey: "input",
historyMessagesKey: "chat_history",
getMessageHistory: async (sessionId) => {
const chatHistory = new AzureCosmsosDBNoSQLChatMessageHistory({
sessionId: sessionId,
userId: "user-id",
databaseName: "DATABASE_NAME",
containerName: "CONTAINER_NAME",
})
return chatHistory;
},
});
await chainWithHistory.invoke(
{ input: "What did I just say my name was?" },
{ configurable: { sessionId: "session-id" } }
);A path to the module that contains the class, eg. ["langchain", "llms"] Usually should be the same as the entrypoint the class is exported from.
Class for storing chat message history with Cosmos DB NoSQL. It extends the BaseListChatMessageHistory class and provides methods to get, add, and clear messages.