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