From b6bf66dcc75c9000149ec5a68fb93a4b5b70658a Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Wed, 8 Mar 2023 01:08:39 +0800 Subject: [PATCH] remove api checking --- src/api/freeApi.ts | 2 +- src/components/ApiMenu/ApiMenu.tsx | 25 +++---------------------- src/hooks/useSubmit.ts | 2 ++ 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/api/freeApi.ts b/src/api/freeApi.ts index 4deb249..135cfc6 100644 --- a/src/api/freeApi.ts +++ b/src/api/freeApi.ts @@ -39,7 +39,7 @@ export const getChatCompletionStream = async ( stream: true, }), }); - if (response.status === 404) + if (response.status === 404 || response.status === 405) throw new Error( 'Message from freechatgpt.chat:\nInvalid API endpoint! We recommend you to check your free API endpoint.' ); diff --git a/src/components/ApiMenu/ApiMenu.tsx b/src/components/ApiMenu/ApiMenu.tsx index a0b117c..15dc267 100644 --- a/src/components/ApiMenu/ApiMenu.tsx +++ b/src/components/ApiMenu/ApiMenu.tsx @@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react'; import useStore from '@store/store'; import PopupModal from '@components/PopupModal'; -import { validateApiKey } from '@api/customApi'; const ApiMenu = ({ isModalOpen, @@ -22,29 +21,16 @@ const ApiMenu = ({ const [_apiKey, _setApiKey] = useState(apiKey || ''); const [_apiFreeEndpoint, _setApiFreeEndpoint] = useState(apiFreeEndpoint); - const [error, setError] = useState(''); const handleSave = async () => { if (_apiFree === true) { setApiFreeEndpoint(_apiFreeEndpoint); setApiFree(true); - setError(''); setIsModalOpen(false); } else { - const valid = await validateApiKey(_apiKey); - if (valid) { - setApiKey(_apiKey); - setApiFree(false); - setError(''); - setIsModalOpen(false); - } else { - setError( - 'Error: Invalid API key or network blocked. Please check your API key and network settings for OpenAI API.' - ); - setTimeout(() => { - setError(''); - }, 10000); - } + setApiKey(_apiKey); + setApiFree(false); + setIsModalOpen(false); } }; @@ -157,11 +143,6 @@ const ApiMenu = ({ purpose of accessing the OpenAI API and not for any other unauthorised use. - {error !== '' && ( -
- {error} -
- )} ) : ( diff --git a/src/hooks/useSubmit.ts b/src/hooks/useSubmit.ts index 2f2353b..fc75a9e 100644 --- a/src/hooks/useSubmit.ts +++ b/src/hooks/useSubmit.ts @@ -50,6 +50,8 @@ const useSubmit = () => { messages, chats[currentChatIndex].config ); + } else { + throw new Error('No API key supplied! Please check your API settings.'); } if (stream) {