Skip to content

Commit aeda422

Browse files
authored
Merge pull request #29 from mckaywrigley/main
2 parents cf79bfd + e8150e7 commit aeda422

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+607
-164
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ You should be able to start chatting.
112112

113113
When deploying the application, the following environment variables can be set:
114114

115-
| Environment Variable | Default value | Description |
116-
| -------------------- | --------------- | ------------------------------------------------------- |
117-
| OPENAI_API_KEY | | The default API key used for authentication with OpenAI |
118-
| DEFAULT_MODEL | `gpt-3.5-turbo` | The default model to use on new conversations |
115+
| Environment Variable | Default value | Description |
116+
| --------------------- | ------------------------------ | ------------------------------------------------------- |
117+
| OPENAI_API_KEY | | The default API key used for authentication with OpenAI |
118+
| DEFAULT_MODEL | `gpt-3.5-turbo` | The default model to use on new conversations |
119+
| DEFAULT_SYSTEM_PROMPT | [see here](utils/app/const.ts) | The defaut system prompt to use on new conversations |
119120

120121
If you do not provide an OpenAI API key with `OPENAI_API_KEY`, users will have to provide their own key.
121122
If you don't have an OpenAI API key, you can get one [here](https://platform.openai.com/account/api-keys).

__tests__/utils/app/importExports.test.ts

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ExportFormatV1, ExportFormatV2 } from '@/types/export';
1+
import { ExportFormatV1, ExportFormatV2, ExportFormatV4 } from '@/types/export';
22
import { OpenAIModels, OpenAIModelID } from '@/types/openai';
33
import { DEFAULT_SYSTEM_PROMPT } from '@/utils/app/const';
44
import { it, describe, expect } from 'vitest';
@@ -8,6 +8,7 @@ import {
88
isExportFormatV1,
99
isExportFormatV2,
1010
isExportFormatV3,
11+
isExportFormatV4,
1112
isLatestExportFormat,
1213
} from '@/utils/app/importExport';
1314

@@ -47,6 +48,18 @@ describe('Export Format Functions', () => {
4748
expect(isExportFormatV3(obj)).toBe(false);
4849
});
4950
});
51+
52+
describe('isExportFormatV4', () => {
53+
it('should return true for v4 format', () => {
54+
const obj = { version: 4, history: [], folders: [], prompts: [] };
55+
expect(isExportFormatV4(obj)).toBe(true);
56+
});
57+
58+
it('should return false for non-v4 formats', () => {
59+
const obj = { version: 5, history: [], folders: [], prompts: [] };
60+
expect(isExportFormatV4(obj)).toBe(false);
61+
});
62+
});
5063
});
5164

5265
describe('cleanData Functions', () => {
@@ -71,7 +84,7 @@ describe('cleanData Functions', () => {
7184
const obj = cleanData(data);
7285
expect(isLatestExportFormat(obj)).toBe(true);
7386
expect(obj).toEqual({
74-
version: 3,
87+
version: 4,
7588
history: [
7689
{
7790
id: 1,
@@ -92,6 +105,7 @@ describe('cleanData Functions', () => {
92105
},
93106
],
94107
folders: [],
108+
prompts:[]
95109
});
96110
});
97111
});
@@ -125,7 +139,42 @@ describe('cleanData Functions', () => {
125139
const obj = cleanData(data);
126140
expect(isLatestExportFormat(obj)).toBe(true);
127141
expect(obj).toEqual({
128-
version: 3,
142+
version: 4,
143+
history: [
144+
{
145+
id: '1',
146+
name: 'conversation 1',
147+
messages: [
148+
{
149+
role: 'user',
150+
content: "what's up ?",
151+
},
152+
{
153+
role: 'assistant',
154+
content: 'Hi',
155+
},
156+
],
157+
model: OpenAIModels[OpenAIModelID.GPT_3_5],
158+
prompt: DEFAULT_SYSTEM_PROMPT,
159+
folderId: null,
160+
},
161+
],
162+
folders: [
163+
{
164+
id: '1',
165+
name: 'folder 1',
166+
type: 'chat',
167+
},
168+
],
169+
prompts: [],
170+
});
171+
});
172+
});
173+
174+
describe('cleaning v4 data', () => {
175+
it('should return the latest format', () => {
176+
const data = {
177+
version: 4,
129178
history: [
130179
{
131180
id: '1',
@@ -152,7 +201,61 @@ describe('cleanData Functions', () => {
152201
type: 'chat',
153202
},
154203
],
204+
prompts: [
205+
{
206+
id: '1',
207+
name: 'prompt 1',
208+
description: '',
209+
content: '',
210+
model: OpenAIModels[OpenAIModelID.GPT_3_5],
211+
folderId: null,
212+
},
213+
],
214+
} as ExportFormatV4;
215+
216+
const obj = cleanData(data);
217+
expect(isLatestExportFormat(obj)).toBe(true);
218+
expect(obj).toEqual({
219+
version: 4,
220+
history: [
221+
{
222+
id: '1',
223+
name: 'conversation 1',
224+
messages: [
225+
{
226+
role: 'user',
227+
content: "what's up ?",
228+
},
229+
{
230+
role: 'assistant',
231+
content: 'Hi',
232+
},
233+
],
234+
model: OpenAIModels[OpenAIModelID.GPT_3_5],
235+
prompt: DEFAULT_SYSTEM_PROMPT,
236+
folderId: null,
237+
},
238+
],
239+
folders: [
240+
{
241+
id: '1',
242+
name: 'folder 1',
243+
type: 'chat',
244+
},
245+
],
246+
prompts: [
247+
{
248+
id: '1',
249+
name: 'prompt 1',
250+
description: '',
251+
content: '',
252+
model: OpenAIModels[OpenAIModelID.GPT_3_5],
253+
folderId: null,
254+
},
255+
],
256+
155257
});
156258
});
157259
});
260+
158261
});

