|
document.getElementById('send-button').addEventListener('click', function() { |
|
let userInput = document.getElementById('user-input').value; |
|
sendMessage(userInput); |
|
}); |
|
|
|
function sendMessage(message) { |
|
fetch('https://huggingface.co/spaces/MosbergControl/CodeNinja-1.0-OpenChat-7B/your-endpoint', { |
|
method: 'POST', |
|
headers: { |
|
'Content-Type': 'application/json', |
|
}, |
|
body: JSON.stringify({ message: message }) |
|
}) |
|
.then(response => response.json()) |
|
.then(data => { |
|
displayMessage(data); |
|
}) |
|
.catch((error) => { |
|
console.error('Error:', error); |
|
}); |
|
} |
|
|
|
function displayMessage(data) { |
|
let chatBox = document.getElementById('chat-box'); |
|
let newMessage = document.createElement('div'); |
|
newMessage.textContent = data.response; |
|
chatBox.appendChild(newMessage); |
|
} |
|
|