Skip to content

Commit bf4e00c

Browse files
author
gavingogamingrepl
committed
Rem
1 parent b4767a9 commit bf4e00c

File tree

13 files changed

+337
-47
lines changed

13 files changed

+337
-47
lines changed

chat.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ const bodyParser = require('body-parser');
33
function parseArray(array) {
44
return JSON.stringify(array);
55
}
6-
function runchat(askGpt, app) {
6+
function runchat(askGpt, app, askImagen) {
77
app.use(bodyParser.json());
88
app.use('/chatbot/customization', (req, res) => {
99
res.end(require('fs').readFileSync('public/customize.html', { encoding: 'utf-8' }));
1010
});
1111
app.use('/chatbot', (req, res) => {
1212
res.end(require('fs').readFileSync('public/chat.html', { encoding: 'utf-8' }));
1313
});
14+
app.use('/imagen', async(req,res)=>{
15+
var q = req.query.prompt;
16+
var r = await askImagen(q);
17+
res.end(r);
18+
});
1419
app.use('/chatbotresponse', async (req, res) => {
1520
try {
1621
var GPTR = await askGpt(`I want you (Brainbase) to act like a ${req.query.character}. Pretend you have already had this conversation with a person:

chats.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

htmlerrorpage.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module.exports = function(fullerror) {
22
return `<html><link rel="stylesheet"
33
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">
44
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script><body style="background-color:black;color:white;font-family:monospace;">
5-
<h1>Dang it! You broke Brainbase. Stop using it so much! The site will be online again in around 1 day. IF it is a school day, the site should be back on by 4:00 PM.</h1>
6-
<h1>${JSON.parse(fullerror).message.replace('\n', "<br>")}</h1>
5+
<h1>${fullerror}</h1>
76
<pre><code class="languge-json" id="simple" style="border: 1px solid white;padding:2px;margin:1px;">${fullerror.replace('\n', "<br>")}</code></pre></body><script>hljs.highlightAll();</script></html>`;
87
}

htmlres.js

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ module.exports = function(jsonAnswer, question) {
33
return `
44
<html>
55
<head>
6+
<title>${question} | Brainbase</title>
67
<link href="https://gtml.gavingogamingrepl.repl.co/regular-ass-style.css" rel="stylesheet">
78
<link href="https://unpkg.com/movement.css/movement.css" rel="stylesheet">
89
<style>
10+
@import url('/navs.css');
911
/* Style the button that is used to open and close the collapsible content */
1012
.collapsible {
1113
background-color: #eee;
@@ -25,7 +27,7 @@ module.exports = function(jsonAnswer, question) {
2527
}
2628
2729
/* Style the collapsible content. Note: hidden by default */
28-
.content {
30+
.content2 {
2931
padding: 0 18px;
3032
display: none;
3133
overflow: hidden;
@@ -36,12 +38,51 @@ module.exports = function(jsonAnswer, question) {
3638
</head>
3739
<body>
3840
39-
<center style="margin-left:17%;margin-right:17%;">
41+
<div class="menu-icon"><i class="fa-solid fa-bars"></i></div>
42+
<div class="close-icon"><i class="fa-solid fa-x"></i></div>
43+
<script>
44+
var menuIcon = document.querySelector(".menu-icon");
45+
var closeIcon = document.querySelector(".close-icon");
46+
menuIcon.onclick = () => {
47+
closeIcon.style.display = "block";
48+
var nav = document.querySelector(".nav");
49+
nav.style.display = "block";
50+
document.querySelector(".content").style.filter = "blur(4px)";
51+
setTimeout(() => {
52+
nav.classList.add("slide-in");
53+
}, 10);
54+
};
55+
closeIcon.onclick = () => {
56+
closeIcon.style.display = "none";
57+
var nav = document.querySelector(".nav");
58+
nav.style.display = "none";
59+
document.querySelector(".content").style.filter = "none";
60+
nav.classList.remove("slide-in");
61+
nav.classList.add("slide-out");
62+
setTimeout(() => {
63+
nav.style.display = "none";
64+
document.querySelector(".content").style.filter = "none";
65+
nav.classList.remove("slide-out");
66+
}, 250);
67+
};
68+
</script>
69+
<nav class="nav">
70+
<ul>
71+
<li data-link="/"><span>Home</span><i class="fa-solid fa-house"></i></li>
72+
<li class="spacer">Pages</li>
73+
<li data-link="/chatbot"><span>Chatbot</span><i class="fa-solid fa-message"></i></li>
74+
<li data-link="/chatbot/customization"><span>Customization</span><i class="fa-solid fa-gear"></i></li>
75+
<li data-link="/ask.html"><span>Classic</span><i class="fa-solid fa-microchip"></i></li>
76+
<li class="spacer">Socials</li>
77+
<li data-link="https://discord.gg/epBXp5hHBQ"><span>Discord</span><i class="fa-brands fa-discord"></i></li>
78+
</ul>
79+
</nav>
80+
<center class=content>
4081
<h1 class="jetbrains-mono">Brainbase</h1>
4182
<p data-m="reveal-right" style="box-sizing:border-box;border:3px solid white;border-radius:1.5px;" id="ques"><h2>Question Asked</h2>${question}</p><br>
4283
<p data-m="reveal-right" style="box-sizing:border-box;border:3px solid white;border-radius:1.5px;" id="answer"><h2>The Result</h2>${realAnswer.replaceAll("\n", "<br>")}</p><br>
4384
<button class="collapsible">See Advanced Details</button>
44-
<div class="content">
85+
<div class="content2">
4586
<a>Object: ${jsonAnswer.object}</a><br>
4687
<a>Model Used: ${jsonAnswer.model}</a><br>
4788
<a>Finish Reason: ${jsonAnswer.choices[0].finish_reason}</a><br>
@@ -64,6 +105,15 @@ for (i = 0; i < coll.length; i++) {
64105
});
65106
}
66107
</script>
108+
<script>
109+
var buttons = document.querySelectorAll(".nav ul li:not(.spacer)");
110+
buttons.forEach((btn) => {
111+
btn.addEventListener("click", () => {
112+
window.location.href = btn.dataset.link;
113+
});
114+
});
115+
</script>
116+
<script src="Public.js"></script>
67117
</body>
68118
</html>
69119
`;

images.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

index.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function run() {
2121
temperature: (textCompletion != null ? 0 : 1)
2222
});
2323
var fs = require('fs');
24-
var orig = JSON.parse(fs.readFileSync((isChatted ? 'chats.json' : 'queries.json'), { encoding: 'utf-8' }));
24+
var orig = JSON.parse(fs.readFileSync((isChatted == true ? 'chats.json' : 'queries.json'), { encoding: 'utf-8' }));
2525
let currentDate = new Date();
2626
let cDay = currentDate.getDate();
2727
let cMonth = currentDate.getMonth() + 1;
@@ -39,6 +39,29 @@ async function run() {
3939
fs.writeFile((isChatted ? 'chats.json' : 'queries.json'), JSON.stringify(orig), 'utf8', () => { console.log("Brainbase has been used"); });
4040
return response.data;
4141
}
42+
async function askIMG(question) {
43+
const response = await openai.createCompletion({
44+
prompt: question,
45+
n: 1,
46+
size: "256x256",
47+
});
48+
49+
var fs = require('fs');
50+
var orig = JSON.parse(fs.readFileSync('images.json', { encoding: 'utf-8' }));
51+
let currentDate = new Date();
52+
let cDate = currentDate.getFullYear() + '-' + (currentDate.getMonth() + 1) + '-' + currentDate.getDate();
53+
let cTime = currentDate.getHours() + ":" + currentDate.getMinutes() + ":" + currentDate.getSeconds();
54+
let dateTime = cDate + ' ' + cTime;
55+
orig.push({
56+
question: question,
57+
response: response.data.data[0].url,
58+
dateTime: "" + dateTime + ""
59+
});
60+
fs.writeFile('images.json', JSON.stringify(orig), 'utf8', () => { console.log("Brainbase has been used"); });
61+
return {
62+
url: response.data.data[0].url
63+
};
64+
}
4265

4366
app.use(express.static('public')); // Serve files from the '/public' folder
4467

@@ -97,7 +120,7 @@ async function run() {
97120
res.end(htmlres(answer, question)); // Write the answer to the screen
98121
})
99122

100-
chat(askGPT, app);
123+
chat(askGPT, app, askIMG);
101124

102125
const port = 3000;
103126
app.listen(port, () => {

public/a.html

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,54 @@
77
<title>GPT Helper</title>
88
<link href="https://gtml.gavingogamingrepl.repl.co/regular-ass-style.css" rel="stylesheet">
99
<link href="https://unpkg.com/movement.css/movement.css" rel="stylesheet">
10+
<style>
11+
@import url('./navs.css');
12+
</style>
1013
</head>
1114
<body>
12-
<center style="margin-left:10%;margin-right:10%;">
13-
<h1 class="jetbrains-mono" data-m="reveal-right" data-m-duration="1.8"><a>&gt;&gt; </a><img style="border-radius:30%;" src="brainbase.png" width=100><a> &lt;&lt;</a><br>Brainbase: A custom chatgpt instance.</h1>
14-
<h3>Brainbase is an OpenAI-Based GPT-3 Server using davinci models provided by OpenAI's API.</h3>
15-
<h2>Your request is being processed. Please wait a bit while we load it.</h2>
16-
<img src="https://upload.wikimedia.org/wikipedia/commons/b/b9/Youtube_loading_symbol_1_(wobbly).gif" width=100><br>
17-
<h4></h4>
18-
</center>
15+
16+
<div class="menu-icon"><i class='fa-solid fa-bars'></i></div>
17+
<div class="close-icon"><i class='fa-solid fa-x'></i></div>
18+
<script>
19+
var menuIcon = document.querySelector('.menu-icon');
20+
var closeIcon = document.querySelector('.close-icon');
21+
menuIcon.onclick=( () => {
22+
closeIcon.style.display = 'block';
23+
var nav = document.querySelector('.nav');
24+
nav.style.display = 'block';
25+
document.querySelector('.content').style.filter = 'blur(4px)';
26+
setTimeout(() => {
27+
nav.classList.add('slide-in');
28+
}, 10);
29+
});
30+
closeIcon.onclick=( () => {
31+
closeIcon.style.display = 'none';
32+
var nav = document.querySelector('.nav');
33+
nav.style.display = 'none';
34+
document.querySelector('.content').style.filter = 'none';
35+
nav.classList.remove('slide-in');
36+
nav.classList.add('slide-out');
37+
setTimeout(() => {
38+
nav.style.display = 'none';
39+
document.querySelector('.content').style.filter = 'none';
40+
nav.classList.remove('slide-out');
41+
}, 250);
42+
});
43+
</script>
44+
45+
<nav class="nav">
46+
<ul>
47+
<li data-link="/"><span>Home</span><i class='fa-solid fa-house'></i></li>
48+
<li class="spacer">Pages</li>
49+
<li data-link="/chatbot"><span>Chatbot</span><i class='fa-solid fa-message'></i></li>
50+
<li data-link="/chatbot/customization"><span>Customization</span><i class='fa-solid fa-gear'></i></li>
51+
<li data-link="/ask.html"><span>Classic</span><i class='fa-solid fa-microchip'></i></li>
52+
<li class="spacer">Socials</li>
53+
<li data-link="https://discord.gg/epBXp5hHBQ"><span>Discord</span><i class='fa-brands fa-discord'></i></li>
54+
</ul>
55+
</nav>
56+
<center class='content'>
57+
Hello, world!
58+
</center>
1959
</body>
2060
</html>

public/chat.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ ul.chat li {
2121
}
2222
input::placeholder {
2323
font-size: 18px;
24+
}
25+
ul.chat li.titleBar {
26+
padding: 18px;
27+
text-shadow: 1px 1px 2px red, 0 0 1em blue, 0 0 0.2em blue;
28+
background-color: #1f1f1f !important;
29+
border-radius: 10px;
30+
margin-right: 30px;
31+
margin-bottom: 8px;
2432
}

public/chat.html

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@
5151
</nav>
5252
<center class="content">
5353
<link href='chat.css' rel="stylesheet">
54-
<h1>Brainbase Chat</h1>
54+
<!-- <h1>Brainbase Chat</h1> -->
5555
<ul class="chat">
56-
<li>
57-
<b><i>*Brainbase has joined the chat...*</i></b>
56+
<li class='titleBar'>
57+
<i class="fa-duotone fa-2x fa-brain-circuit"></i>
58+
<b><a style='font-size:26px'>Brainbase - Chat</a></b>
59+
<i class="fa-duotone fa-user fa-2x"></i>
5860
</li>
5961
</ul>
6062
<br />
@@ -65,9 +67,36 @@ <h1>Brainbase Chat</h1>
6567
<button class=big onclick="addOn()">Send<i class="fa-duotone fa-paper-plane"></i></button><br />
6668
<button onclick="saveConvo()"><a>Save <i class="fa-duotone fa-download"></i></a></button>
6769
<button onclick="loadConvo()"><a>Load <i class="fa-duotone fa-upload"></i></a></button><br />
70+
<button onclick="deleteConvo()"><a>Delete Saved Convo <i class="fa-duotone fa-circle-xmark"></i></a></button><br />
6871
<button onclick="window.location.href='/chatbot/customization'"><a>Customization <i class="fa-duotone fa-paintbrush-pencil"></i></a></button><br />
6972
</center>
7073
<script>
74+
var helper = {
75+
// Remove and return the first occurrence
76+
77+
remove: function(array, predicate) {
78+
for (var i = 0; i < array.length; i++) {
79+
if (predicate(array[i])) {
80+
return array.splice(i, 1);
81+
}
82+
}
83+
},
84+
85+
// Remove and return all occurrences
86+
87+
removeAll: function(array, predicate) {
88+
var removed = [];
89+
90+
for (var i = 0; i < array.length; ) {
91+
if (predicate(array[i])) {
92+
removed.push(array.splice(i, 1));
93+
continue;
94+
}
95+
i++;
96+
}
97+
return removed;
98+
},
99+
};
71100
let history = [];
72101
function saveConvo() {
73102
var Format = `${JSON.stringify(history)}`;
@@ -83,6 +112,28 @@ <h1>Brainbase Chat</h1>
83112
window.localStorage.savedConversations = JSON.stringify(savedCS);
84113
alert("Saved!");
85114
}
115+
116+
function deleteConvo() {
117+
if(window.localStorage.savedConversations==null||window.localStorage.savedConversations==''||window.localStorage.savedConversations==" "){
118+
window.localStorage.savedConversations='[]';
119+
}
120+
var convos = "";
121+
for(var CV of JSON.parse(window.localStorage.savedConversations)) {
122+
convos += "\n"+CV.name;
123+
}
124+
var name = prompt("Enter convo name out of these:"+convos, "");
125+
var comp = false;
126+
JSON.parse(window.localStorage.savedConversations).forEach(item => {
127+
if(item.name === name) {
128+
var osc = JSON.parse(window.localStorage.savedConversations);
129+
var remmed = helper.removeAll(osc, it=>it.name.startsWith(item.name));
130+
window.localStorage.savedConversations = JSON.stringify(osc);
131+
comp = true;
132+
alert('Removed');
133+
}
134+
});
135+
if(!comp) alert("Couldnt find that one.");
136+
}
86137
function loadConvo() {
87138
if(window.localStorage.savedConversations==null||window.localStorage.savedConversations==''||window.localStorage.savedConversations==" "){
88139
window.localStorage.savedConversations='[]';
@@ -97,10 +148,17 @@ <h1>Brainbase Chat</h1>
97148
if(item.name === name) {
98149
history = JSON.parse(item.convo);
99150
var chatList = document.querySelector('.chat');
100-
var content = `<ul class="chat">`;
151+
var content = `<ul class="chat">
152+
<li class='titleBar'>
153+
<i class="fa-duotone fa-2x fa-brain-circuit"></i>
154+
<b><a style='font-size:26px'>Brainbase - Chat</a></b>
155+
<i class="fa-duotone fa-user fa-2x"></i>
156+
</li>`;
101157
for(var hI of history) {
102-
content +=
158+
content += `<li><center><div style="text-align:left;"><i class='fa-duotone fa-${hI.person == 'Brainbase' ? 'brain-circuit' : 'user'}' style='scale:1.3;'></i> <a style='margin-left:1${hI.person == 'Brainbase' ? '0' : '2'}px;'>${hI.answer}</a></div></center></li>`;
103159
}
160+
content += `</ul>`
161+
chatList.outerHTML = content;
104162
alert("Loaded!");
105163
comp = true;
106164
}
@@ -120,7 +178,7 @@ <h1>Brainbase Chat</h1>
120178
.querySelector(".chat")
121179
.insertAdjacentHTML(
122180
"beforeend",
123-
`<li><center><div style="text-align:left;"><i class='fa-solid fa-brain-circuit' style='scale:1.3;'></i> <a style='margin-left:10px;'>${l.replaceAll("\\n", "<br>")}</a></div></center></li>`
181+
`<li><center><div style="text-align:left;"><i class='fa-duotone fa-brain-circuit' style='scale:1.3;'></i> <a style='margin-left:10px;'>${l.replaceAll("\\n", "<br>")}</a></div></center></li>`
124182
);
125183
}
126184
}
@@ -146,7 +204,7 @@ <h1>Brainbase Chat</h1>
146204
}
147205
document
148206
.querySelector(".chat")
149-
.insertAdjacentHTML("beforeend", `<li><div style="text-align:left;"><i class='fa-solid fa-user' style='scale:1.3;'></i> <a style='margin-left:16px;'>${q.replaceAll("\n", "<br>")}</a></div></li>`);
207+
.insertAdjacentHTML("beforeend", `<li><div style="text-align:left;"><i class='fa-duotone fa-user' style='scale:1.3;'></i> <a style='margin-left:12px;'>${q.replaceAll("\n", "<br>")}</a></div></li>`);
150208
history.push({answer: q, person: 'Human'});
151209
const params = { history: formatHistory() };
152210
fetch(

0 commit comments

Comments
 (0)