components/Chat/Chat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export const Chat: FC<Props> = memo(
318318
{showScrollDownButton && (
319319
<div className="absolute bottom-0 right-0 mb-4 mr-4 pb-20">
320320
<button
321-
className="flex h-7 w-7 items-center justify-center rounded-full bg-neutral-200 text-gray-700 shadow-md hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-700"
321+
className="flex h-7 w-7 items-center justify-center rounded-full bg-neutral-300 text-gray-800 shadow-md hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-neutral-200"
322322
onClick={handleScrollDown}
323323
>
324324
<IconArrowDown size={18} />

components/Chat/ChatInput.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,8 @@ export const ChatInput: FC<Props> = ({
214214
if (textareaRef && textareaRef.current) {
215215
textareaRef.current.style.height = 'inherit';
216216
textareaRef.current.style.height = `${textareaRef.current?.scrollHeight}px`;
217-
textareaRef.current.style.overflow = `${
218-
textareaRef?.current?.scrollHeight > 400 ? 'auto' : 'hidden'
219-
}`;
217+
textareaRef.current.style.overflow = `${textareaRef?.current?.scrollHeight > 400 ? 'auto' : 'hidden'
218+
}`;
220219
}
221220
}, [content]);
222221

@@ -242,7 +241,7 @@ export const ChatInput: FC<Props> = ({
242241
<div className="stretch mx-2 mt-4 flex flex-row gap-3 last:mb-2 md:mx-4 md:mt-[52px] md:last:mb-6 lg:mx-auto lg:max-w-3xl">
243242
{messageIsStreaming && (
244243
<button
245-
className="absolute left-0 right-0 mx-auto mt-2 flex w-fit items-center gap-3 rounded border border-neutral-200 bg-white py-2 px-4 text-black hover:opacity-50 dark:border-neutral-600 dark:bg-[#343541] dark:text-white md:top-0"
244+
className="absolute top-0 left-0 right-0 mb-3 md:mb-0 md:mt-2 mx-auto flex w-fit items-center gap-3 rounded border border-neutral-200 bg-white py-2 px-4 text-black hover:opacity-50 dark:border-neutral-600 dark:bg-[#343541] dark:text-white"
246245
onClick={handleStopConversation}
247246
>
248247
<IconPlayerStop size={16} /> {t('Stop Generating')}
@@ -251,7 +250,7 @@ export const ChatInput: FC<Props> = ({
251250

252251
{!messageIsStreaming && !conversationIsEmpty && (
253252
<button
254-
className="absolute left-0 right-0 mx-auto mt-2 flex w-fit items-center gap-3 rounded border border-neutral-200 bg-white py-2 px-4 text-black hover:opacity-50 dark:border-neutral-600 dark:bg-[#343541] dark:text-white md:top-0"
253+
className="absolute top-0 left-0 right-0 mb-3 md:mb-0 md:mt-2 mx-auto flex w-fit items-center gap-3 rounded border border-neutral-200 bg-white py-2 px-4 text-black hover:opacity-50 dark:border-neutral-600 dark:bg-[#343541] dark:text-white"
255254
onClick={onRegenerate}
256255
>
257256
<IconRepeat size={16} /> {t('Regenerate response')}
@@ -266,11 +265,9 @@ export const ChatInput: FC<Props> = ({
266265
resize: 'none',
267266
bottom: `${textareaRef?.current?.scrollHeight}px`,
268267
maxHeight: '400px',
269-
overflow: `${
270-
textareaRef.current && textareaRef.current.scrollHeight > 400
271-
? 'auto'
272-
: 'hidden'
273-
}`,
268+
overflow: `${textareaRef.current && textareaRef.current.scrollHeight > 400
269+
? 'auto' : 'hidden'
270+
}`,
274271
}}
275272
placeholder={
276273
t('Type a message or type "/" to select a prompt...') || ''
@@ -286,10 +283,14 @@ export const ChatInput: FC<Props> = ({
286283
className="absolute right-2 top-2 rounded-sm p-1 text-neutral-800 opacity-60 hover:bg-neutral-200 hover:text-neutral-900 dark:bg-opacity-50 dark:text-neutral-100 dark:hover:text-neutral-200"
287284
onClick={handleSend}
288285
>
289-
<IconSend size={18} />
286+
{messageIsStreaming ? (
287+
<div className="h-4 w-4 animate-spin rounded-full border-t-2 border-neutral-800 opacity-60 dark:border-neutral-100"></div>
288+
) : (
289+
<IconSend size={18} />
290+
)}
290291
</button>
291292

292-
{showPromptList && prompts.length > 0 && (
293+
{showPromptList && filteredPrompts.length > 0 && (
293294
<div className="absolute bottom-12 w-full">
294295
<PromptList
295296
activePromptIndex={activePromptIndex}

components/Chat/ChatMessage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Message } from '@/types/chat';
2-
import { IconCheck, IconCopy, IconEdit } from '@tabler/icons-react';
2+
import { IconCheck, IconCopy, IconEdit, IconUser, IconRobot } from '@tabler/icons-react';
33
import { useTranslation } from 'next-i18next';
44
import { FC, memo, useEffect, useRef, useState } from 'react';
55
import rehypeMathjax from 'rehype-mathjax';
@@ -81,7 +81,7 @@ export const ChatMessage: FC<Props> = memo(
8181
>
8282
<div className="relative m-auto flex gap-4 p-4 text-base md:max-w-2xl md:gap-6 md:py-6 lg:max-w-2xl lg:px-0 xl:max-w-3xl">
8383
<div className="min-w-[40px] text-right font-bold">
84-
{message.role === 'assistant' ? t('AI') : t('You')}:
84+
{message.role === 'assistant' ? <IconRobot size={30}/> : <IconUser size={30}/>}
8585
</div>
8686

8787
<div className="prose mt-[-2px] w-full dark:prose-invert">

components/Chat/SystemPrompt.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export const SystemPrompt: FC<Props> = ({
215215
onKeyDown={handleKeyDown}
216216
/>
217217

218-
{showPromptList && prompts.length > 0 && (
218+
{showPromptList && filteredPrompts.length > 0 && (
219219
<div>
220220
<PromptList
221221
activePromptIndex={activePromptIndex}

components/Chatbar/Chatbar.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { KeyValuePair } from '@/types/data';
33
import { SupportedExportFormats } from '@/types/export';
44
import { Folder } from '@/types/folder';
55
import {
6-
IconArrowBarLeft,
76
IconFolderPlus,
87
IconMessagesOff,
98
IconPlus,
@@ -29,7 +28,6 @@ interface Props {
2928
onToggleLightMode: (mode: 'light' | 'dark') => void;
3029
onSelectConversation: (conversation: Conversation) => void;
3130
onDeleteConversation: (conversation: Conversation) => void;
32-
onToggleSidebar: () => void;
3331
onUpdateConversation: (
3432
conversation: Conversation,
3533
data: KeyValuePair,
@@ -54,7 +52,6 @@ export const Chatbar: FC<Props> = ({
5452
onToggleLightMode,
5553
onSelectConversation,
5654
onDeleteConversation,
57-
onToggleSidebar,
5855
onUpdateConversation,
5956
onApiKeyChange,
6057
onClearConversations,
@@ -138,12 +135,6 @@ export const Chatbar: FC<Props> = ({
138135
>
139136
<IconFolderPlus size={18} />
140137
</button>
141-
142-
<IconArrowBarLeft
143-
className="ml-1 hidden cursor-pointer p-1 text-neutral-300 hover:text-neutral-400 sm:flex"
144-
size={32}
145-
onClick={onToggleSidebar}
146-
/>
147138
</div>
148139

149140
{conversations.length > 1 && (
@@ -176,7 +167,7 @@ export const Chatbar: FC<Props> = ({
176167

177168
{conversations.length > 0 ? (
178169
<div
179-
className="h-full pt-2"
170+
className="pt-2"
180171
onDrop={(e) => handleDrop(e)}
181172
onDragOver={allowDrop}
182173
onDragEnter={highlightDrop}

components/Chatbar/ChatbarSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const ChatbarSettings: FC<Props> = ({
3838
<Import onImport={onImportConversations} />
3939

4040
<SidebarButton
41-
text={t('Export conversations')}
41+
text={t('Export data')}
4242
icon={<IconFileExport size={18} />}
4343
onClick={() => onExportConversations()}
4444
/>

0 commit comments

Comments
 (0)