Spaces:
Paused
Paused
Download scripts/chat.js from privateuserh/StreamAI: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/privateuserh/StreamAI/resolve/47208dd6d9d61ba8f42bb3ce377a70c904c95b2f/scripts/chat.js
- Command line
-
hf download hf://spaces/privateuserh/StreamAI@47208dd6d9d61ba8f42bb3ce377a70c904c95b2f/scripts/chat.js
-
curl -L -o chat.js https://huggingface.co/spaces/privateuserh/StreamAI/resolve/47208dd6d9d61ba8f42bb3ce377a70c904c95b2f/scripts/chat.js
1.43 kB
| // scripts/chat.js | |
| const getElement = (id) => document.getElementById(id); | |
| async function sendMessage() { | |
| const userInput = getElement('user-input'); | |
| const chatMessages = getElement('chat-messages'); | |
| if (userInput.value.trim() === '') return; | |
| // ... (keep the complete sendMessage logic from the previous response here) | |
| // ... (This includes adding user message, creating AI bubble, and the fetch call) | |
| } | |
| function quickPrompt(prompt) { | |
| getElement('user-input').value = prompt; | |
| sendMessage(); | |
| } | |
| function updateRecommendationsFromAI(aiResponse) { | |
| // This is a placeholder. You can enhance this logic. | |
| let filter = 'all'; | |
| if (aiResponse.includes('comedy')) filter = 'comedy'; | |
| else if (aiResponse.includes('thriller')) filter = 'thriller'; | |
| else if (aiResponse.includes('romance')) filter = 'romance'; | |
| // In a truly modular system, this would emit an event that ui.js listens for. | |
| // For simplicity, we'll call a function defined in the global scope (see app.js). | |
| window.loadRecommendations(filter); | |
| } | |
| export function initChat() { | |
| getElement('send-btn').addEventListener('click', sendMessage); | |
| getElement('user-input').addEventListener('keypress', (e) => { | |
| if (e.key === 'Enter') { | |
| sendMessage(); | |
| } | |
| }); | |
| // Make quickPrompt globally accessible for the inline HTML onclick attributes | |
| window.quickPrompt = quickPrompt; | |
| } |