From 831f9503ee1ff6dfabf7a35dbfd57e62e85684a4 Mon Sep 17 00:00:00 2001 From: deftio Date: Mon, 21 Oct 2024 18:47:03 -0700 Subject: [PATCH] added export chat history to /examples/openai --- examples/openai.html | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/examples/openai.html b/examples/openai.html index e4172ee..b5b31b6 100644 --- a/examples/openai.html +++ b/examples/openai.html @@ -42,6 +42,9 @@ font-weight: 300; } + button { + margin-bottom: 4px; + } button:hover { background-color: #0056b3; @@ -91,7 +94,13 @@

Settings

-

Chat

+
+

Chat

+
+ + +
+
@@ -217,6 +226,39 @@

Chat

} }); }); + + // Export chat history to a text file + // Add the export functionality + document.getElementById('exportChat').addEventListener('click', function () { + const chatHistory = chatInstance.historyGetAllCopy(); + const blob = new Blob([JSON.stringify(chatHistory, null, 2)], { type: 'application/json' }); + const url = URL.createObjectURL(blob); + const dateTime = new Date().toISOString().replace(/[:.]/g, '-'); + const link = document.createElement('a'); + link.href = url; + link.download = `quikchat-history-${dateTime}.json`; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + }); + + // Export chat history and prompt to a text file + document.getElementById('exportChatAndPrompt').addEventListener('click', function () { + const exportData = {} + exportData["history"]= chatInstance.historyGetAllCopy(); + exportData["prompt"] = document.getElementById('prompt').value; + + const blob = new Blob([JSON.stringify(exportData, null, 2)], { type: 'application/json' }); + const url = URL.createObjectURL(blob); + const dateTime = new Date().toISOString().replace(/[:.]/g, '-'); + const link = document.createElement('a'); + link.href = url; + link.download = `quikchat-history-${dateTime}.json`; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + }); +