Spaces:
Running
Running
Update chat.js
Browse files
chat.js
CHANGED
@@ -1,62 +1,39 @@
|
|
1 |
// chat.js
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
// API-Anfrage, um die Antwort des Chatbots zu erhalten
|
20 |
-
getBotResponse(userMessage).then(botMessage => {
|
21 |
-
addToConversationHistory("Bot", botMessage);
|
22 |
-
});
|
23 |
-
|
24 |
-
// Eingabefeld leeren
|
25 |
-
messageInput.value = "";
|
26 |
-
}
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
}
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
return `Echo: ${message}`;
|
41 |
}
|
|
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
messageInput.addEventListener("keypress", function(event) {
|
48 |
-
if (event.key === "Enter") {
|
49 |
-
sendMessage();
|
50 |
-
}
|
51 |
-
});
|
52 |
-
|
53 |
-
// Event-Listener für den Button "Neue Unterhaltung"
|
54 |
-
newConversationButton.addEventListener("click", function() {
|
55 |
-
conversationHistory.innerHTML = "";
|
56 |
-
});
|
57 |
-
|
58 |
-
// Event-Listener für den Button "Unterhaltungen löschen"
|
59 |
-
clearConversationsButton.addEventListener("click", function() {
|
60 |
-
conversationHistory.innerHTML = "";
|
61 |
-
});
|
62 |
});
|
|
|
1 |
// chat.js
|
2 |
|
3 |
+
const express = require('express');
|
4 |
+
const bodyParser = require('body-parser');
|
5 |
+
const LangChain = require('langchain'); // Stellen Sie sicher, dass Sie die LangChain-Bibliothek installiert haben
|
6 |
+
|
7 |
+
const app = express();
|
8 |
+
app.use(bodyParser.json());
|
9 |
+
|
10 |
+
// Erstellen des LangChain-Modells
|
11 |
+
const llm = LangChain.CTransformers({
|
12 |
+
model: 'TheBloke/CodeLlama-7B-GGUF',
|
13 |
+
model_type: 'llama',
|
14 |
+
max_new_tokens: 1096,
|
15 |
+
temperature: 0.2,
|
16 |
+
repetition_penalty: 1.13,
|
17 |
+
gpu_layers: 2
|
18 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
// API-Endpunkt für Chatbot-Anfragen
|
21 |
+
app.post('/chatbot', async (req, res) => {
|
22 |
+
const userQuery = req.body.query;
|
23 |
+
if (!userQuery) {
|
24 |
+
return res.status(400).send({ error: 'Query is required' });
|
25 |
}
|
26 |
|
27 |
+
try {
|
28 |
+
const response = await llm.run({query: userQuery});
|
29 |
+
res.send({ reply: response });
|
30 |
+
} catch (error) {
|
31 |
+
res.status(500).send({ error: 'Error processing request' });
|
|
|
32 |
}
|
33 |
+
});
|
34 |
|
35 |
+
// Starten des Servers
|
36 |
+
const PORT = 3000;
|
37 |
+
app.listen(PORT, () => {
|
38 |
+
console.log(`Server running on port ${PORT}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
});
|