From d94bb3fed42592a1da80ae253c298c83d221885b Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Thu, 31 Jul 2025 11:58:31 +0200 Subject: [PATCH] lazy load most app config values, store them as lazy too Signed-off-by: Julien Veyssier --- .../Version030102Date20241003155512.php | 2 +- .../Version030103Date20241009172829.php | 2 +- lib/Service/OpenAiAPIService.php | 18 ++-- lib/Service/OpenAiSettingsService.php | 88 ++++++++++--------- lib/TaskProcessing/AnalyzeImagesProvider.php | 6 +- .../AudioToAudioChatProvider.php | 18 ++-- lib/TaskProcessing/AudioToTextProvider.php | 2 +- lib/TaskProcessing/ChangeToneProvider.php | 6 +- lib/TaskProcessing/ContextWriteProvider.php | 6 +- lib/TaskProcessing/EmojiProvider.php | 6 +- lib/TaskProcessing/HeadlineProvider.php | 6 +- lib/TaskProcessing/ProofreadProvider.php | 6 +- lib/TaskProcessing/ReformulateProvider.php | 6 +- lib/TaskProcessing/SummaryProvider.php | 4 +- lib/TaskProcessing/TextToImageProvider.php | 10 +-- lib/TaskProcessing/TextToSpeechProvider.php | 10 +-- lib/TaskProcessing/TextToTextChatProvider.php | 2 +- .../TextToTextChatWithToolsProvider.php | 2 +- lib/TaskProcessing/TextToTextProvider.php | 6 +- lib/TaskProcessing/TopicsProvider.php | 6 +- lib/TaskProcessing/TranslateProvider.php | 6 +- 21 files changed, 110 insertions(+), 108 deletions(-) diff --git a/lib/Migration/Version030102Date20241003155512.php b/lib/Migration/Version030102Date20241003155512.php index 24d7af24..1ac8e59b 100644 --- a/lib/Migration/Version030102Date20241003155512.php +++ b/lib/Migration/Version030102Date20241003155512.php @@ -37,7 +37,7 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $value = $this->appConfig->getValueString(Application::APP_ID, $key); if ($value !== '') { $encryptedValue = $this->crypto->encrypt($value); - $this->appConfig->setValueString(Application::APP_ID, $key, $encryptedValue); + $this->appConfig->setValueString(Application::APP_ID, $key, $encryptedValue, lazy: true); } } diff --git a/lib/Migration/Version030103Date20241009172829.php b/lib/Migration/Version030103Date20241009172829.php index 057fdedd..866b06ff 100644 --- a/lib/Migration/Version030103Date20241009172829.php +++ b/lib/Migration/Version030103Date20241009172829.php @@ -34,7 +34,7 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $value = $this->appConfig->getValueString(Application::APP_ID, $key); if ($value !== '') { $decryptedValue = $this->crypto->decrypt($value); - $this->appConfig->setValueString(Application::APP_ID, $key, $decryptedValue, false, true); + $this->appConfig->setValueString(Application::APP_ID, $key, $decryptedValue, true, true); } } } diff --git a/lib/Service/OpenAiAPIService.php b/lib/Service/OpenAiAPIService.php index cad206a7..283eef99 100644 --- a/lib/Service/OpenAiAPIService.php +++ b/lib/Service/OpenAiAPIService.php @@ -647,7 +647,7 @@ public function createChatCompletion( * @return array|null */ private function getAdminExtraParams(string $configKey): ?array { - $stringValue = $this->appConfig->getValueString(Application::APP_ID, $configKey); + $stringValue = $this->appConfig->getValueString(Application::APP_ID, $configKey, lazy: true); if ($stringValue === '') { return null; } @@ -861,8 +861,8 @@ public function requestSpeechCreation( */ public function getExpTextProcessingTime(): int { return $this->isUsingOpenAi() - ? intval($this->appConfig->getValueString(Application::APP_ID, 'openai_text_generation_time', strval(Application::DEFAULT_OPENAI_TEXT_GENERATION_TIME))) - : intval($this->appConfig->getValueString(Application::APP_ID, 'localai_text_generation_time', strval(Application::DEFAULT_LOCALAI_TEXT_GENERATION_TIME))); + ? intval($this->appConfig->getValueString(Application::APP_ID, 'openai_text_generation_time', strval(Application::DEFAULT_OPENAI_TEXT_GENERATION_TIME), lazy: true)) + : intval($this->appConfig->getValueString(Application::APP_ID, 'localai_text_generation_time', strval(Application::DEFAULT_LOCALAI_TEXT_GENERATION_TIME), lazy: true)); } /** @@ -874,9 +874,9 @@ public function updateExpTextProcessingTime(int $runtime): void { $newTime = (1.0 - Application::EXPECTED_RUNTIME_LOWPASS_FACTOR) * $oldTime + Application::EXPECTED_RUNTIME_LOWPASS_FACTOR * floatval($runtime); if ($this->isUsingOpenAi()) { - $this->appConfig->setValueString(Application::APP_ID, 'openai_text_generation_time', strval(intval($newTime))); + $this->appConfig->setValueString(Application::APP_ID, 'openai_text_generation_time', strval(intval($newTime)), lazy: true); } else { - $this->appConfig->setValueString(Application::APP_ID, 'localai_text_generation_time', strval(intval($newTime))); + $this->appConfig->setValueString(Application::APP_ID, 'localai_text_generation_time', strval(intval($newTime)), lazy: true); } } @@ -885,8 +885,8 @@ public function updateExpTextProcessingTime(int $runtime): void { */ public function getExpImgProcessingTime(): int { return $this->isUsingOpenAi() - ? intval($this->appConfig->getValueString(Application::APP_ID, 'openai_image_generation_time', strval(Application::DEFAULT_OPENAI_IMAGE_GENERATION_TIME))) - : intval($this->appConfig->getValueString(Application::APP_ID, 'localai_image_generation_time', strval(Application::DEFAULT_LOCALAI_IMAGE_GENERATION_TIME))); + ? intval($this->appConfig->getValueString(Application::APP_ID, 'openai_image_generation_time', strval(Application::DEFAULT_OPENAI_IMAGE_GENERATION_TIME), lazy: true)) + : intval($this->appConfig->getValueString(Application::APP_ID, 'localai_image_generation_time', strval(Application::DEFAULT_LOCALAI_IMAGE_GENERATION_TIME), lazy: true)); } /** @@ -898,9 +898,9 @@ public function updateExpImgProcessingTime(int $runtime): void { $newTime = (1.0 - Application::EXPECTED_RUNTIME_LOWPASS_FACTOR) * $oldTime + Application::EXPECTED_RUNTIME_LOWPASS_FACTOR * floatval($runtime); if ($this->isUsingOpenAi()) { - $this->appConfig->setValueString(Application::APP_ID, 'openai_image_generation_time', strval(intval($newTime))); + $this->appConfig->setValueString(Application::APP_ID, 'openai_image_generation_time', strval(intval($newTime)), lazy: true); } else { - $this->appConfig->setValueString(Application::APP_ID, 'localai_image_generation_time', strval(intval($newTime))); + $this->appConfig->setValueString(Application::APP_ID, 'localai_image_generation_time', strval(intval($newTime)), lazy: true); } } diff --git a/lib/Service/OpenAiSettingsService.php b/lib/Service/OpenAiSettingsService.php index 55bf7b45..ec4ff028 100644 --- a/lib/Service/OpenAiSettingsService.php +++ b/lib/Service/OpenAiSettingsService.php @@ -138,7 +138,7 @@ public function invalidateModelsCache(): void { * @throws Exception */ public function getAdminApiKey(): string { - return $this->appConfig->getValueString(Application::APP_ID, 'api_key'); + return $this->appConfig->getValueString(Application::APP_ID, 'api_key', lazy: true); } /** @@ -162,42 +162,42 @@ public function getUserApiKey(?string $userId, bool $fallBackOnAdminValue = fals * @return string */ public function getAdminDefaultCompletionModelId(): string { - return $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_COMPLETION_MODEL_ID) ?: Application::DEFAULT_COMPLETION_MODEL_ID; + return $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_COMPLETION_MODEL_ID, lazy: true) ?: Application::DEFAULT_COMPLETION_MODEL_ID; } /** * @return string */ public function getAdminDefaultSttModelId(): string { - return $this->appConfig->getValueString(Application::APP_ID, 'default_stt_model_id') ?: Application::DEFAULT_MODEL_ID; + return $this->appConfig->getValueString(Application::APP_ID, 'default_stt_model_id', lazy: true) ?: Application::DEFAULT_MODEL_ID; } /** * @return string */ public function getAdminDefaultImageModelId(): string { - return $this->appConfig->getValueString(Application::APP_ID, 'default_image_model_id') ?: Application::DEFAULT_MODEL_ID; + return $this->appConfig->getValueString(Application::APP_ID, 'default_image_model_id', lazy: true) ?: Application::DEFAULT_MODEL_ID; } /** * @return string */ public function getAdminDefaultImageSize(): string { - return $this->appConfig->getValueString(Application::APP_ID, 'default_image_size') ?: Application::DEFAULT_DEFAULT_IMAGE_SIZE; + return $this->appConfig->getValueString(Application::APP_ID, 'default_image_size', lazy: true) ?: Application::DEFAULT_DEFAULT_IMAGE_SIZE; } /** * @return string */ public function getAdminDefaultTtsModelId(): string { - return $this->appConfig->getValueString(Application::APP_ID, 'default_speech_model_id') ?: Application::DEFAULT_MODEL_ID; + return $this->appConfig->getValueString(Application::APP_ID, 'default_speech_model_id', lazy: true) ?: Application::DEFAULT_MODEL_ID; } /** * @return string */ public function getAdminDefaultTtsVoice(): string { - return $this->appConfig->getValueString(Application::APP_ID, 'default_speech_voice') ?: Application::DEFAULT_SPEECH_VOICE; + return $this->appConfig->getValueString(Application::APP_ID, 'default_speech_voice', lazy: true) ?: Application::DEFAULT_SPEECH_VOICE; } /** @@ -207,7 +207,8 @@ public function getAdminTtsVoices(): array { $voices = json_decode( $this->appConfig->getValueString( Application::APP_ID, 'tts_voices', - json_encode(Application::DEFAULT_SPEECH_VOICES) + json_encode(Application::DEFAULT_SPEECH_VOICES), + lazy: true, ) ?: json_encode(Application::DEFAULT_SPEECH_VOICES), true, ); @@ -228,35 +229,35 @@ public function getServiceUrl(): string { * @return string */ public function getServiceName(): string { - return $this->appConfig->getValueString(Application::APP_ID, 'service_name'); + return $this->appConfig->getValueString(Application::APP_ID, 'service_name', lazy: true); } /** * @return int */ public function getRequestTimeout(): int { - return intval($this->appConfig->getValueString(Application::APP_ID, 'request_timeout', strval(Application::OPENAI_DEFAULT_REQUEST_TIMEOUT))) ?: Application::OPENAI_DEFAULT_REQUEST_TIMEOUT; + return intval($this->appConfig->getValueString(Application::APP_ID, 'request_timeout', strval(Application::OPENAI_DEFAULT_REQUEST_TIMEOUT), lazy: true)) ?: Application::OPENAI_DEFAULT_REQUEST_TIMEOUT; } /** * @return int */ public function getChunkSize(): int { - return $this->appConfig->getValueInt(Application::APP_ID, 'chunk_size', Application::DEFAULT_CHUNK_SIZE) ?: Application::DEFAULT_CHUNK_SIZE; + return $this->appConfig->getValueInt(Application::APP_ID, 'chunk_size', Application::DEFAULT_CHUNK_SIZE, lazy: true) ?: Application::DEFAULT_CHUNK_SIZE; } /** * @return int */ public function getMaxTokens(): int { - return intval($this->appConfig->getValueString(Application::APP_ID, 'max_tokens', strval(Application::DEFAULT_MAX_NUM_OF_TOKENS))) ?: Application::DEFAULT_MAX_NUM_OF_TOKENS; + return intval($this->appConfig->getValueString(Application::APP_ID, 'max_tokens', strval(Application::DEFAULT_MAX_NUM_OF_TOKENS), lazy: true)) ?: Application::DEFAULT_MAX_NUM_OF_TOKENS; } /** * @return string */ public function getLlmExtraParams(): string { - return $this->appConfig->getValueString(Application::APP_ID, 'llm_extra_params'); + return $this->appConfig->getValueString(Application::APP_ID, 'llm_extra_params', lazy: true); } /** @@ -264,7 +265,7 @@ public function getLlmExtraParams(): string { */ public function getQuotaPeriod(): array { $value = json_decode( - $this->appConfig->getValueString(Application::APP_ID, 'quota_period', json_encode(Application::DEFAULT_QUOTA_CONFIG)), + $this->appConfig->getValueString(Application::APP_ID, 'quota_period', json_encode(Application::DEFAULT_QUOTA_CONFIG), lazy: true), true ) ?: Application::DEFAULT_QUOTA_CONFIG; // Migrate from old quota period to new one @@ -286,7 +287,8 @@ public function getQuotas(): array { $quotas = json_decode( $this->appConfig->getValueString( Application::APP_ID, 'quotas', - json_encode(Application::DEFAULT_QUOTAS) + json_encode(Application::DEFAULT_QUOTAS), + lazy: true, ) ?: json_encode(Application::DEFAULT_QUOTAS), true, ); @@ -300,7 +302,7 @@ public function getQuotas(): array { $quotas[$quotaType] = Application::DEFAULT_QUOTAS[$quotaType]; } } - $this->appConfig->setValueString(Application::APP_ID, 'quotas', json_encode($quotas)); + $this->appConfig->setValueString(Application::APP_ID, 'quotas', json_encode($quotas), lazy: true); } return $quotas; @@ -310,7 +312,7 @@ public function getQuotas(): array { * @return boolean */ public function getChatEndpointEnabled(): bool { - return $this->appConfig->getValueString(Application::APP_ID, 'chat_endpoint_enabled', '1') === '1'; + return $this->appConfig->getValueString(Application::APP_ID, 'chat_endpoint_enabled', '1', lazy: true) === '1'; } /** @@ -347,7 +349,7 @@ public function getUserBasicPassword(?string $userId, bool $fallBackOnAdminValue * @return string */ public function getAdminBasicUser(): string { - return $this->appConfig->getValueString(Application::APP_ID, 'basic_user'); + return $this->appConfig->getValueString(Application::APP_ID, 'basic_user', lazy: true); } /** @@ -356,14 +358,14 @@ public function getAdminBasicUser(): string { * @throws Exception */ public function getAdminBasicPassword(): string { - return $this->appConfig->getValueString(Application::APP_ID, 'basic_password'); + return $this->appConfig->getValueString(Application::APP_ID, 'basic_password', lazy: true); } /** * @return boolean */ public function getUseBasicAuth(): bool { - return $this->appConfig->getValueString(Application::APP_ID, 'use_basic_auth', '0') === '1'; + return $this->appConfig->getValueString(Application::APP_ID, 'use_basic_auth', '0', lazy: true) === '1'; } /** @@ -430,7 +432,7 @@ public function getUseMaxCompletionTokensParam(): bool { $isUsingOpenAI = $serviceUrl === '' || $serviceUrl === Application::OPENAI_API_BASE_URL; // we know OpenAI expects "use_max_completion_tokens_param", let's assume the other services don't $default = $isUsingOpenAI ? '1' : '0'; - return $this->appConfig->getValueString(Application::APP_ID, 'use_max_completion_tokens_param', $default) === '1'; + return $this->appConfig->getValueString(Application::APP_ID, 'use_max_completion_tokens_param', $default, lazy: true) === '1'; } /** @@ -447,7 +449,7 @@ public function getIsImageRetrievalAuthenticated(): bool { $serviceUrl = $this->getServiceUrl(); $isUsingOpenAI = $serviceUrl === '' || $serviceUrl === Application::OPENAI_API_BASE_URL; $default = $isUsingOpenAI ? '0' : '1'; - return $this->appConfig->getValueString(Application::APP_ID, 'image_request_auth', $default) === '1'; + return $this->appConfig->getValueString(Application::APP_ID, 'image_request_auth', $default, lazy: true) === '1'; } /** @@ -515,7 +517,7 @@ public function setQuotas(array $quotas): void { } } - $this->appConfig->setValueString(Application::APP_ID, 'quotas', json_encode($quotas, JSON_THROW_ON_ERROR)); + $this->appConfig->setValueString(Application::APP_ID, 'quotas', json_encode($quotas, JSON_THROW_ON_ERROR), lazy: true); } /** @@ -524,7 +526,7 @@ public function setQuotas(array $quotas): void { */ public function setAdminApiKey(string $apiKey): void { // No need to validate. As long as it's a string, we're happy campers - $this->appConfig->setValueString(Application::APP_ID, 'api_key', $apiKey, false, true); + $this->appConfig->setValueString(Application::APP_ID, 'api_key', $apiKey, true, true); $this->invalidateModelsCache(); } @@ -550,7 +552,7 @@ public function setUserApiKey(string $userId, string $apiKey): void { */ public function setAdminDefaultCompletionModelId(string $defaultCompletionModelId): void { // No need to validate. As long as it's a string, we're happy campers - $this->appConfig->setValueString(Application::APP_ID, 'default_completion_model_id', $defaultCompletionModelId); + $this->appConfig->setValueString(Application::APP_ID, 'default_completion_model_id', $defaultCompletionModelId, lazy: true); } /** @@ -559,7 +561,7 @@ public function setAdminDefaultCompletionModelId(string $defaultCompletionModelI */ public function setAdminDefaultSttModelId(string $defaultSttModelId): void { // No need to validate. As long as it's a string, we're happy campers - $this->appConfig->setValueString(Application::APP_ID, 'default_stt_model_id', $defaultSttModelId); + $this->appConfig->setValueString(Application::APP_ID, 'default_stt_model_id', $defaultSttModelId, lazy: true); } /** @@ -568,7 +570,7 @@ public function setAdminDefaultSttModelId(string $defaultSttModelId): void { */ public function setAdminDefaultTtsModelId(string $defaultTtsModelId): void { // No need to validate. As long as it's a string, we're happy campers - $this->appConfig->setValueString(Application::APP_ID, 'default_speech_model_id', $defaultTtsModelId); + $this->appConfig->setValueString(Application::APP_ID, 'default_speech_model_id', $defaultTtsModelId, lazy: true); } /** @@ -577,7 +579,7 @@ public function setAdminDefaultTtsModelId(string $defaultTtsModelId): void { */ public function setAdminDefaultImageModelId(string $defaultImageModelId): void { // No need to validate. As long as it's a string, we're happy campers - $this->appConfig->setValueString(Application::APP_ID, 'default_image_model_id', $defaultImageModelId); + $this->appConfig->setValueString(Application::APP_ID, 'default_image_model_id', $defaultImageModelId, lazy: true); } /** @@ -585,7 +587,7 @@ public function setAdminDefaultImageModelId(string $defaultImageModelId): void { * @return void */ public function setAdminDefaultTtsVoice(string $voice): void { - $this->appConfig->setValueString(Application::APP_ID, 'default_speech_voice', $voice); + $this->appConfig->setValueString(Application::APP_ID, 'default_speech_voice', $voice, lazy: true); } /** @@ -597,7 +599,7 @@ public function setAdminDefaultImageSize(string $defaultImageSize): void { if ($defaultImageSize !== '' && preg_match('/^\d+x\d+$/', $defaultImageSize) !== 1) { throw new Exception('Invalid image size value'); } - $this->appConfig->setValueString(Application::APP_ID, 'default_image_size', $defaultImageSize); + $this->appConfig->setValueString(Application::APP_ID, 'default_image_size', $defaultImageSize, lazy: true); } /** @@ -620,7 +622,7 @@ public function setServiceUrl(string $serviceUrl): void { * @throws Exception */ public function setServiceName(string $serviceName): void { - $this->appConfig->setValueString(Application::APP_ID, 'service_name', $serviceName); + $this->appConfig->setValueString(Application::APP_ID, 'service_name', $serviceName, lazy: true); } /** @@ -630,7 +632,7 @@ public function setServiceName(string $serviceName): void { public function setRequestTimeout(int $requestTimeout): void { // Validate input: $requestTimeout = max(1, $requestTimeout); - $this->appConfig->setValueString(Application::APP_ID, 'request_timeout', strval($requestTimeout)); + $this->appConfig->setValueString(Application::APP_ID, 'request_timeout', strval($requestTimeout), lazy: true); } /** @@ -644,7 +646,7 @@ public function setChunkSize(int $chunkSize): void { if ($chunkSize) { $chunkSize = max(Application::MIN_CHUNK_SIZE, $chunkSize); } - $this->appConfig->setValueInt(Application::APP_ID, 'chunk_size', $chunkSize); + $this->appConfig->setValueInt(Application::APP_ID, 'chunk_size', $chunkSize, lazy: true); } /** @@ -655,7 +657,7 @@ public function setChunkSize(int $chunkSize): void { public function setMaxTokens(int $maxTokens): void { // Validate input: $maxTokens = max(100, $maxTokens); - $this->appConfig->setValueString(Application::APP_ID, 'max_tokens', strval($maxTokens)); + $this->appConfig->setValueString(Application::APP_ID, 'max_tokens', strval($maxTokens), lazy: true); } public function setLlmExtraParams(string $llmExtraParams): void { @@ -665,7 +667,7 @@ public function setLlmExtraParams(string $llmExtraParams): void { throw new Exception('Invalid model extra parameters, must be a valid JSON object string or an empty string'); } } - $this->appConfig->setValueString(Application::APP_ID, 'llm_extra_params', $llmExtraParams); + $this->appConfig->setValueString(Application::APP_ID, 'llm_extra_params', $llmExtraParams, lazy: true); } /** @@ -693,7 +695,7 @@ public function setQuotaPeriod(array $quotaPeriod): void { } elseif ($quotaPeriod['unit'] !== 'day') { throw new Exception('Invalid quota period unit'); } - $this->appConfig->setValueString(Application::APP_ID, 'quota_period', json_encode($quotaPeriod)); + $this->appConfig->setValueString(Application::APP_ID, 'quota_period', json_encode($quotaPeriod), lazy: true); } /** @@ -701,7 +703,7 @@ public function setQuotaPeriod(array $quotaPeriod): void { * @return void */ public function setAdminBasicUser(string $basicUser): void { - $this->appConfig->setValueString(Application::APP_ID, 'basic_user', $basicUser); + $this->appConfig->setValueString(Application::APP_ID, 'basic_user', $basicUser, lazy: true); $this->invalidateModelsCache(); } @@ -710,7 +712,7 @@ public function setAdminBasicUser(string $basicUser): void { * @return void */ public function setAdminBasicPassword(string $basicPassword): void { - $this->appConfig->setValueString(Application::APP_ID, 'basic_password', $basicPassword, false, true); + $this->appConfig->setValueString(Application::APP_ID, 'basic_password', $basicPassword, true, true); $this->invalidateModelsCache(); } @@ -742,7 +744,7 @@ public function setUserBasicPassword(string $userId, string $basicPassword): voi * @return void */ public function setUseBasicAuth(bool $useBasicAuth): void { - $this->appConfig->setValueString(Application::APP_ID, 'use_basic_auth', $useBasicAuth ? '1' : '0'); + $this->appConfig->setValueString(Application::APP_ID, 'use_basic_auth', $useBasicAuth ? '1' : '0', lazy: true); $this->invalidateModelsCache(); } @@ -751,7 +753,7 @@ public function setUseBasicAuth(bool $useBasicAuth): void { * @return void */ public function setAdminTtsVoices(array $voices): void { - $this->appConfig->setValueString(Application::APP_ID, 'tts_voices', json_encode($voices)); + $this->appConfig->setValueString(Application::APP_ID, 'tts_voices', json_encode($voices), lazy: true); $this->invalidateModelsCache(); } @@ -893,7 +895,7 @@ public function setUserConfig(string $userId, array $userConfig): void { * @return void */ public function setUseMaxCompletionParam(bool $enabled): void { - $this->appConfig->setValueString(Application::APP_ID, 'use_max_completion_tokens_param', $enabled ? '1' : '0'); + $this->appConfig->setValueString(Application::APP_ID, 'use_max_completion_tokens_param', $enabled ? '1' : '0', lazy: true); } /** @@ -909,7 +911,7 @@ public function setTranslationProviderEnabled(bool $enabled): void { * @return void */ public function setIsImageRetrievalAuthenticated(bool $enabled): void { - $this->appConfig->setValueString(Application::APP_ID, 'image_request_auth', $enabled ? '1' : '0'); + $this->appConfig->setValueString(Application::APP_ID, 'image_request_auth', $enabled ? '1' : '0', lazy: true); } /** @@ -956,6 +958,6 @@ public function setAnalyzeImageProviderEnabled(bool $enabled): void { * @param bool $enabled */ public function setChatEndpointEnabled(bool $enabled): void { - $this->appConfig->setValueString(Application::APP_ID, 'chat_endpoint_enabled', $enabled ? '1' : '0'); + $this->appConfig->setValueString(Application::APP_ID, 'chat_endpoint_enabled', $enabled ? '1' : '0', lazy: true); } } diff --git a/lib/TaskProcessing/AnalyzeImagesProvider.php b/lib/TaskProcessing/AnalyzeImagesProvider.php index 0e272bb4..1b74cc47 100644 --- a/lib/TaskProcessing/AnalyzeImagesProvider.php +++ b/lib/TaskProcessing/AnalyzeImagesProvider.php @@ -84,8 +84,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); return [ 'max_tokens' => $this->openAiSettingsService->getMaxTokens(), 'model' => $adminModel, @@ -167,7 +167,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_COMPLETION_MODEL_ID) ?: Application::DEFAULT_COMPLETION_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_COMPLETION_MODEL_ID, lazy: true) ?: Application::DEFAULT_COMPLETION_MODEL_ID; } $maxTokens = null; diff --git a/lib/TaskProcessing/AudioToAudioChatProvider.php b/lib/TaskProcessing/AudioToAudioChatProvider.php index 637843f5..4cbe3ac3 100644 --- a/lib/TaskProcessing/AudioToAudioChatProvider.php +++ b/lib/TaskProcessing/AudioToAudioChatProvider.php @@ -92,7 +92,7 @@ public function getOptionalInputShape(): array { public function getOptionalInputShapeEnumValues(): array { $isUsingOpenAi = $this->openAiAPIService->isUsingOpenAi(); - $voices = json_decode($this->appConfig->getValueString(Application::APP_ID, 'tts_voices')) ?: Application::DEFAULT_SPEECH_VOICES; + $voices = json_decode($this->appConfig->getValueString(Application::APP_ID, 'tts_voices', lazy: true)) ?: Application::DEFAULT_SPEECH_VOICES; $models = $this->openAiAPIService->getModelEnumValues($this->userId); $enumValues = [ 'voice' => array_map(function ($v) { return new ShapeEnumValue($v, $v); }, $voices), @@ -106,16 +106,16 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $isUsingOpenAi = $this->openAiAPIService->isUsingOpenAi(); - $adminVoice = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_voice') ?: Application::DEFAULT_SPEECH_VOICE; + $adminVoice = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_voice', lazy: true) ?: Application::DEFAULT_SPEECH_VOICE; $adminLlmModel = $isUsingOpenAi ? 'gpt-4o-audio-preview' - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); $defaults = [ 'voice' => $adminVoice, 'llm_model' => $adminLlmModel, ]; if (!$isUsingOpenAi) { - $adminTtsModel = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_model_id') ?: Application::DEFAULT_SPEECH_MODEL_ID; + $adminTtsModel = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_model_id', lazy: true) ?: Application::DEFAULT_SPEECH_MODEL_ID; $defaults['tts_model'] = $adminTtsModel; $defaults['speed'] = 1; } @@ -164,7 +164,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['tts_model']) && is_string($input['tts_model'])) { $ttsModel = $input['tts_model']; } else { - $ttsModel = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_model_id', Application::DEFAULT_SPEECH_MODEL_ID) ?: Application::DEFAULT_SPEECH_MODEL_ID; + $ttsModel = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_model_id', Application::DEFAULT_SPEECH_MODEL_ID, lazy: true) ?: Application::DEFAULT_SPEECH_MODEL_ID; } if (isset($input['llm_model']) && is_string($input['llm_model'])) { @@ -173,14 +173,14 @@ public function process(?string $userId, array $input, callable $reportProgress) $isUsingOpenAi = $this->openAiAPIService->isUsingOpenAi(); $llmModel = $isUsingOpenAi ? 'gpt-4o-audio-preview' - : ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID); + : ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID); } if (isset($input['voice']) && is_string($input['voice'])) { $outputVoice = $input['voice']; } else { - $outputVoice = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_voice', Application::DEFAULT_SPEECH_VOICE) ?: Application::DEFAULT_SPEECH_VOICE; + $outputVoice = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_voice', Application::DEFAULT_SPEECH_VOICE, lazy: true) ?: Application::DEFAULT_SPEECH_VOICE; } $speed = 1; @@ -195,8 +195,8 @@ public function process(?string $userId, array $input, callable $reportProgress) } } - $sttModel = $this->appConfig->getValueString(Application::APP_ID, 'default_stt_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; - $serviceName = $this->appConfig->getValueString(Application::APP_ID, 'service_name') ?: Application::APP_ID; + $sttModel = $this->appConfig->getValueString(Application::APP_ID, 'default_stt_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; + $serviceName = $this->appConfig->getValueString(Application::APP_ID, 'service_name', lazy: true) ?: Application::APP_ID; // Using the chat API if connected to OpenAI // there is an issue if the history mostly contains text, the model will answer text even if we add the audio modality diff --git a/lib/TaskProcessing/AudioToTextProvider.php b/lib/TaskProcessing/AudioToTextProvider.php index 562bd24b..d030933a 100644 --- a/lib/TaskProcessing/AudioToTextProvider.php +++ b/lib/TaskProcessing/AudioToTextProvider.php @@ -82,7 +82,7 @@ public function process(?string $userId, array $input, callable $reportProgress) } $inputFile = $input['input']; - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_stt_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_stt_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; try { $transcription = $this->openAiAPIService->transcribeFile($userId, $inputFile, false, $model); diff --git a/lib/TaskProcessing/ChangeToneProvider.php b/lib/TaskProcessing/ChangeToneProvider.php index 515a712d..9afcd292 100644 --- a/lib/TaskProcessing/ChangeToneProvider.php +++ b/lib/TaskProcessing/ChangeToneProvider.php @@ -96,8 +96,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); return [ 'max_tokens' => $this->openAiSettingsService->getMaxTokens(), 'model' => $adminModel, @@ -133,7 +133,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; } $chunks = $this->chunkService->chunkSplitPrompt($textInput, true, $maxTokens); diff --git a/lib/TaskProcessing/ContextWriteProvider.php b/lib/TaskProcessing/ContextWriteProvider.php index fabee1a2..719ac8df 100644 --- a/lib/TaskProcessing/ContextWriteProvider.php +++ b/lib/TaskProcessing/ContextWriteProvider.php @@ -81,8 +81,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); return [ 'max_tokens' => $this->openAiSettingsService->getMaxTokens(), 'model' => $adminModel, @@ -122,7 +122,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; } $chunks = $this->chunkService->chunkSplitPrompt($sourceMaterial, true, $maxTokens); diff --git a/lib/TaskProcessing/EmojiProvider.php b/lib/TaskProcessing/EmojiProvider.php index 8922c534..10926f57 100644 --- a/lib/TaskProcessing/EmojiProvider.php +++ b/lib/TaskProcessing/EmojiProvider.php @@ -79,8 +79,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); return [ 'max_tokens' => 100, 'model' => $adminModel, @@ -116,7 +116,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; } try { diff --git a/lib/TaskProcessing/HeadlineProvider.php b/lib/TaskProcessing/HeadlineProvider.php index 8924f220..a20172c6 100644 --- a/lib/TaskProcessing/HeadlineProvider.php +++ b/lib/TaskProcessing/HeadlineProvider.php @@ -79,8 +79,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); return [ 'max_tokens' => 1000, 'model' => $adminModel, @@ -116,7 +116,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; } try { diff --git a/lib/TaskProcessing/ProofreadProvider.php b/lib/TaskProcessing/ProofreadProvider.php index 9e2c6b5f..bd1b42a7 100644 --- a/lib/TaskProcessing/ProofreadProvider.php +++ b/lib/TaskProcessing/ProofreadProvider.php @@ -81,8 +81,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); return [ 'max_tokens' => $this->openAiSettingsService->getMaxTokens(), 'model' => $adminModel, @@ -118,7 +118,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; } $chunks = $this->chunkService->chunkSplitPrompt($textInput, true, $maxTokens); diff --git a/lib/TaskProcessing/ReformulateProvider.php b/lib/TaskProcessing/ReformulateProvider.php index 22592bc1..f27b37d9 100644 --- a/lib/TaskProcessing/ReformulateProvider.php +++ b/lib/TaskProcessing/ReformulateProvider.php @@ -81,8 +81,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); return [ 'max_tokens' => $this->openAiSettingsService->getMaxTokens(), 'model' => $adminModel, @@ -117,7 +117,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; } $chunks = $this->chunkService->chunkSplitPrompt($prompt, true, $maxTokens); $result = ''; diff --git a/lib/TaskProcessing/SummaryProvider.php b/lib/TaskProcessing/SummaryProvider.php index a684fba8..30a89d8d 100644 --- a/lib/TaskProcessing/SummaryProvider.php +++ b/lib/TaskProcessing/SummaryProvider.php @@ -81,8 +81,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); return [ 'max_tokens' => $this->openAiSettingsService->getMaxTokens(), 'model' => $adminModel, diff --git a/lib/TaskProcessing/TextToImageProvider.php b/lib/TaskProcessing/TextToImageProvider.php index 9dde7f26..eb80f454 100644 --- a/lib/TaskProcessing/TextToImageProvider.php +++ b/lib/TaskProcessing/TextToImageProvider.php @@ -62,7 +62,7 @@ public function getInputShapeDefaults(): array { } public function getOptionalInputShape(): array { - $defaultImageSize = $this->appConfig->getValueString(Application::APP_ID, 'default_image_size') ?: Application::DEFAULT_DEFAULT_IMAGE_SIZE; + $defaultImageSize = $this->appConfig->getValueString(Application::APP_ID, 'default_image_size', lazy: true) ?: Application::DEFAULT_DEFAULT_IMAGE_SIZE; return [ 'size' => new ShapeDescriptor( $this->l->t('Size'), @@ -85,8 +85,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_image_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_image_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_image_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_image_model_id', lazy: true); return [ 'model' => $adminModel, ]; @@ -117,7 +117,7 @@ public function process(?string $userId, array $input, callable $reportProgress) $nbImages = $input['numberOfImages']; } - $size = $this->appConfig->getValueString(Application::APP_ID, 'default_image_size') ?: Application::DEFAULT_DEFAULT_IMAGE_SIZE; + $size = $this->appConfig->getValueString(Application::APP_ID, 'default_image_size', lazy: true) ?: Application::DEFAULT_DEFAULT_IMAGE_SIZE; if (isset($input['size']) && is_string($input['size']) && preg_match('/^\d+x\d+$/', $input['size'])) { $size = trim($input['size']); } @@ -125,7 +125,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_image_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_image_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; } try { diff --git a/lib/TaskProcessing/TextToSpeechProvider.php b/lib/TaskProcessing/TextToSpeechProvider.php index 59cff238..2849d524 100644 --- a/lib/TaskProcessing/TextToSpeechProvider.php +++ b/lib/TaskProcessing/TextToSpeechProvider.php @@ -84,7 +84,7 @@ public function getOptionalInputShape(): array { } public function getOptionalInputShapeEnumValues(): array { - $voices = json_decode($this->appConfig->getValueString(Application::APP_ID, 'tts_voices')) ?: Application::DEFAULT_SPEECH_VOICES; + $voices = json_decode($this->appConfig->getValueString(Application::APP_ID, 'tts_voices', lazy: true)) ?: Application::DEFAULT_SPEECH_VOICES; return [ 'voice' => array_map(function ($v) { return new ShapeEnumValue($v, $v); }, $voices), 'model' => $this->openAiAPIService->getModelEnumValues($this->userId), @@ -92,8 +92,8 @@ public function getOptionalInputShapeEnumValues(): array { } public function getOptionalInputShapeDefaults(): array { - $adminVoice = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_voice') ?: Application::DEFAULT_SPEECH_VOICE; - $adminModel = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_model_id') ?: Application::DEFAULT_SPEECH_MODEL_ID; + $adminVoice = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_voice', lazy: true) ?: Application::DEFAULT_SPEECH_VOICE; + $adminModel = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_model_id', lazy: true) ?: Application::DEFAULT_SPEECH_MODEL_ID; return [ 'voice' => $adminVoice, 'model' => $adminModel, @@ -124,14 +124,14 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_model_id', Application::DEFAULT_SPEECH_MODEL_ID) ?: Application::DEFAULT_SPEECH_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_model_id', Application::DEFAULT_SPEECH_MODEL_ID, lazy: true) ?: Application::DEFAULT_SPEECH_MODEL_ID; } if (isset($input['voice']) && is_string($input['voice'])) { $voice = $input['voice']; } else { - $voice = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_voice', Application::DEFAULT_SPEECH_VOICE) ?: Application::DEFAULT_SPEECH_VOICE; + $voice = $this->appConfig->getValueString(Application::APP_ID, 'default_speech_voice', Application::DEFAULT_SPEECH_VOICE, lazy: true) ?: Application::DEFAULT_SPEECH_VOICE; } $speed = 1; diff --git a/lib/TaskProcessing/TextToTextChatProvider.php b/lib/TaskProcessing/TextToTextChatProvider.php index 3f406dc2..52084d7b 100644 --- a/lib/TaskProcessing/TextToTextChatProvider.php +++ b/lib/TaskProcessing/TextToTextChatProvider.php @@ -85,7 +85,7 @@ public function getOptionalOutputShapeEnumValues(): array { public function process(?string $userId, array $input, callable $reportProgress): array { $startTime = time(); - $adminModel = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_COMPLETION_MODEL_ID) ?: Application::DEFAULT_COMPLETION_MODEL_ID; + $adminModel = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_COMPLETION_MODEL_ID, lazy: true) ?: Application::DEFAULT_COMPLETION_MODEL_ID; if (!isset($input['input']) || !is_string($input['input'])) { throw new RuntimeException('Invalid input'); diff --git a/lib/TaskProcessing/TextToTextChatWithToolsProvider.php b/lib/TaskProcessing/TextToTextChatWithToolsProvider.php index 24c72e2b..b3173387 100644 --- a/lib/TaskProcessing/TextToTextChatWithToolsProvider.php +++ b/lib/TaskProcessing/TextToTextChatWithToolsProvider.php @@ -85,7 +85,7 @@ public function getOptionalOutputShapeEnumValues(): array { public function process(?string $userId, array $input, callable $reportProgress): array { $startTime = time(); - $adminModel = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_COMPLETION_MODEL_ID) ?: Application::DEFAULT_COMPLETION_MODEL_ID; + $adminModel = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_COMPLETION_MODEL_ID, lazy: true) ?: Application::DEFAULT_COMPLETION_MODEL_ID; if (!isset($input['input']) || !is_string($input['input'])) { throw new RuntimeException('Invalid input'); diff --git a/lib/TaskProcessing/TextToTextProvider.php b/lib/TaskProcessing/TextToTextProvider.php index f0351fa7..4c4e0951 100644 --- a/lib/TaskProcessing/TextToTextProvider.php +++ b/lib/TaskProcessing/TextToTextProvider.php @@ -79,8 +79,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); return [ 'max_tokens' => 1000, 'model' => $adminModel, @@ -121,7 +121,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; } try { diff --git a/lib/TaskProcessing/TopicsProvider.php b/lib/TaskProcessing/TopicsProvider.php index 0f48ab18..f9637c05 100644 --- a/lib/TaskProcessing/TopicsProvider.php +++ b/lib/TaskProcessing/TopicsProvider.php @@ -83,8 +83,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); return [ 'max_tokens' => 1000, 'model' => $adminModel, @@ -119,7 +119,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; } $prompts = $this->chunkService->chunkSplitPrompt($prompt); $newNumChunks = count($prompts); diff --git a/lib/TaskProcessing/TranslateProvider.php b/lib/TaskProcessing/TranslateProvider.php index f23e5457..0c2683e9 100644 --- a/lib/TaskProcessing/TranslateProvider.php +++ b/lib/TaskProcessing/TranslateProvider.php @@ -99,8 +99,8 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiAPIService->isUsingOpenAi() - ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID) - : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id'); + ? ($this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID) + : $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true); return [ 'max_tokens' => $this->openAiSettingsService->getMaxTokens(), 'model' => $adminModel, @@ -140,7 +140,7 @@ public function process(?string $userId, array $input, callable $reportProgress) if (isset($input['model']) && is_string($input['model'])) { $model = $input['model']; } else { - $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID) ?: Application::DEFAULT_MODEL_ID; + $model = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID; } if (!isset($input['input']) || !is_string($input['input'])) {