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
6 changes: 2 additions & 4 deletions lib/OldProcessing/Translation/TranslationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OCA\OpenAi\Service\OpenAiAPIService;
use OCA\OpenAi\Service\OpenAiSettingsService;
use OCA\OpenAi\Service\TranslateService;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\Translation\IDetectLanguageProvider;
use OCP\Translation\ITranslationProvider;
Expand All @@ -27,7 +26,6 @@ public function __construct(
private ICacheFactory $cacheFactory,
private OpenAiAPIService $openAiAPIService,
private LoggerInterface $logger,
private IAppConfig $appConfig,
private ?string $userId,
private OpenAiSettingsService $openAiSettingsService,
) {
Expand Down Expand Up @@ -69,7 +67,7 @@ public function getAvailableLanguages(): array {

public function detectLanguage(string $text): ?string {
$prompt = 'What language is this (answer with the language name only, in English): ' . $text;
$adminModel = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID;
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
try {
if ($this->openAiAPIService->isUsingOpenAi() || $this->openAiSettingsService->getChatEndpointEnabled()) {
$completion = $this->openAiAPIService->createChatCompletion($this->userId, $adminModel, $prompt, null, null, 1, 100);
Expand Down Expand Up @@ -107,7 +105,7 @@ public function translate(?string $fromLanguage, string $toLanguage, string $tex
$this->logger->debug('OpenAI translation TO[' . $toLanguage . ']', ['app' => Application::APP_ID]);
$prompt = 'Translate to ' . $toLanguage . ': ' . $text;
}
$adminModel = $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID;
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();

if ($this->openAiAPIService->isUsingOpenAi() || $this->openAiSettingsService->getChatEndpointEnabled()) {
$completion = $this->openAiAPIService->createChatCompletion($this->userId, $adminModel, $prompt, null, null, 1, PHP_INT_MAX);
Expand Down
8 changes: 2 additions & 6 deletions lib/TaskProcessing/AnalyzeImagesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use OCA\OpenAi\Service\OpenAiAPIService;
use OCA\OpenAi\Service\OpenAiSettingsService;
use OCP\Files\File;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\ISynchronousProvider;
Expand All @@ -28,7 +27,6 @@ public function __construct(
private OpenAiSettingsService $openAiSettingsService,
private IL10N $l,
private LoggerInterface $logger,
private IAppConfig $appConfig,
private ?string $userId,
) {
}
Expand Down Expand Up @@ -83,9 +81,7 @@ 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, lazy: true) ?: Application::DEFAULT_MODEL_ID)
: $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true);
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
return [
'max_tokens' => $this->openAiSettingsService->getMaxTokens(),
'model' => $adminModel,
Expand Down Expand Up @@ -167,7 +163,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, lazy: true) ?: Application::DEFAULT_COMPLETION_MODEL_ID;
$model = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
}

$maxTokens = null;
Expand Down
6 changes: 4 additions & 2 deletions lib/TaskProcessing/AudioToAudioChatProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Exception;
use OCA\OpenAi\AppInfo\Application;
use OCA\OpenAi\Service\OpenAiAPIService;
use OCA\OpenAi\Service\OpenAiSettingsService;
use OCP\Files\File;
use OCP\IAppConfig;
use OCP\IL10N;
Expand Down Expand Up @@ -39,6 +40,7 @@ public function __construct(
private IL10N $l,
private LoggerInterface $logger,
private IAppConfig $appConfig,
private OpenAiSettingsService $openAiSettingsService,
private ?string $userId,
) {
}
Expand Down Expand Up @@ -125,7 +127,7 @@ public function getOptionalInputShapeDefaults(): array {
$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', lazy: true);
: $this->openAiSettingsService->getAdminDefaultCompletionModelId();
$defaults = [
'voice' => $adminVoice,
'llm_model' => $adminLlmModel,
Expand Down Expand Up @@ -194,7 +196,7 @@ 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, lazy: true) ?: Application::DEFAULT_MODEL_ID);
: $this->openAiSettingsService->getAdminDefaultCompletionModelId();
}


Expand Down
8 changes: 2 additions & 6 deletions lib/TaskProcessing/ChangeToneProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OCA\OpenAi\Service\ChunkService;
use OCA\OpenAi\Service\OpenAiAPIService;
use OCA\OpenAi\Service\OpenAiSettingsService;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\ISynchronousProvider;
Expand All @@ -27,7 +26,6 @@ class ChangeToneProvider implements ISynchronousProvider {

public function __construct(
private OpenAiAPIService $openAiAPIService,
private IAppConfig $appConfig,
private OpenAiSettingsService $openAiSettingsService,
private IL10N $l,
private ChunkService $chunkService,
Expand Down Expand Up @@ -95,9 +93,7 @@ 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, lazy: true) ?: Application::DEFAULT_MODEL_ID)
: $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true);
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
return [
'max_tokens' => $this->openAiSettingsService->getMaxTokens(),
'model' => $adminModel,
Expand Down Expand Up @@ -133,7 +129,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, lazy: true) ?: Application::DEFAULT_MODEL_ID;
$model = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
}

