diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index c34ddfe6..708d1b35 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -46,6 +46,8 @@ class Application extends App implements IBootstrap { public const DEFAULT_QUOTA_PERIOD = 30; public const MAX_QUOTA_PERIOD_DAYS = 3650; public const MAX_QUOTA_PERIOD_MONTHS = 120; + public const DEFAULT_SUMMARY_SYSTEM_PROMPT = 'You are a helpful assistant that summarizes text in the same language as the text. ' + . 'You should only return the summary without any additional information.'; public const DEFAULT_QUOTA_CONFIG = ['length' => self::DEFAULT_QUOTA_PERIOD, 'unit' => 'day', 'day' => 1]; public const DEFAULT_OPENAI_TEXT_GENERATION_TIME = 10; // seconds diff --git a/lib/Service/OpenAiSettingsService.php b/lib/Service/OpenAiSettingsService.php index 8e48a555..33e17570 100644 --- a/lib/Service/OpenAiSettingsService.php +++ b/lib/Service/OpenAiSettingsService.php @@ -27,6 +27,7 @@ class OpenAiSettingsService { private const ADMIN_CONFIG_TYPES = [ 'quota_period' => 'array', 'usage_storage_time' => 'integer', + 'summary_system_prompt' => 'string', ]; private const USER_CONFIG_TYPES = [ @@ -135,6 +136,19 @@ public function getUsageStorageTime(): int { return $this->appConfig->getValueInt(Application::APP_ID, 'usage_storage_time', Application::DEFAULT_QUOTA_PERIOD, lazy: true); } + /** + * System prompt for the summary provider. Empty falls back to the default unless $raw is true. + */ + public function getSummarySystemPrompt(bool $raw = false): string { + $default = $raw ? '' : Application::DEFAULT_SUMMARY_SYSTEM_PROMPT; + return $this->appConfig->getValueString( + Application::APP_ID, + 'summary_system_prompt', + $default, + lazy: true + ) ?: $default; + } + /** * @param string|null $userId * @return string @@ -146,12 +160,13 @@ public function getUserSTTLanguage(?string $userId): string { /** * Get the instance-wide admin config for the settings page * - * @return array{quota_period: array, usage_storage_time: int} + * @return array{quota_period: array, usage_storage_time: int, summary_system_prompt: string} */ public function getAdminConfig(): array { return [ 'quota_period' => $this->getQuotaPeriod(), 'usage_storage_time' => $this->getUsageStorageTime(), + 'summary_system_prompt' => $this->getSummarySystemPrompt(true), ]; } @@ -218,6 +233,15 @@ public function setUsageStorageTime(int $usageStorageTime): void { $this->appConfig->setValueInt(Application::APP_ID, 'usage_storage_time', $usageStorageTime, lazy: true); } + public function setSummarySystemPrompt(string $summarySystemPrompt): void { + $this->appConfig->setValueString( + Application::APP_ID, + 'summary_system_prompt', + $summarySystemPrompt, + lazy: true + ); + } + /** * @param string $userId * @param string $language @@ -250,6 +274,9 @@ public function setAdminConfig(array $adminConfig): void { if (isset($adminConfig['usage_storage_time'])) { $this->setUsageStorageTime($adminConfig['usage_storage_time']); } + if (isset($adminConfig['summary_system_prompt'])) { + $this->setSummarySystemPrompt($adminConfig['summary_system_prompt']); + } } /** diff --git a/lib/TaskProcessing/ProviderFactory.php b/lib/TaskProcessing/ProviderFactory.php index 43a2792e..2f2949e7 100644 --- a/lib/TaskProcessing/ProviderFactory.php +++ b/lib/TaskProcessing/ProviderFactory.php @@ -12,6 +12,7 @@ use OCA\OpenAi\AppInfo\Application; use OCA\OpenAi\Service\ChunkService; use OCA\OpenAi\Service\OpenAiAPIService; +use OCA\OpenAi\Service\OpenAiSettingsService; use OCA\OpenAi\Service\ServiceConfig; use OCA\OpenAi\Service\ServicesService; use OCA\OpenAi\Service\TranslateService; @@ -35,6 +36,7 @@ class ProviderFactory { public function __construct( private ServicesService $servicesService, private OpenAiAPIService $openAiAPIService, + private OpenAiSettingsService $openAiSettingsService, private ChunkService $chunkService, private TranslateService $translateService, private WatermarkingService $watermarkingService, @@ -80,7 +82,7 @@ private function getTextProviders(ServiceConfig $service, string $model): array new TextToTextProvider($this->openAiAPIService, $this->l, $service, $model), new TextToTextChatProvider($this->openAiAPIService, $this->l, $service, $model), new TextToTextChatWithToolsProvider($this->openAiAPIService, $this->l, $service, $model), - new SummaryProvider($this->openAiAPIService, $this->l, $this->chunkService, $service, $model), + new SummaryProvider($this->openAiAPIService, $this->l, $this->chunkService, $this->openAiSettingsService, $service, $model), new HeadlineProvider($this->openAiAPIService, $this->l, $service, $model), new TopicsProvider($this->openAiAPIService, $this->l, $this->chunkService, $this->logger, $service, $model), new ContextWriteProvider($this->openAiAPIService, $this->chunkService, $this->l, $service, $model), diff --git a/lib/TaskProcessing/SummaryProvider.php b/lib/TaskProcessing/SummaryProvider.php index f84709f5..63c1e140 100644 --- a/lib/TaskProcessing/SummaryProvider.php +++ b/lib/TaskProcessing/SummaryProvider.php @@ -11,6 +11,7 @@ use OCA\OpenAi\Service\ChunkService; use OCA\OpenAi\Service\OpenAiAPIService; +use OCA\OpenAi\Service\OpenAiSettingsService; use OCA\OpenAi\Service\ServiceConfig; use OCP\IL10N; use OCP\TaskProcessing\EShapeType; @@ -28,6 +29,7 @@ public function __construct( private OpenAiAPIService $openAiAPIService, private IL10N $l, private ChunkService $chunkService, + private OpenAiSettingsService $openAiSettingsService, private ServiceConfig $service, private string $model, ) { @@ -142,8 +144,7 @@ public function process(?string $userId, array $input, callable $reportProgress) try { $completions = []; - $summarySystemPrompt = 'You are a helpful assistant that summarizes text in the same language as the text. ' - . 'You should only return the summary without any additional information. '; + $summarySystemPrompt = $this->openAiSettingsService->getSummarySystemPrompt() . ' '; if (isset($input['format'])) { if ($input['format'] === 'paragraph') { $summarySystemPrompt .= 'Return the summary as a paragraph. '; diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue index 4503922c..91f9c0b6 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -58,6 +58,19 @@ +