Update sss.html
Browse files
sss.html
CHANGED
|
@@ -230,11 +230,6 @@
|
|
| 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 |
-
<a href="https://joermd-test11.static.hf.space" target="_blank" id="micButton" class="bg-green-500 hover:bg-green-600 text-white rounded-full p-2 transition-colors">
|
| 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>
|
|
@@ -246,7 +241,7 @@
|
|
| 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');
|
|
@@ -423,10 +418,11 @@
|
|
| 423 |
messagesContainer.insertAdjacentHTML('beforeend', createBotMessage('', messageId));
|
| 424 |
scrollToBottom();
|
| 425 |
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
|
|
|
|
| 430 |
const response = await fetch(API_URL, {
|
| 431 |
method: 'POST',
|
| 432 |
headers: { 'Content-Type': 'application/json' },
|
|
@@ -437,17 +433,38 @@
|
|
| 437 |
signal: currentController.signal
|
| 438 |
});
|
| 439 |
|
| 440 |
-
const
|
| 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 {
|
|
|
|
| 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 |
<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">
|
| 234 |
<option value="short">⚡ ردود قصيرة</option>
|
| 235 |
<option value="normal" selected>◯ عادي</option>
|
|
|
|
| 241 |
</footer>
|
| 242 |
|
| 243 |
<script>
|
| 244 |
+
const API_URL = 'https://nvgsxt9jqx730v-7777.proxy.runpod.net/proxy/8000/chat/stream';
|
| 245 |
const messagesContainer = document.getElementById('messagesContainer');
|
| 246 |
const messageInput = document.getElementById('messageInput');
|
| 247 |
const sendButton = document.getElementById('sendMessage');
|
|
|
|
| 418 |
messagesContainer.insertAdjacentHTML('beforeend', createBotMessage('', messageId));
|
| 419 |
scrollToBottom();
|
| 420 |
|
| 421 |
+
let fullResponse = '';
|
| 422 |
+
currentController = new AbortController();
|
| 423 |
+
toggleSendButton(true);
|
| 424 |
|
| 425 |
+
try {
|
| 426 |
const response = await fetch(API_URL, {
|
| 427 |
method: 'POST',
|
| 428 |
headers: { 'Content-Type': 'application/json' },
|
|
|
|
| 433 |
signal: currentController.signal
|
| 434 |
});
|
| 435 |
|
| 436 |
+
const reader = response.body.getReader();
|
| 437 |
+
const decoder = new TextDecoder();
|
| 438 |
+
|
| 439 |
+
while (true) {
|
| 440 |
+
const { value, done } = await reader.read();
|
| 441 |
+
if (done) break;
|
| 442 |
+
|
| 443 |
+
const chunk = decoder.decode(value);
|
| 444 |
+
const lines = chunk.split('\n');
|
| 445 |
+
|
| 446 |
+
for (const line of lines) {
|
| 447 |
+
if (line.startsWith('data: ')) {
|
| 448 |
+
const content = line.slice(6).trim();
|
| 449 |
+
if (content === '[DONE]') {
|
| 450 |
+
break;
|
| 451 |
+
}
|
| 452 |
+
fullResponse += content;
|
| 453 |
+
await typeText(messageId, fullResponse);
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
chatHistory.push({
|
| 459 |
human: actualMessage,
|
| 460 |
+
assistant: fullResponse
|
| 461 |
});
|
| 462 |
+
|
| 463 |
} catch (error) {
|
| 464 |
if (error.name === 'AbortError') {
|
| 465 |
document.getElementById(messageId).textContent = 'تم إيقاف التوليد.';
|
| 466 |
} else {
|
| 467 |
+
console.error('Error:', error);
|
| 468 |
document.getElementById(messageId).textContent = 'عذراً، حدث خطأ في المعالجة.';
|
| 469 |
}
|
| 470 |
} finally {
|