$chunks = $this->chunkService->chunkSplitPrompt($textInput, true, $maxTokens);
Expand Down
8 changes: 2 additions & 6 deletions lib/TaskProcessing/ContextWriteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OCA\OpenAi\Service\ChunkService;
use OCA\OpenAi\Service\OpenAiAPIService;
use OCA\OpenAi\Service\OpenAiSettingsService;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\ISynchronousProvider;
Expand All @@ -26,7 +25,6 @@ class ContextWriteProvider implements ISynchronousProvider {

public function __construct(
private OpenAiAPIService $openAiAPIService,
private IAppConfig $appConfig,
private OpenAiSettingsService $openAiSettingsService,
private ChunkService $chunkService,
private IL10N $l,
Expand Down Expand Up @@ -80,9 +78,7 @@ 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, lazy: true) ?: Application::DEFAULT_MODEL_ID)
: $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true);
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
return [
'max_tokens' => $this->openAiSettingsService->getMaxTokens(),
'model' => $adminModel,
Expand Down Expand Up @@ -122,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, lazy: true) ?: Application::DEFAULT_MODEL_ID;
$model = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
}

$chunks = $this->chunkService->chunkSplitPrompt($sourceMaterial, true, $maxTokens);
Expand Down
8 changes: 2 additions & 6 deletions lib/TaskProcessing/EmojiProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use OCA\OpenAi\AppInfo\Application;
use OCA\OpenAi\Service\OpenAiAPIService;
use OCA\OpenAi\Service\OpenAiSettingsService;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\ISynchronousProvider;
Expand All @@ -25,7 +24,6 @@ class EmojiProvider implements ISynchronousProvider {

public function __construct(
private OpenAiAPIService $openAiAPIService,
private IAppConfig $appConfig,
private OpenAiSettingsService $openAiSettingsService,
private IL10N $l,
private ?string $userId,
Expand Down Expand Up @@ -78,9 +76,7 @@ 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, lazy: true) ?: Application::DEFAULT_MODEL_ID)
: $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true);
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
return [
'max_tokens' => 100,
'model' => $adminModel,
Expand Down Expand Up @@ -116,7 +112,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, lazy: true) ?: Application::DEFAULT_MODEL_ID;
$model = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
}

try {
Expand Down
8 changes: 2 additions & 6 deletions lib/TaskProcessing/HeadlineProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use OCA\OpenAi\AppInfo\Application;
use OCA\OpenAi\Service\OpenAiAPIService;
use OCA\OpenAi\Service\OpenAiSettingsService;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\ISynchronousProvider;
Expand All @@ -25,7 +24,6 @@ class HeadlineProvider implements ISynchronousProvider {

public function __construct(
private OpenAiAPIService $openAiAPIService,
private IAppConfig $appConfig,
private OpenAiSettingsService $openAiSettingsService,
private IL10N $l,
private ?string $userId,
Expand Down Expand Up @@ -78,9 +76,7 @@ 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, lazy: true) ?: Application::DEFAULT_MODEL_ID)
: $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true);
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
return [
'max_tokens' => 100,
'model' => $adminModel,
Expand Down Expand Up @@ -116,7 +112,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, lazy: true) ?: Application::DEFAULT_MODEL_ID;
$model = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
}

