diff --git a/.gitignore b/.gitignore index c87c9b3..b167e2d 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts +.idea diff --git a/components/Chat/Chat.tsx b/components/Chat/Chat.tsx index a78f3cd..6c09133 100644 --- a/components/Chat/Chat.tsx +++ b/components/Chat/Chat.tsx @@ -1,5 +1,5 @@ import { Conversation, KeyValuePair, Message, OpenAIModel } from "@/types"; -import { FC, useEffect, useRef, useState } from "react"; +import { FC, MutableRefObject, useEffect, useRef, useState } from "react"; import { ChatInput } from "./ChatInput"; import { ChatLoader } from "./ChatLoader"; import { ChatMessage } from "./ChatMessage"; @@ -17,9 +17,10 @@ interface Props { lightMode: "light" | "dark"; onSend: (message: Message, isResend: boolean) => void; onUpdateConversation: (conversation: Conversation, data: KeyValuePair) => void; + stopConversationRef: MutableRefObject; } -export const Chat: FC = ({ conversation, models, messageIsStreaming, modelError, messageError, loading, lightMode, onSend, onUpdateConversation }) => { +export const Chat: FC = ({ conversation, models, messageIsStreaming, modelError, messageError, loading, lightMode, onSend, onUpdateConversation, stopConversationRef }) => { const [currentMessage, setCurrentMessage] = useState(); const messagesEndRef = useRef(null); @@ -33,7 +34,7 @@ export const Chat: FC = ({ conversation, models, messageIsStreaming, mode }, [conversation.messages]); return ( -
+
{modelError ? (
Error fetching models.
@@ -96,6 +97,7 @@ export const Chat: FC = ({ conversation, models, messageIsStreaming, mode /> ) : ( { setCurrentMessage(message); diff --git a/components/Chat/ChatInput.tsx b/components/Chat/ChatInput.tsx index 5423f1d..a498dab 100644 --- a/components/Chat/ChatInput.tsx +++ b/components/Chat/ChatInput.tsx @@ -1,14 +1,15 @@ import { Message, OpenAIModel, OpenAIModelID } from "@/types"; -import { IconSend } from "@tabler/icons-react"; -import { FC, KeyboardEvent, useEffect, useRef, useState } from "react"; +import { IconHandStop, IconSend } from "@tabler/icons-react"; +import { FC, KeyboardEvent, MutableRefObject, useEffect, useRef, useState } from "react"; interface Props { messageIsStreaming: boolean; onSend: (message: Message) => void; model: OpenAIModel; + stopConversationRef: MutableRefObject; } -export const ChatInput: FC = ({ onSend, messageIsStreaming, model }) => { +export const ChatInput: FC = ({ onSend, messageIsStreaming, model, stopConversationRef }) => { const [content, setContent] = useState(); const [isTyping, setIsTyping] = useState(false); @@ -67,37 +68,68 @@ export const ChatInput: FC = ({ onSend, messageIsStreaming, model }) => { } }, [content]); + function handleStopConversation() { + stopConversationRef.current = true; + setTimeout(() => { + stopConversationRef.current = false; + }, 1000); + } + return (
-
-