Spaces:
Running
Running
Update chat.js
Browse files
chat.js
CHANGED
@@ -1,55 +1,38 @@
|
|
1 |
-
const userInput = document.getElementById('message-input');
|
2 |
const sendButton = document.getElementById('send-message');
|
|
|
3 |
const chatBox = document.getElementById('conversation-history');
|
4 |
-
const status = document.getElementById('status');
|
5 |
-
|
6 |
-
// Funktion, um eine Abfrage an die Hugging Face API zu senden
|
7 |
-
async function queryHuggingFace(data) {
|
8 |
-
const response = await fetch(
|
9 |
-
"https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-v0.1",
|
10 |
-
{
|
11 |
-
headers: { Authorization: "Bearer IhrHuggingFaceAPIToken" },
|
12 |
-
method: "POST",
|
13 |
-
body: JSON.stringify(data),
|
14 |
-
}
|
15 |
-
);
|
16 |
-
const result = await response.json();
|
17 |
-
return result;
|
18 |
-
}
|
19 |
-
|
20 |
-
// Event-Listener für den Senden-Button
|
21 |
-
sendButton.addEventListener('click', () => {
|
22 |
-
const message = userInput.value.trim();
|
23 |
-
if (!message) return;
|
24 |
|
|
|
|
|
|
|
25 |
displayMessage('Du: ' + message, 'user');
|
26 |
userInput.value = '';
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
}
|
34 |
-
.
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
});
|
39 |
|
40 |
-
// Nachricht im Chat anzeigen
|
41 |
function displayMessage(message, sender) {
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
}
|
48 |
|
49 |
-
// Enter-Taste als Alternative zum Senden
|
50 |
-
userInput.addEventListener('keypress', function(e) {
|
51 |
-
if (e.key === 'Enter') {
|
52 |
-
sendButton.click();
|
53 |
-
}
|
54 |
-
});
|
55 |
|
|
|
|
|
1 |
const sendButton = document.getElementById('send-message');
|
2 |
+
const userInput = document.getElementById('message-input');
|
3 |
const chatBox = document.getElementById('conversation-history');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
sendButton.addEventListener('click', async () => {
|
6 |
+
const message = userInput.value.trim();
|
7 |
+
if (message) {
|
8 |
displayMessage('Du: ' + message, 'user');
|
9 |
userInput.value = '';
|
10 |
|
11 |
+
try {
|
12 |
+
const response = await fetch('http://localhost:7860/api/chat/', {
|
13 |
+
method: 'POST',
|
14 |
+
headers: {
|
15 |
+
'Content-Type': 'application/json',
|
16 |
+
},
|
17 |
+
body: JSON.stringify({
|
18 |
+
"inputs": message,
|
19 |
+
}),
|
20 |
+
});
|
21 |
+
const data = await response.json();
|
22 |
+
|
23 |
+
displayMessage('Bot: ' + data, 'bot');
|
24 |
+
} catch (error) {
|
25 |
+
console.error('Fehler beim Senden der Nachricht:', error);
|
26 |
+
}
|
27 |
+
}
|
28 |
});
|
29 |
|
|
|
30 |
function displayMessage(message, sender) {
|
31 |
+
const messageElement = document.createElement('div');
|
32 |
+
messageElement.className = 'message ' + sender;
|
33 |
+
messageElement.textContent = message;
|
34 |
+
chatBox.appendChild(messageElement);
|
35 |
+
chatBox.scrollTop = chatBox.scrollHeight; // Scroll to the bottom
|
36 |
}
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|