From 83217c6d83e65b4400f5ab408d0cef9ccfc3c8c5 Mon Sep 17 00:00:00 2001 From: Mckay Wrigley Date: Thu, 23 Mar 2023 08:54:22 -0600 Subject: [PATCH] new load behavior --- components/Chat/Chat.tsx | 10 +++++++++- components/Chat/ChatLoader.tsx | 6 +++--- pages/index.tsx | 12 +++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/components/Chat/Chat.tsx b/components/Chat/Chat.tsx index 744b71c..e83d2ae 100644 --- a/components/Chat/Chat.tsx +++ b/components/Chat/Chat.tsx @@ -10,6 +10,7 @@ import { SystemPrompt } from "./SystemPrompt"; interface Props { conversation: Conversation; models: OpenAIModel[]; + apiKey: string; messageIsStreaming: boolean; modelError: boolean; messageError: boolean; @@ -20,7 +21,7 @@ interface Props { stopConversationRef: MutableRefObject; } -export const Chat: FC = ({ conversation, models, messageIsStreaming, modelError, messageError, loading, lightMode, onSend, onUpdateConversation, stopConversationRef }) => { +export const Chat: FC = ({ conversation, models, apiKey, messageIsStreaming, modelError, messageError, loading, lightMode, onSend, onUpdateConversation, stopConversationRef }) => { const [currentMessage, setCurrentMessage] = useState(); const [autoScrollEnabled, setAutoScrollEnabled] = useState(true); @@ -64,6 +65,13 @@ export const Chat: FC = ({ conversation, models, messageIsStreaming, mode return (
+ {!apiKey && ( +
+
OpenAI API Key Required
+
Please set your OpenAI API key in the bottom left of the sidebar.
+
+ )} + {modelError ? (
Error fetching models.
diff --git a/components/Chat/ChatLoader.tsx b/components/Chat/ChatLoader.tsx index fcea9fe..6c3ff91 100644 --- a/components/Chat/ChatLoader.tsx +++ b/components/Chat/ChatLoader.tsx @@ -6,11 +6,11 @@ interface Props {} export const ChatLoader: FC = () => { return (
-
-
AI:
+
+
AI:
diff --git a/pages/index.tsx b/pages/index.tsx index 5af5df4..6024cab 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -82,7 +82,7 @@ export default function Home() { } if (updatedConversation.messages.length === 1) { - const {content} = message + const { content } = message; const customName = content.length > 30 ? content.substring(0, 30) + "..." : content; updatedConversation = { @@ -291,7 +291,9 @@ export default function Home() { }, [selectedConversation]); useEffect(() => { - fetchModels(apiKey); + if (apiKey) { + fetchModels(apiKey); + } }, [apiKey]); useEffect(() => { @@ -300,9 +302,10 @@ export default function Home() { setLightMode(theme as "dark" | "light"); } - const apiKey = localStorage.getItem("apiKey") || ""; + const apiKey = localStorage.getItem("apiKey"); if (apiKey) { setApiKey(apiKey); + fetchModels(apiKey); } if (window.innerWidth < 640) { @@ -330,8 +333,6 @@ export default function Home() { prompt: DEFAULT_SYSTEM_PROMPT }); } - - fetchModels(apiKey); }, []); return ( @@ -396,6 +397,7 @@ export default function Home() {