HocusPocus
HocusPocus•5mo ago

HocusPocus - Hey guys, I want to save the chat ...

Hey guys, I want to save the chat history for my ai chat in a database like firebase. Did anyone find a way to solve it? It would help me out a lot😀
2 Replies
Harini
Harini•5mo ago
@Bhavya - could you share some examples or docs for this.
Bhavya
Bhavya•5mo ago
Hey @HocusPocus, to store the chat history via the AI Assistant nodes to any database your could follow the following approach: - Your OpenAI Assistant node already uses a threadId for maintaining the chat history, which is also being returned from the Assistant node for reference. This can be used as the Document ID in the collection for storing the chat history externally. - The OpenAI Assistant also returns an output called messages which is an array of the entire chat history associated with the threadId. This is the data we need to store to our database. (or, process as required and then store depending upon your usecase). - For instance, we need to store the chat history to our BuildShip Database. All we need to do is simply add a "Create Document" node from the BuildShip Database Integration. Give it a Collection Name. The Document ID needs to be the threadId as returned from the AI Assistant node. Pass in the messages output from the OpenAI Assistant node as the Data to be added/updated, as:
{
"fieldName": Messages
}
{
"fieldName": Messages
}
Make sure to set the Merge field for the Create Document node as false. This would entirely update the messages field every time, as the items get added to the chat history.
No description