Update sss.html
Browse files
sss.html
CHANGED
@@ -4,27 +4,18 @@
|
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>Speedy Chat</title>
|
7 |
-
<!-- Tailwind CSS -->
|
8 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
|
9 |
-
<!-- Prism.js for code highlighting -->
|
10 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism-tomorrow.min.css" rel="stylesheet">
|
11 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/plugins/line-numbers/prism-line-numbers.min.css" rel="stylesheet">
|
12 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
|
13 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/plugins/line-numbers/prism-line-numbers.min.js"></script>
|
14 |
-
<!-- TinyMCE for rich text editing -->
|
15 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.10.7/tinymce.min.js"></script>
|
16 |
<style>
|
17 |
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@100;200;300;400;500;600;700&display=swap');
|
18 |
-
@import url('https://fonts.googleapis.com/css2?family=Noto+Kufi+Arabic:wght@100;200;300;400;500;600;700;800;900&display=swap');
|
19 |
|
20 |
body {
|
21 |
font-family: 'IBM Plex Sans Arabic', sans-serif;
|
22 |
line-height: 1.6;
|
23 |
-
letter-spacing: -0.01em;
|
24 |
transition: background-color 0.3s, color 0.3s;
|
25 |
}
|
26 |
|
27 |
-
/* Light/Dark Mode Styles */
|
28 |
body.light-mode {
|
29 |
background-color: #fafafa;
|
30 |
color: #374151;
|
@@ -51,145 +42,53 @@
|
|
51 |
color: #e5e5e5;
|
52 |
}
|
53 |
|
54 |
-
.dark-mode .style-select {
|
55 |
-
background-color: #363636;
|
56 |
-
border-color: #404040;
|
57 |
-
color: #e5e5e5;
|
58 |
-
}
|
59 |
-
|
60 |
.dark-mode .bot-message {
|
61 |
background-color: #363636;
|
62 |
color: #e5e5e5;
|
63 |
}
|
64 |
-
|
65 |
-
.dark-mode .action-button {
|
66 |
-
color: #e5e5e5;
|
67 |
-
background-color: #404040;
|
68 |
-
}
|
69 |
-
|
70 |
-
/* Code Block Styles */
|
71 |
-
pre[class*="language-"] {
|
72 |
-
direction: ltr;
|
73 |
-
text-align: left;
|
74 |
-
border-radius: 0.5rem;
|
75 |
-
margin: 1rem 0;
|
76 |
-
padding: 1rem;
|
77 |
-
font-size: 0.9rem;
|
78 |
-
line-height: 1.5;
|
79 |
-
}
|
80 |
-
|
81 |
-
.code-block-wrapper {
|
82 |
-
position: relative;
|
83 |
-
margin: 1rem 0;
|
84 |
-
border-radius: 0.5rem;
|
85 |
-
overflow: hidden;
|
86 |
-
}
|
87 |
-
|
88 |
-
.code-block-header {
|
89 |
-
display: flex;
|
90 |
-
justify-content: space-between;
|
91 |
-
align-items: center;
|
92 |
-
background: #2d2d2d;
|
93 |
-
color: white;
|
94 |
-
padding: 0.5rem 1rem;
|
95 |
-
}
|
96 |
-
|
97 |
-
/* Long Text Styles */
|
98 |
-
.long-text-wrapper {
|
99 |
-
max-height: 300px;
|
100 |
-
overflow-y: auto;
|
101 |
-
padding: 1rem;
|
102 |
-
background: #f8f9fa;
|
103 |
-
border-radius: 0.5rem;
|
104 |
-
margin: 1rem 0;
|
105 |
-
}
|
106 |
-
|
107 |
-
/* Rich Text Editor Styles */
|
108 |
-
.editor-wrapper {
|
109 |
-
display: none;
|
110 |
-
background: white;
|
111 |
-
border-radius: 0.5rem;
|
112 |
-
margin: 1rem 0;
|
113 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
114 |
-
}
|
115 |
-
|
116 |
-
.editor-toolbar {
|
117 |
-
display: flex;
|
118 |
-
gap: 0.5rem;
|
119 |
-
padding: 0.5rem;
|
120 |
-
border-bottom: 1px solid #e5e7eb;
|
121 |
-
}
|
122 |
-
|
123 |
-
/* Message Input Styles */
|
124 |
.message-input {
|
125 |
resize: none;
|
126 |
min-height: 50px;
|
127 |
max-height: 200px;
|
128 |
}
|
129 |
-
|
130 |
-
.message-input:focus {
|
131 |
-
outline: none;
|
132 |
-
box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
|
133 |
-
}
|
134 |
-
|
135 |
-
/* Welcome Text Style */
|
136 |
-
.welcome-text {
|
137 |
-
font-family: 'Noto Kufi Arabic', sans-serif;
|
138 |
-
font-size: 2rem;
|
139 |
-
font-weight: 700;
|
140 |
-
text-align: center;
|
141 |
-
margin: 1.5rem 0;
|
142 |
-
letter-spacing: -0.02em;
|
143 |
-
}
|
144 |
-
|
145 |
-
/* Message Animation */
|
146 |
.message {
|
147 |
opacity: 0;
|
148 |
transform: translateY(20px);
|
149 |
animation: fadeIn 0.3s ease forwards;
|
150 |
}
|
151 |
-
|
152 |
@keyframes fadeIn {
|
153 |
to {
|
154 |
opacity: 1;
|
155 |
transform: translateY(0);
|
156 |
}
|
157 |
}
|
158 |
-
|
159 |
-
/* Utility Classes */
|
160 |
.bot-avatar {
|
161 |
width: 40px;
|
162 |
height: 40px;
|
163 |
border-radius: 50%;
|
164 |
object-fit: cover;
|
165 |
}
|
166 |
-
|
167 |
-
.
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
font-size: 0.875rem;
|
175 |
-
color: #6B7280;
|
176 |
-
background-color: #F3F4F6;
|
177 |
-
}
|
178 |
-
|
179 |
-
.action-button:hover {
|
180 |
-
background-color: #E5E7EB;
|
181 |
}
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
background-repeat: no-repeat;
|
187 |
-
background-position: left 0.5rem center;
|
188 |
-
background-size: 1em;
|
189 |
}
|
190 |
</style>
|
191 |
</head>
|
192 |
-
<body class="
|
193 |
<header class="fixed top-0 left-0 right-0 bg-white border-b border-gray-100 z-50 shadow-sm">
|
194 |
<div class="flex items-center px-4 py-2">
|
195 |
<div class="flex items-center flex-1">
|
@@ -210,7 +109,6 @@
|
|
210 |
|
211 |
<main class="pt-24 pb-24">
|
212 |
<div class="max-w-3xl mx-auto px-4">
|
213 |
-
<div class="welcome-text">سبيدي هنا لمساعدتك</div>
|
214 |
<div id="messagesContainer" class="space-y-4"></div>
|
215 |
</div>
|
216 |
</main>
|
@@ -230,12 +128,7 @@
|
|
230 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"></path>
|
231 |
</svg>
|
232 |
</button>
|
233 |
-
<
|
234 |
-
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
235 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 01-3-3V5a3 3 0 116 0v6a3 3 0 01-3 3z"></path>
|
236 |
-
</svg>
|
237 |
-
</a>
|
238 |
-
<select id="styleSelect" class="style-select bg-gray-50 border border-gray-200 text-gray-600 text-sm rounded-lg pl-8 pr-2 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-200">
|
239 |
<option value="short">⚡ ردود قصيرة</option>
|
240 |
<option value="normal" selected>◯ عادي</option>
|
241 |
<option value="long">↔ ردود مفصلة</option>
|
@@ -245,8 +138,11 @@
|
|
245 |
</div>
|
246 |
</footer>
|
247 |
|
|
|
|
|
|
|
248 |
<script>
|
249 |
-
const API_URL = 'https://nvgsxt9jqx730v-7777.proxy.runpod.net/proxy/8000/chat/stream
|
250 |
const messagesContainer = document.getElementById('messagesContainer');
|
251 |
const messageInput = document.getElementById('messageInput');
|
252 |
const sendButton = document.getElementById('sendMessage');
|
@@ -257,16 +153,6 @@
|
|
257 |
let currentStyle = 'normal';
|
258 |
let currentController = null;
|
259 |
|
260 |
-
// Dark mode toggle
|
261 |
-
darkModeToggle.addEventListener('click', () => {
|
262 |
-
document.body.classList.toggle('dark-mode');
|
263 |
-
document.body.classList.toggle('light-mode');
|
264 |
-
});
|
265 |
-
|
266 |
-
styleSelect.addEventListener('change', (e) => {
|
267 |
-
currentStyle = e.target.value;
|
268 |
-
});
|
269 |
-
|
270 |
function createUserMessage(text) {
|
271 |
return `
|
272 |
<div class="message flex justify-end mb-4">
|
@@ -288,25 +174,19 @@
|
|
288 |
<div class="max-w-[80%] mr-3">
|
289 |
<div class="bot-message bg-white rounded-lg p-4 shadow-sm">
|
290 |
<p id="${messageId}" class="text-gray-700"></p>
|
291 |
-
<div class="message-actions">
|
292 |
-
<button class="
|
293 |
-
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
294 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012
|
295 |
</svg>
|
296 |
نسخ
|
297 |
</button>
|
298 |
-
<button class="
|
299 |
-
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
300 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
|
301 |
</svg>
|
302 |
إعادة التوليد
|
303 |
</button>
|
304 |
-
<button class="action-button edit-text-btn">
|
305 |
-
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
306 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
|
307 |
-
</svg>
|
308 |
-
تحرير كمستند
|
309 |
-
</button>
|
310 |
</div>
|
311 |
</div>
|
312 |
</div>
|
@@ -316,86 +196,33 @@
|
|
316 |
|
317 |
function formatCodeBlock(code, language) {
|
318 |
return `
|
319 |
-
<div class="code-block
|
320 |
-
<div class="code-block-header">
|
321 |
-
<span>${language}</span>
|
322 |
-
<button class="copy-code-btn">
|
323 |
-
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
324 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2"></path>
|
325 |
-
</svg>
|
326 |
-
</button>
|
327 |
-
</div>
|
328 |
<pre class="line-numbers"><code class="language-${language}">${code}</code></pre>
|
329 |
-
</div
|
|
|
330 |
}
|
331 |
|
332 |
async function typeText(elementId, text) {
|
333 |
const element = document.getElementById(elementId);
|
334 |
-
element
|
335 |
|
336 |
-
// Check if text contains code blocks
|
337 |
const codeBlockRegex = /```(\w+)\n([\s\S]+?)```/g;
|
338 |
let lastIndex = 0;
|
339 |
let match;
|
|
|
340 |
|
341 |
while ((match = codeBlockRegex.exec(text)) !== null) {
|
342 |
-
|
343 |
-
const beforeText = text.slice(lastIndex, match.index);
|
344 |
-
if (beforeText) {
|
345 |
-
await addTextWithEditor(element, beforeText);
|
346 |
-
}
|
347 |
-
|
348 |
-
// Add code block
|
349 |
const [, language, code] = match;
|
350 |
-
|
351 |
lastIndex = match.index + match[0].length;
|
352 |
}
|
353 |
|
354 |
-
|
355 |
-
|
356 |
-
if (remainingText) {
|
357 |
-
await addTextWithEditor(element, remainingText);
|
358 |
-
}
|
359 |
-
|
360 |
-
// Initialize Prism.js
|
361 |
Prism.highlightAllUnder(element);
|
362 |
}
|
363 |
|
364 |
-
async function addTextWithEditor(element, text) {
|
365 |
-
const textWrapper = document.createElement('div');
|
366 |
-
textWrapper.className = 'long-text-wrapper';
|
367 |
-
textWrapper.innerHTML = text;
|
368 |
-
|
369 |
-
const editorWrapper = document.createElement('div');
|
370 |
-
editorWrapper.className = 'editor-wrapper';
|
371 |
-
editorWrapper.innerHTML = `
|
372 |
-
<div class="editor-toolbar">
|
373 |
-
<button class="save-btn action-button">حفظ</button>
|
374 |
-
<button class="cancel-btn action-button">إلغاء</button>
|
375 |
-
</div>
|
376 |
-
<textarea class="tinymce-editor"></textarea>
|
377 |
-
`;
|
378 |
-
|
379 |
-
element.appendChild(textWrapper);
|
380 |
-
element.appendChild(editorWrapper);
|
381 |
-
|
382 |
-
// Initialize TinyMCE for this textarea
|
383 |
-
tinymce.init({
|
384 |
-
selector: '.tinymce-editor:last',
|
385 |
-
directionality: 'rtl',
|
386 |
-
height: 400,
|
387 |
-
menubar: false,
|
388 |
-
plugins: 'lists link table',
|
389 |
-
toolbar: 'undo redo | formatselect | bold italic | alignleft aligncenter alignright | bullist numlist | link table',
|
390 |
-
content_style: 'body { font-family: "IBM Plex Sans Arabic", sans-serif; }',
|
391 |
-
setup: function(editor) {
|
392 |
-
editor.on('init', function() {
|
393 |
-
editor.setContent(text);
|
394 |
-
});
|
395 |
-
}
|
396 |
-
});
|
397 |
-
}
|
398 |
-
|
399 |
async function sendMessage() {
|
400 |
const message = messageInput.value.trim();
|
401 |
if (!message) return;
|
@@ -429,7 +256,10 @@
|
|
429 |
|
430 |
const response = await fetch(API_URL, {
|
431 |
method: 'POST',
|
432 |
-
headers: {
|
|
|
|
|
|
|
433 |
body: JSON.stringify({
|
434 |
message: actualMessage,
|
435 |
history: chatHistory
|
@@ -437,17 +267,37 @@
|
|
437 |
signal: currentController.signal
|
438 |
});
|
439 |
|
440 |
-
|
441 |
-
|
442 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
443 |
chatHistory.push({
|
444 |
human: actualMessage,
|
445 |
-
assistant:
|
446 |
});
|
|
|
447 |
} catch (error) {
|
448 |
if (error.name === 'AbortError') {
|
449 |
document.getElementById(messageId).textContent = 'تم إيقاف التوليد.';
|
450 |
} else {
|
|
|
451 |
document.getElementById(messageId).textContent = 'عذراً، حدث خطأ في المعالجة.';
|
452 |
}
|
453 |
} finally {
|
@@ -458,16 +308,12 @@
|
|
458 |
}
|
459 |
|
460 |
function toggleSendButton(isGenerating) {
|
461 |
-
const sendButton = document.getElementById('sendMessage');
|
462 |
if (isGenerating) {
|
463 |
-
sendButton.classList.add('stop-generation');
|
464 |
sendButton.innerHTML = `
|
465 |
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
466 |
-
|
467 |
-
</svg>
|
468 |
`;
|
469 |
} else {
|
470 |
-
sendButton.classList.remove('stop-generation');
|
471 |
sendButton.innerHTML = `
|
472 |
<svg class="w-6 h-6 transform rotate-90" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
473 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"></path>
|
@@ -478,7 +324,7 @@
|
|
478 |
|
479 |
function adjustTextareaHeight() {
|
480 |
messageInput.style.height = 'auto';
|
481 |
-
messageInput.style.height = messageInput.scrollHeight + 'px';
|
482 |
}
|
483 |
|
484 |
function scrollToBottom() {
|
@@ -490,70 +336,22 @@
|
|
490 |
|
491 |
// Event Listeners
|
492 |
document.addEventListener('click', async (e) => {
|
493 |
-
|
494 |
-
|
495 |
-
await navigator.clipboard.writeText(codeBlock.textContent);
|
496 |
-
const btn = e.target.closest('.copy-code-btn');
|
497 |
-
btn.innerHTML = 'تم النسخ!';
|
498 |
-
setTimeout(() => {
|
499 |
-
btn.innerHTML = `<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
500 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2"></path>
|
501 |
-
</svg>`;
|
502 |
-
}, 2000);
|
503 |
-
}
|
504 |
|
505 |
-
if (
|
506 |
-
const
|
507 |
-
const
|
508 |
-
await navigator.clipboard.writeText(
|
509 |
-
|
510 |
-
|
|
|
511 |
setTimeout(() => {
|
512 |
-
|
513 |
-
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
514 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2"></path>
|
515 |
-
</svg>
|
516 |
-
نسخ
|
517 |
-
`;
|
518 |
}, 2000);
|
519 |
}
|
520 |
|
521 |
-
if (
|
522 |
-
const messageWrapper = e.target.closest('.bot-message');
|
523 |
-
const textWrapper = messageWrapper.querySelector('.long-text-wrapper');
|
524 |
-
const editorWrapper = messageWrapper.querySelector('.editor-wrapper');
|
525 |
-
|
526 |
-
if (textWrapper && editorWrapper) {
|
527 |
-
textWrapper.style.display = 'none';
|
528 |
-
editorWrapper.style.display = 'block';
|
529 |
-
}
|
530 |
-
}
|
531 |
-
|
532 |
-
if (e.target.closest('.save-btn')) {
|
533 |
-
const messageWrapper = e.target.closest('.bot-message');
|
534 |
-
const textWrapper = messageWrapper.querySelector('.long-text-wrapper');
|
535 |
-
const editorWrapper = messageWrapper.querySelector('.editor-wrapper');
|
536 |
-
const editor = tinymce.get(editorWrapper.querySelector('.tinymce-editor').id);
|
537 |
-
|
538 |
-
if (textWrapper && editor) {
|
539 |
-
textWrapper.innerHTML = editor.getContent();
|
540 |
-
textWrapper.style.display = 'block';
|
541 |
-
editorWrapper.style.display = 'none';
|
542 |
-
}
|
543 |
-
}
|
544 |
-
|
545 |
-
if (e.target.closest('.cancel-btn')) {
|
546 |
-
const messageWrapper = e.target.closest('.bot-message');
|
547 |
-
const textWrapper = messageWrapper.querySelector('.long-text-wrapper');
|
548 |
-
const editorWrapper = messageWrapper.querySelector('.editor-wrapper');
|
549 |
-
|
550 |
-
if (textWrapper && editorWrapper) {
|
551 |
-
textWrapper.style.display = 'block';
|
552 |
-
editorWrapper.style.display = 'none';
|
553 |
-
}
|
554 |
-
}
|
555 |
-
|
556 |
-
if (e.target.closest('.regenerate-button')) {
|
557 |
if (chatHistory.length > 0) {
|
558 |
const lastMessage = chatHistory[chatHistory.length - 1].human;
|
559 |
messageInput.value = lastMessage;
|
@@ -562,6 +360,24 @@
|
|
562 |
}
|
563 |
});
|
564 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
565 |
sendButton.addEventListener('click', sendMessage);
|
566 |
messageInput.addEventListener('keypress', (e) => {
|
567 |
if (e.key === 'Enter' && !e.shiftKey) {
|
@@ -570,15 +386,13 @@
|
|
570 |
}
|
571 |
});
|
572 |
messageInput.addEventListener('input', adjustTextareaHeight);
|
573 |
-
clearButton.addEventListener('click', () => {
|
574 |
-
messagesContainer.innerHTML = '';
|
575 |
-
chatHistory = [];
|
576 |
-
});
|
577 |
|
578 |
-
// Initial
|
579 |
-
|
580 |
-
|
581 |
-
|
|
|
|
|
582 |
</script>
|
583 |
</body>
|
584 |
</html>
|
|
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>Speedy Chat</title>
|
|
|
7 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
|
|
|
8 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism-tomorrow.min.css" rel="stylesheet">
|
9 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/plugins/line-numbers/prism-line-numbers.min.css" rel="stylesheet">
|
|
|
|
|
|
|
|
|
10 |
<style>
|
11 |
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@100;200;300;400;500;600;700&display=swap');
|
|
|
12 |
|
13 |
body {
|
14 |
font-family: 'IBM Plex Sans Arabic', sans-serif;
|
15 |
line-height: 1.6;
|
|
|
16 |
transition: background-color 0.3s, color 0.3s;
|
17 |
}
|
18 |
|
|
|
19 |
body.light-mode {
|
20 |
background-color: #fafafa;
|
21 |
color: #374151;
|
|
|
42 |
color: #e5e5e5;
|
43 |
}
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
.dark-mode .bot-message {
|
46 |
background-color: #363636;
|
47 |
color: #e5e5e5;
|
48 |
}
|
49 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
.message-input {
|
51 |
resize: none;
|
52 |
min-height: 50px;
|
53 |
max-height: 200px;
|
54 |
}
|
55 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
.message {
|
57 |
opacity: 0;
|
58 |
transform: translateY(20px);
|
59 |
animation: fadeIn 0.3s ease forwards;
|
60 |
}
|
61 |
+
|
62 |
@keyframes fadeIn {
|
63 |
to {
|
64 |
opacity: 1;
|
65 |
transform: translateY(0);
|
66 |
}
|
67 |
}
|
68 |
+
|
|
|
69 |
.bot-avatar {
|
70 |
width: 40px;
|
71 |
height: 40px;
|
72 |
border-radius: 50%;
|
73 |
object-fit: cover;
|
74 |
}
|
75 |
+
|
76 |
+
.code-block {
|
77 |
+
direction: ltr;
|
78 |
+
text-align: left;
|
79 |
+
background: #2d2d2d;
|
80 |
+
border-radius: 0.5rem;
|
81 |
+
padding: 1rem;
|
82 |
+
margin: 1rem 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
}
|
84 |
+
|
85 |
+
pre[class*="language-"] {
|
86 |
+
margin: 0;
|
87 |
+
padding: 0;
|
|
|
|
|
|
|
88 |
}
|
89 |
</style>
|
90 |
</head>
|
91 |
+
<body class="light-mode">
|
92 |
<header class="fixed top-0 left-0 right-0 bg-white border-b border-gray-100 z-50 shadow-sm">
|
93 |
<div class="flex items-center px-4 py-2">
|
94 |
<div class="flex items-center flex-1">
|
|
|
109 |
|
110 |
<main class="pt-24 pb-24">
|
111 |
<div class="max-w-3xl mx-auto px-4">
|
|
|
112 |
<div id="messagesContainer" class="space-y-4"></div>
|
113 |
</div>
|
114 |
</main>
|
|
|
128 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"></path>
|
129 |
</svg>
|
130 |
</button>
|
131 |
+
<select id="styleSelect" class="bg-gray-50 border border-gray-200 text-gray-600 text-sm rounded-lg pl-8 pr-2 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-200">
|
|
|
|
|
|
|
|
|
|
|
132 |
<option value="short">⚡ ردود قصيرة</option>
|
133 |
<option value="normal" selected>◯ عادي</option>
|
134 |
<option value="long">↔ ردود مفصلة</option>
|
|
|
138 |
</div>
|
139 |
</footer>
|
140 |
|
141 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
|
142 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/plugins/line-numbers/prism-line-numbers.min.js"></script>
|
143 |
+
|
144 |
<script>
|
145 |
+
const API_URL = 'https://nvgsxt9jqx730v-7777.proxy.runpod.net/proxy/8000/chat/stream';
|
146 |
const messagesContainer = document.getElementById('messagesContainer');
|
147 |
const messageInput = document.getElementById('messageInput');
|
148 |
const sendButton = document.getElementById('sendMessage');
|
|
|
153 |
let currentStyle = 'normal';
|
154 |
let currentController = null;
|
155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
function createUserMessage(text) {
|
157 |
return `
|
158 |
<div class="message flex justify-end mb-4">
|
|
|
174 |
<div class="max-w-[80%] mr-3">
|
175 |
<div class="bot-message bg-white rounded-lg p-4 shadow-sm">
|
176 |
<p id="${messageId}" class="text-gray-700"></p>
|
177 |
+
<div class="message-actions mt-2">
|
178 |
+
<button class="copy-button text-sm text-gray-500 hover:text-gray-700 mr-2">
|
179 |
+
<svg class="w-4 h-4 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
180 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2"></path>
|
181 |
</svg>
|
182 |
نسخ
|
183 |
</button>
|
184 |
+
<button class="regenerate-button text-sm text-gray-500 hover:text-gray-700">
|
185 |
+
<svg class="w-4 h-4 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
186 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
|
187 |
</svg>
|
188 |
إعادة التوليد
|
189 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
</div>
|
191 |
</div>
|
192 |
</div>
|
|
|
196 |
|
197 |
function formatCodeBlock(code, language) {
|
198 |
return `
|
199 |
+
<div class="code-block">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
<pre class="line-numbers"><code class="language-${language}">${code}</code></pre>
|
201 |
+
</div>
|
202 |
+
`;
|
203 |
}
|
204 |
|
205 |
async function typeText(elementId, text) {
|
206 |
const element = document.getElementById(elementId);
|
207 |
+
if (!element) return;
|
208 |
|
|
|
209 |
const codeBlockRegex = /```(\w+)\n([\s\S]+?)```/g;
|
210 |
let lastIndex = 0;
|
211 |
let match;
|
212 |
+
let formattedText = '';
|
213 |
|
214 |
while ((match = codeBlockRegex.exec(text)) !== null) {
|
215 |
+
formattedText += text.slice(lastIndex, match.index);
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
const [, language, code] = match;
|
217 |
+
formattedText += formatCodeBlock(code.trim(), language);
|
218 |
lastIndex = match.index + match[0].length;
|
219 |
}
|
220 |
|
221 |
+
formattedText += text.slice(lastIndex);
|
222 |
+
element.innerHTML = formattedText;
|
|
|
|
|
|
|
|
|
|
|
223 |
Prism.highlightAllUnder(element);
|
224 |
}
|
225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
async function sendMessage() {
|
227 |
const message = messageInput.value.trim();
|
228 |
if (!message) return;
|
|
|
256 |
|
257 |
const response = await fetch(API_URL, {
|
258 |
method: 'POST',
|
259 |
+
headers: {
|
260 |
+
'Content-Type': 'application/json',
|
261 |
+
'Accept': 'text/event-stream'
|
262 |
+
},
|
263 |
body: JSON.stringify({
|
264 |
message: actualMessage,
|
265 |
history: chatHistory
|
|
|
267 |
signal: currentController.signal
|
268 |
});
|
269 |
|
270 |
+
if (!response.ok) {
|
271 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
272 |
+
}
|
273 |
+
|
274 |
+
const reader = response.body.getReader();
|
275 |
+
const decoder = new TextDecoder();
|
276 |
+
let fullResponse = '';
|
277 |
+
|
278 |
+
while (true) {
|
279 |
+
const { value, done } = await reader.read();
|
280 |
+
if (done) break;
|
281 |
+
|
282 |
+
const chunk = decoder.decode(value, { stream: true });
|
283 |
+
fullResponse += chunk;
|
284 |
+
|
285 |
+
const messageElement = document.getElementById(messageId);
|
286 |
+
if (messageElement) {
|
287 |
+
await typeText(messageId, fullResponse);
|
288 |
+
}
|
289 |
+
}
|
290 |
+
|
291 |
chatHistory.push({
|
292 |
human: actualMessage,
|
293 |
+
assistant: fullResponse
|
294 |
});
|
295 |
+
|
296 |
} catch (error) {
|
297 |
if (error.name === 'AbortError') {
|
298 |
document.getElementById(messageId).textContent = 'تم إيقاف التوليد.';
|
299 |
} else {
|
300 |
+
console.error('Error:', error);
|
301 |
document.getElementById(messageId).textContent = 'عذراً، حدث خطأ في المعالجة.';
|
302 |
}
|
303 |
} finally {
|
|
|
308 |
}
|
309 |
|
310 |
function toggleSendButton(isGenerating) {
|
|
|
311 |
if (isGenerating) {
|
|
|
312 |
sendButton.innerHTML = `
|
313 |
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
314 |
+
</svg>
|
|
|
315 |
`;
|
316 |
} else {
|
|
|
317 |
sendButton.innerHTML = `
|
318 |
<svg class="w-6 h-6 transform rotate-90" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
319 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"></path>
|
|
|
324 |
|
325 |
function adjustTextareaHeight() {
|
326 |
messageInput.style.height = 'auto';
|
327 |
+
messageInput.style.height = Math.min(messageInput.scrollHeight, 200) + 'px';
|
328 |
}
|
329 |
|
330 |
function scrollToBottom() {
|
|
|
336 |
|
337 |
// Event Listeners
|
338 |
document.addEventListener('click', async (e) => {
|
339 |
+
const target = e.target.closest('button');
|
340 |
+
if (!target) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
|
342 |
+
if (target.classList.contains('copy-button')) {
|
343 |
+
const messageWrapper = target.closest('.bot-message');
|
344 |
+
const textContent = messageWrapper.querySelector('p').textContent;
|
345 |
+
await navigator.clipboard.writeText(textContent);
|
346 |
+
|
347 |
+
const originalHTML = target.innerHTML;
|
348 |
+
target.textContent = 'تم النسخ!';
|
349 |
setTimeout(() => {
|
350 |
+
target.innerHTML = originalHTML;
|
|
|
|
|
|
|
|
|
|
|
351 |
}, 2000);
|
352 |
}
|
353 |
|
354 |
+
if (target.classList.contains('regenerate-button')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
if (chatHistory.length > 0) {
|
356 |
const lastMessage = chatHistory[chatHistory.length - 1].human;
|
357 |
messageInput.value = lastMessage;
|
|
|
360 |
}
|
361 |
});
|
362 |
|
363 |
+
// Style Toggle
|
364 |
+
styleSelect.addEventListener('change', (e) => {
|
365 |
+
currentStyle = e.target.value;
|
366 |
+
});
|
367 |
+
|
368 |
+
// Dark Mode Toggle
|
369 |
+
darkModeToggle.addEventListener('click', () => {
|
370 |
+
document.body.classList.toggle('dark-mode');
|
371 |
+
document.body.classList.toggle('light-mode');
|
372 |
+
});
|
373 |
+
|
374 |
+
// Clear Chat
|
375 |
+
clearButton.addEventListener('click', () => {
|
376 |
+
messagesContainer.innerHTML = '';
|
377 |
+
chatHistory = [];
|
378 |
+
});
|
379 |
+
|
380 |
+
// Send Message Events
|
381 |
sendButton.addEventListener('click', sendMessage);
|
382 |
messageInput.addEventListener('keypress', (e) => {
|
383 |
if (e.key === 'Enter' && !e.shiftKey) {
|
|
|
386 |
}
|
387 |
});
|
388 |
messageInput.addEventListener('input', adjustTextareaHeight);
|
|
|
|
|
|
|
|
|
389 |
|
390 |
+
// Initial Welcome Message
|
391 |
+
window.addEventListener('load', () => {
|
392 |
+
const initialMessageId = 'msg-initial';
|
393 |
+
messagesContainer.insertAdjacentHTML('beforeend', createBotMessage('', initialMessageId));
|
394 |
+
typeText(initialMessageId, 'مرحباً! كيف يمكنني مساعدتك اليوم؟');
|
395 |
+
});
|
396 |
</script>
|
397 |
</body>
|
398 |
</html>
|