From 23b08173ff0601212796f70072f2d3b3ab83cfc2 Mon Sep 17 00:00:00 2001 From: Xrystal Date: Sun, 17 Sep 2023 13:41:36 +0800 Subject: [PATCH 1/3] Asynchronously fetch chats --- public/script.js | 61 +++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 27 deletions(-) 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; } From 359277deb55af62baca5e439bac50fb7f4abd83d Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 17 Sep 2023 15:21:26 +0300 Subject: [PATCH 2/3] Remove header #1144 --- public/scripts/extensions.js | 1 - 1 file changed, 1 deletion(-) 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); From a78bb82b442ea4cd630f2e3ca40b0e93985711a1 Mon Sep 17 00:00:00 2001 From: city-unit <140349364+city-unit@users.noreply.github.com> Date: Sun, 17 Sep 2023 23:53:11 -0400 Subject: [PATCH 3/3] Fix collab to generate an api key --- colab/GPU.ipynb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/colab/GPU.ipynb b/colab/GPU.ipynb index a1ab0207d..6084690a3 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", @@ -119,6 +120,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",