diff --git a/src/assets/js/main.js b/src/assets/js/main.js new file mode 100644 index 0000000..5e38841 --- /dev/null +++ b/src/assets/js/main.js @@ -0,0 +1,39 @@ +// Variables +const llmHost = 'https://chat.vfsh.me'; +const generateEndpoint = '/api/generate'; + +// Grab elements from the page +const userInput = document.getElementById('userInput'); +const sendButton = document.getElementById('sendButton'); +const outputArea = document.getElementById('outputArea'); + +// Functions +async function sendGen() { + const response = await fetch(`${llmHost}${generateEndpoint}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ model: 'llama3.2', prompt: userInput.value }) + }); + + return response; +} + +async function readResponse(response) { + const reader = response.body.getReader(); + const decoder = new TextDecoder('utf-8'); + let done = false; + + try { + while (!done) { + const { value, done: readerDone } = await reader.read(); + done = readerDone; + const chunk = decoder.decode(value, { stream: true }); + outputArea.innerHTML += chunk; + outputArea.scrollTop = outputArea.scrollHeight; + } + } catch (error) { + outputArea.innerHTML = `Error: ${error.message}`; + } +} \ No newline at end of file diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..5c90f38 --- /dev/null +++ b/src/index.html @@ -0,0 +1,19 @@ + + +
+ + +