2023-08-02 21:50:13 -04:00
|
|
|
// Functions for downloading JSON files
|
|
|
|
function getCurrentTimestamp() {
|
2023-10-07 22:07:57 -04:00
|
|
|
const now = new Date();
|
|
|
|
const timezoneOffset = now.getTimezoneOffset() * 60000; // Convert to milliseconds
|
|
|
|
const localTime = new Date(now.getTime() - timezoneOffset);
|
|
|
|
const formattedTimestamp = localTime.toISOString().replace(/[-:]/g, "").slice(0, 15);
|
|
|
|
return formattedTimestamp;
|
2023-08-02 21:50:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveFile(contents, filename) {
|
2023-10-07 22:07:57 -04:00
|
|
|
const element = document.createElement("a");
|
|
|
|
element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(contents));
|
|
|
|
element.setAttribute("download", filename);
|
|
|
|
element.style.display = "none";
|
|
|
|
document.body.appendChild(element);
|
|
|
|
element.click();
|
|
|
|
document.body.removeChild(element);
|
2023-08-02 21:50:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveHistory(history, character, mode) {
|
2023-10-07 22:07:57 -04:00
|
|
|
let path = null;
|
2023-08-02 21:50:13 -04:00
|
|
|
|
2023-10-07 22:07:57 -04:00
|
|
|
if (["chat", "chat-instruct"].includes(mode) && character && character.trim() !== "") {
|
|
|
|
path = `history_${character}_${getCurrentTimestamp()}.json`;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
path = `history_${mode}_${getCurrentTimestamp()}.json`;
|
|
|
|
} catch (error) {
|
|
|
|
path = `history_${getCurrentTimestamp()}.json`;
|
2023-08-02 21:50:13 -04:00
|
|
|
}
|
2023-10-07 22:07:57 -04:00
|
|
|
}
|
|
|
|
saveFile(history, path);
|
2023-08-02 21:50:13 -04:00
|
|
|
}
|
|
|
|
|
2023-08-13 00:12:15 -04:00
|
|
|
function saveSession(session) {
|
2023-10-07 22:07:57 -04:00
|
|
|
let path = null;
|
2023-08-02 21:50:13 -04:00
|
|
|
|
2023-10-07 22:07:57 -04:00
|
|
|
path = `session_${getCurrentTimestamp()}.json`;
|
|
|
|
saveFile(session, path);
|
2023-08-02 21:50:13 -04:00
|
|
|
}
|