remove api checking

This commit is contained in:
Jing Hua 2023-03-08 01:08:39 +08:00
parent ae9499301a
commit b6bf66dcc7
3 changed files with 6 additions and 23 deletions

View file

@ -39,7 +39,7 @@ export const getChatCompletionStream = async (
stream: true, stream: true,
}), }),
}); });
if (response.status === 404) if (response.status === 404 || response.status === 405)
throw new Error( throw new Error(
'Message from freechatgpt.chat:\nInvalid API endpoint! We recommend you to check your free API endpoint.' 'Message from freechatgpt.chat:\nInvalid API endpoint! We recommend you to check your free API endpoint.'
); );

View file

@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react';
import useStore from '@store/store'; import useStore from '@store/store';
import PopupModal from '@components/PopupModal'; import PopupModal from '@components/PopupModal';
import { validateApiKey } from '@api/customApi';
const ApiMenu = ({ const ApiMenu = ({
isModalOpen, isModalOpen,
@ -22,29 +21,16 @@ const ApiMenu = ({
const [_apiKey, _setApiKey] = useState<string>(apiKey || ''); const [_apiKey, _setApiKey] = useState<string>(apiKey || '');
const [_apiFreeEndpoint, _setApiFreeEndpoint] = const [_apiFreeEndpoint, _setApiFreeEndpoint] =
useState<string>(apiFreeEndpoint); useState<string>(apiFreeEndpoint);
const [error, setError] = useState<string>('');
const handleSave = async () => { const handleSave = async () => {
if (_apiFree === true) { if (_apiFree === true) {
setApiFreeEndpoint(_apiFreeEndpoint); setApiFreeEndpoint(_apiFreeEndpoint);
setApiFree(true); setApiFree(true);
setError('');
setIsModalOpen(false); setIsModalOpen(false);
} else { } else {
const valid = await validateApiKey(_apiKey);
if (valid) {
setApiKey(_apiKey); setApiKey(_apiKey);
setApiFree(false); setApiFree(false);
setError('');
setIsModalOpen(false); 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);
}
} }
}; };
@ -157,11 +143,6 @@ const ApiMenu = ({
purpose of accessing the OpenAI API and not for any other unauthorised purpose of accessing the OpenAI API and not for any other unauthorised
use. use.
</div> </div>
{error !== '' && (
<div className='bg-red-600/50 p-2 rounded-sm mt-3 text-gray-900 dark:text-gray-300 text-sm'>
{error}
</div>
)}
</div> </div>
</PopupModal> </PopupModal>
) : ( ) : (

View file

@ -50,6 +50,8 @@ const useSubmit = () => {
messages, messages,
chats[currentChatIndex].config chats[currentChatIndex].config
); );
} else {
throw new Error('No API key supplied! Please check your API settings.');
} }
if (stream) { if (stream) {