Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
|
@@ -1,44 +1,41 @@
|
|
| 1 |
-
// Sie sollten prüfen, ob Sie die Transformers.js-Bibliothek korrekt eingebunden haben.
|
| 2 |
-
// Der folgende Code ist ein Beispiel und muss möglicherweise für Ihre spezifische Implementierung angepasst werden.
|
| 3 |
-
|
| 4 |
-
const status = document.getElementById('status');
|
| 5 |
const userInput = document.getElementById('message-input');
|
| 6 |
const sendButton = document.getElementById('send-message');
|
| 7 |
const chatBox = document.getElementById('conversation-history');
|
|
|
|
| 8 |
|
| 9 |
-
//
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
});
|
| 23 |
|
| 24 |
-
//
|
| 25 |
-
|
| 26 |
const message = userInput.value.trim();
|
| 27 |
if (!message) return;
|
| 28 |
|
| 29 |
displayMessage('Du: ' + message, 'user');
|
| 30 |
userInput.value = '';
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
}
|
|
|
|
| 42 |
|
| 43 |
// Nachricht im Chat anzeigen
|
| 44 |
function displayMessage(message, sender) {
|
|
@@ -49,12 +46,10 @@ function displayMessage(message, sender) {
|
|
| 49 |
chatBox.scrollTop = chatBox.scrollHeight; // Scroll to the bottom
|
| 50 |
}
|
| 51 |
|
| 52 |
-
// Event-Listener für den Senden-Button
|
| 53 |
-
sendButton.addEventListener('click', sendMessage);
|
| 54 |
-
|
| 55 |
// Enter-Taste als Alternative zum Senden
|
| 56 |
userInput.addEventListener('keypress', function(e) {
|
| 57 |
if (e.key === 'Enter') {
|
| 58 |
-
|
| 59 |
}
|
| 60 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
status.textContent = 'Der Bot antwortet...';
|
| 29 |
+
queryHuggingFace({"inputs": message})
|
| 30 |
+
.then(response => {
|
| 31 |
+
displayMessage('Bot: ' + response.generated_text, 'bot');
|
| 32 |
+
status.textContent = '';
|
| 33 |
+
})
|
| 34 |
+
.catch(error => {
|
| 35 |
+
displayMessage('Fehler beim Generieren der Antwort: ' + error, 'error');
|
| 36 |
+
status.textContent = '';
|
| 37 |
+
});
|
| 38 |
+
});
|
| 39 |
|
| 40 |
// Nachricht im Chat anzeigen
|
| 41 |
function displayMessage(message, sender) {
|
|
|
|
| 46 |
chatBox.scrollTop = chatBox.scrollHeight; // Scroll to the bottom
|
| 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 |
+
|