Skip to content

Commit

Permalink
added password masking to /examples/openai.html
Browse files Browse the repository at this point in the history
  • Loading branch information
deftio committed Oct 22, 2024
1 parent 831f950 commit fa35a1b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions examples/openai.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ <h3>Settings</h3>
placeholder="">You are a helpful assistant. Answer the user's questions but say 'I don't know that' if you don't know the answer.</textarea>
<label for="apiKey">API Key</label>
<input type="text" id="apiKey" name="apiKey"
placeholder="sk-01234-put-your-api-key-here. It-is-not-stored-on-any-server.">
placeholder="sk-01234-put-your-api-key-here. It-is-not-stored-on-any-server."
onblur="maskInput()" onfocus="unmaskInput()">
<label for="baseUrl">Base URL (optional):</label>
<input type="text" id="baseUrl" name="baseUrl"
placeholder="https://api.openai.com/v1/chat/completions"
Expand Down Expand Up @@ -196,6 +197,20 @@ <h3 class="mb-0">Chat</h3>
//}
);

// Mask the API key input
function maskInput() {
var input = document.getElementById("apiKey");
if (input.value !== "") {
input.type = "password"; // Change to password to show bullets
}
}

// Unmask the API key input
function unmaskInput() {
var input = document.getElementById("apiKey");
input.type = "text"; // Change back to text to show input and placeholder
}

// set remember the api key to a local cookie
document.getElementById('settingsForm').addEventListener('submit', function (e) {
e.preventDefault();
Expand All @@ -220,6 +235,7 @@ <h3 class="mb-0">Chat</h3>
}
if (name.trim() === 'apiKey') {
document.getElementById('apiKey').value = decodeURIComponent(value);
maskInput();
}
if (name.trim() === 'baseUrl') {
document.getElementById('baseUrl').value = decodeURIComponent(value);
Expand All @@ -244,10 +260,10 @@ <h3 class="mb-0">Chat</h3>

// Export chat history and prompt to a text file
document.getElementById('exportChatAndPrompt').addEventListener('click', function () {
const exportData = {}
exportData["history"]= chatInstance.historyGetAllCopy();
const exportData = {}
exportData["history"] = chatInstance.historyGetAllCopy();
exportData["prompt"] = document.getElementById('prompt').value;

const blob = new Blob([JSON.stringify(exportData, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const dateTime = new Date().toISOString().replace(/[:.]/g, '-');
Expand Down

0 comments on commit fa35a1b

Please sign in to comment.