Decrease connection timeout, set 'valid' status on 'invalid URL', don't wait if not needed Fixes #3683

f362f94c2d56881cffd30c8673a911bdd1b597dc

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +5 -8Ignore whitespace
public/script.js+4 -2
@@ -9288,10 +9288,12 @@ async function connectAPISlash(args, text) {
9288 const toast = quiet ? jQuery() : toastr.info(t`API set to ${text}, trying to connect..`);9288 const toast = quiet ? jQuery() : toastr.info(t`API set to ${text}, trying to connect..`);
92899289
9290 try {9290 try {
9291 await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100);9291 if (connectionRequired) {
9292 await waitUntilCondition(() => online_status !== 'no_connection', 5000, 500);
9293 }
9292 console.log('Connection successful');9294 console.log('Connection successful');
9293 } catch {9295 } catch {
9294 console.log('Could not connect after 10 seconds, skipping.');9296 console.log('Could not connect after 5 seconds, skipping.');
9295 }9297 }
92969298
9297 toastr.clear(toast);9299 toastr.clear(toast);
public/scripts/openai.js+1 -6
@@ -3493,7 +3493,7 @@ async function getStatusOpen() {
34933493
3494 if (oai_settings.chat_completion_source === chat_completion_sources.CUSTOM && !isValidUrl(oai_settings.custom_url)) {3494 if (oai_settings.chat_completion_source === chat_completion_sources.CUSTOM && !isValidUrl(oai_settings.custom_url)) {
3495 console.debug('Invalid endpoint URL of Custom OpenAI API:', oai_settings.custom_url);3495 console.debug('Invalid endpoint URL of Custom OpenAI API:', oai_settings.custom_url);
3496 setOnlineStatus('no_connection');3496 setOnlineStatus(t`Invalid endpoint URL. Requests may fail.`);
3497 return resultCheckStatus();3497 return resultCheckStatus();
3498 }3498 }
34993499
@@ -4757,11 +4757,6 @@ async function onConnectButtonClick(e) {
4757 if (api_key_custom.length) {4757 if (api_key_custom.length) {
4758 await writeSecret(SECRET_KEYS.CUSTOM, api_key_custom);4758 await writeSecret(SECRET_KEYS.CUSTOM, api_key_custom);
4759 }4759 }
4760
4761 if (!oai_settings.custom_url) {
4762 console.log('No API URL saved for Custom');
4763 return;
4764 }
4765 }4760 }
47664761
4767 if (oai_settings.chat_completion_source == chat_completion_sources.COHERE) {4762 if (oai_settings.chat_completion_source == chat_completion_sources.COHERE) {