Skip to content

Commit

Permalink
added export chat history to /examples/openai
Browse files Browse the repository at this point in the history
  • Loading branch information
deftio committed Oct 22, 2024
1 parent 9be01d4 commit 831f950
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion examples/openai.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
font-weight: 300;
}

button {
margin-bottom: 4px;
}

button:hover {
background-color: #0056b3;
Expand Down Expand Up @@ -91,7 +94,13 @@ <h3>Settings</h3>
</form>
</div>
<div class="col-7" id="chatContainer">
<h3>Chat</h3>
<div class="d-flex justify-content-between align-items-center">
<h3 class="mb-0">Chat</h3>
<div>
<button id="exportChat" class="btn btn-primary me-2">Export Chat History</button>
<button id="exportChatAndPrompt" class="btn btn-primary">Export History And Prompt</button>
</div>
</div>
<div id="chatBox" class="chat-container"></div>
</div>
</div>
Expand Down Expand Up @@ -217,6 +226,39 @@ <h3>Chat</h3>
}
});
});

// 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);
});

</script>
</body>

Expand Down

0 comments on commit 831f950

Please sign in to comment.