Spaces:
Running
Running
Add 3 files
Browse files- README.md +7 -5
- index.html +955 -19
- prompts.txt +0 -0
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: openchatai-qwen
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,955 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Qwen AI Chatbot</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
.chat-message.user {
|
| 11 |
+
background-color: #3b82f6;
|
| 12 |
+
color: white;
|
| 13 |
+
border-radius: 1rem 1rem 0 1rem;
|
| 14 |
+
}
|
| 15 |
+
.chat-message.ai {
|
| 16 |
+
background-color: #f3f4f6;
|
| 17 |
+
color: #1f2937;
|
| 18 |
+
border-radius: 1rem 1rem 1rem 0;
|
| 19 |
+
}
|
| 20 |
+
.fade-in {
|
| 21 |
+
animation: fadeIn 0.3s ease-in-out;
|
| 22 |
+
}
|
| 23 |
+
@keyframes fadeIn {
|
| 24 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 25 |
+
to { opacity: 1; transform: translateY(0); }
|
| 26 |
+
}
|
| 27 |
+
.slide-in {
|
| 28 |
+
animation: slideIn 0.3s ease-out;
|
| 29 |
+
}
|
| 30 |
+
@keyframes slideIn {
|
| 31 |
+
from { transform: translateX(100%); }
|
| 32 |
+
to { transform: translateX(0); }
|
| 33 |
+
}
|
| 34 |
+
</style>
|
| 35 |
+
</head>
|
| 36 |
+
<body class="bg-gray-100 font-sans">
|
| 37 |
+
<div id="app" class="min-h-screen flex flex-col">
|
| 38 |
+
<!-- Auth Modal -->
|
| 39 |
+
<div id="auth-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
| 40 |
+
<div class="bg-white rounded-lg p-6 w-full max-w-md">
|
| 41 |
+
<div class="flex justify-between items-center mb-4">
|
| 42 |
+
<h2 class="text-xl font-bold" id="auth-modal-title">Sign In</h2>
|
| 43 |
+
<button id="close-auth-modal" class="text-gray-500 hover:text-gray-700">
|
| 44 |
+
<i class="fas fa-times"></i>
|
| 45 |
+
</button>
|
| 46 |
+
</div>
|
| 47 |
+
<div id="auth-tabs" class="flex border-b mb-4">
|
| 48 |
+
<button class="auth-tab py-2 px-4 font-medium text-blue-500 border-b-2 border-blue-500" data-tab="signin">Sign In</button>
|
| 49 |
+
<button class="auth-tab py-2 px-4 font-medium text-gray-500" data-tab="signup">Sign Up</button>
|
| 50 |
+
</div>
|
| 51 |
+
<div id="signin-form">
|
| 52 |
+
<div class="mb-4">
|
| 53 |
+
<label for="signin-email" class="block text-sm font-medium text-gray-700 mb-1">Email</label>
|
| 54 |
+
<input type="email" id="signin-email" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 55 |
+
</div>
|
| 56 |
+
<div class="mb-4">
|
| 57 |
+
<label for="signin-password" class="block text-sm font-medium text-gray-700 mb-1">Password</label>
|
| 58 |
+
<input type="password" id="signin-password" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 59 |
+
</div>
|
| 60 |
+
<button id="signin-btn" class="w-full bg-blue-500 text-white py-2 px-4 rounded-md hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">Sign In</button>
|
| 61 |
+
</div>
|
| 62 |
+
<div id="signup-form" class="hidden">
|
| 63 |
+
<div class="mb-4">
|
| 64 |
+
<label for="signup-name" class="block text-sm font-medium text-gray-700 mb-1">Name</label>
|
| 65 |
+
<input type="text" id="signup-name" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 66 |
+
</div>
|
| 67 |
+
<div class="mb-4">
|
| 68 |
+
<label for="signup-email" class="block text-sm font-medium text-gray-700 mb-1">Email</label>
|
| 69 |
+
<input type="email" id="signup-email" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 70 |
+
</div>
|
| 71 |
+
<div class="mb-4">
|
| 72 |
+
<label for="signup-password" class="block text-sm font-medium text-gray-700 mb-1">Password</label>
|
| 73 |
+
<input type="password" id="signup-password" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 74 |
+
</div>
|
| 75 |
+
<div class="mb-4">
|
| 76 |
+
<label for="signup-confirm-password" class="block text-sm font-medium text-gray-700 mb-1">Confirm Password</label>
|
| 77 |
+
<input type="password" id="signup-confirm-password" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 78 |
+
</div>
|
| 79 |
+
<button id="signup-btn" class="w-full bg-blue-500 text-white py-2 px-4 rounded-md hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">Sign Up</button>
|
| 80 |
+
</div>
|
| 81 |
+
<div id="auth-message" class="mt-4 text-sm text-red-500 hidden"></div>
|
| 82 |
+
</div>
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<!-- Context Modal -->
|
| 86 |
+
<div id="context-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
| 87 |
+
<div class="bg-white rounded-lg p-6 w-full max-w-2xl max-h-[90vh] overflow-y-auto">
|
| 88 |
+
<div class="flex justify-between items-center mb-4">
|
| 89 |
+
<h2 class="text-xl font-bold">Chat Context</h2>
|
| 90 |
+
<button id="close-context-modal" class="text-gray-500 hover:text-gray-700">
|
| 91 |
+
<i class="fas fa-times"></i>
|
| 92 |
+
</button>
|
| 93 |
+
</div>
|
| 94 |
+
<div class="mb-4">
|
| 95 |
+
<label class="block text-sm font-medium text-gray-700 mb-1">User Information</label>
|
| 96 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 97 |
+
<div>
|
| 98 |
+
<label for="context-name" class="block text-xs text-gray-500 mb-1">Name</label>
|
| 99 |
+
<input type="text" id="context-name" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 100 |
+
</div>
|
| 101 |
+
<div>
|
| 102 |
+
<label for="context-location" class="block text-xs text-gray-500 mb-1">Location</label>
|
| 103 |
+
<input type="text" id="context-location" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 104 |
+
</div>
|
| 105 |
+
<div>
|
| 106 |
+
<label for="context-pets" class="block text-xs text-gray-500 mb-1">Pets</label>
|
| 107 |
+
<input type="text" id="context-pets" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 108 |
+
</div>
|
| 109 |
+
<div>
|
| 110 |
+
<label for="context-interests" class="block text-xs text-gray-500 mb-1">Interests</label>
|
| 111 |
+
<input type="text" id="context-interests" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
<div class="mb-4">
|
| 116 |
+
<label for="context-info" class="block text-sm font-medium text-gray-700 mb-1">Additional Information</label>
|
| 117 |
+
<textarea id="context-info" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"></textarea>
|
| 118 |
+
</div>
|
| 119 |
+
<div class="mb-4">
|
| 120 |
+
<label for="context-instructions" class="block text-sm font-medium text-gray-700 mb-1">Chat Instructions</label>
|
| 121 |
+
<textarea id="context-instructions" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"></textarea>
|
| 122 |
+
<p class="text-xs text-gray-500 mt-1">Tell the AI how you want it to respond (e.g., "Be concise", "Explain like I'm 5", etc.)</p>
|
| 123 |
+
</div>
|
| 124 |
+
<div class="flex justify-end space-x-2">
|
| 125 |
+
<button id="cancel-context-btn" class="px-4 py-2 border border-gray-300 rounded-md hover:bg-gray-50">Cancel</button>
|
| 126 |
+
<button id="save-context-btn" class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600">Save Context</button>
|
| 127 |
+
</div>
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
| 130 |
+
|
| 131 |
+
<!-- Rename Chat Modal -->
|
| 132 |
+
<div id="rename-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
| 133 |
+
<div class="bg-white rounded-lg p-6 w-full max-w-md">
|
| 134 |
+
<div class="flex justify-between items-center mb-4">
|
| 135 |
+
<h2 class="text-xl font-bold">Rename Chat</h2>
|
| 136 |
+
<button id="close-rename-modal" class="text-gray-500 hover:text-gray-700">
|
| 137 |
+
<i class="fas fa-times"></i>
|
| 138 |
+
</button>
|
| 139 |
+
</div>
|
| 140 |
+
<div class="mb-4">
|
| 141 |
+
<label for="new-chat-name" class="block text-sm font-medium text-gray-700 mb-1">New Chat Name</label>
|
| 142 |
+
<input type="text" id="new-chat-name" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 143 |
+
</div>
|
| 144 |
+
<div class="flex justify-end space-x-2">
|
| 145 |
+
<button id="cancel-rename-btn" class="px-4 py-2 border border-gray-300 rounded-md hover:bg-gray-50">Cancel</button>
|
| 146 |
+
<button id="save-rename-btn" class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600">Rename</button>
|
| 147 |
+
</div>
|
| 148 |
+
</div>
|
| 149 |
+
</div>
|
| 150 |
+
|
| 151 |
+
<!-- Header -->
|
| 152 |
+
<header class="bg-white shadow-sm">
|
| 153 |
+
<div class="max-w-7xl mx-auto px-4 py-4 sm:px-6 lg:px-8 flex justify-between items-center">
|
| 154 |
+
<h1 class="text-xl font-bold text-gray-900">Qwen AI Chatbot</h1>
|
| 155 |
+
<div id="auth-buttons" class="flex items-center space-x-4">
|
| 156 |
+
<button id="signin-btn-header" class="text-gray-600 hover:text-gray-900">Sign In</button>
|
| 157 |
+
<button id="signup-btn-header" class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600">Sign Up</button>
|
| 158 |
+
</div>
|
| 159 |
+
<div id="user-info" class="hidden flex items-center space-x-4">
|
| 160 |
+
<span id="username-display" class="font-medium"></span>
|
| 161 |
+
<button id="signout-btn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300">Sign Out</button>
|
| 162 |
+
</div>
|
| 163 |
+
</div>
|
| 164 |
+
</header>
|
| 165 |
+
|
| 166 |
+
<!-- Main Content -->
|
| 167 |
+
<main class="flex-1 flex overflow-hidden">
|
| 168 |
+
<!-- Sidebar -->
|
| 169 |
+
<div id="sidebar" class="hidden md:block w-64 bg-white border-r border-gray-200 overflow-y-auto">
|
| 170 |
+
<div class="p-4">
|
| 171 |
+
<button id="new-chat-btn" class="w-full flex items-center justify-center px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 mb-4">
|
| 172 |
+
<i class="fas fa-plus mr-2"></i> New Chat
|
| 173 |
+
</button>
|
| 174 |
+
<div class="flex items-center justify-between mb-2">
|
| 175 |
+
<h2 class="font-medium text-gray-700">Your Chats</h2>
|
| 176 |
+
<button id="edit-chats-btn" class="text-gray-500 hover:text-gray-700">
|
| 177 |
+
<i class="fas fa-edit"></i>
|
| 178 |
+
</button>
|
| 179 |
+
</div>
|
| 180 |
+
<div id="chat-list" class="space-y-1">
|
| 181 |
+
<!-- Chats will be populated here -->
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
| 184 |
+
</div>
|
| 185 |
+
|
| 186 |
+
<!-- Mobile Sidebar Toggle -->
|
| 187 |
+
<button id="sidebar-toggle" class="md:hidden fixed bottom-4 right-4 bg-white p-3 rounded-full shadow-lg z-40">
|
| 188 |
+
<i class="fas fa-bars text-gray-700"></i>
|
| 189 |
+
</button>
|
| 190 |
+
|
| 191 |
+
<!-- Mobile Sidebar -->
|
| 192 |
+
<div id="mobile-sidebar" class="fixed inset-0 bg-white z-30 transform translate-x-full transition-transform duration-300 ease-in-out md:hidden">
|
| 193 |
+
<div class="p-4">
|
| 194 |
+
<div class="flex justify-between items-center mb-4">
|
| 195 |
+
<h2 class="text-lg font-bold">Your Chats</h2>
|
| 196 |
+
<button id="close-mobile-sidebar" class="text-gray-500 hover:text-gray-700">
|
| 197 |
+
<i class="fas fa-times"></i>
|
| 198 |
+
</button>
|
| 199 |
+
</div>
|
| 200 |
+
<button id="new-chat-btn-mobile" class="w-full flex items-center justify-center px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 mb-4">
|
| 201 |
+
<i class="fas fa-plus mr-2"></i> New Chat
|
| 202 |
+
</button>
|
| 203 |
+
<div id="mobile-chat-list" class="space-y-1">
|
| 204 |
+
<!-- Chats will be populated here -->
|
| 205 |
+
</div>
|
| 206 |
+
</div>
|
| 207 |
+
</div>
|
| 208 |
+
|
| 209 |
+
<!-- Chat Area -->
|
| 210 |
+
<div class="flex-1 flex flex-col overflow-hidden">
|
| 211 |
+
<!-- Chat Header -->
|
| 212 |
+
<div class="bg-white border-b border-gray-200 p-4 flex justify-between items-center">
|
| 213 |
+
<div class="flex items-center">
|
| 214 |
+
<button id="sidebar-toggle-inline" class="md:hidden mr-4 text-gray-500 hover:text-gray-700">
|
| 215 |
+
<i class="fas fa-bars"></i>
|
| 216 |
+
</button>
|
| 217 |
+
<h2 id="current-chat-title" class="text-lg font-medium">New Chat</h2>
|
| 218 |
+
</div>
|
| 219 |
+
<div class="flex items-center space-x-2">
|
| 220 |
+
<button id="edit-chat-btn" class="p-2 text-gray-500 hover:text-gray-700" title="Rename Chat">
|
| 221 |
+
<i class="fas fa-edit"></i>
|
| 222 |
+
</button>
|
| 223 |
+
<button id="context-btn" class="p-2 text-gray-500 hover:text-gray-700" title="Chat Context">
|
| 224 |
+
<i class="fas fa-cog"></i>
|
| 225 |
+
</button>
|
| 226 |
+
</div>
|
| 227 |
+
</div>
|
| 228 |
+
|
| 229 |
+
<!-- Messages -->
|
| 230 |
+
<div id="messages" class="flex-1 overflow-y-auto p-4 space-y-4">
|
| 231 |
+
<div class="text-center py-8 text-gray-500">
|
| 232 |
+
<i class="fas fa-comments text-4xl mb-2"></i>
|
| 233 |
+
<p>Start a conversation with Qwen AI</p>
|
| 234 |
+
</div>
|
| 235 |
+
</div>
|
| 236 |
+
|
| 237 |
+
<!-- Input Area -->
|
| 238 |
+
<div class="bg-white border-t border-gray-200 p-4">
|
| 239 |
+
<form id="message-form" class="flex space-x-2">
|
| 240 |
+
<input
|
| 241 |
+
id="message-input"
|
| 242 |
+
type="text"
|
| 243 |
+
placeholder="Type your message..."
|
| 244 |
+
class="flex-1 px-4 py-2 border border-gray-300 rounded-full focus:outline-none focus:ring-2 focus:ring-blue-500"
|
| 245 |
+
autocomplete="off"
|
| 246 |
+
>
|
| 247 |
+
<button
|
| 248 |
+
type="submit"
|
| 249 |
+
id="send-btn"
|
| 250 |
+
class="px-4 py-2 bg-blue-500 text-white rounded-full hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
|
| 251 |
+
>
|
| 252 |
+
<i class="fas fa-paper-plane"></i>
|
| 253 |
+
</button>
|
| 254 |
+
</form>
|
| 255 |
+
<p class="text-xs text-gray-500 mt-2">Qwen AI may produce inaccurate information about people, places, or facts.</p>
|
| 256 |
+
</div>
|
| 257 |
+
</div>
|
| 258 |
+
</main>
|
| 259 |
+
</div>
|
| 260 |
+
|
| 261 |
+
<script>
|
| 262 |
+
// API Configuration
|
| 263 |
+
const API_KEY = 'sk_ROxVP2yyiAWaOM5X3Ghjp-eqn71Eyh27dX-m43irL8Y';
|
| 264 |
+
const API_URL = 'https://api.novita.ai/v3/inference';
|
| 265 |
+
|
| 266 |
+
// State Management
|
| 267 |
+
let state = {
|
| 268 |
+
currentUser: null,
|
| 269 |
+
currentChatId: null,
|
| 270 |
+
chats: [],
|
| 271 |
+
editMode: false,
|
| 272 |
+
isGenerating: false
|
| 273 |
+
};
|
| 274 |
+
|
| 275 |
+
// DOM Elements
|
| 276 |
+
const elements = {
|
| 277 |
+
authModal: document.getElementById('auth-modal'),
|
| 278 |
+
authModalTitle: document.getElementById('auth-modal-title'),
|
| 279 |
+
authTabs: document.getElementById('auth-tabs'),
|
| 280 |
+
authTabsButtons: document.querySelectorAll('.auth-tab'),
|
| 281 |
+
signinForm: document.getElementById('signin-form'),
|
| 282 |
+
signupForm: document.getElementById('signup-form'),
|
| 283 |
+
signinEmail: document.getElementById('signin-email'),
|
| 284 |
+
signinPassword: document.getElementById('signin-password'),
|
| 285 |
+
signinBtn: document.getElementById('signin-btn'),
|
| 286 |
+
signupName: document.getElementById('signup-name'),
|
| 287 |
+
signupEmail: document.getElementById('signup-email'),
|
| 288 |
+
signupPassword: document.getElementById('signup-password'),
|
| 289 |
+
signupConfirmPassword: document.getElementById('signup-confirm-password'),
|
| 290 |
+
signupBtn: document.getElementById('signup-btn'),
|
| 291 |
+
authMessage: document.getElementById('auth-message'),
|
| 292 |
+
closeAuthModal: document.getElementById('close-auth-modal'),
|
| 293 |
+
contextModal: document.getElementById('context-modal'),
|
| 294 |
+
closeContextModal: document.getElementById('close-context-modal'),
|
| 295 |
+
cancelContextBtn: document.getElementById('cancel-context-btn'),
|
| 296 |
+
saveContextBtn: document.getElementById('save-context-btn'),
|
| 297 |
+
renameModal: document.getElementById('rename-modal'),
|
| 298 |
+
closeRenameModal: document.getElementById('close-rename-modal'),
|
| 299 |
+
cancelRenameBtn: document.getElementById('cancel-rename-btn'),
|
| 300 |
+
saveRenameBtn: document.getElementById('save-rename-btn'),
|
| 301 |
+
newChatName: document.getElementById('new-chat-name'),
|
| 302 |
+
authButtons: document.getElementById('auth-buttons'),
|
| 303 |
+
userInfo: document.getElementById('user-info'),
|
| 304 |
+
usernameDisplay: document.getElementById('username-display'),
|
| 305 |
+
signoutBtn: document.getElementById('signout-btn'),
|
| 306 |
+
signinBtnHeader: document.getElementById('signin-btn-header'),
|
| 307 |
+
signupBtnHeader: document.getElementById('signup-btn-header'),
|
| 308 |
+
sidebar: document.getElementById('sidebar'),
|
| 309 |
+
mobileSidebar: document.getElementById('mobile-sidebar'),
|
| 310 |
+
sidebarToggle: document.getElementById('sidebar-toggle'),
|
| 311 |
+
sidebarToggleInline: document.getElementById('sidebar-toggle-inline'),
|
| 312 |
+
closeMobileSidebar: document.getElementById('close-mobile-sidebar'),
|
| 313 |
+
chatList: document.getElementById('chat-list'),
|
| 314 |
+
mobileChatList: document.getElementById('mobile-chat-list'),
|
| 315 |
+
newChatBtn: document.getElementById('new-chat-btn'),
|
| 316 |
+
newChatBtnMobile: document.getElementById('new-chat-btn-mobile'),
|
| 317 |
+
editChatsBtn: document.getElementById('edit-chats-btn'),
|
| 318 |
+
editChatBtn: document.getElementById('edit-chat-btn'),
|
| 319 |
+
contextBtn: document.getElementById('context-btn'),
|
| 320 |
+
currentChatTitle: document.getElementById('current-chat-title'),
|
| 321 |
+
messages: document.getElementById('messages'),
|
| 322 |
+
messageForm: document.getElementById('message-form'),
|
| 323 |
+
messageInput: document.getElementById('message-input'),
|
| 324 |
+
sendBtn: document.getElementById('send-btn'),
|
| 325 |
+
contextName: document.getElementById('context-name'),
|
| 326 |
+
contextLocation: document.getElementById('context-location'),
|
| 327 |
+
contextPets: document.getElementById('context-pets'),
|
| 328 |
+
contextInterests: document.getElementById('context-interests'),
|
| 329 |
+
contextInfo: document.getElementById('context-info'),
|
| 330 |
+
contextInstructions: document.getElementById('context-instructions')
|
| 331 |
+
};
|
| 332 |
+
|
| 333 |
+
// Initialize the app
|
| 334 |
+
function init() {
|
| 335 |
+
loadUserFromLocalStorage();
|
| 336 |
+
setupEventListeners();
|
| 337 |
+
renderUI();
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
// Load user from localStorage
|
| 341 |
+
function loadUserFromLocalStorage() {
|
| 342 |
+
const userData = localStorage.getItem('qwenChatUser');
|
| 343 |
+
if (userData) {
|
| 344 |
+
state.currentUser = JSON.parse(userData);
|
| 345 |
+
loadUserChats();
|
| 346 |
+
}
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
// Load user's chats
|
| 350 |
+
function loadUserChats() {
|
| 351 |
+
if (!state.currentUser) return;
|
| 352 |
+
|
| 353 |
+
const userChats = localStorage.getItem(`qwenChats_${state.currentUser.id}`);
|
| 354 |
+
if (userChats) {
|
| 355 |
+
state.chats = JSON.parse(userChats);
|
| 356 |
+
|
| 357 |
+
// If there are chats but no current chat, set the first one as current
|
| 358 |
+
if (state.chats.length > 0 && !state.currentChatId) {
|
| 359 |
+
state.currentChatId = state.chats[0].id;
|
| 360 |
+
}
|
| 361 |
+
} else {
|
| 362 |
+
// Create a default chat if none exists
|
| 363 |
+
createNewChat();
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
// Save user's chats to localStorage
|
| 368 |
+
function saveUserChats() {
|
| 369 |
+
if (!state.currentUser) return;
|
| 370 |
+
localStorage.setItem(`qwenChats_${state.currentUser.id}`, JSON.stringify(state.chats));
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
// Setup event listeners
|
| 374 |
+
function setupEventListeners() {
|
| 375 |
+
// Auth modal
|
| 376 |
+
elements.signinBtnHeader.addEventListener('click', () => showAuthModal('signin'));
|
| 377 |
+
elements.signupBtnHeader.addEventListener('click', () => showAuthModal('signup'));
|
| 378 |
+
elements.closeAuthModal.addEventListener('click', hideAuthModal);
|
| 379 |
+
|
| 380 |
+
// Auth tabs
|
| 381 |
+
elements.authTabsButtons.forEach(button => {
|
| 382 |
+
button.addEventListener('click', () => {
|
| 383 |
+
const tab = button.dataset.tab;
|
| 384 |
+
showAuthTab(tab);
|
| 385 |
+
});
|
| 386 |
+
});
|
| 387 |
+
|
| 388 |
+
// Auth forms
|
| 389 |
+
elements.signinBtn.addEventListener('click', handleSignIn);
|
| 390 |
+
elements.signupBtn.addEventListener('click', handleSignUp);
|
| 391 |
+
elements.signoutBtn.addEventListener('click', handleSignOut);
|
| 392 |
+
|
| 393 |
+
// Context modal
|
| 394 |
+
elements.contextBtn.addEventListener('click', showContextModal);
|
| 395 |
+
elements.closeContextModal.addEventListener('click', hideContextModal);
|
| 396 |
+
elements.cancelContextBtn.addEventListener('click', hideContextModal);
|
| 397 |
+
elements.saveContextBtn.addEventListener('click', saveContext);
|
| 398 |
+
|
| 399 |
+
// Rename modal
|
| 400 |
+
elements.editChatBtn.addEventListener('click', showRenameModal);
|
| 401 |
+
elements.closeRenameModal.addEventListener('click', hideRenameModal);
|
| 402 |
+
elements.cancelRenameBtn.addEventListener('click', hideRenameModal);
|
| 403 |
+
elements.saveRenameBtn.addEventListener('click', renameCurrentChat);
|
| 404 |
+
|
| 405 |
+
// Chat operations
|
| 406 |
+
elements.newChatBtn.addEventListener('click', createNewChat);
|
| 407 |
+
elements.newChatBtnMobile.addEventListener('click', createNewChat);
|
| 408 |
+
elements.editChatsBtn.addEventListener('click', toggleEditMode);
|
| 409 |
+
|
| 410 |
+
// Message form
|
| 411 |
+
elements.messageForm.addEventListener('submit', handleMessageSubmit);
|
| 412 |
+
|
| 413 |
+
// Sidebar toggles
|
| 414 |
+
elements.sidebarToggle.addEventListener('click', toggleMobileSidebar);
|
| 415 |
+
elements.sidebarToggleInline.addEventListener('click', toggleMobileSidebar);
|
| 416 |
+
elements.closeMobileSidebar.addEventListener('click', toggleMobileSidebar);
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
// Show auth modal
|
| 420 |
+
function showAuthModal(tab = 'signin') {
|
| 421 |
+
elements.authModal.classList.remove('hidden');
|
| 422 |
+
showAuthTab(tab);
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
// Hide auth modal
|
| 426 |
+
function hideAuthModal() {
|
| 427 |
+
elements.authModal.classList.add('hidden');
|
| 428 |
+
elements.authMessage.classList.add('hidden');
|
| 429 |
+
elements.authMessage.textContent = '';
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
// Show auth tab
|
| 433 |
+
function showAuthTab(tab) {
|
| 434 |
+
elements.authTabsButtons.forEach(button => {
|
| 435 |
+
if (button.dataset.tab === tab) {
|
| 436 |
+
button.classList.add('text-blue-500', 'border-blue-500');
|
| 437 |
+
button.classList.remove('text-gray-500');
|
| 438 |
+
} else {
|
| 439 |
+
button.classList.remove('text-blue-500', 'border-blue-500');
|
| 440 |
+
button.classList.add('text-gray-500');
|
| 441 |
+
}
|
| 442 |
+
});
|
| 443 |
+
|
| 444 |
+
if (tab === 'signin') {
|
| 445 |
+
elements.signinForm.classList.remove('hidden');
|
| 446 |
+
elements.signupForm.classList.add('hidden');
|
| 447 |
+
elements.authModalTitle.textContent = 'Sign In';
|
| 448 |
+
} else {
|
| 449 |
+
elements.signinForm.classList.add('hidden');
|
| 450 |
+
elements.signupForm.classList.remove('hidden');
|
| 451 |
+
elements.authModalTitle.textContent = 'Sign Up';
|
| 452 |
+
}
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
// Handle sign in
|
| 456 |
+
function handleSignIn(e) {
|
| 457 |
+
e.preventDefault();
|
| 458 |
+
|
| 459 |
+
const email = elements.signinEmail.value.trim();
|
| 460 |
+
const password = elements.signinPassword.value.trim();
|
| 461 |
+
|
| 462 |
+
if (!email || !password) {
|
| 463 |
+
showAuthMessage('Please fill in all fields');
|
| 464 |
+
return;
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
// In a real app, this would be an API call to your backend
|
| 468 |
+
const users = JSON.parse(localStorage.getItem('qwenUsers') || '[]');
|
| 469 |
+
const user = users.find(u => u.email === email && u.password === password);
|
| 470 |
+
|
| 471 |
+
if (!user) {
|
| 472 |
+
showAuthMessage('Invalid email or password');
|
| 473 |
+
return;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
// Successfully signed in
|
| 477 |
+
state.currentUser = user;
|
| 478 |
+
localStorage.setItem('qwenChatUser', JSON.stringify(user));
|
| 479 |
+
hideAuthModal();
|
| 480 |
+
loadUserChats();
|
| 481 |
+
renderUI();
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
// Handle sign up
|
| 485 |
+
function handleSignUp(e) {
|
| 486 |
+
e.preventDefault();
|
| 487 |
+
|
| 488 |
+
const name = elements.signupName.value.trim();
|
| 489 |
+
const email = elements.signupEmail.value.trim();
|
| 490 |
+
const password = elements.signupPassword.value.trim();
|
| 491 |
+
const confirmPassword = elements.signupConfirmPassword.value.trim();
|
| 492 |
+
|
| 493 |
+
if (!name || !email || !password || !confirmPassword) {
|
| 494 |
+
showAuthMessage('Please fill in all fields');
|
| 495 |
+
return;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
if (password !== confirmPassword) {
|
| 499 |
+
showAuthMessage('Passwords do not match');
|
| 500 |
+
return;
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
if (password.length < 6) {
|
| 504 |
+
showAuthMessage('Password must be at least 6 characters');
|
| 505 |
+
return;
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
// Check if email already exists
|
| 509 |
+
const users = JSON.parse(localStorage.getItem('qwenUsers') || '[]');
|
| 510 |
+
if (users.some(u => u.email === email)) {
|
| 511 |
+
showAuthMessage('Email already in use');
|
| 512 |
+
return;
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
// Create new user
|
| 516 |
+
const newUser = {
|
| 517 |
+
id: Date.now().toString(),
|
| 518 |
+
name,
|
| 519 |
+
email,
|
| 520 |
+
password,
|
| 521 |
+
createdAt: new Date().toISOString()
|
| 522 |
+
};
|
| 523 |
+
|
| 524 |
+
// Save user
|
| 525 |
+
users.push(newUser);
|
| 526 |
+
localStorage.setItem('qwenUsers', JSON.stringify(users));
|
| 527 |
+
|
| 528 |
+
// Sign in the new user
|
| 529 |
+
state.currentUser = newUser;
|
| 530 |
+
localStorage.setItem('qwenChatUser', JSON.stringify(newUser));
|
| 531 |
+
hideAuthModal();
|
| 532 |
+
|
| 533 |
+
// Create first chat for the new user
|
| 534 |
+
createNewChat();
|
| 535 |
+
renderUI();
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
// Handle sign out
|
| 539 |
+
function handleSignOut() {
|
| 540 |
+
state.currentUser = null;
|
| 541 |
+
state.currentChatId = null;
|
| 542 |
+
state.chats = [];
|
| 543 |
+
localStorage.removeItem('qwenChatUser');
|
| 544 |
+
renderUI();
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
// Show auth message
|
| 548 |
+
function showAuthMessage(message) {
|
| 549 |
+
elements.authMessage.textContent = message;
|
| 550 |
+
elements.authMessage.classList.remove('hidden');
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
// Show context modal
|
| 554 |
+
function showContextModal() {
|
| 555 |
+
if (!state.currentUser || !state.currentChatId) return;
|
| 556 |
+
|
| 557 |
+
const chat = state.chats.find(c => c.id === state.currentChatId);
|
| 558 |
+
if (!chat) return;
|
| 559 |
+
|
| 560 |
+
// Fill in the context form with existing data
|
| 561 |
+
elements.contextName.value = chat.context?.name || '';
|
| 562 |
+
elements.contextLocation.value = chat.context?.location || '';
|
| 563 |
+
elements.contextPets.value = chat.context?.pets || '';
|
| 564 |
+
elements.contextInterests.value = chat.context?.interests || '';
|
| 565 |
+
elements.contextInfo.value = chat.context?.additionalInfo || '';
|
| 566 |
+
elements.contextInstructions.value = chat.context?.instructions || '';
|
| 567 |
+
|
| 568 |
+
elements.contextModal.classList.remove('hidden');
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
// Hide context modal
|
| 572 |
+
function hideContextModal() {
|
| 573 |
+
elements.contextModal.classList.add('hidden');
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
// Save context
|
| 577 |
+
function saveContext() {
|
| 578 |
+
if (!state.currentUser || !state.currentChatId) return;
|
| 579 |
+
|
| 580 |
+
const chatIndex = state.chats.findIndex(c => c.id === state.currentChatId);
|
| 581 |
+
if (chatIndex === -1) return;
|
| 582 |
+
|
| 583 |
+
state.chats[chatIndex].context = {
|
| 584 |
+
name: elements.contextName.value.trim(),
|
| 585 |
+
location: elements.contextLocation.value.trim(),
|
| 586 |
+
pets: elements.contextPets.value.trim(),
|
| 587 |
+
interests: elements.contextInterests.value.trim(),
|
| 588 |
+
additionalInfo: elements.contextInfo.value.trim(),
|
| 589 |
+
instructions: elements.contextInstructions.value.trim()
|
| 590 |
+
};
|
| 591 |
+
|
| 592 |
+
saveUserChats();
|
| 593 |
+
hideContextModal();
|
| 594 |
+
renderChatList();
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
// Show rename modal
|
| 598 |
+
function showRenameModal() {
|
| 599 |
+
if (!state.currentUser || !state.currentChatId) return;
|
| 600 |
+
|
| 601 |
+
const chat = state.chats.find(c => c.id === state.currentChatId);
|
| 602 |
+
if (!chat) return;
|
| 603 |
+
|
| 604 |
+
elements.newChatName.value = chat.title;
|
| 605 |
+
elements.renameModal.classList.remove('hidden');
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
// Hide rename modal
|
| 609 |
+
function hideRenameModal() {
|
| 610 |
+
elements.renameModal.classList.add('hidden');
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
// Rename current chat
|
| 614 |
+
function renameCurrentChat() {
|
| 615 |
+
const newName = elements.newChatName.value.trim();
|
| 616 |
+
if (!newName || !state.currentUser || !state.currentChatId) {
|
| 617 |
+
hideRenameModal();
|
| 618 |
+
return;
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
const chatIndex = state.chats.findIndex(c => c.id === state.currentChatId);
|
| 622 |
+
if (chatIndex === -1) {
|
| 623 |
+
hideRenameModal();
|
| 624 |
+
return;
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
state.chats[chatIndex].title = newName;
|
| 628 |
+
saveUserChats();
|
| 629 |
+
hideRenameModal();
|
| 630 |
+
renderUI();
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
// Toggle edit mode
|
| 634 |
+
function toggleEditMode() {
|
| 635 |
+
state.editMode = !state.editMode;
|
| 636 |
+
renderChatList();
|
| 637 |
+
}
|
| 638 |
+
|
| 639 |
+
// Create new chat
|
| 640 |
+
function createNewChat() {
|
| 641 |
+
if (!state.currentUser) {
|
| 642 |
+
showAuthModal('signin');
|
| 643 |
+
return;
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
+
const newChat = {
|
| 647 |
+
id: Date.now().toString(),
|
| 648 |
+
title: `Chat ${state.chats.length + 1}`,
|
| 649 |
+
createdAt: new Date().toISOString(),
|
| 650 |
+
updatedAt: new Date().toISOString(),
|
| 651 |
+
messages: [],
|
| 652 |
+
context: {}
|
| 653 |
+
};
|
| 654 |
+
|
| 655 |
+
state.chats.unshift(newChat);
|
| 656 |
+
state.currentChatId = newChat.id;
|
| 657 |
+
saveUserChats();
|
| 658 |
+
renderUI();
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
// Handle message submission
|
| 662 |
+
async function handleMessageSubmit(e) {
|
| 663 |
+
e.preventDefault();
|
| 664 |
+
|
| 665 |
+
if (!state.currentUser || !state.currentChatId || state.isGenerating) return;
|
| 666 |
+
|
| 667 |
+
const messageText = elements.messageInput.value.trim();
|
| 668 |
+
if (!messageText) return;
|
| 669 |
+
|
| 670 |
+
// Add user message to chat
|
| 671 |
+
const userMessage = {
|
| 672 |
+
id: Date.now().toString(),
|
| 673 |
+
role: 'user',
|
| 674 |
+
content: messageText,
|
| 675 |
+
timestamp: new Date().toISOString()
|
| 676 |
+
};
|
| 677 |
+
|
| 678 |
+
addMessageToCurrentChat(userMessage);
|
| 679 |
+
elements.messageInput.value = '';
|
| 680 |
+
|
| 681 |
+
// Show loading indicator
|
| 682 |
+
state.isGenerating = true;
|
| 683 |
+
elements.sendBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i>';
|
| 684 |
+
|
| 685 |
+
try {
|
| 686 |
+
// Get current chat
|
| 687 |
+
const chatIndex = state.chats.findIndex(c => c.id === state.currentChatId);
|
| 688 |
+
if (chatIndex === -1) return;
|
| 689 |
+
|
| 690 |
+
const chat = state.chats[chatIndex];
|
| 691 |
+
|
| 692 |
+
// Prepare messages for API
|
| 693 |
+
let messagesForApi = [
|
| 694 |
+
{
|
| 695 |
+
role: 'system',
|
| 696 |
+
content: buildSystemPrompt(chat.context)
|
| 697 |
+
},
|
| 698 |
+
...chat.messages.map(msg => ({
|
| 699 |
+
role: msg.role,
|
| 700 |
+
content: msg.content
|
| 701 |
+
}))
|
| 702 |
+
];
|
| 703 |
+
|
| 704 |
+
// Call Qwen API
|
| 705 |
+
const response = await fetch(API_URL, {
|
| 706 |
+
method: 'POST',
|
| 707 |
+
headers: {
|
| 708 |
+
'Content-Type': 'application/json',
|
| 709 |
+
'Authorization': `Bearer ${API_KEY}`
|
| 710 |
+
},
|
| 711 |
+
body: JSON.stringify({
|
| 712 |
+
model_name: 'qwen1.5-14b-chat',
|
| 713 |
+
messages: messagesForApi,
|
| 714 |
+
max_tokens: 2048,
|
| 715 |
+
temperature: 0.7
|
| 716 |
+
})
|
| 717 |
+
});
|
| 718 |
+
|
| 719 |
+
if (!response.ok) {
|
| 720 |
+
throw new Error('API request failed');
|
| 721 |
+
}
|
| 722 |
+
|
| 723 |
+
const data = await response.json();
|
| 724 |
+
const aiMessage = data.choices[0].message;
|
| 725 |
+
|
| 726 |
+
// Add AI response to chat
|
| 727 |
+
const formattedAiMessage = {
|
| 728 |
+
id: Date.now().toString(),
|
| 729 |
+
role: 'assistant',
|
| 730 |
+
content: aiMessage.content,
|
| 731 |
+
timestamp: new Date().toISOString()
|
| 732 |
+
};
|
| 733 |
+
|
| 734 |
+
addMessageToCurrentChat(formattedAiMessage);
|
| 735 |
+
} catch (error) {
|
| 736 |
+
console.error('Error:', error);
|
| 737 |
+
// Show error message to user
|
| 738 |
+
const errorMessage = {
|
| 739 |
+
id: Date.now().toString(),
|
| 740 |
+
role: 'assistant',
|
| 741 |
+
content: 'Sorry, I encountered an error. Please try again.',
|
| 742 |
+
timestamp: new Date().toISOString()
|
| 743 |
+
};
|
| 744 |
+
addMessageToCurrentChat(errorMessage);
|
| 745 |
+
} finally {
|
| 746 |
+
state.isGenerating = false;
|
| 747 |
+
elements.sendBtn.innerHTML = '<i class="fas fa-paper-plane"></i>';
|
| 748 |
+
}
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
// Build system prompt from context
|
| 752 |
+
function buildSystemPrompt(context = {}) {
|
| 753 |
+
let prompt = "You are Qwen, a helpful AI assistant. ";
|
| 754 |
+
|
| 755 |
+
if (context.name) prompt += `The user's name is ${context.name}. `;
|
| 756 |
+
if (context.location) prompt += `They are from ${context.location}. `;
|
| 757 |
+
if (context.pets) prompt += `They have pets: ${context.pets}. `;
|
| 758 |
+
if (context.interests) prompt += `Their interests include: ${context.interests}. `;
|
| 759 |
+
if (context.additionalInfo) prompt += `Additional info about them: ${context.additionalInfo}. `;
|
| 760 |
+
|
| 761 |
+
if (context.instructions) {
|
| 762 |
+
prompt += `Follow these instructions when responding: ${context.instructions}`;
|
| 763 |
+
} else {
|
| 764 |
+
prompt += "Be helpful, friendly, and concise in your responses.";
|
| 765 |
+
}
|
| 766 |
+
|
| 767 |
+
return prompt;
|
| 768 |
+
}
|
| 769 |
+
|
| 770 |
+
// Add message to current chat
|
| 771 |
+
function addMessageToCurrentChat(message) {
|
| 772 |
+
if (!state.currentChatId) return;
|
| 773 |
+
|
| 774 |
+
const chatIndex = state.chats.findIndex(c => c.id === state.currentChatId);
|
| 775 |
+
if (chatIndex === -1) return;
|
| 776 |
+
|
| 777 |
+
state.chats[chatIndex].messages.push(message);
|
| 778 |
+
state.chats[chatIndex].updatedAt = new Date().toISOString();
|
| 779 |
+
saveUserChats();
|
| 780 |
+
renderMessages();
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
// Toggle mobile sidebar
|
| 784 |
+
function toggleMobileSidebar() {
|
| 785 |
+
elements.mobileSidebar.classList.toggle('translate-x-full');
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
// Render UI based on current state
|
| 789 |
+
function renderUI() {
|
| 790 |
+
if (state.currentUser) {
|
| 791 |
+
// User is signed in
|
| 792 |
+
elements.authButtons.classList.add('hidden');
|
| 793 |
+
elements.userInfo.classList.remove('hidden');
|
| 794 |
+
elements.usernameDisplay.textContent = state.currentUser.name;
|
| 795 |
+
|
| 796 |
+
// Enable chat features
|
| 797 |
+
elements.messageInput.disabled = false;
|
| 798 |
+
elements.sendBtn.disabled = false;
|
| 799 |
+
|
| 800 |
+
// Render chat list and messages
|
| 801 |
+
renderChatList();
|
| 802 |
+
renderMessages();
|
| 803 |
+
} else {
|
| 804 |
+
// User is not signed in
|
| 805 |
+
elements.authButtons.classList.remove('hidden');
|
| 806 |
+
elements.userInfo.classList.add('hidden');
|
| 807 |
+
|
| 808 |
+
// Disable chat features
|
| 809 |
+
elements.messageInput.disabled = true;
|
| 810 |
+
elements.sendBtn.disabled = true;
|
| 811 |
+
|
| 812 |
+
// Clear chat list and show sign in prompt
|
| 813 |
+
elements.chatList.innerHTML = '';
|
| 814 |
+
elements.mobileChatList.innerHTML = '';
|
| 815 |
+
elements.messages.innerHTML = `
|
| 816 |
+
<div class="text-center py-8 text-gray-500">
|
| 817 |
+
<i class="fas fa-comments text-4xl mb-2"></i>
|
| 818 |
+
<p>Please sign in to start chatting</p>
|
| 819 |
+
<button class="mt-4 px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600" onclick="showAuthModal('signin')">
|
| 820 |
+
Sign In
|
| 821 |
+
</button>
|
| 822 |
+
</div>
|
| 823 |
+
`;
|
| 824 |
+
}
|
| 825 |
+
}
|
| 826 |
+
|
| 827 |
+
// Render chat list
|
| 828 |
+
function renderChatList() {
|
| 829 |
+
if (!state.currentUser) return;
|
| 830 |
+
|
| 831 |
+
// Desktop chat list
|
| 832 |
+
elements.chatList.innerHTML = state.chats.map(chat => `
|
| 833 |
+
<div class="group flex items-center justify-between p-2 rounded-md hover:bg-gray-100 ${chat.id === state.currentChatId ? 'bg-blue-50' : ''}">
|
| 834 |
+
<button
|
| 835 |
+
class="flex-1 text-left truncate ${chat.id === state.currentChatId ? 'font-medium text-blue-600' : 'text-gray-700'}"
|
| 836 |
+
onclick="switchToChat('${chat.id}')"
|
| 837 |
+
>
|
| 838 |
+
<i class="fas fa-comment-dots mr-2 text-gray-400"></i>
|
| 839 |
+
${chat.title}
|
| 840 |
+
</button>
|
| 841 |
+
${state.editMode ? `
|
| 842 |
+
<button class="p-1 text-gray-400 hover:text-gray-700" onclick="deleteChat('${chat.id}', event)">
|
| 843 |
+
<i class="fas fa-trash"></i>
|
| 844 |
+
</button>
|
| 845 |
+
` : ''}
|
| 846 |
+
</div>
|
| 847 |
+
`).join('');
|
| 848 |
+
|
| 849 |
+
// Mobile chat list
|
| 850 |
+
elements.mobileChatList.innerHTML = state.chats.map(chat => `
|
| 851 |
+
<div class="group flex items-center justify-between p-2 rounded-md hover:bg-gray-100 ${chat.id === state.currentChatId ? 'bg-blue-50' : ''}">
|
| 852 |
+
<button
|
| 853 |
+
class="flex-1 text-left truncate ${chat.id === state.currentChatId ? 'font-medium text-blue-600' : 'text-gray-700'}"
|
| 854 |
+
onclick="switchToChat('${chat.id}')"
|
| 855 |
+
>
|
| 856 |
+
<i class="fas fa-comment-dots mr-2 text-gray-400"></i>
|
| 857 |
+
${chat.title}
|
| 858 |
+
</button>
|
| 859 |
+
${state.editMode ? `
|
| 860 |
+
<button class="p-1 text-gray-400 hover:text-gray-700" onclick="deleteChat('${chat.id}', event)">
|
| 861 |
+
<i class="fas fa-trash"></i>
|
| 862 |
+
</button>
|
| 863 |
+
` : ''}
|
| 864 |
+
</div>
|
| 865 |
+
`).join('');
|
| 866 |
+
}
|
| 867 |
+
|
| 868 |
+
// Render messages for current chat
|
| 869 |
+
function renderMessages() {
|
| 870 |
+
if (!state.currentChatId) {
|
| 871 |
+
elements.messages.innerHTML = `
|
| 872 |
+
<div class="text-center py-8 text-gray-500">
|
| 873 |
+
<i class="fas fa-comments text-4xl mb-2"></i>
|
| 874 |
+
<p>Start a new conversation with Qwen AI</p>
|
| 875 |
+
</div>
|
| 876 |
+
`;
|
| 877 |
+
return;
|
| 878 |
+
}
|
| 879 |
+
|
| 880 |
+
const chat = state.chats.find(c => c.id === state.currentChatId);
|
| 881 |
+
if (!chat) return;
|
| 882 |
+
|
| 883 |
+
elements.currentChatTitle.textContent = chat.title;
|
| 884 |
+
|
| 885 |
+
if (chat.messages.length === 0) {
|
| 886 |
+
elements.messages.innerHTML = `
|
| 887 |
+
<div class="text-center py-8 text-gray-500">
|
| 888 |
+
<i class="fas fa-comments text-4xl mb-2"></i>
|
| 889 |
+
<p>Start a conversation with Qwen AI</p>
|
| 890 |
+
</div>
|
| 891 |
+
`;
|
| 892 |
+
return;
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
elements.messages.innerHTML = chat.messages.map(message => `
|
| 896 |
+
<div class="chat-message ${message.role} p-4 max-w-3/4 ${message.role === 'user' ? 'ml-auto' : 'mr-auto'} fade-in">
|
| 897 |
+
<div class="flex items-start space-x-2">
|
| 898 |
+
<div class="flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center ${message.role === 'user' ? 'bg-blue-100 text-blue-600' : 'bg-gray-200 text-gray-600'}">
|
| 899 |
+
${message.role === 'user' ? '<i class="fas fa-user"></i>' : '<i class="fas fa-robot"></i>'}
|
| 900 |
+
</div>
|
| 901 |
+
<div class="flex-1">
|
| 902 |
+
<div class="text-sm font-medium mb-1 ${message.role === 'user' ? 'text-blue-100' : 'text-gray-500'}">
|
| 903 |
+
${message.role === 'user' ? 'You' : 'Qwen AI'}
|
| 904 |
+
</div>
|
| 905 |
+
<div class="text-sm ${message.role === 'user' ? 'text-white' : 'text-gray-800'}">
|
| 906 |
+
${message.content.replace(/\n/g, '<br>')}
|
| 907 |
+
</div>
|
| 908 |
+
<div class="text-xs mt-1 ${message.role === 'user' ? 'text-blue-100' : 'text-gray-500'}">
|
| 909 |
+
${new Date(message.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
|
| 910 |
+
</div>
|
| 911 |
+
</div>
|
| 912 |
+
</div>
|
| 913 |
+
</div>
|
| 914 |
+
`).join('');
|
| 915 |
+
|
| 916 |
+
// Scroll to bottom
|
| 917 |
+
elements.messages.scrollTop = elements.messages.scrollHeight;
|
| 918 |
+
}
|
| 919 |
+
|
| 920 |
+
// Switch to a different chat
|
| 921 |
+
function switchToChat(chatId) {
|
| 922 |
+
state.currentChatId = chatId;
|
| 923 |
+
renderUI();
|
| 924 |
+
toggleMobileSidebar();
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
// Delete a chat
|
| 928 |
+
function deleteChat(chatId, event) {
|
| 929 |
+
event.stopPropagation();
|
| 930 |
+
|
| 931 |
+
if (!confirm('Are you sure you want to delete this chat?')) return;
|
| 932 |
+
|
| 933 |
+
const chatIndex = state.chats.findIndex(c => c.id === chatId);
|
| 934 |
+
if (chatIndex === -1) return;
|
| 935 |
+
|
| 936 |
+
state.chats.splice(chatIndex, 1);
|
| 937 |
+
|
| 938 |
+
if (state.currentChatId === chatId) {
|
| 939 |
+
state.currentChatId = state.chats.length > 0 ? state.chats[0].id : null;
|
| 940 |
+
}
|
| 941 |
+
|
| 942 |
+
saveUserChats();
|
| 943 |
+
renderUI();
|
| 944 |
+
}
|
| 945 |
+
|
| 946 |
+
// Initialize the app
|
| 947 |
+
init();
|
| 948 |
+
|
| 949 |
+
// Make functions available globally for HTML onclick handlers
|
| 950 |
+
window.showAuthModal = showAuthModal;
|
| 951 |
+
window.switchToChat = switchToChat;
|
| 952 |
+
window.deleteChat = deleteChat;
|
| 953 |
+
</script>
|
| 954 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=BarBar288/openchatai-qwen" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 955 |
+
</html>
|
prompts.txt
ADDED
|
File without changes
|