$(document).ready(function() { var memoryMode = 'full'; $('#memory-toggle').change(function() { memoryMode = $(this).is(':checked') ? 'smart' : 'full'; }); $('#chat-form').submit(function(event) { event.preventDefault(); var userInput = $('#user-input').val(); $('#chat-container').append('
'); $('#user-input').val(''); $('#send-button').prop('disabled', true); $('#loading-message').show(); var $botMessage = $(' '); $('#chat-container').append($botMessage); var botResponse = ''; $.ajax({ url: '/chat', method: 'POST', data: JSON.stringify({ user_input: userInput, mode: memoryMode }), contentType: 'application/json', dataType: 'text', // Add this line to handle the response as text xhrFields: { onprogress: function(e) { var chunk = e.currentTarget.response.slice(botResponse.length); botResponse += chunk; $botMessage.html('' + botResponse.replace(/\n/g, '