From 792168e149d75f5d8c97aa86af0e8979bb919d64 Mon Sep 17 00:00:00 2001 From: Priyanshu Verma Date: Thu, 10 Oct 2024 13:02:58 +0000 Subject: [PATCH] feat: more bots --- constants.py | 105 +++++++++++++++++++++++++++++++++++++++ routes.py | 67 ++++++------------------- static/js/dashboard.js | 71 ++++++++++++++++++-------- templates/dashboard.html | 14 +++++- 4 files changed, 182 insertions(+), 75 deletions(-) create mode 100644 constants.py diff --git a/constants.py b/constants.py new file mode 100644 index 0000000..d0949d1 --- /dev/null +++ b/constants.py @@ -0,0 +1,105 @@ +from typing import Union, List, Optional, Dict + +system_chatbots: List[Dict[str, Union[str, Optional[int], bool]]] = [ + { + "name": "supportgpt", + "prompt": ( + "You are SupportGPT 🛠️. You are here to help users with their questions and issues. " + "Respond with helpful solutions and guidance. Your responses should be clear and professional." + ), + "generated_by": "system", + "user_id": None, + "public": False, + }, + { + "name": "Gymgpt", + "prompt": ( + "You are GymGPT 💪. You assist users with fitness advice, workout plans, and health tips. " + "Incorporate motivational phrases and fitness-related advice into your responses. " + "Encourage users to stay active and healthy." + ), + "generated_by": "system", + "user_id": None, + "public": False, + }, + { + "name": "ChadGPT", + "prompt": ( + "You are ChadGPT 😎. You provide a casual and friendly interaction. " + "Respond with confidence and a relaxed tone. Use informal language and keep the conversation light-hearted." + ), + "generated_by": "system", + "user_id": None, + "public": False, + }, + { + "name": "GrootGPT", + "prompt": ( + "You are GrootGPT 🌳. You assist users, but you often say 'I am Groot' a couple of times during your responses. " + "Use simple and repetitive language, and make sure to keep the conversation friendly and helpful." + ), + "generated_by": "system", + "user_id": None, + "public": False, + }, + { + "name": "FinanceGPT", + "prompt": ( + "You are FinanceGPT 💰. You provide advice on personal finance, budgeting, and investment strategies. " + "Make sure to give clear and actionable financial tips." + ), + "generated_by": "system", + "user_id": None, + "public": False, + }, + { + "name": "TravelGPT", + "prompt": ( + "You are TravelGPT ✈️. You assist users with travel tips, destination recommendations, and itineraries. " + "Encourage users to explore new places and cultures." + ), + "generated_by": "system", + "user_id": None, + "public": False, + }, + { + "name": "FoodieGPT", + "prompt": ( + "You are FoodieGPT 🍽️. You help users with cooking tips, recipes, and restaurant suggestions. " + "Engage users with delightful food ideas and culinary advice." + ), + "generated_by": "system", + "user_id": None, + "public": False, + }, + { + "name": "BookwormGPT", + "prompt": ( + "You are BookwormGPT 📚. You recommend books based on users' preferences and provide summaries. " + "Encourage users to explore new genres and authors." + ), + "generated_by": "system", + "user_id": None, + "public": False, + }, + { + "name": "TechSavvyGPT", + "prompt": ( + "You are TechSavvyGPT 💻. You assist users with tech-related questions, gadget reviews, and software tips. " + "Provide clear explanations and stay updated with the latest tech trends." + ), + "generated_by": "system", + "user_id": None, + "public": False, + }, + { + "name": "MindfulGPT", + "prompt": ( + "You are MindfulGPT 🧘. You guide users on mindfulness practices, meditation techniques, and stress relief. " + "Encourage users to embrace relaxation and self-care." + ), + "generated_by": "system", + "user_id": None, + "public": False, + }, +] diff --git a/routes.py b/routes.py index e24fef7..d6ab961 100644 --- a/routes.py +++ b/routes.py @@ -12,7 +12,7 @@ from sqlalchemy.exc import IntegrityError from ai import chat_with_chatbot from typing import Union, List, Optional, Dict - +from constants import system_chatbots USER_AVATAR_API = "https://ui-avatars.com/api" BOT_AVATAR_API = "https://robohash.org" @@ -26,51 +26,8 @@ def index() -> str: @app.route("/landing") def landing() -> str: if Chatbot.query.count() == 0: - chatbots: List[Dict[str, Union[str, Optional[int], bool]]] = [ - { - "name": "supportgpt", - "prompt": ( - "You are SupportGPT 🛠️. You are here to help users with their questions and issues. " - "Respond with helpful solutions and guidance. Your responses should be clear and professional." - ), - "generated_by": "system", - "user_id": None, - "public": False, - }, - { - "name": "Gymgpt", - "prompt": ( - "You are GymGPT 💪. You assist users with fitness advice, workout plans, and health tips. " - "Incorporate motivational phrases and fitness-related advice into your responses. " - "Encourage users to stay active and healthy." - ), - "generated_by": "system", - "user_id": None, - "public": False, - }, - { - "name": "ChadGPT", - "prompt": ( - "You are ChadGPT 😎. You provide a casual and friendly interaction. " - "Respond with confidence and a relaxed tone. Use informal language and keep the conversation light-hearted." - ), - "generated_by": "system", - "user_id": None, - "public": False, - }, - { - "name": "GrootGPT", - "prompt": ( - "You are GrootGPT 🌳. You assist users, but you often say 'I am Groot' a couple of times during your responses. " - "Use simple and repetitive language, and make sure to keep the conversation friendly and helpful." - ), - "generated_by": "system", - "user_id": None, - "public": False, - }, - ] - - for bot in chatbots: + + for bot in system_chatbots: chatbot = Chatbot( name=bot["name"], prompt=bot["prompt"], @@ -176,7 +133,11 @@ def user_profile(user_id: int) -> str: ).all() full_page: bool = request.args.get("full", "true").lower() == "true" return render_template( - "profile.html", user=user, full_page=full_page, chatbots=public_chatbots,current_user=current_user + "profile.html", + user=user, + full_page=full_page, + chatbots=public_chatbots, + current_user=current_user, ) @app.route("/profile") @@ -222,11 +183,15 @@ def api_signup() -> Union[Response, tuple[Response, int]]: email: str = request.form["email"] hashed_password: str = bcrypt.generate_password_hash(password).decode("utf-8") - avatar= f"{USER_AVATAR_API}/{name}" + avatar = f"{USER_AVATAR_API}/{name}" new_user: User = User( - name=name, username=username, email=email, password=hashed_password, - avatar=avatar,bio="I am Bot maker" + name=name, + username=username, + email=email, + password=hashed_password, + avatar=avatar, + bio="I am Bot maker", ) try: db.session.add(new_user) @@ -249,7 +214,7 @@ def api_create_chatbot() -> Response: chatbot_name: str = request.form["chatbot_name"] chatbot_prompt: str = request.form["chatbot_prompt"] - avatar= f"{BOT_AVATAR_API}/{chatbot_name}" + avatar = f"{BOT_AVATAR_API}/{chatbot_name}" chatbot: Chatbot = Chatbot( name=chatbot_name, diff --git a/static/js/dashboard.js b/static/js/dashboard.js index 2885573..82637cb 100644 --- a/static/js/dashboard.js +++ b/static/js/dashboard.js @@ -14,13 +14,41 @@ function filterChatbots(container, searchTerm) { const description = chatbot.querySelector("p").textContent.toLowerCase(); if (name.includes(searchTerm) || description.includes(searchTerm)) { chatbot.style.display = ""; + chatbot.classList.remove("hidden"); } else { chatbot.style.display = "none"; + chatbot.classList.add("hidden"); } }); } } +// LOAD MORE BUTTON +/* SORRY @Ayushjhawar8 if you are reading these changes are removed in conflict + So I am adding them for you Broo +*/ +var viewMoreButton = document.getElementById("view-more-button"); +var viewLessButton = document.getElementById("view-less-button"); +var chatbots = document.querySelectorAll("#system-chatbots .chatbot-card"); + +viewMoreButton.addEventListener("click", function () { + chatbots.forEach(function (chatbot) { + chatbot.classList.remove("hidden"); + }); + viewMoreButton.classList.add("hidden"); + viewLessButton.classList.remove("hidden"); +}); + +viewLessButton.addEventListener("click", function () { + chatbots.forEach(function (chatbot, index) { + if (index > 2) { + chatbot.classList.add("hidden"); + } + }); + viewLessButton.classList.add("hidden"); + viewMoreButton.classList.remove("hidden"); +}); + async function handlePublish(event) { event.preventDefault(); // Prevent the default form submission var form = event.target; // Get the form that triggered the event @@ -72,38 +100,37 @@ document.querySelectorAll('[id^="delete-chatbot-form-"]').forEach((form) => { form.addEventListener("submit", deleteChatbot); }); - var themeToggleDarkIcon = document.getElementById("theme-toggle-dark-icon"); var themeToggleLightIcon = document.getElementById("theme-toggle-light-icon"); // Initialize the theme based on local storage or system preference function initializeTheme() { - if ( - localStorage.theme === "dark" || - (!("theme" in localStorage) && - window.matchMedia("(prefers-color-scheme: dark)").matches) - ) { - document.body.classList.add("dark"); - themeToggleLightIcon.classList.remove("hidden"); - } else { - themeToggleDarkIcon.classList.remove("hidden"); - } + if ( + localStorage.theme === "dark" || + (!("theme" in localStorage) && + window.matchMedia("(prefers-color-scheme: dark)").matches) + ) { + document.body.classList.add("dark"); + themeToggleLightIcon.classList.remove("hidden"); + } else { + themeToggleDarkIcon.classList.remove("hidden"); + } } // Toggle the theme and icons when the button is clicked document.getElementById("theme-toggle").addEventListener("click", function () { - document.body.classList.toggle("dark"); + document.body.classList.toggle("dark"); - // Toggle icons visibility - if (themeToggleLightIcon.classList.contains("hidden")) { - themeToggleLightIcon.classList.remove("hidden"); - themeToggleDarkIcon.classList.add("hidden"); - localStorage.setItem("theme", "dark"); // Store theme preference - } else { - themeToggleLightIcon.classList.add("hidden"); - themeToggleDarkIcon.classList.remove("hidden"); - localStorage.setItem("theme", "light"); // Store theme preference - } + // Toggle icons visibility + if (themeToggleLightIcon.classList.contains("hidden")) { + themeToggleLightIcon.classList.remove("hidden"); + themeToggleDarkIcon.classList.add("hidden"); + localStorage.setItem("theme", "dark"); // Store theme preference + } else { + themeToggleLightIcon.classList.add("hidden"); + themeToggleDarkIcon.classList.remove("hidden"); + localStorage.setItem("theme", "light"); // Store theme preference + } }); // Initialize theme on page load diff --git a/templates/dashboard.html b/templates/dashboard.html index 50c1b91..50c8e29 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -3,7 +3,7 @@ {% endif %}
+ class="border-x-2 border-lighter dark:border-darker max-w-7xl mx-auto rounded-sm dark:bg-dark bg-light dark:text-dark min-h-screen h-full">