From 0ba15e65f401b2b294eb7e4e39ed6e684564c4b8 Mon Sep 17 00:00:00 2001 From: Zaki-1052 Date: Mon, 1 Apr 2024 11:08:14 -0700 Subject: [PATCH] editable custom instructions --- public/portal.html | 8 +++++++- public/script.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- server.js | 25 +++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/public/portal.html b/public/portal.html index e19daa9..7b69f65 100644 --- a/public/portal.html +++ b/public/portal.html @@ -8,6 +8,7 @@ +
@@ -54,9 +55,14 @@
Voice Mode ON
+
Assistants Mode
-
Assistants Mode
+ + \ No newline at end of file diff --git a/public/script.js b/public/script.js index 9660b50..c11b0e7 100644 --- a/public/script.js +++ b/public/script.js @@ -1015,4 +1015,47 @@ document.getElementById('file-input').addEventListener('change', function(event) } else { updateUploadStatus('No file selected or unsupported file type'); } -}); \ No newline at end of file +}); + +document.getElementById('edit-instructions-btn').addEventListener('click', function() { + const container = document.getElementById('edit-instructions-container'); + const isHidden = container.style.display === 'none'; + + // Toggle the display of the container + container.style.display = isHidden ? 'block' : 'none'; + + // If we're showing the container, load the content and scroll to it + if (isHidden) { + fetch('/get-instructions') + .then(response => response.text()) + .then(data => { + document.getElementById('instructions-content').value = data; + container.scrollIntoView({ behavior: 'smooth' }); + }) + .catch(error => { + console.error('Error:', error); + }); + } +}); + +function saveChanges() { + const content = document.getElementById('instructions-content').value; + fetch('/update-instructions', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ content: content }) + }) + .then(response => response.json()) + .then(data => { + console.log('Success:', data); + // Show a success message + alert('Changes saved successfully'); + // Hide the edit container + document.getElementById('edit-instructions-container').style.display = 'none'; + }) + .catch(error => { + console.error('Error:', error); + }); +} diff --git a/server.js b/server.js index 1626166..ef2daf6 100644 --- a/server.js +++ b/server.js @@ -1039,7 +1039,11 @@ if (modelID.startsWith('gpt') || modelID.startsWith('claude')) { +let tokens = 4000; +if (modelID === 'gpt-4') { + tokens = 6000; // If 'modelID' is 'gpt-4', set 'tokens' to 6000 +} // Model Parameters Below! @@ -1260,6 +1264,27 @@ app.get('/export-chat-html', async (req, res) => { }); +app.get('/get-instructions', (req, res) => { + fs.readFile('./public/instructions.md', 'utf8', (err, data) => { + if (err) { + console.error(err); + return res.status(500).send('Error reading the file'); + } + res.send(data); + }); +}); + +app.post('/update-instructions', (req, res) => { + const newContent = req.body.content; + fs.writeFile('./public/instructions.md', newContent, 'utf8', (err) => { + if (err) { + console.error(err); + return res.status(500).send({ message: 'Error saving the file' }); + } + res.send({ message: 'File updated successfully' }); + }); +}); + app.get('/portal', (req, res) => { res.sendFile('portal.html', { root: 'public' });