Spaces:
Running
Running
add support for new lines in assistant's response and mark down in asssistant's response - Follow Up Deployment
Browse files- index.html +19 -3
index.html
CHANGED
|
@@ -72,6 +72,17 @@
|
|
| 72 |
.transition-all {
|
| 73 |
transition: all 0.3s ease;
|
| 74 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
</style>
|
| 76 |
</head>
|
| 77 |
<body class="bg-gray-50 dark:bg-dark-900 text-gray-800 dark:text-gray-200 min-h-screen">
|
|
@@ -513,7 +524,7 @@
|
|
| 513 |
<i class="fas fa-robot"></i>
|
| 514 |
</div>
|
| 515 |
<div class="max-w-[80%] bg-white dark:bg-gray-800 rounded-lg p-4 shadow-sm relative group">
|
| 516 |
-
<div class="prose dark:prose-invert">${msg.content}</div>
|
| 517 |
<div class="absolute right-2 top-2 opacity-0 group-hover:opacity-100 transition-opacity flex gap-1">
|
| 518 |
<button class="message-action bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 p-1 rounded text-gray-700 dark:text-gray-300" data-action="regenerate" title="Regenerate">
|
| 519 |
<i class="fas fa-sync-alt text-xs"></i>
|
|
@@ -527,7 +538,7 @@
|
|
| 527 |
} else {
|
| 528 |
messageElement.innerHTML = `
|
| 529 |
<div class="max-w-[80%] bg-primary-500 text-white rounded-lg p-4 shadow-sm relative group">
|
| 530 |
-
<div class="prose prose-white">${msg.content}</div>
|
| 531 |
<div class="absolute right-2 top-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
| 532 |
<button class="message-action bg-primary-600 hover:bg-primary-700 p-1 rounded text-white" data-action="edit" title="Edit">
|
| 533 |
<i class="fas fa-edit text-xs"></i>
|
|
@@ -738,7 +749,12 @@
|
|
| 738 |
const parsed = JSON.parse(data);
|
| 739 |
const content = parsed.choices?.[0]?.delta?.content || '';
|
| 740 |
result += content;
|
| 741 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 742 |
chatArea.scrollTop = chatArea.scrollHeight;
|
| 743 |
} catch (e) {
|
| 744 |
console.error('Error parsing stream data:', e);
|
|
|
|
| 72 |
.transition-all {
|
| 73 |
transition: all 0.3s ease;
|
| 74 |
}
|
| 75 |
+
|
| 76 |
+
/* Code block styling */
|
| 77 |
+
.prose code {
|
| 78 |
+
background-color: rgba(0,0,0,0.1);
|
| 79 |
+
padding: 0.2em 0.4em;
|
| 80 |
+
border-radius: 0.25em;
|
| 81 |
+
font-family: monospace;
|
| 82 |
+
}
|
| 83 |
+
.dark .prose code {
|
| 84 |
+
background-color: rgba(255,255,255,0.1);
|
| 85 |
+
}
|
| 86 |
</style>
|
| 87 |
</head>
|
| 88 |
<body class="bg-gray-50 dark:bg-dark-900 text-gray-800 dark:text-gray-200 min-h-screen">
|
|
|
|
| 524 |
<i class="fas fa-robot"></i>
|
| 525 |
</div>
|
| 526 |
<div class="max-w-[80%] bg-white dark:bg-gray-800 rounded-lg p-4 shadow-sm relative group">
|
| 527 |
+
<div class="prose dark:prose-invert whitespace-pre-wrap">${msg.content.replace(/\n/g, '<br>')}</div>
|
| 528 |
<div class="absolute right-2 top-2 opacity-0 group-hover:opacity-100 transition-opacity flex gap-1">
|
| 529 |
<button class="message-action bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 p-1 rounded text-gray-700 dark:text-gray-300" data-action="regenerate" title="Regenerate">
|
| 530 |
<i class="fas fa-sync-alt text-xs"></i>
|
|
|
|
| 538 |
} else {
|
| 539 |
messageElement.innerHTML = `
|
| 540 |
<div class="max-w-[80%] bg-primary-500 text-white rounded-lg p-4 shadow-sm relative group">
|
| 541 |
+
<div class="prose prose-white whitespace-pre-wrap">${msg.content.replace(/\n/g, '<br>')}</div>
|
| 542 |
<div class="absolute right-2 top-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
| 543 |
<button class="message-action bg-primary-600 hover:bg-primary-700 p-1 rounded text-white" data-action="edit" title="Edit">
|
| 544 |
<i class="fas fa-edit text-xs"></i>
|
|
|
|
| 749 |
const parsed = JSON.parse(data);
|
| 750 |
const content = parsed.choices?.[0]?.delta?.content || '';
|
| 751 |
result += content;
|
| 752 |
+
// Replace newlines with <br> and preserve markdown formatting
|
| 753 |
+
contentElement.innerHTML = result
|
| 754 |
+
.replace(/\n/g, '<br>')
|
| 755 |
+
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
| 756 |
+
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
| 757 |
+
.replace(/`(.*?)`/g, '<code>$1</code>');
|
| 758 |
chatArea.scrollTop = chatArea.scrollHeight;
|
| 759 |
} catch (e) {
|
| 760 |
console.error('Error parsing stream data:', e);
|