From 6dc93b66bef86370edd46feda805ace082de7551 Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Mon, 5 Aug 2024 17:27:49 +0200 Subject: [PATCH] =?UTF-8?q?Anropar=20Flask=20f=C3=B6r=20att=20f=C3=A5=20en?= =?UTF-8?q?=20lista=20med=20tillg=C3=A4ngliga=20endpoints=20och=20LLM:er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartassist/src/static/js/frontend.js | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/smartassist/src/static/js/frontend.js b/smartassist/src/static/js/frontend.js index 8738ad7..77d71fd 100644 --- a/smartassist/src/static/js/frontend.js +++ b/smartassist/src/static/js/frontend.js @@ -53,6 +53,28 @@ const frontendApi = { // Append the message element to the chatbox immediately chatbox.appendChild(messageElement); }, + // Make an AJAX request to fetch endpoint data from Flask backend + fillMenu: function() { + fetch('/api/endpoints') + .then(response => response.json()) + .then(data => { + const dropdownContainer = document.getElementById('endpoint-dropdown'); + + // Clear existing content + dropdownContainer.innerHTML = ''; + + // Populate the dropdown menu with received data + data.forEach(endpoint => { + const linkElement = document.createElement('a'); + linkElement.href = '#'; + linkElement.onclick = () => frontendApi.setEndpointAndLlm(endpoint.endpoint, endpoint.llm); + linkElement.textContent = `${endpoint.endpoint} - ${endpoint.llm}`; + + dropdownContainer.appendChild(linkElement); + }); + }) + .catch(error => console.error('Error fetching endpoints:', error)); + }, // Set the endpoint and LLM variables setEndpointAndLlm: function(endpoint, llm) { window.endpoint = endpoint; @@ -89,3 +111,12 @@ document.addEventListener('keyup', function() { sendButton.style.backgroundColor = ''; // Restore the original style when any key is released }); + +function init() { + // Other initialization code here... + frontendApi.fillMenu(); +} + +document.addEventListener('DOMContentLoaded', init); + +