From f2500841d46530e1774ac0dbadc7f02f6c34b76f Mon Sep 17 00:00:00 2001 From: Lukas Schaefer Date: Wed, 11 Feb 2026 12:03:01 -0500 Subject: [PATCH] Fix empty model list for image, tts, and stt when not overriden Signed-off-by: Lukas Schaefer --- lib/Cron/RefreshModels.php | 5 +++++ lib/Service/OpenAiAPIService.php | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/Cron/RefreshModels.php b/lib/Cron/RefreshModels.php index 0de60679..a53e8380 100644 --- a/lib/Cron/RefreshModels.php +++ b/lib/Cron/RefreshModels.php @@ -9,6 +9,7 @@ namespace OCA\OpenAi\Cron; +use OCA\OpenAi\AppInfo\Application; use OCA\OpenAi\Service\OpenAiAPIService; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; @@ -27,5 +28,9 @@ public function __construct( protected function run($argument) { $this->logger->debug('Run daily model refresh job'); $this->openAIAPIService->getModels(null, true); + $this->openAIAPIService->getModels(null, true, Application::SERVICE_TYPE_TTS); + $this->openAIAPIService->getModels(null, true, Application::SERVICE_TYPE_STT); + $this->openAIAPIService->getModels(null, true, Application::SERVICE_TYPE_IMAGE); + } } diff --git a/lib/Service/OpenAiAPIService.php b/lib/Service/OpenAiAPIService.php index 9c643869..e9b02c78 100644 --- a/lib/Service/OpenAiAPIService.php +++ b/lib/Service/OpenAiAPIService.php @@ -142,6 +142,14 @@ private function isModelListValid($models): bool { * @throws Exception */ public function getModels(?string $userId, bool $refresh = false, ?string $serviceType = null): array { + // Use default service type if service type is not overridden + if ($serviceType === Application::SERVICE_TYPE_IMAGE && !$this->openAiSettingsService->imageOverrideEnabled()) { + $serviceType = null; + } elseif ($serviceType === Application::SERVICE_TYPE_STT && !$this->openAiSettingsService->sttOverrideEnabled()) { + $serviceType = null; + } elseif ($serviceType === Application::SERVICE_TYPE_TTS && !$this->openAiSettingsService->ttsOverrideEnabled()) { + $serviceType = null; + } $cache = $this->cacheFactory->createDistributed(Application::APP_ID); $userCacheKey = Application::MODELS_CACHE_KEY . '_' . ($userId ?? '') . '_' . ($serviceType ?? 'main'); $adminCacheKey = Application::MODELS_CACHE_KEY . '-main' . '_' . ($serviceType ?? 'main');