diff --git a/colab/GPU.ipynb b/colab/GPU.ipynb index a50e1b446..4a12a7933 100644 --- a/colab/GPU.ipynb +++ b/colab/GPU.ipynb @@ -73,6 +73,7 @@ "#@markdown Enables ChromaDB for Infinity Context plugin\n", "\n", "import subprocess\n", + "import secrets\n", "\n", "# ---\n", "# SillyTavern extras\n", @@ -131,6 +132,13 @@ "!wget https://github.com/cloudflare/cloudflared/releases/download/2023.5.0/cloudflared-linux-amd64 -O /tmp/cloudflared-linux-amd64\n", "!chmod +x /tmp/cloudflared-linux-amd64\n", "\n", + "# Generate a random API key\n", + "api_key = secrets.token_hex(5)\n", + "\n", + "# Write the API key to api_key.txt\n", + "with open('./api_key.txt', 'w') as f:\n", + " f.write(api_key)\n", + "print(f\"API Key generated: {api_key}\")\n", "\n", "cmd = f\"python server.py {' '.join(params)}\"\n", "print(cmd)\n", diff --git a/public/script.js b/public/script.js index e6f3a67ef..6db1a56d6 100644 --- a/public/script.js +++ b/public/script.js @@ -5172,39 +5172,46 @@ export async function getChatsFromFiles(data, isGroupChat) { let chat_dict = {}; let chat_list = Object.values(data).sort((a, b) => a["file_name"].localeCompare(b["file_name"])).reverse(); - for (const { file_name } of chat_list) { - try { - const endpoint = isGroupChat ? '/getgroupchat' : '/getchat'; - const requestBody = isGroupChat - ? JSON.stringify({ id: file_name }) - : JSON.stringify({ - ch_name: characters[context.characterId].name, - file_name: file_name.replace('.jsonl', ''), - avatar_url: characters[context.characterId].avatar + let chat_promise = chat_list.map(({ file_name}) => { + return new Promise(async (res, rej) => { + try { + const endpoint = isGroupChat ? '/getgroupchat' : '/getchat'; + const requestBody = isGroupChat + ? JSON.stringify({ id: file_name }) + : JSON.stringify({ + ch_name: characters[context.characterId].name, + file_name: file_name.replace('.jsonl', ''), + avatar_url: characters[context.characterId].avatar + }); + + const chatResponse = await fetch(endpoint, { + method: 'POST', + headers: getRequestHeaders(), + body: requestBody, + cache: 'no-cache', }); - const chatResponse = await fetch(endpoint, { - method: 'POST', - headers: getRequestHeaders(), - body: requestBody, - cache: 'no-cache', - }); + if (!chatResponse.ok) { + return res(); + // continue; + } - if (!chatResponse.ok) { - continue; + const currentChat = await chatResponse.json(); + if (!isGroupChat) { + // remove the first message, which is metadata, only for individual chats + currentChat.shift(); + } + chat_dict[file_name] = currentChat; + + } catch (error) { + console.error(error); } - const currentChat = await chatResponse.json(); - if (!isGroupChat) { - // remove the first message, which is metadata, only for individual chats - currentChat.shift(); - } - chat_dict[file_name] = currentChat; + return res(); + }) + }) - } catch (error) { - console.error(error); - } - } + await Promise.all(chat_promise) return chat_dict; } diff --git a/public/scripts/extensions.js b/public/scripts/extensions.js index 0d0018d17..40c5d7624 100644 --- a/public/scripts/extensions.js +++ b/public/scripts/extensions.js @@ -192,7 +192,6 @@ async function doExtrasFetch(endpoint, args) { } Object.assign(args.headers, { 'Authorization': `Bearer ${extension_settings.apiKey}`, - 'Bypass-Tunnel-Reminder': 'bypass' }); const response = await fetch(endpoint, args);