Spaces:
Running
Running
A resposta do modelo será um markdown, formate o markdown e mostre a reposta
Browse files- index.html +28 -8
index.html
CHANGED
|
@@ -242,9 +242,15 @@
|
|
| 242 |
const messageDiv = document.createElement('div');
|
| 243 |
messageDiv.className = `message-bubble ${sender === 'user' ? 'bg-white rounded-2xl p-4 shadow-md ml-auto' : 'bg-[#21223a] text-white rounded-2xl p-4 shadow-md'}`;
|
| 244 |
|
| 245 |
-
const messageContent = document.createElement('
|
| 246 |
messageContent.className = sender === 'user' ? 'text-gray-800' : 'text-white';
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
const timestamp = document.createElement('span');
|
| 250 |
timestamp.className = `text-xs block mt-2 ${sender === 'user' ? 'text-gray-500' : 'text-gray-300'}`;
|
|
@@ -258,6 +264,20 @@
|
|
| 258 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 259 |
}
|
| 260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
function addTypingIndicator() {
|
| 262 |
const typingDiv = document.createElement('div');
|
| 263 |
typingDiv.className = 'message-bubble bg-[#21223a] text-white rounded-2xl p-4 shadow-md';
|
|
@@ -288,14 +308,14 @@
|
|
| 288 |
|
| 289 |
function getAIResponse(userMessage) {
|
| 290 |
const responses = [
|
| 291 |
-
"Entendi sua pergunta! Deixe-me ajudar com isso...",
|
| 292 |
-
"Excelente pergunta!
|
| 293 |
-
"Com base na sua solicitação
|
| 294 |
-
"Ótimo ponto!
|
| 295 |
-
"Obrigado pela pergunta
|
| 296 |
];
|
| 297 |
|
| 298 |
-
return responses[Math.floor(Math.random() * responses.length)]
|
| 299 |
}
|
| 300 |
|
| 301 |
// Enter key to send message
|
|
|
|
| 242 |
const messageDiv = document.createElement('div');
|
| 243 |
messageDiv.className = `message-bubble ${sender === 'user' ? 'bg-white rounded-2xl p-4 shadow-md ml-auto' : 'bg-[#21223a] text-white rounded-2xl p-4 shadow-md'}`;
|
| 244 |
|
| 245 |
+
const messageContent = document.createElement('div');
|
| 246 |
messageContent.className = sender === 'user' ? 'text-gray-800' : 'text-white';
|
| 247 |
+
|
| 248 |
+
if (sender === 'ai') {
|
| 249 |
+
// Parse and format markdown
|
| 250 |
+
messageContent.innerHTML = formatMarkdown(text);
|
| 251 |
+
} else {
|
| 252 |
+
messageContent.textContent = text;
|
| 253 |
+
}
|
| 254 |
|
| 255 |
const timestamp = document.createElement('span');
|
| 256 |
timestamp.className = `text-xs block mt-2 ${sender === 'user' ? 'text-gray-500' : 'text-gray-300'}`;
|
|
|
|
| 264 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 265 |
}
|
| 266 |
|
| 267 |
+
function formatMarkdown(text) {
|
| 268 |
+
// Basic markdown formatting
|
| 269 |
+
return text
|
| 270 |
+
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>') // bold
|
| 271 |
+
.replace(/\*(.*?)\*/g, '<em>$1</em>') // italic
|
| 272 |
+
.replace(/`(.*?)`/g, '<code class="bg-gray-700 px-1 py-0.5 rounded text-sm">$1</code>') // inline code
|
| 273 |
+
.replace(/^# (.*$)/gm, '<h1 class="text-xl font-bold mb-2">$1</h1>') // h1
|
| 274 |
+
.replace(/^## (.*$)/gm, '<h2 class="text-lg font-bold mb-2">$1</h2>') // h2
|
| 275 |
+
.replace(/^### (.*$)/gm, '<h3 class="text-base font-bold mb-2">$1</h3>') // h3
|
| 276 |
+
.replace(/^- (.*$)/gm, '<li class="ml-4">$1</li>') // list items
|
| 277 |
+
.replace(/(<li.*?<\/li>)/gs, '<ul class="list-disc pl-6 my-2">$1</ul>') // wrap lists
|
| 278 |
+
.replace(/\n/g, '<br>'); // line breaks
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
function addTypingIndicator() {
|
| 282 |
const typingDiv = document.createElement('div');
|
| 283 |
typingDiv.className = 'message-bubble bg-[#21223a] text-white rounded-2xl p-4 shadow-md';
|
|
|
|
| 308 |
|
| 309 |
function getAIResponse(userMessage) {
|
| 310 |
const responses = [
|
| 311 |
+
"**Entendi sua pergunta!** Deixe-me ajudar com isso...\n\nEsta é uma resposta simulada com **markdown formatado**. Aqui estão alguns exemplos:\n\n- **Negrito** com **\n- *Itálico* com *\n- `Código inline` com `\n- Listas com -",
|
| 312 |
+
"## Excelente pergunta!\n\nAqui está a informação que você precisa:\n\n- Primeiro ponto importante\n- Segundo ponto relevante\n- Terceira observação útil\n\n**Dica:** Use `código` para exemplos técnicos.",
|
| 313 |
+
"### Com base na sua solicitação\n\nAqui está o que posso compartilhar:\n\n**Principais tópicos:**\n- Tópico 1 com *detalhes*\n- Tópico 2 com `exemplo`\n- Tópico 3 importante\n\nEsta resposta demonstra **formatação markdown**.",
|
| 314 |
+
"## Ótimo ponto!\n\nDeixe-me elaborar sobre isso:\n\n**Explicação detalhada:**\n*Este texto está em itálico* enquanto **este está em negrito**.\n\n`Código de exemplo` para ilustrar melhor.",
|
| 315 |
+
"### Obrigado pela pergunta\n\n**Aqui está minha resposta formatada:**\n\n- Item 1: Descrição *com ênfase*\n- Item 2: Exemplo `com código`\n- Item 3: Conclusão **importante**\n\nEsta é uma demonstração de markdown."
|
| 316 |
];
|
| 317 |
|
| 318 |
+
return responses[Math.floor(Math.random() * responses.length)];
|
| 319 |
}
|
| 320 |
|
| 321 |
// Enter key to send message
|