diff --git a/index.html b/index.html index 6cbaa63..e3f8663 100644 --- a/index.html +++ b/index.html @@ -18,14 +18,10 @@ max-width: 960px; margin: 0 auto; } - + - - - - + @@ -237,13 +234,12 @@ hermes.ai.unturf.com {
We will likely implement a rate limit based on client IP address.
-Because we don't use API keys we don't have any real need for a server.
+view the page source, it's _all_ there!
+Because we don't require a valid API key, we don't have any real need for a server.
-TODO: a Javascript CDN bundle of the minimum viable web client for this demo will be hosted and provided free of charge.
+This web client-only solution uses uncloseai.js which is designed to support static sites or CDNs hosting HTML content. In this architecture, the browser serves as the client, directly interacting with the API without the need for an intermediary server/client. Because we eliminate the requirement for a valid API key, we allow the API to handle requests on behalf of the browser client, making it an efficient & accessible for thin clients which are often on battery.
Feel free to message us in the box below.
+Feel free to message us in the box below.
- - -You: ${userInput}
`; + + // Create a new paragraph for the AI response + const aiResponseParagraph = document.createElement('p'); + aiResponseParagraph.innerHTML = 'AI: '; + chatBox.appendChild(aiResponseParagraph); + + // Create a span element for the actual response content + const responseContent = document.createElement('span'); + aiResponseParagraph.appendChild(responseContent); + + let accumulatedContent = ''; + for await (const chunk of sendMessage(userInput)) { + accumulatedContent += chunk; + const parsedChunk = marked.parse(accumulatedContent); + responseContent.innerHTML = parsedChunk; + + // Apply syntax highlighting to code blocks + responseContent.querySelectorAll('pre code').forEach((block) => { + hljs.highlightElement(block); + }); + } + + chatBox.scrollTop = chatBox.scrollHeight; +} + +// Function to initialize the chat interface +function initializeChatInterface() { + const pageContent = extractWebpageContent(); + chatHistory.push({ + role: "system", + content: `Here's the content of the webpage: ${pageContent}` + }); + + // Set up marked.js options + marked.setOptions({ + highlight: function(code, lang) { + const language = hljs.getLanguage(lang) ? lang : 'plaintext'; + return hljs.highlight(code, { language }).value; + } + }); +} + +document.getElementById("user-input").addEventListener("keydown", function(event) { + if (event.key === "Enter" && !event.shiftKey) { + event.preventDefault(); + handleUserInput(); + } +}); + +// Initialize the chat interface when the page loads +window.onload = initializeChatInterface; + +// Expose handleUserInput to the global scope +window.handleUserInput = handleUserInput; +