Skip to content

Commit

Permalink
editable custom instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaki-1052 committed Apr 1, 2024
1 parent 4364a8c commit 0ba15e6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
8 changes: 7 additions & 1 deletion public/portal.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link rel="stylesheet" href="chat.css">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dompurify/dist/purify.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap" rel="stylesheet">
</head>
<body>
<div>
Expand Down Expand Up @@ -54,9 +55,14 @@
<button type="button" id="voice-button">🎤</button>
<div id="voice-indicator">Voice Mode ON</div>
<button id="send-button">Send</button>
<div class="custom-select" id="mode-selector">Assistants Mode</div>
<div id="upload-status"></div>
</div>
<div class="custom-select" id="mode-selector">Assistants Mode</div>
<button id="edit-instructions-btn" class="custom-select">Edit Instructions</button>
<div id="edit-instructions-container" style="display:none;">
<textarea id="instructions-content" rows="10" cols="80"></textarea>
<button onclick="saveChanges()">Save Changes</button>
</div>
<script src="script.js"></script>
</body>
</html>
45 changes: 44 additions & 1 deletion public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -1015,4 +1015,47 @@ document.getElementById('file-input').addEventListener('change', function(event)
} else {
updateUploadStatus('No file selected or unsupported file type');
}
});
});

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);
});
}
25 changes: 25 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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' });
Expand Down

0 comments on commit 0ba15e6

Please sign in to comment.