Spaces:
Runtime error
Runtime error
| <html> | |
| <head> | |
| <title>Onboarder</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| <!-- Meta description --> | |
| <meta name="description" | |
| content="Experience the seamless interaction with your digital lifestyle needs using Jio Copilot. From shopping with JioMart, exploring health and beauty products with TiraBeauty, streaming content with JioCinema, to navigating internet plans with JioFiber, Jio Copilot caters to all. Enjoy a streamlined, efficient digital experience across multiple platforms." /> | |
| <!-- Open Graph --> | |
| <meta property="og:type" content="website" /> | |
| <meta property="og:url" content="https://jio.copilot.live/" /> | |
| <meta property="og:title" content="DwightAI" /> | |
| <meta property="og:description" | |
| content="Experience the seamless interaction with your digital lifestyle needs using Jio Copilot. From shopping with JioMart, exploring health and beauty products with TiraBeauty, streaming content with JioCinema, to navigating internet plans with JioFiber, Jio Copilot caters to all. Enjoy a streamlined, efficient digital experience across multiple platforms." /> | |
| <meta property="og:image" content="https://cdn.copilot.live/v2/original/icons/JioGPT_icon.png" /> | |
| <link rel="stylesheet" | |
| href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css" /> | |
| <link rel="icon" href="https://cdn.copilot.live/v2/original/icons/JioGPT_icon.png" type="image/x-icon" /> | |
| <style> | |
| body { | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| height: 100vh; | |
| margin: 0; | |
| background-color: white; | |
| font-family: Arial, sans-serif; | |
| } | |
| #title-bar { | |
| font-size: 20px; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| margin: 12px 0px; | |
| } | |
| #chat-container { | |
| width: 95%; | |
| height: 100%; | |
| max-width: 800px; | |
| overflow: hidden; | |
| display: flex; | |
| flex-direction: column; | |
| justify-content: space-between; | |
| } | |
| #chat { | |
| height: calc(100vh - 160px); | |
| overflow: auto; | |
| border-radius: 10px; | |
| } | |
| .message { | |
| padding: 10px; | |
| margin-bottom: 10px; | |
| border-radius: 10px; | |
| } | |
| .user { | |
| align-self: flex-end; | |
| background-color: #f4a91e; | |
| color: white; | |
| display: flex; | |
| align-items: flex-start; | |
| justify-content: unset; | |
| gap: 13px; | |
| } | |
| .ai { | |
| align-self: flex-start; | |
| background-color: #eee; | |
| color: black; | |
| display: flex; | |
| align-items: flex-start; | |
| justify-content: unset; | |
| gap: 13px; | |
| } | |
| #input-container { | |
| display: flex; | |
| height: 70px; | |
| border-radius: 10px; | |
| margin-bottom: 10px; | |
| } | |
| #message { | |
| width: 80%; | |
| border: 0; | |
| font-size: 16px; | |
| padding: 10px; | |
| border-radius: 10px 0 0 10px; | |
| background-color: #eee; | |
| } | |
| #message:focus-visible { | |
| outline: 0; | |
| } | |
| #send { | |
| width: 20%; | |
| max-width: 200px; | |
| background-color: #3635f0; | |
| color: white; | |
| border: none; | |
| font-size: 16px; | |
| cursor: pointer; | |
| } | |
| #clear-history { | |
| width: 80px; | |
| font-size: 16px; | |
| border: none; | |
| color: white; | |
| background-color: #1ecbae; | |
| border-radius: 0 10px 10px 0; | |
| cursor: pointer; | |
| } | |
| .disable-button { | |
| background-color: #eee ; | |
| cursor: not-allowed ; | |
| color: #c3c3c3 ; | |
| } | |
| .cursor { | |
| height: 1.2em; | |
| width: 0.7em; | |
| background-color: #374151; | |
| animation: blink 1s infinite; | |
| } | |
| /* Animation */ | |
| @keyframes blink { | |
| 0% { | |
| opacity: 1; | |
| } | |
| 50% { | |
| opacity: 0; | |
| } | |
| 100% { | |
| opacity: 1; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="chat-container"> | |
| <div id="title-bar"> | |
| <img src="https://cdn.copilot.live/v2/original/icons/JioGPT_icon.png" width="40px" height="40px" /> | |
| DwightAI | |
| </div> | |
| <div id="chat"></div> | |
| <div id="input-container"> | |
| <input id="message" type="text" placeholder="Type your message" /> | |
| <button id="send" title="Send Message">Send</button> | |
| <button id="clear-history" title="Clear history">Clear</button> | |
| </div> | |
| </div> | |
| <!-- Import marked.js for markdown rendering --> | |
| <script src="https://cdn.jsdelivr.net/npm/marked@5.1.0/marked.min.js"></script> | |
| <script> | |
| const renderer = new marked.Renderer(); | |
| const linkRenderer = renderer.link; | |
| renderer.link = (href, title, text) => { | |
| const html = linkRenderer.call(renderer, href, title, text); | |
| return html.replace( | |
| /^<a /, | |
| '<a target="_blank" rel="noopener noreferrer" ' | |
| ); | |
| }; | |
| marked.setOptions({ renderer }); | |
| class StateManager { | |
| constructor(initialState = {}) { | |
| this.state = initialState; | |
| this.listeners = []; | |
| } | |
| getState() { | |
| return this.state; | |
| } | |
| subscribe(listener) { | |
| this.listeners.push(listener); | |
| } | |
| updateState(newState) { | |
| this.state = { ...this.state, ...newState }; | |
| this.listeners.forEach((listener) => listener(this.state)); | |
| } | |
| } | |
| const stateManager = new StateManager({ inprogress: false }); | |
| const chatElement = document.getElementById("chat"); | |
| document.addEventListener("DOMContentLoaded", (event) => { | |
| const messageElement = document.querySelector("#message"); | |
| const sendButton = document.querySelector("#send"); | |
| const clearButton = document.querySelector("#clear-history"); | |
| sendButton.addEventListener("click", sendMessage); | |
| messageElement.addEventListener("keydown", (event) => { | |
| if (event.key === "Enter") { | |
| const inprogress = stateManager.getState().inprogress; | |
| if (!inprogress) { | |
| sendMessage(); | |
| } | |
| } | |
| }); | |
| clearButton.addEventListener("click", clearHistory); | |
| loadChatHistory(); | |
| }); | |
| async function loadChatHistory() { | |
| const response = await fetch("/history", { method: "GET" }); | |
| if (!response.ok) { | |
| console.error("Failed to fetch chat history"); | |
| return; | |
| } | |
| const chatHistory = await response.json(); | |
| for (const message of chatHistory) { | |
| appendMessage( | |
| message.content, | |
| message.role === "user" ? "user" : "ai" | |
| ); | |
| } | |
| } | |
| async function clearHistory() { | |
| const response = await fetch("/history", { method: "DELETE" }); | |
| if (response.ok) { | |
| chatElement.replaceChildren(chatElement.firstChild); | |
| stateManager.updateState({ inprogress: false }); | |
| } else { | |
| console.error("Failed to clear chat history"); | |
| } | |
| } | |
| async function sendMessage() { | |
| const messageElement = document.querySelector("#message"); | |
| const message = messageElement.value; | |
| messageElement.value = ""; | |
| appendMessage(message, "user"); | |
| const aiMessageContainer = appendMessage("", "ai"); | |
| const aiMessageElement = aiMessageContainer.childNodes[1]; | |
| const sendButton = document.getElementById("send"); | |
| sendButton.disabled = true; | |
| sendButton.classList.add("disable-button"); | |
| const cursor = document.createElement("div"); | |
| cursor.classList.add("cursor"); | |
| aiMessageElement.appendChild(cursor) | |
| const response = await fetch("/openai", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ prompt: message }), | |
| }); | |
| const reader = response.body | |
| .pipeThrough(new TextDecoderStream()) | |
| .getReader(); | |
| let serverMessage = ""; | |
| let count = 0; | |
| while (true) { | |
| stateManager.updateState({ inprogress: true }); | |
| const { value, done } = await reader.read(); | |
| if (done) { | |
| stateManager.updateState({ inprogress: false }); | |
| document.getElementById("send").disabled = false; | |
| sendButton.disabled = false; | |
| sendButton.classList.remove("disable-button"); | |
| break; | |
| } | |
| serverMessage += value; | |
| aiMessageElement.innerHTML = marked.parse( | |
| serverMessage.replace(/\\n/g, "<br>"), | |
| { breaks: true } | |
| ); | |
| if ( | |
| count % 10 == 0 && | |
| chatElement.scrollHeight - | |
| chatElement.scrollTop - | |
| chatElement.clientHeight <= | |
| 44 | |
| ) { | |
| aiMessageElement.scrollIntoView(); | |
| } | |
| count++; | |
| } | |
| chatElement.scrollTop = chatElement.scrollHeight; | |
| } | |
| function appendMessage(message, sender) { | |
| const div = document.createElement("div"); | |
| div.classList.add("message", "markdown-body", sender); | |
| div.appendChild(createIcon(sender)); | |
| div.appendChild(createTextElement(message, sender)); | |
| chatElement.appendChild(div); | |
| div.scrollIntoView(); | |
| chatElement.scrollTop = chatElement.scrollHeight; | |
| return div; | |
| } | |
| function createIcon(sender) { | |
| const icon = document.createElement("img"); | |
| icon.style.width = "40px"; | |
| icon.style.height = "40px"; | |
| icon.style.marginTop = "10px"; | |
| icon.style.backgroundColor = "unset"; | |
| icon.alt = sender.charAt(0).toUpperCase() + sender.slice(1) + " Icon"; | |
| icon.src = | |
| sender === "ai" | |
| ? "https://cdn.copilot.live/v2/original/icons/JioGPT_icon.png" | |
| : "https://img.icons8.com/?size=512&id=108296&format=png"; | |
| return icon; | |
| } | |
| function createTextElement(message, sender) { | |
| const textElement = document.createElement("div"); | |
| textElement.innerHTML = marked.parse(message, { breaks: true }); | |
| return textElement; | |
| } | |
| </script> | |
| </body> | |
| </html> |