-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
51 lines (42 loc) · 1.59 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function AISend() {
var userInput = document.getElementById("user-input").value;
var encodedPrompt = encodeURIComponent(userInput);
var chatMessages = document.getElementById("chat-messages");
var userLi = document.createElement("li");
userLi.classList.add("user-message");
userLi.textContent = userInput;
chatMessages.appendChild(userLi);
var aiTypingLi = document.createElement("li");
aiTypingLi.classList.add("ai-message", "ai-typing-message");
aiTypingLi.textContent = "AI is typing...";
chatMessages.appendChild(aiTypingLi);
scrollToBottom(chatMessages);
// reset to old but mostly working version //ok
// nice! it works
AiMessage(userInput, 'Be a helpful assistant.', "meta-llama/Llama-2-7b-chat-hf").then(response => {
resp2 = JSON.parse(response)
aiTypingLi.remove(); // Remove the old "AI is typing..." message
var aiLi = document.createElement("li");
aiLi.classList.add("ai-message");
aiLi.textContent = resp2.choices[0].message.content; // Use the extracted content here
chatMessages.appendChild(aiLi);
scrollToBottom(chatMessages);
})
document.getElementById("user-input").value = "";
}
function scrollToBottom(element) {
element.scrollTop = element.scrollHeight;
}
// Add event listener for Enter key press
document
.getElementById("user-input")
.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
event.preventDefault();
AISend();
}
});
function myFunction() {
var element = document.body;
element.classList.toggle("dark-mode");
}