Skip to content

Latest commit

 

History

History
105 lines (91 loc) · 3.52 KB

chat.md

File metadata and controls

105 lines (91 loc) · 3.52 KB
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style> #user-input { width: 200px; } #chat-container { text-align: center; } #send-button { display: block; margin: 20px auto 0; } </style>
<textarea id="user-input" placeholder="Copy paste your meeting notes..."></textarea> Submit
<script> document.addEventListener('DOMContentLoaded', (event) => { document.getElementById('send-button').addEventListener('click', sendMessage); function removeSpecialCharsAtStart(str) { return str.replace(/^[^a-zA-Z]+/, ''); } function formatResponse(responseText) { // Add a newline before the key phrase "%%Action Items%%" return responseText.replace(/----/g, '\n----'); } async function sendMessage() { const userInput = document.getElementById('user-input').value; const chatHistory = document.getElementById('chat-history'); // Display user's message chatHistory.innerHTML += `
User: ${userInput}
`; const controller = new AbortController(); const signal = controller.signal; // Set a timeout to abort the fetch request const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 seconds try { const response = await fetch('https://meetingchat.vercel.app/api/generate', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ meetingchat: userInput }), signal: signal, mode: 'cors' // Add this line to enable CORS }); const data = await response.json(); // Display Chatbot's response const formattedResponse = formatResponse(removeSpecialCharsAtStart(data.result)); chatHistory.innerHTML += `
Bot: ${formattedResponse}
`; } catch (error) { if (error.name === 'AbortError') { chatHistory.innerHTML += `
Error: Request timed out
`; } else { chatHistory.innerHTML += `
Error: ${error.message}
`; } } finally { clearTimeout(timeoutId); } // SQL POSTING try { const post = await fetch('http://localhost:808/newmeeting', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(userInput), }); if (post.status === 201) { const sqldata = await post.json(); const responseText = await post.text(); console.log(responseText); } else { console.log('Error posting to SQL'); } } catch (error) { console.log('Error: ' + error); } } }); </script>