Skip to content

Commit 00b9de6

Browse files
authored
fix(OldProcessing): use IAppConfig to get the selected model (#318)
This fixes 2 things: * use the correct fallback model ID * read as lazy because if it's stored as lazy and read as non-lazy, it will most likely always return an empty string. Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
1 parent de41ef8 commit 00b9de6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/OldProcessing/Translation/TranslationProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
use OCA\OpenAi\AppInfo\Application;
1414
use OCA\OpenAi\Service\OpenAiAPIService;
1515
use OCA\OpenAi\Service\OpenAiSettingsService;
16+
use OCP\IAppConfig;
1617
use OCP\ICacheFactory;
17-
use OCP\IConfig;
1818
use OCP\L10N\IFactory;
1919
use OCP\Translation\IDetectLanguageProvider;
2020
use OCP\Translation\ITranslationProvider;
@@ -28,7 +28,7 @@ public function __construct(
2828
private IFactory $l10nFactory,
2929
private OpenAiAPIService $openAiAPIService,
3030
private LoggerInterface $logger,
31-
private IConfig $config,
31+
private IAppConfig $appConfig,
3232
private ?string $userId,
3333
private OpenAiSettingsService $openAiSettingsService,
3434
) {
@@ -71,7 +71,7 @@ public function getAvailableLanguages(): array {
7171

7272
public function detectLanguage(string $text): ?string {
7373
$prompt = 'What language is this (answer with the language name only, in English): ' . $text;
74-
$adminModel = $this->config->getAppValue(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_COMPLETION_MODEL_ID) ?: Application::DEFAULT_COMPLETION_MODEL_ID;
74+
$adminModel = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID;
7575
try {
7676
if ($this->openAiAPIService->isUsingOpenAi() || $this->openAiSettingsService->getChatEndpointEnabled()) {
7777
$completion = $this->openAiAPIService->createChatCompletion($this->userId, $adminModel, $prompt, null, null, 1, 100);
@@ -118,7 +118,7 @@ public function translate(?string $fromLanguage, string $toLanguage, string $tex
118118
$this->logger->debug('OpenAI translation TO[' . $toLanguage . ']', ['app' => Application::APP_ID]);
119119
$prompt = 'Translate to ' . $toLanguage . ': ' . $text;
120120
}
121-
$adminModel = $this->config->getAppValue(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_COMPLETION_MODEL_ID) ?: Application::DEFAULT_COMPLETION_MODEL_ID;
121+
$adminModel = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID;
122122

123123
if ($this->openAiAPIService->isUsingOpenAi() || $this->openAiSettingsService->getChatEndpointEnabled()) {
124124
$completion = $this->openAiAPIService->createChatCompletion($this->userId, $adminModel, $prompt, null, null, 1, PHP_INT_MAX);

0 commit comments

Comments
 (0)