modified: index.html
This commit is contained in:
parent
880c09bc86
commit
65a37318f0
1 changed files with 12 additions and 6 deletions
18
index.html
18
index.html
|
|
@ -297,17 +297,23 @@ async function handleUserInput() {
|
|||
const chatBox = document.getElementById('chat-box');
|
||||
chatBox.innerHTML += `<p><strong>You:</strong> ${userInput}</p>`;
|
||||
|
||||
chatBox.innerHTML += `<p><strong>AI:</strong> `;
|
||||
const messageElement = chatBox.lastElementChild;
|
||||
// Create a new paragraph for the AI response
|
||||
const aiResponseParagraph = document.createElement('p');
|
||||
aiResponseParagraph.innerHTML = '<strong>AI:</strong> ';
|
||||
chatBox.appendChild(aiResponseParagraph);
|
||||
|
||||
// Create a span element for the actual response content
|
||||
const responseContent = document.createElement('span');
|
||||
aiResponseParagraph.appendChild(responseContent);
|
||||
|
||||
let accumulatedContent = '';
|
||||
for await (const chunk of sendMessage(userInput)) {
|
||||
accumulatedContent += chunk;
|
||||
const parsedChunk = marked.parse(accumulatedContent);
|
||||
messageElement.innerHTML = parsedChunk;
|
||||
responseContent.innerHTML = parsedChunk;
|
||||
|
||||
// Apply syntax highlighting to code blocks
|
||||
messageElement.querySelectorAll('pre code').forEach((block) => {
|
||||
responseContent.querySelectorAll('pre code').forEach((block) => {
|
||||
hljs.highlightElement(block);
|
||||
});
|
||||
}
|
||||
|
|
@ -332,8 +338,8 @@ function initializeChatInterface() {
|
|||
});
|
||||
}
|
||||
|
||||
document.getElementById("user-input").addEventListener("keypress", function(event) {
|
||||
if (event.key === "Enter") {
|
||||
document.getElementById("user-input").addEventListener("keydown", function(event) {
|
||||
if (event.key === "Enter" && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
handleUserInput();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue