Build/Refactor: lint pre-commit hook and reformat repo to spec (#314)

* build/refactor: move lint/prettier packages to project root, install husky, add pre-commit hook

* refactor: reformat files

* build: put full eslintrc back with all rules
This commit is contained in:
Dan Orlando 2023-05-18 11:09:31 -07:00 committed by GitHub
parent 8d75b25104
commit 7fdc862042
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
157 changed files with 4836 additions and 2403 deletions

View file

@ -14,7 +14,7 @@ export default function buildTree(messages, groupAll = false) {
}
if (!groupAll) {
// Traverse the messages array and store each element in messageMap.
messages.forEach(message => {
messages.forEach((message) => {
messageMap[message.messageId] = { ...message, children: [] };
const parentMessage = messageMap[message.parentMessageId];

View file

@ -44,7 +44,9 @@ const cleanupPreset = ({ preset: _preset, endpointsConfig = {} }) => {
endpoint,
presetId: _preset?.presetId ?? null,
model:
_preset?.model ?? endpointsConfig[endpoint]?.availableModels?.[0] ?? 'text-davinci-002-render-sha',
_preset?.model ??
endpointsConfig[endpoint]?.availableModels?.[0] ??
'text-davinci-002-render-sha',
title: _preset?.title ?? 'New Preset'
};
} else if (endpoint === null) {

View file

@ -33,11 +33,13 @@ const buildDefaultConversation = ({
'chat-bison',
modelLabel: lastConversationSetup?.modelLabel ?? null,
promptPrefix: lastConversationSetup?.promptPrefix ?? null,
examples: lastConversationSetup?.examples ?? [{ input: { content: '' }, output: { content: '' }}],
examples: lastConversationSetup?.examples ?? [
{ input: { content: '' }, output: { content: '' } }
],
temperature: lastConversationSetup?.temperature ?? 0.2,
maxOutputTokens: lastConversationSetup?.maxOutputTokens ?? 1024,
topP: lastConversationSetup?.topP ?? 0.95,
topK: lastConversationSetup?.topK ?? 40,
topK: lastConversationSetup?.topK ?? 40
};
} else if (endpoint === 'bingAI') {
conversation = {
@ -125,7 +127,9 @@ const getDefaultConversation = ({ conversation, prevConversation, endpointsConfi
// if anything happens, reset to default model
const endpoint = ['openAI', 'azureOpenAI', 'bingAI', 'chatGPTBrowser', 'google'].find(e => endpointsConfig?.[e]);
const endpoint = ['openAI', 'azureOpenAI', 'bingAI', 'chatGPTBrowser', 'google'].find(
e => endpointsConfig?.[e]
);
if (endpoint) {
conversation = buildDefaultConversation({ conversation, endpoint, endpointsConfig });
return conversation;

View file

@ -5,7 +5,7 @@ import GPTIcon from '../components/svg/GPTIcon';
import BingIcon from '../components/svg/BingIcon';
import { useAuthContext } from '~/hooks/AuthContext';
const getIcon = props => {
const getIcon = (props) => {
// { size = 30, isCreatedByUser, model, chatGptLabel, error, ...props }
const { size = 30, isCreatedByUser, button, model } = props;
const { user, logout } = useAuthContext();
@ -22,7 +22,10 @@ const getIcon = props => {
>
<img
className="rounded-sm"
src={user?.avatar || `https://api.dicebear.com/6.x/initials/svg?seed=${user?.name}&fontFamily=Verdana&fontSize=36`}
src={
user?.avatar ||
`https://api.dicebear.com/6.x/initials/svg?seed=${user?.name}&fontFamily=Verdana&fontSize=36`
}
alt="avatar"
/>
</div>
@ -39,13 +42,16 @@ const getIcon = props => {
} else if (endpoint === 'openAI') {
const { chatGptLabel } = props;
icon = <GPTIcon size={size * 0.7} />;
bg = model && model.toLowerCase().startsWith('gpt-4') ? '#AB68FF' : (chatGptLabel
? `rgba(16, 163, 127, ${button ? 0.75 : 1})`
: `rgba(16, 163, 127, ${button ? 0.75 : 1})`);
bg =
model && model.toLowerCase().startsWith('gpt-4')
? '#AB68FF'
: chatGptLabel
? `rgba(16, 163, 127, ${button ? 0.75 : 1})`
: `rgba(16, 163, 127, ${button ? 0.75 : 1})`;
name = chatGptLabel || 'ChatGPT';
} else if (endpoint === 'google') {
const { modelLabel } = props;
icon = <img src='/assets/palm.png' />;
icon = <img src="/assets/palm.png" />;
name = modelLabel || 'PaLM2';
} else if (endpoint === 'bingAI') {
const { jailbreak } = props;
@ -54,7 +60,10 @@ const getIcon = props => {
name = jailbreak ? 'Sydney' : 'BingAI';
} else if (endpoint === 'chatGPTBrowser') {
icon = <GPTIcon size={size * 0.7} />;
bg = model && model.toLowerCase().startsWith('gpt-4') ? '#AB68FF' : `rgba(0, 163, 255, ${button ? 0.75 : 1})`;
bg =
model && model.toLowerCase().startsWith('gpt-4')
? '#AB68FF'
: `rgba(0, 163, 255, ${button ? 0.75 : 1})`;
name = 'ChatGPT';
} else if (endpoint === null) {
icon = <GPTIcon size={size * 0.7} />;
@ -74,7 +83,9 @@ const getIcon = props => {
width: size,
height: size
}}
className={`relative flex items-center justify-center rounded-sm text-white ` + props?.className}
className={
`relative flex items-center justify-center rounded-sm text-white ` + props?.className
}
>
{icon}
{error && (

View file

@ -31,7 +31,9 @@ const useMessageHandler = () => {
endpointOption = {
endpoint,
model:
currentConversation?.model ?? endpointsConfig[endpoint]?.availableModels?.[0] ?? 'gpt-3.5-turbo',
currentConversation?.model ??
endpointsConfig[endpoint]?.availableModels?.[0] ??
'gpt-3.5-turbo',
chatGptLabel: currentConversation?.chatGptLabel ?? null,
promptPrefix: currentConversation?.promptPrefix ?? null,
temperature: currentConversation?.temperature ?? 1,
@ -45,10 +47,14 @@ const useMessageHandler = () => {
endpointOption = {
endpoint,
model:
currentConversation?.model ?? endpointsConfig[endpoint]?.availableModels?.[0] ?? 'chat-bison',
currentConversation?.model ??
endpointsConfig[endpoint]?.availableModels?.[0] ??
'chat-bison',
chatGptLabel: currentConversation?.chatGptLabel ?? null,
promptPrefix: currentConversation?.promptPrefix ?? null,
examples: currentConversation?.examples ?? [{ input: { content: '' }, output: { content: '' } }],
examples: currentConversation?.examples ?? [
{ input: { content: '' }, output: { content: '' } }
],
temperature: currentConversation?.temperature ?? 0.2,
maxOutputTokens: currentConversation?.maxOutputTokens ?? 1024,
topP: currentConversation?.topP ?? 0.95,
@ -94,7 +100,8 @@ const useMessageHandler = () => {
// this is not a real messageId, it is used as placeholder before real messageId returned
text = text.trim();
const fakeMessageId = v4();
parentMessageId = parentMessageId || latestMessage?.messageId || '00000000-0000-0000-0000-000000000000';
parentMessageId =
parentMessageId || latestMessage?.messageId || '00000000-0000-0000-0000-000000000000';
conversationId = conversationId || currentConversation?.conversationId;
if (conversationId == 'search') {
console.error('cannot send any message under search view!');
@ -122,7 +129,7 @@ const useMessageHandler = () => {
parentMessageId: isRegenerate ? messageId : fakeMessageId,
messageId: (isRegenerate ? messageId : fakeMessageId) + '_',
conversationId,
unfinished: (endpoint === 'azureOpenAI' || endpoint === 'openAI') ? false : true,
unfinished: endpoint === 'azureOpenAI' || endpoint === 'openAI' ? false : true,
submitting: true
};
@ -154,8 +161,12 @@ const useMessageHandler = () => {
const regenerate = ({ parentMessageId }) => {
const parentMessage = messages?.find(element => element.messageId == parentMessageId);
if (parentMessage && parentMessage.isCreatedByUser) ask({ ...parentMessage }, { isRegenerate: true });
else console.error('Failed to regenerate the message: parentMessage not found or not created by user.');
if (parentMessage && parentMessage.isCreatedByUser)
ask({ ...parentMessage }, { isRegenerate: true });
else
console.error(
'Failed to regenerate the message: parentMessage not found or not created by user.'
);
};
const stopGenerating = () => {

View file

@ -6,11 +6,11 @@ const ScreenshotContext = createContext({});
export const useScreenshot = () => {
const { ref } = useContext(ScreenshotContext);
const takeScreenShot = node => {
const takeScreenShot = (node) => {
if (!node) {
throw new Error('You should provide correct html node.');
}
return html2canvas(node).then(canvas => {
return html2canvas(node).then((canvas) => {
const croppedCanvas = document.createElement('canvas');
const croppedCanvasContext = croppedCanvas.getContext('2d');
// init data