diff --git a/servers/fastapi/api/routers/presentation/handlers/list_available_custom_models.py b/servers/fastapi/api/routers/presentation/handlers/list_available_custom_models.py index dbdf88d8..cae873af 100644 --- a/servers/fastapi/api/routers/presentation/handlers/list_available_custom_models.py +++ b/servers/fastapi/api/routers/presentation/handlers/list_available_custom_models.py @@ -11,4 +11,6 @@ class ListAvailableCustomModelsHandler: self.api_key = api_key async def get(self, logging_service: LoggingService, log_metadata: LogMetadata): + print("-" * 40) + print(self.url, self.api_key) return await list_available_custom_models(self.url, self.api_key) diff --git a/servers/fastapi/api/utils/model_utils.py b/servers/fastapi/api/utils/model_utils.py index 9274faac..1a11ba01 100644 --- a/servers/fastapi/api/utils/model_utils.py +++ b/servers/fastapi/api/utils/model_utils.py @@ -42,6 +42,7 @@ async def list_available_custom_models( client = openai.AsyncOpenAI(api_key=api_key or "null", base_url=url) models = [] async for model in client.models.list(): + print(model) models.append(model.id) return models diff --git a/servers/nextjs/app/settings/SettingPage.tsx b/servers/nextjs/app/settings/SettingPage.tsx index 65dd7769..f42ae744 100644 --- a/servers/nextjs/app/settings/SettingPage.tsx +++ b/servers/nextjs/app/settings/SettingPage.tsx @@ -215,8 +215,14 @@ const SettingsPage = () => { api_key: llmConfig.CUSTOM_LLM_API_KEY || '' }) }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data = await response.json(); setCustomModels(data); + // Only set customModelsChecked to true if the API call succeeds setCustomModelsChecked(true); // Check if currently selected model is still available @@ -233,6 +239,8 @@ const SettingsPage = () => { } } catch (error) { console.error('Error fetching custom models:', error); + // Don't set customModelsChecked to true on error, so the button remains visible + setCustomModels([]); toast({ title: 'Error', description: 'Failed to fetch available models. Please check your URL and API key.', @@ -639,7 +647,7 @@ const SettingsPage = () => { {customModelsChecked && customModels.length === 0 && (

- No models found. Please check your URL and API key, or try again. + No models found. Please make sure models are available.

)} diff --git a/servers/nextjs/components/Home.tsx b/servers/nextjs/components/Home.tsx index 3acd340d..36d1bc30 100644 --- a/servers/nextjs/components/Home.tsx +++ b/servers/nextjs/components/Home.tsx @@ -322,11 +322,19 @@ export default function Home() { api_key: llmConfig.CUSTOM_LLM_API_KEY || '' }) }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data = await response.json(); setCustomModels(data); + // Only set customModelsChecked to true if the API call succeeds setCustomModelsChecked(true); } catch (error) { console.error('Error fetching custom models:', error); + // Don't set customModelsChecked to true on error, so the button remains visible + setCustomModels([]); toast({ title: 'Error', description: 'Failed to fetch available models. Please check your URL and API key.', @@ -724,7 +732,7 @@ export default function Home() { {customModelsChecked && customModels.length === 0 && (

- No models found. Please check your URL and API key, or try again. + No models found. Please make sure models are available.

)}