Skip to content

Commit

Permalink
Merge pull request #69 from priyanshuverma-dev/add-chatbots
Browse files Browse the repository at this point in the history
feat: more bots
  • Loading branch information
kom-senapati authored Oct 10, 2024
2 parents 4f8cbf1 + 792168e commit 018952e
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 75 deletions.
105 changes: 105 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -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,
},
]
67 changes: 16 additions & 51 deletions routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"],
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
71 changes: 49 additions & 22 deletions static/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% endif %}

<div
class="border-x-2 border-lighter dark:border-darker max-w-7xl mx-auto rounded-sm dark:bg-dark bg-light dark:text-dark">
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">


<nav class="flex justify-between items-center px-6 py-4 rounded-md border-b-2 dark:border-darker border-lighter">
Expand Down Expand Up @@ -140,7 +140,7 @@ <h2 class="text-2xl font-bold mb-6 p-3">System Chatbots</h2>
<div id="system-chatbots" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8 p-3">
{% for chatbot in system_chatbots %}
<div
class="chatbot-card bg-light dark:bg-dark p-6 rounded-lg drop-shadow hover:shadow border border-lighter dark:border-darker flex flex-col justify-between h-64">
class="{% if loop.index > 3 %}hidden{% endif %} chatbot-card bg-light dark:bg-dark p-6 rounded-lg drop-shadow hover:shadow border border-lighter dark:border-darker flex flex-col justify-between h-64">
<div>
<div class="flex items-center space-x-2">
<img src="{{ chatbot.avatar }}" alt="{{ chatbot.name }}'s avatar"
Expand All @@ -165,6 +165,16 @@ <h3 class="text-xl font-semibold truncate" title="{{ chatbot.name }}">
</div>
{% endfor %}
</div>
<div class="flex justify-center mt-4">
<button id="view-more-button"
class="bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded transition duration-300">
View More
</button>
<button id="view-less-button"
class="bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded transition duration-300 hidden ml-2">
View Less
</button>
</div>
</div>
{% endif %}

Expand Down

0 comments on commit 018952e

Please sign in to comment.