Skip to content

Commit

Permalink
Merge pull request #36 from baloise/main
Browse files Browse the repository at this point in the history
Refactoring custom LLM settings
  • Loading branch information
robbizbal authored Nov 13, 2024
2 parents b68fe74 + f85e97a commit 0e1efa2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
52 changes: 51 additions & 1 deletion src/static/scripts/mask.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// shows/hides checkbox when LLM is selected
document.getElementById('backendType').addEventListener('change', function() {
var llmInputCheckbox = document.getElementById('LLMcustomLabel');
if (this.value === 'LLM') {
Expand All @@ -7,15 +8,64 @@ document.getElementById('backendType').addEventListener('change', function() {
}
});

// shows/hides custom input fields when checkbox is checked
document.getElementById('LLMcustom').addEventListener('change', function() {
var llmInputDiv = document.getElementById('LLMInput');
var llmInputDiv = document.getElementById('LLMInput');
var llmInputReset = document.getElementById('LLMReset');
if (this.checked === true) {
llmInputDiv.style.display = 'flex'; // Show the LLMInput div
llmInputReset.style.display = 'flex';
} else {
llmInputDiv.style.display = 'none'; // Hide the LLMInput div
llmInputReset.style.display = 'none';
}
});

// Load values from local storage when checkbox is true
document.getElementById('LLMcustom').addEventListener('change', function() {
const llmUrl = localStorage.getItem('LLMURL');
const llmModel = localStorage.getItem('LLMMODEL');

if (this.checked === true) {
if (llmUrl) {
document.getElementById('inputLLMurl').value = llmUrl;
}
if (llmModel) {
document.getElementById('inputLLMmodel').value = llmModel;
}
} else {
document.getElementById('inputLLMurl').value = "";
document.getElementById('inputLLMmodel').value = "";
}
});

// Store values in local storage when form is submitted
document.getElementById('inputForm').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent the form from submitting normally

// Get the values from the input fields
const llmUrl = document.getElementById('inputLLMurl').value;
const llmModel = document.getElementById('inputLLMmodel').value;

// Store the values in local storage if value is set
if (llmUrl) {
localStorage.setItem('LLMURL', llmUrl);
}
if (llmModel) {
localStorage.setItem('LLMMODEL', llmModel);
}
});

// Reset stored values when reset button is clicked
document.getElementById('btnLLMReset').addEventListener('click', function() {
alert('Reset stored custom LLM settings');
document.getElementById('inputLLMurl').value = "";
localStorage.setItem('LLMURL', "");

document.getElementById('inputLLMmodel').value = "";
localStorage.setItem('LLMMODEL', "");
});

document.getElementById('inputForm').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent the default form submission

Expand Down
6 changes: 1 addition & 5 deletions src/static/styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ footer {
white-space: pre-wrap; /* Preserve whitespace */
}

#LLMInput {
display: none; /* Hide by default */
}

#LLMcustomLabel {
#LLMcustomLabel, #LLMReset, #LLMInput {
display: none; /* Hide by default */
}

Expand Down
3 changes: 3 additions & 0 deletions src/templates/html/mask.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ <h3>Input</h3>
<div class="flex-item">
<input type="text" name="LLMMODEL" id="inputLLMmodel" placeholder="e.g.: llama3.2:latest"></input>
</div>
<div id="LLMReset" class="flex-item">
<button id="btnLLMReset"type="button">Reset</button>
</div>
</div>
<div class="flex-item">
<input type="submit" value="Submit">
Expand Down

0 comments on commit 0e1efa2

Please sign in to comment.