Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Cron/RefreshModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

}
}
8 changes: 8 additions & 0 deletions lib/Service/OpenAiAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading