Skip to content

Commit

Permalink
GPT maker bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
scalabled committed Nov 22, 2023
1 parent c38c559 commit fa1cce7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 38 deletions.
69 changes: 47 additions & 22 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h1 id="gpt-name"></h1>
<input type="radio" id="config-tab" name="tabs">
<label for="config-tab">Configure</label>
<div class="content">
<form>
<div class="form">
<label for="name">Name</label>
<input type="text" id="name" name="name" />
<label for="welcome">Welcome Message</label>
Expand All @@ -69,15 +69,15 @@ <h1 id="gpt-name"></h1>
<textarea id="instructions" name="instructions" rows="20"></textarea>
<label>
<input type="checkbox" id="use-files" name="use-files" />
Use files
Use files (will search user-uploaded files)
</label>
<label>
<input type="checkbox" id="use-dalle" name="use-dalle" />
Use DALL-E
Use DALL-E (will return only images)
</label>
<label>
<input type="checkbox" id="use-speech" name="use-speech" />
Use speech
Use speech (will speak every response)
</label>
<label for="voice-list">Voice</label>
<select id="voice-list">
Expand All @@ -93,7 +93,7 @@ <h1 id="gpt-name"></h1>
<button id="save-button">Save</button>
<button id="cancel-button">Cancel</button>
</div>
</form>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -140,7 +140,7 @@ <h1 id="gpt-name"></h1>
welcome: "Hello, how can I assist you today?",
instructions: "You are a helpful assistant.",
useFiles: true,
useDalle: true,
useDalle: false,
useSpeech: false,
voice: 'alloy'
}
Expand All @@ -150,6 +150,7 @@ <h1 id="gpt-name"></h1>
gpts = JSON.parse(gpts_json)
}
let gpt = gpts.ChatGPT
let creatingGPT = false
const openAI = initOpenAI(OPENAI_API_KEY, OPENAI_API_ORG);
const vectorStore = createVectorStore(openAI.getEmbeddings);
let sendConversationMessage = createConversation(gpt.instructions, openAI.getCompletion, openAI.getImage, vectorStore.vectorSearch);
Expand Down Expand Up @@ -189,31 +190,38 @@ <h1 id="gpt-name"></h1>
useSpeechInput.checked = false;
voiceList.value = 'alloy';
configTab.checked = true;
creatingGPT = true;
});
deleteButton.addEventListener('click', (e) => {
e.preventDefault();
if (creatingGPT || gpt.name === "ChatGPT") {
alert('You cannot delete this GPT')
return
}
if (confirm('Are you sure you want to delete this GPT?')) {
delete gpts[nameInput.value];
delete gpts[gpt.name];
localStorage.setItem('gpts', JSON.stringify(gpts));
renderSidebar();
loadGPT('ChatGPT');
}
});
cancelButton.addEventListener('click', (e) => {
e.preventDefault();
loadGPT(nameInput.value);
creatingGPT = false;
loadGPT(gpt.name);
});
saveButton.addEventListener('click', (e) => {
e.preventDefault();
if (saveGPT()) {
creatingGPT = false;
loadGPT(nameInput.value);
}
});
chatTab.addEventListener('click', (e) => {
if (saveGPT()) {
loadGPT(nameInput.value);
} else {
e.preventDefault();
if (gpt.name !== "ChatGPT") {
if (saveGPT()) {
creatingGPT = false;
loadGPT(nameInput.value);
} else {
e.preventDefault();
}
}
});

Expand All @@ -235,7 +243,11 @@ <h1 id="gpt-name"></h1>
}

function saveGPT() {
const name = nameInput.value;
const name = nameInput.value.trim();
if (!creatingGPT && gpt.name === "ChatGPT" && name !== "ChatGPT") {
alert('You cannot change the name of this GPT')
return
}
const welcome = welcomeInput.value;
const icon = iconInput.files[0];
const instructions = instructionsInput.value;
Expand All @@ -247,11 +259,15 @@ <h1 id="gpt-name"></h1>
alert('Please enter a name')
return
}
if (!welcome) {
alert('Please enter the welcome message')
return
}
if (!instructions) {
alert('Please enter the instructions')
return
}
const gpt = {
const gptData = {
name,
welcome,
icon,
Expand All @@ -261,7 +277,12 @@ <h1 id="gpt-name"></h1>
useSpeech,
voice
};
gpts[name] = gpt;
gpts[name] = gptData;
if (!creatingGPT && name !== gpt.name) {
console.log('deleting', gpt.name, name, gpts)
delete gpts[gpt.name]
console.log('deleted', gpts)
}
localStorage.setItem('gpts', JSON.stringify(gpts));
renderSidebar();
return true
Expand Down Expand Up @@ -309,6 +330,8 @@ <h1 id="gpt-name"></h1>
if (!content) {
message.innerHTML = loading
}
document.body.scrollTop = document.body.scrollHeight;
document.documentElement.scrollTop = document.documentElement.scrollHeight
return (text, replace) => {
if (!content) {
message.innerHTML = ""
Expand All @@ -321,6 +344,8 @@ <h1 id="gpt-name"></h1>
} else {
message.innerHTML = renderMarkdown((content += text))
}
document.body.scrollTop = document.body.scrollHeight;
document.documentElement.scrollTop = document.documentElement.scrollHeight
}
}

Expand All @@ -343,14 +368,14 @@ <h1 id="gpt-name"></h1>
userImages = []
}
const appendOutput = addOutput("", gpt.name)
if (useDalleInput.checked) {
const image = await sendConversationMessage(input, undefined, useFilesInput.checked, true);
if (gpt.useDalle) {
const image = await sendConversationMessage(input, undefined, gpt.useFiles, true);
if (image) {
appendOutput(addImage(image))
}
} else {
const result = await sendConversationMessage(input, appendOutput, useFilesInput.checked);
if (useSpeechInput.checked) {
const result = await sendConversationMessage(input, appendOutput, gpt.useFiles);
if (gpt.useSpeech) {
await openAI.playSpeech(result, voiceList.value);
}
}
Expand Down
28 changes: 12 additions & 16 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
box-sizing: border-box;
}

html {
overflow: hidden;
}

body {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
Expand Down Expand Up @@ -202,7 +198,7 @@ main h1 {
right: 2px;
}

form {
.form {
width: 50%;
margin: 20px auto;
}
Expand All @@ -223,7 +219,7 @@ input[type="file"] {
}

aside button,
form button,
.form button,
.ac-pushButton {
background-color: #10A37F;
border: none;
Expand All @@ -238,11 +234,11 @@ form button,
padding: 4px 6px;
}

form label {
.form label {
display: block;
}

form button {
.form button {
display: inline-block;
margin: 5px;
width: 150px;
Expand Down Expand Up @@ -417,19 +413,19 @@ form button {
margin: 0;
}

form {
.form {
width: 100%;
}

form button {
.form button {
width: calc((100% - 80px) / 3);
}
form label,
form textarea,
form select,
form .buttons,
form input[type="text"],
form input[type="file"] {
.form label,
.form textarea,
.form select,
.form .buttons,
.form input[type="text"],
.form input[type="file"] {
width: calc(100% - 60px);
margin-left: 30px;
}
Expand Down

0 comments on commit fa1cce7

Please sign in to comment.