try {
Expand Down
8 changes: 2 additions & 6 deletions lib/TaskProcessing/ProofreadProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OCA\OpenAi\Service\ChunkService;
use OCA\OpenAi\Service\OpenAiAPIService;
use OCA\OpenAi\Service\OpenAiSettingsService;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\ISynchronousProvider;
Expand All @@ -26,7 +25,6 @@ class ProofreadProvider implements ISynchronousProvider {

public function __construct(
private OpenAiAPIService $openAiAPIService,
private IAppConfig $appConfig,
private OpenAiSettingsService $openAiSettingsService,
private IL10N $l,
private ChunkService $chunkService,
Expand Down Expand Up @@ -80,9 +78,7 @@ 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, lazy: true) ?: Application::DEFAULT_MODEL_ID)
: $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true);
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
return [
'max_tokens' => $this->openAiSettingsService->getMaxTokens(),
'model' => $adminModel,
Expand Down Expand Up @@ -118,7 +114,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, lazy: true) ?: Application::DEFAULT_MODEL_ID;
$model = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
}

$chunks = $this->chunkService->chunkSplitPrompt($textInput, true, $maxTokens);
Expand Down
8 changes: 2 additions & 6 deletions lib/TaskProcessing/ReformulateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OCA\OpenAi\Service\ChunkService;
use OCA\OpenAi\Service\OpenAiAPIService;
use OCA\OpenAi\Service\OpenAiSettingsService;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\ISynchronousProvider;
Expand All @@ -26,7 +25,6 @@ class ReformulateProvider implements ISynchronousProvider {

public function __construct(
private OpenAiAPIService $openAiAPIService,
private IAppConfig $appConfig,
private OpenAiSettingsService $openAiSettingsService,
private IL10N $l,
private ChunkService $chunkService,
Expand Down Expand Up @@ -80,9 +78,7 @@ 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, lazy: true) ?: Application::DEFAULT_MODEL_ID)
: $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true);
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
return [
'max_tokens' => $this->openAiSettingsService->getMaxTokens(),
'model' => $adminModel,
Expand Down Expand Up @@ -117,7 +113,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, lazy: true) ?: Application::DEFAULT_MODEL_ID;
$model = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
}
$chunks = $this->chunkService->chunkSplitPrompt($prompt, true, $maxTokens);
$result = '';
Expand Down
6 changes: 1 addition & 5 deletions lib/TaskProcessing/SummaryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OCA\OpenAi\Service\ChunkService;
use OCA\OpenAi\Service\OpenAiAPIService;
use OCA\OpenAi\Service\OpenAiSettingsService;
use OCP\IAppConfig;
use OCP\IL10N;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\ISynchronousProvider;
Expand All @@ -26,7 +25,6 @@ class SummaryProvider implements ISynchronousProvider {

public function __construct(
private OpenAiAPIService $openAiAPIService,
private IAppConfig $appConfig,
private OpenAiSettingsService $openAiSettingsService,
private IL10N $l,
private ChunkService $chunkService,
Expand Down Expand Up @@ -80,9 +78,7 @@ 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, lazy: true) ?: Application::DEFAULT_MODEL_ID)
: $this->appConfig->getValueString(Application::APP_ID, 'default_completion_model_id', lazy: true);
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
return [
'max_tokens' => $this->openAiSettingsService->getMaxTokens(),
'model' => $adminModel,
Expand Down
6 changes: 3 additions & 3 deletions lib/TaskProcessing/TextToTextChatProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Exception;
use OCA\OpenAi\AppInfo\Application;
use OCA\OpenAi\Service\OpenAiAPIService;
use OCP\IAppConfig;
use OCA\OpenAi\Service\OpenAiSettingsService;
use OCP\IL10N;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\ISynchronousProvider;
Expand All @@ -24,7 +24,7 @@ class TextToTextChatProvider implements ISynchronousProvider {

public function __construct(
private OpenAiAPIService $openAiAPIService,
private IAppConfig $appConfig,
private OpenAiSettingsService $openAiSettingsService,
private IL10N $l,
) {
}
Expand Down Expand Up @@ -90,7 +90,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, lazy: true) ?: Application::DEFAULT_COMPLETION_MODEL_ID;
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();

if (!isset($input['input']) || !is_string($input['input'])) {
throw new RuntimeException('Invalid input');
Expand Down
Loading
Loading