Skip to content

Commit

Permalink
chore: add eslint to project
Browse files Browse the repository at this point in the history
  • Loading branch information
waylaidwanderer committed Mar 11, 2023
1 parent 72f313d commit 9d99b55
Show file tree
Hide file tree
Showing 12 changed files with 1,987 additions and 160 deletions.
49 changes: 49 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'plugin:vue/vue3-essential',
'airbnb-base',
],
overrides: [],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: [
'vue',
],
rules: {
'vue/multi-word-component-names': ['error', {
ignores: ['Chat'],
}],
'import/no-unresolved': 'off',
indent: ['error', 4, { SwitchCase: 1 }],
'max-len': [
'error', {
code: 150,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreComments: true,
},
],
'linebreak-style': 0,
'arrow-parens': [2, 'as-needed', { requireForBlockBody: true }],
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
'no-console': 'off',
'import/extensions': 'off',
'no-use-before-define': [
'error', {
functions: false,
},
],
'no-promise-executor-return': 'off',
'no-param-reassign': 'off',
'no-continue': 'off',
'no-restricted-syntax': 'off',
'no-undef': 'off',
'import/prefer-default-export': 'off',
},
};
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
<Chat/>
</main>
<footer class="px-3 py-6 text-center">
<span class="text-xs font-light text-slate-400">powered by <a href="https://github.com/waylaidwanderer/node-chatgpt-api" target="_blank">https://github.com/waylaidwanderer/node-chatgpt-api</a></span>
<span class="text-xs font-light text-slate-400">
powered by
<a href="https://github.com/waylaidwanderer/node-chatgpt-api" target="_blank">
https://github.com/waylaidwanderer/node-chatgpt-api
</a>
</span>
</footer>
</div>
</template>
Expand Down
56 changes: 34 additions & 22 deletions components/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { marked } from 'marked';
import DOMPurify from 'isomorphic-dompurify';
import hljs from 'highlight.js';
import { v4 as uuidv4 } from 'uuid';
import { storeToRefs } from 'pinia';
import BingIcon from '~/components/Icons/BingIcon.vue';
import GPTIcon from '~/components/Icons/GPTIcon.vue';
import ClientDropdown from '~/components/Chat/ClientDropdown.vue';
import ClientSettings from '~/components/Chat/ClientSettings.vue';
import { storeToRefs } from 'pinia';
marked.setOptions({
silent: true,
Expand Down Expand Up @@ -60,13 +60,6 @@ const inputRows = computed(() => {
return Math.min(newlines + 1, 7);
});
// watch inputRows for change and call `setChatContainerHeight` to adjust height
watch(inputRows, () => {
nextTick(() => {
setChatContainerHeight();
});
});
const scrollToBottom = () => {
messagesContainerElement.value.scrollTop = messagesContainerElement.value.scrollHeight;
};
Expand Down Expand Up @@ -163,18 +156,18 @@ const sendMessage = async (input) => {
throw new Error(`Failed to send message. HTTP ${response.status} - ${response.statusText}`);
},
onclose() {
throw new Error(`Failed to send message. Server closed the connection unexpectedly.`);
throw new Error('Failed to send message. Server closed the connection unexpectedly.');
},
onerror(err) {
throw err;
},
onmessage(message) {
if (message.data === '[DONE]') {
onmessage(eventMessage) {
if (eventMessage.data === '[DONE]') {
processingController.value.abort();
return;
}
if (message.event === 'result') {
const result = JSON.parse(message.data);
if (eventMessage.event === 'result') {
const result = JSON.parse(eventMessage.data);
if (result.jailbreakConversationId) {
conversationData.value = {
jailbreakConversationId: result.jailbreakConversationId,
Expand Down Expand Up @@ -208,15 +201,15 @@ const sendMessage = async (input) => {
nextTick().then(() => scrollToBottom());
return;
}
if (message.event === 'error') {
const data = JSON.parse(message.data);
botMessage.text = data.error || 'An error occurred. Please try again.';
if (eventMessage.event === 'error') {
const eventMessageData = JSON.parse(eventMessage.data);
botMessage.text = eventMessageData.error || 'An error occurred. Please try again.';
botMessage.error = true;
botMessage.raw = data;
botMessage.raw = eventMessageData;
nextTick().then(() => scrollToBottom());
return;
}
botMessage.text += JSON.parse(message.data);
botMessage.text += JSON.parse(eventMessage.data);
nextTick().then(() => scrollToBottom());
},
});
Expand All @@ -237,7 +230,10 @@ const setChatContainerHeight = () => {
const footerElementHeight = document.querySelector('footer').offsetHeight;
const inputContainerElementHeight = inputContainerElement.value.offsetHeight;
const heightOffset = window.document.documentElement.clientHeight - window.innerHeight + 50;
const containerHeight = window.document.documentElement.clientHeight - (headerElementHeight + footerElementHeight) - inputContainerElementHeight - (heightOffset / 2);
const containerHeight = window.document.documentElement.clientHeight
- (headerElementHeight + footerElementHeight)
- inputContainerElementHeight
- (heightOffset / 2);
// set container height
messagesContainerElement.value.style.height = `${containerHeight}px`;
// move input container element bottom down
Expand Down Expand Up @@ -295,6 +291,13 @@ if (!process.server) {
window.removeEventListener('resize', setChatContainerHeight);
stopProcessing();
});
// watch inputRows for change and call `setChatContainerHeight` to adjust height
watch(inputRows, () => {
nextTick(() => {
setChatContainerHeight();
});
});
}
</script>
Expand Down Expand Up @@ -359,15 +362,21 @@ if (!process.server) {
<button
v-if="processingController"
@click="stopProcessing"
class="flex-1 py-2 px-5 bg-white/10 backdrop-blur-sm text-slate-300 text-sm shadow rounded transition duration-300 ease-in-out hover:bg-white/20"
class="
flex-1 py-2 px-5 bg-white/10 backdrop-blur-sm text-slate-300 text-sm
shadow rounded transition duration-300 ease-in-out hover:bg-white/20
"
>
Stop
</button>
<button
v-for="response in suggestedResponses"
:key="response"
@click="sendMessage(response)"
class="flex-1 py-2 px-3 bg-white/10 backdrop-blur-sm text-slate-300 text-sm shadow rounded transition duration-300 ease-in-out hover:bg-white/20"
class="
flex-1 py-2 px-3 bg-white/10 backdrop-blur-sm text-slate-300 text-sm
shadow rounded transition duration-300 ease-in-out hover:bg-white/20
"
>
{{ response }}
</button>
Expand Down Expand Up @@ -425,7 +434,10 @@ if (!process.server) {
@keydown.enter.exact.prevent="sendMessage(message)"
placeholder="Type your message here..."
:disabled="!!processingController"
class="py-4 pl-14 pr-14 rounded-l-sm text-slate-100 w-full bg-white/5 backdrop-blur-sm placeholder-white/40 focus:outline-none resize-none placeholder:truncate"
class="
py-4 pl-14 pr-14 rounded-l-sm text-slate-100 w-full bg-white/5 backdrop-blur-sm
placeholder-white/40 focus:outline-none resize-none placeholder:truncate
"
:class="{
'opacity-50 cursor-not-allowed': !!processingController,
}"
Expand Down
13 changes: 7 additions & 6 deletions components/Chat/ClientDropdown.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup>
import { storeToRefs } from 'pinia';
import GPTIcon from '~/components/Icons/GPTIcon.vue';
import BingIcon from '~/components/Icons/BingIcon.vue';
import { usePresetsStore } from '~/stores/presets';
import { storeToRefs } from 'pinia';
defineProps({
presetName: {
Expand All @@ -28,24 +28,24 @@ const importAppData = () => {
const input = document.createElement('input');
input.type = 'file';
input.accept = 'application/json';
input.onchange = e => {
input.onchange = (e) => {
const file = e.target.files[0];
const reader = new FileReader();
reader.readAsText(file, 'UTF-8');
reader.onload = readerEvent => {
reader.onload = (readerEvent) => {
const content = readerEvent.target.result;
localStorage.clear();
Object.assign(localStorage, JSON.parse(content));
location.reload();
window.location.reload();
};
};
input.click();
}
};
const exportAppData = () => {
// turn localStorage into JSON and save it as a file
const dataStr = JSON.stringify(localStorage);
const dataUri = 'data:application/json;charset=utf-8,' + encodeURIComponent(dataStr);
const dataUri = `data:application/json;charset=utf-8,${encodeURIComponent(dataStr)}`;
const exportFileDefaultName = 'appData.json';
Expand Down Expand Up @@ -127,6 +127,7 @@ const exportAppData = () => {
</div>
<div
v-for="preset in customPresets"
:key="preset.name"
class="w-full flex flex-row"
>
<button
Expand Down
Loading

0 comments on commit 9d99b55

Please sign in to comment.