add markdown
This commit is contained in:
parent
4d2e5332d8
commit
a7dfbe2ebd
@ -1,5 +1,6 @@
|
||||
let chatCount = 0; // Zähler für Chat-Sessions
|
||||
let currentChatId = null; // Aktuell angezeigte Chat-ID
|
||||
let useMarkdown = true;
|
||||
|
||||
document.getElementById('newChatButton').addEventListener('click', () => {
|
||||
createNewChat();
|
||||
@ -13,7 +14,14 @@ document.getElementById('sendButton').addEventListener('click', () => {
|
||||
if (messageText !== '' && currentChatId !== null) { // Stelle sicher, dass eine Chat-ID vorhanden ist
|
||||
const messageElement = document.createElement('div');
|
||||
messageElement.classList.add('chat-message', 'user');
|
||||
messageElement.innerText = messageText;
|
||||
//messageElement.innerText = messageText;
|
||||
|
||||
if (useMarkdown) {
|
||||
messageElement.innerHTML = renderMarkdown(messageText);
|
||||
} else {
|
||||
messageElement.innerText = messageText;
|
||||
}
|
||||
|
||||
chatBox.prepend(messageElement);
|
||||
|
||||
// Nachricht speichern
|
||||
@ -238,6 +246,10 @@ function getLastUserMessage() {
|
||||
return ''; // Rückgabe eines leeren Strings, falls keine Nachricht gefunden wird
|
||||
}
|
||||
|
||||
function renderMarkdown(content) {
|
||||
return marked.parse(content);
|
||||
}
|
||||
|
||||
async function stream_api_open_ai(userMessage) {
|
||||
// Neues div-Element für die Antwort des Chatbots erstellen
|
||||
const chatBox = document.getElementById('chatBox');
|
||||
@ -287,8 +299,11 @@ async function stream_api_open_ai(userMessage) {
|
||||
const token = json.choices[0].delta.content;
|
||||
result += token;
|
||||
|
||||
// Live-Update des Chatbot-Textes
|
||||
botMessageDiv.textContent = result;
|
||||
if (useMarkdown) {
|
||||
botMessageDiv.innerHTML = renderMarkdown(result);
|
||||
} else {
|
||||
botMessageDiv.textContent = result;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error parsing JSON:', error, 'Received:', jsonStr);
|
||||
|
@ -43,7 +43,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<script src="js/chat.js"></script>
|
||||
<script src="js/main.js"></script>
|
||||
</body>
|
||||
|
Loading…
Reference in New Issue
Block a user