-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
91 lines (76 loc) · 2.25 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import {
generateSpeechInstructions,
goToBed,
printToChat,
printToLogs,
printToSubtitles,
} from "./helpers.js";
import { GUI } from "three/addons/libs/lil-gui.module.min.js";
import {
SampleMeanYoutubeComments,
initialInstructions,
sampleUsernames,
} from "./constants.js";
import SceneManager from "./3d/index.js";
import ChatGPT from "./3d/chat.js";
var Scene = new SceneManager();
const chatGPT = new ChatGPT("https://api.perplexity.ai/chat/completions");
var modes = [ "chatMode", "radioMode", "galleryMode",];
function setupGUI() {
modes.forEach(mode => {
document
.getElementById("console-" + mode)
.addEventListener("click", function (e) {
showMode(mode);
});
}
);
// document
// .getElementById("console-radioMode")
// .addEventListener("click", function (e) {
// var characters = Scene.getCharacters();
// Scene.setInstructions(goToBed(characters));
// });
// document
// .getElementById("console-galleryMode")
// .addEventListener("click", function (e) {
// showMode("galleryMode");
// var xPos = Math.random() * 4 - 2;
// var yPos = Math.random() * 4 - 2;
// Scene.setInstructions([`move milady1 ${xPos},${yPos} 500`, "sleep 500"]);
// });
showMode();
}
function showMode(screen = "chatMode") {
modes.forEach(element => {
document.getElementById(element).style.display = "none";
});
document.getElementById(screen).style.display = "flex";
}
function processChat(message) {
if (message.length == 0) return;
printToChat("You", message);
chatGPT
.callChatGPT(message)
.then((response) => {
var instructions = generateSpeechInstructions(response);
Scene.setInstructions(instructions);
})
.catch((error) => {
console.error("An error occurred:", error);
});
}
document.getElementById("chat-submit").addEventListener("click", function (e) {
var input = document.getElementById("chat-input").value;
document.getElementById("chat-input").value = "";
processChat(input);
});
document.getElementById("chat-input").addEventListener("keydown", function chatInput(e) {
if (e.keyCode == 13) {
var input = document.getElementById("chat-input").value;
document.getElementById("chat-input").value = "";
processChat(input);
}
}
);
setupGUI();