diff --git a/app/app.py b/app/app.py index 38e3b3d..ce2b33c 100644 --- a/app/app.py +++ b/app/app.py @@ -1,27 +1,28 @@ from flask import Flask, request, jsonify +from transformers import AutoModelForCausalLM, AutoTokenizer +# Initialize Flask app app = Flask(__name__) -@app.route('/') -def home(): - return "

Welcome to the Mental Health Chatbot

Use /chat to interact.

" - -@app.route('/chat', methods=['POST']) -def chat(): - user_input = request.json.get('message') - response = get_response(user_input) # Call the response function - return jsonify({'response': response}) - -def get_response(user_input): - # Simple logic based on keywords - if "anxiety" in user_input.lower(): - return "It's okay to feel anxious. Consider practicing deep breathing." - elif "stress" in user_input.lower(): - return "Stress can be managed with meditation and exercise." - elif "depression" in user_input.lower(): - return "It's important to talk to someone. You're not alone." - else: - return "I'm here to help. Can you tell me more about what you're feeling?" +# Load the fine-tuned model and tokenizer +# Change this line: + +# To this line (removing the './'): +model = AutoModelForCausalLM.from_pretrained('fine_tuned_model') + +tokenizer = AutoTokenizer.from_pretrained('./fine_tuned_model') + +@app.route('/predict', methods=['POST']) +def predict(): + data = request.get_json() + input_text = data['text'] # Get the input text from the request + inputs = tokenizer.encode(input_text, return_tensors='pt') + + # Generate predictions + outputs = model.generate(inputs, max_length=100) + predicted_text = tokenizer.decode(outputs[0], skip_special_tokens=True) + + return jsonify({'response': predicted_text}) if __name__ == '__main__': app.run(debug=True) diff --git a/app/static/script.js b/app/static/script.js index bb4b931..97a3816 100644 --- a/app/static/script.js +++ b/app/static/script.js @@ -27,17 +27,36 @@ document.getElementById('send-button').onclick = function() { }); }; -// Add event listener for form submission (optional) -document.getElementById('chat-form').addEventListener('submit', function(event) { - event.preventDefault(); // Prevent default form submission - document.getElementById('send-button').click(); // Trigger the send button click +// Add event listener for 'Enter' key +document.getElementById('user-input').addEventListener('keydown', function(event) { + if (event.key === 'Enter') { // Check if the pressed key is 'Enter' + event.preventDefault(); // Prevent default action (e.g., adding a new line) + document.getElementById('send-button').click(); // Simulate a click on the send button + } }); // Function to display a message in the chatbox function displayMessage(message, sender) { const messageDiv = document.createElement('div'); messageDiv.classList.add(sender === 'user' ? 'user-message' : 'ai-message'); - messageDiv.textContent = message; + + // Create a container for the message + const messageContainer = document.createElement('div'); + messageContainer.classList.add('message-container'); + + // Add avatar for AI responses only + if (sender === 'ai') { + const avatar = document.createElement('img'); + avatar.src = 'path/to/ai-avatar.png'; // Update with the actual path to the AI avatar + avatar.classList.add('avatar'); + messageContainer.appendChild(avatar); // Append the avatar to the message container + } + + // Append message text to the container + messageContainer.appendChild(document.createTextNode(message)); + + messageDiv.appendChild(messageContainer); + document.getElementById('messages').appendChild(messageDiv); // Auto-scroll to latest message document.getElementById('chatbox').scrollTop = document.getElementById('chatbox').scrollHeight; diff --git a/app/static/styles.css b/app/static/styles.css index eafd2b7..585e9e1 100644 --- a/app/static/styles.css +++ b/app/static/styles.css @@ -1,35 +1,40 @@ body { font-family: Arial, sans-serif; - background-color: #f2f2f2; + background-color: #FFFFFF; /* No background color for full-screen effect */ + color: black; /* Black text for readability */ margin: 0; - padding: 20px; + padding: 0; /* Remove padding */ + height: 100vh; /* Full height */ } .container { - max-width: 600px; - margin: auto; - background: white; + max-width: 100%; /* Full width */ + height: calc(100vh - 50px); /* Full height minus footer space */ + margin: 0; /* Remove margin */ + background: #FFFFFF; /* White background */ padding: 20px; - border-radius: 8px; - box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); + border-radius: 0; /* Remove border radius */ + box-shadow: none; /* Remove box shadow */ + display: flex; + flex-direction: column; /* Stack elements vertically */ } h1 { text-align: center; - color: #333; + color: #001F3F; /* Dark blue text */ margin-bottom: 20px; } #chatbox { - height: 400px; + flex-grow: 1; /* Fill remaining space */ overflow-y: auto; - border: 1px solid #ccc; + border: 2px solid #003366; /* Dark blue border */ margin-bottom: 10px; padding: 10px; display: flex; flex-direction: column; border-radius: 5px; - background-color: #f9f9f9; + background-color: #F9F9F9; /* Light gray background */ } #messages { @@ -38,23 +43,32 @@ h1 { flex-grow: 1; } -.user-message, .ai-message { - padding: 10px; - margin: 5px 0; - border-radius: 5px; - transition: background-color 0.3s ease; /* Smooth transition for hover effect */ +.message-container { + display: flex; /* Align items horizontally */ + align-items: center; /* Center items vertically */ + margin: 5px 0; /* Space between messages */ } .user-message { - background-color: #e1ffc7; + padding: 10px; + border-radius: 5px; + transition: background-color 0.3s ease; /* Smooth transition for hover effect */ + background-color: #3D9970; /* Dark green background */ + color: white; /* White text */ align-self: flex-end; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); + max-width: 70%; /* Limit the width of user messages */ } .ai-message { - background-color: #d1e6ff; + padding: 10px; + border-radius: 5px; + transition: background-color 0.3s ease; /* Smooth transition for hover effect */ + background-color: #0074D9; /* Dark blue background */ + color: white; /* White text */ align-self: flex-start; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); + max-width: 70%; /* Limit the width of AI messages */ } .input-area { @@ -66,19 +80,19 @@ h1 { #user-input { flex-grow: 1; padding: 10px; - border: 1px solid #ccc; + border: 2px solid #003366; /* Dark blue border */ border-radius: 4px; transition: border-color 0.3s ease; /* Smooth transition for focus effect */ } #user-input:focus { - border-color: #4CAF50; /* Change border color on focus */ + border-color: #3D9970; /* Dark green border on focus */ outline: none; /* Remove default outline */ } #send-button { padding: 10px 15px; - background-color: #4CAF50; + background-color: #3D9970; /* Dark green button */ color: white; border: none; border-radius: 4px; @@ -87,20 +101,24 @@ h1 { } #send-button:hover { - background-color: #45a049; + background-color: #2C7A4B; /* Darker green on hover */ } +/* Helpline Styling */ #helpline { - margin-top: 10px; font-weight: bold; - white-space: nowrap; - overflow: hidden; - position: relative; + color: white; /* White text for helpline */ text-align: center; /* Center align helpline text */ + background-color: red; /* Full red background */ + padding: 10px; /* Add padding for better appearance */ + position: relative; /* Changed to relative for proper stacking */ + margin-top: 10px; /* Space above the helpline */ } .scrolling-helpline { - animation: scroll 10s linear infinite; + white-space: nowrap; /* Prevent line breaks */ + display: inline-block; /* Allow inline block for scrolling */ + animation: scroll 10s linear infinite; /* Continuous scrolling */ } @keyframes scroll { @@ -108,22 +126,26 @@ h1 { 100% { transform: translateX(-100%); } } -.helpline-number { - color: red; -} - footer { text-align: center; margin-top: 20px; font-size: 0.9em; - color: #777; + color: black; /* Black text */ } footer a { - color: #4CAF50; /* Link color */ + color: #3D9970; /* Dark green link color */ text-decoration: none; } footer a:hover { text-decoration: underline; /* Underline links on hover */ } + +/* Avatar styles */ +.avatar { + width: 40px; /* Set avatar width */ + height: 40px; /* Set avatar height */ + border-radius: 50%; /* Make it circular */ + margin-right: 10px; /* Space between avatar and message text */ +} diff --git a/app/templates/index.html b/app/templates/index.html index 6376c6b..de149a3 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -3,27 +3,24 @@ - Mental Health Support Chatbot - + + Mental Health Chatbot
-

