diff --git a/.env.local.example b/.env.local.example new file mode 100644 index 0000000..e6c4374 --- /dev/null +++ b/.env.local.example @@ -0,0 +1 @@ +OPENAI_API_KEY=YOUR_KEY \ No newline at end of file diff --git a/components/Chat/ChatInput.tsx b/components/Chat/ChatInput.tsx index 8f748f5..f140f03 100644 --- a/components/Chat/ChatInput.tsx +++ b/components/Chat/ChatInput.tsx @@ -141,7 +141,7 @@ export const ChatInput: FC = ({ } else { setActivePromptIndex(0); } - } else if (e.key === 'Enter' && !isMobile() && !e.shiftKey) { + } else if (e.key === 'Enter' && !isTyping && !isMobile() && !e.shiftKey) { e.preventDefault(); handleSend(); } diff --git a/components/Chat/ChatMessage.tsx b/components/Chat/ChatMessage.tsx index b6545ef..5848b32 100644 --- a/components/Chat/ChatMessage.tsx +++ b/components/Chat/ChatMessage.tsx @@ -1,8 +1,7 @@ import { Message } from '@/types/chat'; -import { IconEdit } from '@tabler/icons-react'; +import { IconCheck, IconCopy, IconEdit } from '@tabler/icons-react'; import { useTranslation } from 'next-i18next'; import { FC, memo, useEffect, useRef, useState } from 'react'; -import { IconCheck, IconCopy } from '@tabler/icons-react'; import rehypeMathjax from 'rehype-mathjax'; import remarkGfm from 'remark-gfm'; import remarkMath from 'remark-math'; @@ -19,6 +18,7 @@ export const ChatMessage: FC = memo( ({ message, messageIndex, onEditMessage }) => { const { t } = useTranslation('chat'); const [isEditing, setIsEditing] = useState(false); + const [isTyping, setIsTyping] = useState(false); const [messageContent, setMessageContent] = useState(message.content); const [messagedCopied, setMessageCopied] = useState(false); @@ -46,7 +46,7 @@ export const ChatMessage: FC = memo( }; const handlePressEnter = (e: React.KeyboardEvent) => { - if (e.key === 'Enter' && !e.shiftKey) { + if (e.key === 'Enter' && !isTyping && !e.shiftKey) { e.preventDefault(); handleEditMessage(); } @@ -80,7 +80,7 @@ export const ChatMessage: FC = memo( style={{ overflowWrap: 'anywhere' }} >
-
+
{message.role === 'assistant' ? t('AI') : t('You')}:
@@ -95,6 +95,8 @@ export const ChatMessage: FC = memo( value={messageContent} onChange={handleInputChange} onKeyDown={handlePressEnter} + onCompositionStart={() => setIsTyping(true)} + onCompositionEnd={() => setIsTyping(false)} style={{ fontFamily: 'inherit', fontSize: 'inherit',