CoolFace
Apppublic

sleepdeep/llm-deploy

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
save_files.js41 linesDownload Raw Back to js
1// Functions for downloading JSON files2function getCurrentTimestamp() {3  const now = new Date();4  const timezoneOffset = now.getTimezoneOffset() * 60000; // Convert to milliseconds5  const localTime = new Date(now.getTime() - timezoneOffset);6  const formattedTimestamp = localTime.toISOString().replace(/[-:]/g, "").slice(0, 15);7  return formattedTimestamp;8}9 10function saveFile(contents, filename) {11  const element = document.createElement("a");12  element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(contents));13  element.setAttribute("download", filename);14  element.style.display = "none";15  document.body.appendChild(element);16  element.click();17  document.body.removeChild(element);18}19 20function saveHistory(history, character, mode) {21  let path = null;22 23  if (["chat", "chat-instruct"].includes(mode) && character && character.trim() !== "") {24    path = `history_${character}_${getCurrentTimestamp()}.json`;25  } else {26    try {27      path = `history_${mode}_${getCurrentTimestamp()}.json`;28    } catch (error) {29      path = `history_${getCurrentTimestamp()}.json`;30    }31  }32  saveFile(history, path);33}34 35function saveSession(session) {36  let path = null;37 38  path = `session_${getCurrentTimestamp()}.json`;39  saveFile(session, path);40}41