Download script.js from Mosberg-Control/CodeNinjaOpenChat: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/Mosberg-Control/CodeNinjaOpenChat/resolve/6bdd515bb34781b426d9a1ecff6832d64801bc3e/script.js
- Command line
-
hf download hf://spaces/Mosberg-Control/CodeNinjaOpenChat@6bdd515bb34781b426d9a1ecff6832d64801bc3e/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Mosberg-Control/CodeNinjaOpenChat/resolve/6bdd515bb34781b426d9a1ecff6832d64801bc3e/script.js
1.29 kB
| document.getElementById('send-button').addEventListener('click', function() { | |
| let userInput = document.getElementById('user-input').value.trim(); | |
| if (userInput) { | |
| displayMessage(userInput, 'user'); | |
| sendMessage(userInput); | |
| document.getElementById('user-input').value = ''; | |
| } | |
| }); | |
| function sendMessage(message) { | |
| fetch('https://huggingface.co/spaces/Mosberg-Control/CodeNinjaOpenChat', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ message: message }) | |
| }) | |
| .then(response => { | |
| if (!response.ok) { | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| return response.json(); | |
| }) | |
| .then(data => { | |
| displayMessage(data.response, 'bot'); | |
| }) | |
| .catch((error) => { | |
| console.error('Error:', error); | |
| displayMessage(`Sorry, there was an error processing your request. Error: ${error.message}`, 'error'); | |
| }); | |
| } | |
| function displayMessage(message, sender) { | |
| let chatBox = document.getElementById('chat-box'); | |
| let newMessage = document.createElement('div'); | |
| newMessage.classList.add('message', sender); | |
| newMessage.textContent = message; | |
| chatBox.appendChild(newMessage); | |
| } | |