From 33a36ed3d93667f063160f04bcd44daab328cb8b Mon Sep 17 00:00:00 2001 From: abdudsoul Date: Sun, 6 Aug 2023 21:55:23 +0400 Subject: [PATCH] fix loop issue on fail. --- src/App.tsx | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index d6d3afc67..4339d24b5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -23,29 +23,37 @@ function App() const setApiKey = useStore((state) => state.setApiKey); const setCurrentChatIndex = useStore((state) => state.setCurrentChatIndex); - (async () => + if (!isInitialized) { - const initalizeModelDataResult = await initaliseModelData(); - if (!initalizeModelDataResult) + (async () => { - alert("Failed getting model data from OpenRouterAI API.\nTry restarting or refreshing.\n\n(Currently default models will be shown that may include deprecated model or invalid information.)"); - } + var fixDefaultModels = true; - const localChats = useStore.getState().chats; - if (localChats && localChats.length > 0) - { - for (var i = 0; i < localChats.length; i++) + const initalizeModelDataResult = await initaliseModelData(); + if (initalizeModelDataResult) { - const chat: ChatInterface = localChats[i]; - if (!modelOptions.includes(chat.config.model)) + fixDefaultModels = confirm("Failed getting model data from OpenRouterAI API.\nTry restarting or refreshing.\n\n(Currently default models will be shown that may include deprecated model or invalid information.)\n\nIf you proceed to continue, chats with the model that is not in the current list will be changed to the default model."); + } + + if (fixDefaultModels) + { + const localChats = useStore.getState().chats; + if (localChats && localChats.length > 0) { - chat.config.model = defaultModel; + for (var i = 0; i < localChats.length; i++) + { + const chat: ChatInterface = localChats[i]; + if (!modelOptions.includes(chat.config.model)) + { + chat.config.model = defaultModel; + } + } } - } - } + } - setIsInitialized(true); - })(); + setIsInitialized(true); + })(); + } useEffect(() => {