Mental Health Support Chatbot

+

Mental Health Chatbot

- +
-
- If you need immediate help, please call 1-800-273-8255 -
+
If you are in crisis, please call the national helpline at 1-800-273-TALK (1-800-273-8255).
- + diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 46fb739..4c1a648 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -4,6 +4,36 @@ "lockfileVersion": 3, "requires": true, "packages": { + "node_modules/@huggingface/gguf": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/@huggingface/gguf/-/gguf-0.1.12.tgz", + "integrity": "sha512-m+u/ms28wE74v2VVCTncfI/KB2v897MRMOoRuYSU62P85fJ6/B2exMlHCNyAXkgDLeXBWDivXl4gPq+XbHmkaA==", + "license": "MIT", + "engines": { + "node": ">=20" + } + }, + "node_modules/@huggingface/inference": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/@huggingface/inference/-/inference-2.8.1.tgz", + "integrity": "sha512-EfsNtY9OR6JCNaUa5bZu2mrs48iqeTz0Gutwf+fU0Kypx33xFQB4DKMhp8u4Ee6qVbLbNWvTHuWwlppLQl4p4Q==", + "license": "MIT", + "dependencies": { + "@huggingface/tasks": "^0.12.9" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@huggingface/tasks": { + "version": "0.12.26", + "resolved": "https://registry.npmjs.org/@huggingface/tasks/-/tasks-0.12.26.tgz", + "integrity": "sha512-h7Rs35blf8UcC0UIG7JU4zlZ5xvlT1sDozv9rd3aRkzOWrXajn4wUhEd4AYcgEv/M5gDLVfWI+m9mRpNFAoPPA==", + "license": "MIT", + "dependencies": { + "@huggingface/gguf": "^0.1.12" + } + }, "node_modules/@mongodb-js/saslprep": { "version": "1.1.9", "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.9.tgz", @@ -72,6 +102,25 @@ "@redis/client": "^1.0.0" } }, + "node_modules/@types/node": { + "version": "18.19.59", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.59.tgz", + "integrity": "sha512-vizm2EqwV/7Zay+A6J3tGl9Lhr7CjZe2HmWS988sefiEmsyP9CeXEleho6i4hJk/8UtZAo0bWN4QPZZr83RxvQ==", + "license": "MIT", + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/@types/node-fetch": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", + "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", + "license": "MIT", + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.0" + } + }, "node_modules/@types/webidl-conversions": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", @@ -87,6 +136,18 @@ "@types/webidl-conversions": "*" } }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "license": "MIT", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -120,6 +181,18 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/agentkeepalive": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz", + "integrity": "sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==", + "license": "MIT", + "dependencies": { + "humanize-ms": "^1.2.1" + }, + "engines": { + "node": ">= 8.0.0" + } + }, "node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -159,6 +232,12 @@ "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", "license": "MIT" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -297,6 +376,18 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -387,6 +478,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -484,6 +584,15 @@ "node": ">= 0.6" } }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/eventemitter3": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", @@ -600,6 +709,39 @@ } } }, + "node_modules/form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/form-data-encoder": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz", + "integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==", + "license": "MIT" + }, + "node_modules/formdata-node": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz", + "integrity": "sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==", + "license": "MIT", + "dependencies": { + "node-domexception": "1.0.0", + "web-streams-polyfill": "4.0.0-beta.3" + }, + "engines": { + "node": ">= 12.20" + } + }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -802,6 +944,15 @@ "node": ">=12" } }, + "node_modules/humanize-ms": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", + "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", + "license": "MIT", + "dependencies": { + "ms": "^2.0.0" + } + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -1139,6 +1290,67 @@ "node": ">= 0.6" } }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "license": "MIT", + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/node-fetch/node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, + "node_modules/node-fetch/node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, + "node_modules/node-fetch/node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -1172,6 +1384,32 @@ "node": ">= 0.8" } }, + "node_modules/openai": { + "version": "4.68.4", + "resolved": "https://registry.npmjs.org/openai/-/openai-4.68.4.tgz", + "integrity": "sha512-LRinV8iU9VQplkr25oZlyrsYGPGasIwYN8KFMAAFTHHLHjHhejtJ5BALuLFrkGzY4wfbKhOhuT+7lcHZ+F3iEA==", + "license": "Apache-2.0", + "dependencies": { + "@types/node": "^18.11.18", + "@types/node-fetch": "^2.6.4", + "abort-controller": "^3.0.0", + "agentkeepalive": "^4.2.1", + "form-data-encoder": "1.7.2", + "formdata-node": "^4.3.2", + "node-fetch": "^2.6.7" + }, + "bin": { + "openai": "bin/cli" + }, + "peerDependencies": { + "zod": "^3.23.8" + }, + "peerDependenciesMeta": { + "zod": { + "optional": true + } + } + }, "node_modules/opener": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz", @@ -1684,6 +1922,12 @@ "integrity": "sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==", "license": "MIT" }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "license": "MIT" + }, "node_modules/union": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/union/-/union-0.5.0.tgz", @@ -1741,6 +1985,15 @@ "node": ">= 0.8" } }, + "node_modules/web-streams-polyfill": { + "version": "4.0.0-beta.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", + "integrity": "sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==", + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/package-lock.json b/package-lock.json index f619109..bdafff3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,43 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@huggingface/inference": "^2.8.1", "body-parser": "^1.20.3", "cors": "^2.8.5", "ejs": "^3.1.10", "express": "^4.21.1", - "natural": "^8.0.1" + "natural": "^8.0.1", + "openai": "^4.68.4" + } + }, + "node_modules/@huggingface/gguf": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/@huggingface/gguf/-/gguf-0.1.12.tgz", + "integrity": "sha512-m+u/ms28wE74v2VVCTncfI/KB2v897MRMOoRuYSU62P85fJ6/B2exMlHCNyAXkgDLeXBWDivXl4gPq+XbHmkaA==", + "license": "MIT", + "engines": { + "node": ">=20" + } + }, + "node_modules/@huggingface/inference": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/@huggingface/inference/-/inference-2.8.1.tgz", + "integrity": "sha512-EfsNtY9OR6JCNaUa5bZu2mrs48iqeTz0Gutwf+fU0Kypx33xFQB4DKMhp8u4Ee6qVbLbNWvTHuWwlppLQl4p4Q==", + "license": "MIT", + "dependencies": { + "@huggingface/tasks": "^0.12.9" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@huggingface/tasks": { + "version": "0.12.26", + "resolved": "https://registry.npmjs.org/@huggingface/tasks/-/tasks-0.12.26.tgz", + "integrity": "sha512-h7Rs35blf8UcC0UIG7JU4zlZ5xvlT1sDozv9rd3aRkzOWrXajn4wUhEd4AYcgEv/M5gDLVfWI+m9mRpNFAoPPA==", + "license": "MIT", + "dependencies": { + "@huggingface/gguf": "^0.1.12" } }, "node_modules/@mongodb-js/saslprep": { @@ -84,6 +116,25 @@ "@redis/client": "^1.0.0" } }, + "node_modules/@types/node": { + "version": "18.19.59", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.59.tgz", + "integrity": "sha512-vizm2EqwV/7Zay+A6J3tGl9Lhr7CjZe2HmWS988sefiEmsyP9CeXEleho6i4hJk/8UtZAo0bWN4QPZZr83RxvQ==", + "license": "MIT", + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/@types/node-fetch": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", + "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", + "license": "MIT", + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.0" + } + }, "node_modules/@types/webidl-conversions": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", @@ -99,6 +150,18 @@ "@types/webidl-conversions": "*" } }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "license": "MIT", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -132,6 +195,18 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/agentkeepalive": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz", + "integrity": "sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==", + "license": "MIT", + "dependencies": { + "humanize-ms": "^1.2.1" + }, + "engines": { + "node": ">= 8.0.0" + } + }, "node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -171,6 +246,12 @@ "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", "license": "MIT" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -309,6 +390,18 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -399,6 +492,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -496,6 +598,15 @@ "node": ">= 0.6" } }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/eventemitter3": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", @@ -612,6 +723,39 @@ } } }, + "node_modules/form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/form-data-encoder": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz", + "integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==", + "license": "MIT" + }, + "node_modules/formdata-node": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz", + "integrity": "sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==", + "license": "MIT", + "dependencies": { + "node-domexception": "1.0.0", + "web-streams-polyfill": "4.0.0-beta.3" + }, + "engines": { + "node": ">= 12.20" + } + }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -814,6 +958,15 @@ "node": ">=12" } }, + "node_modules/humanize-ms": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", + "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", + "license": "MIT", + "dependencies": { + "ms": "^2.0.0" + } + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -1151,6 +1304,67 @@ "node": ">= 0.6" } }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "license": "MIT", + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/node-fetch/node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, + "node_modules/node-fetch/node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, + "node_modules/node-fetch/node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -1184,6 +1398,32 @@ "node": ">= 0.8" } }, + "node_modules/openai": { + "version": "4.68.4", + "resolved": "https://registry.npmjs.org/openai/-/openai-4.68.4.tgz", + "integrity": "sha512-LRinV8iU9VQplkr25oZlyrsYGPGasIwYN8KFMAAFTHHLHjHhejtJ5BALuLFrkGzY4wfbKhOhuT+7lcHZ+F3iEA==", + "license": "Apache-2.0", + "dependencies": { + "@types/node": "^18.11.18", + "@types/node-fetch": "^2.6.4", + "abort-controller": "^3.0.0", + "agentkeepalive": "^4.2.1", + "form-data-encoder": "1.7.2", + "formdata-node": "^4.3.2", + "node-fetch": "^2.6.7" + }, + "bin": { + "openai": "bin/cli" + }, + "peerDependencies": { + "zod": "^3.23.8" + }, + "peerDependenciesMeta": { + "zod": { + "optional": true + } + } + }, "node_modules/opener": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz", @@ -1696,6 +1936,12 @@ "integrity": "sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==", "license": "MIT" }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "license": "MIT" + }, "node_modules/union": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/union/-/union-0.5.0.tgz", @@ -1753,6 +1999,15 @@ "node": ">= 0.8" } }, + "node_modules/web-streams-polyfill": { + "version": "4.0.0-beta.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", + "integrity": "sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==", + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/package.json b/package.json index 5927808..ae11960 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,12 @@ "author": "", "license": "ISC", "dependencies": { + "@huggingface/inference": "^2.8.1", "body-parser": "^1.20.3", "cors": "^2.8.5", "ejs": "^3.1.10", "express": "^4.21.1", - "natural": "^8.0.1" + "natural": "^8.0.1", + "openai": "^4.68.4" } } diff --git a/server.js b/server.js index 2a74fda..1a68e39 100644 --- a/server.js +++ b/server.js @@ -11,6 +11,9 @@ app.use(express.static(path.join(__dirname, 'app/static'))); // Serve static fil app.set('views', path.join(__dirname, 'app/templates')); // Set views directory app.set('view engine', 'ejs'); // Use EJS as template engine +// Variable to track the last response type +let lastResponseType = 'general'; + // Routes app.get('/', (req, res) => { res.render('index'); // Render the index view @@ -33,28 +36,123 @@ app.post('/api/chat', (req, res) => { // Function to generate AI responses based on keywords function getAIResponse(userInput) { const responses = { - 'anxiety': 'I understand. Deep breathing can help; would you like to try a simple exercise?', - 'stress': 'It can be tough to handle stress. A short break might help you clear your mind.', - 'sad': 'I’m here to listen. Talking to someone close might also bring comfort.', - 'suicidal': 'Please reach out to a friend or mental health professional. You don’t have to go through this alone.', - 'depression': 'You’re not alone. Consider small steps toward self-care, and talking to someone might be a relief.', - 'lonely': 'Many feel this way sometimes. Connecting with others, even a short chat, might help.', - 'insomnia': 'Good sleep hygiene can help. Try reducing screen time and create a calming pre-sleep routine.', - 'overthinking': 'I know it can be overwhelming. Sometimes, writing down your thoughts helps put things in perspective.', - 'addiction': 'Seeking help from professionals can be a strong step forward. There’s always support available.', - 'frustration': 'It’s okay to feel frustrated. Taking deep breaths can help release some of that tension.', - 'nightmares': 'Nightmares can be distressing. Calming activities before bed may help create a more restful sleep.', - 'panic attack': 'Try grounding exercises. Focus on things you can see, hear, touch, and breathe slowly.', - 'general': 'Feel free to share anything on your mind. I’m here to support you.' + 'anxiety': [ + 'I understand. Deep breathing can help; would you like to try a simple exercise?', + 'It can be tough to manage anxiety. Have you tried grounding techniques?', + 'Talking to someone can really help. Do you want to share what’s on your mind?', + 'Mindfulness can be a great tool. Would you like to explore that?', + 'You’re not alone in feeling this way. Let’s talk about it.' + ], + 'stress': [ + 'It can be tough to handle stress. A short break might help you clear your mind.', + 'How about taking a few minutes to breathe deeply? It might help relieve some tension.', + 'Do you have any activities that help you unwind? Sometimes a hobby can be a good distraction.', + 'Consider jotting down your thoughts. Writing can be a great way to process stress.', + 'Remember, it’s okay to ask for help when things feel overwhelming.' + ], + 'sad': [ + 'I’m here to listen. Talking to someone close might also bring comfort.', + 'It’s perfectly okay to feel sad sometimes. Would you like to share more about it?', + 'Engaging in activities you love can sometimes lift your spirits. What do you think?', + 'Consider doing something small for yourself today; it can make a difference.', + 'Would you like some suggestions for self-care activities?' + ], + 'suicidal': [ + 'Please reach out to a friend or mental health professional. You don’t have to go through this alone.', + 'It’s really important to talk to someone who can help. Can I assist you in finding support?', + 'You are valued, and your feelings matter. I encourage you to seek professional help.', + 'Remember, there are people who care and want to help you. Please talk to someone.', + 'You’re not alone; help is available. Can I provide you with some resources?' + ], + 'depression': [ + 'You’re not alone. Consider small steps toward self-care, and talking to someone might be a relief.', + 'Have you considered reaching out to someone who can support you? Talking helps.', + 'Try to engage in activities that bring you joy, even if they feel small. What do you think?', + 'Creating a daily routine can sometimes help. Would you like tips on that?', + 'It’s okay to seek help. Would you like to explore that option?' + ], + 'lonely': [ + 'Many feel this way sometimes. Connecting with others, even a short chat, might help.', + 'Have you thought about reaching out to a friend or family member? They might be willing to chat.', + 'Joining a group or community can also help. Would you like to know about options?', + 'Feeling lonely can be tough. Let’s talk about it if you’d like.', + 'Would you like suggestions for activities that can help connect you with others?' + ], + 'insomnia': [ + 'Good sleep hygiene can help. Try reducing screen time and create a calming pre-sleep routine.', + 'Consider relaxation techniques before bed, such as meditation or reading.', + 'A consistent sleep schedule might be beneficial. Have you tried going to bed and waking up at the same time?', + 'Limiting caffeine intake in the afternoon can also help improve your sleep quality.', + 'Have you tried creating a comfortable sleeping environment? It can make a big difference.' + ], + 'overthinking': [ + 'I know it can be overwhelming. Sometimes, writing down your thoughts helps put things in perspective.', + 'Taking a break and doing something enjoyable can also help your mind relax.', + 'Have you tried mindfulness or meditation techniques? They can be very calming.', + 'Talking things out can also help clarify your thoughts. Would you like to do that?', + 'Creating a list of priorities may help you focus on what’s important. Would you like tips on that?' + ], + 'addiction': [ + 'Seeking help from professionals can be a strong step forward. There’s always support available.', + 'Connecting with a support group can also be beneficial. Would you like help finding resources?', + 'It’s great that you’re recognizing this. Small steps can lead to positive changes.', + 'Have you considered speaking to a therapist? They can provide personalized support.', + 'You don’t have to face this alone; there are people ready to help you.' + ], + 'frustration': [ + 'It’s okay to feel frustrated. Taking deep breaths can help release some of that tension.', + 'Sometimes stepping away from the situation can give you a fresh perspective. Would you like to talk about it?', + 'Do you have strategies that help you cope with frustration? Let’s explore them.', + 'Physical activity can also be a great outlet for frustration. Would you like some suggestions?', + 'It’s helpful to express what you’re feeling. Would you like to share more?' + ], + 'nightmares': [ + 'Nightmares can be distressing. Calming activities before bed may help create a more restful sleep.', + 'Talking about your nightmares can help reduce their impact. Would you like to do that?', + 'Creating a soothing bedtime routine might also improve your sleep quality.', + 'Have you considered keeping a dream journal? It can help you process your feelings.', + 'Sometimes understanding what triggers your nightmares can be beneficial. Would you like to explore this?' + ], + 'panic attack': [ + 'Try grounding exercises. Focus on things you can see, hear, touch, and breathe slowly.', + 'Have you considered using breathing techniques to help calm your body during a panic attack?', + 'Talking to someone who understands can help. Would you like to share what you’re experiencing?', + 'Recognizing the signs of a panic attack can help you manage it better. Would you like tips on that?', + 'It’s important to take care of yourself during these moments. Let’s talk about strategies that work for you.' + ], + 'general': [ + 'Feel free to share anything on your mind. I’m here to support you.', + 'I’m here for you. What would you like to talk about today?', + 'Let’s discuss what’s bothering you. Your feelings are important.', + 'I’m ready to listen. Please share what you’re thinking.', + 'How can I assist you right now? I’m here to help.' + ] }; // Check for a matching keyword in the user's input - for (const keyword in responses) { + for (let keyword in responses) { if (userInput.includes(keyword)) { - return responses[keyword]; // Return the matched response + let replies = responses[keyword]; // Get array of responses + let randomIndex = Math.floor(Math.random() * replies.length); // Generate a random index based on the array length + + // Update last response type + lastResponseType = keyword; + return replies[randomIndex]; // Return the response at the random index } } - return responses['general']; // Default response if no keyword is matched + + // If no keyword matches, check last response type + if (lastResponseType !== 'general') { + lastResponseType = 'general'; // Reset to general if the last response was specific + const generalReplies = responses['general']; + const randomGeneralIndex = Math.floor(Math.random() * generalReplies.length); // Get random index for general responses + return generalReplies[randomGeneralIndex]; // Return a random general response + } + + // Return a general response only if it was the last response + const generalReplies = responses['general']; + const randomGeneralIndex = Math.floor(Math.random() * generalReplies.length); + return generalReplies[randomGeneralIndex]; // Return a random general response } // Start server