diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index fdb50ed8..cd47201c 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -62,6 +62,8 @@ class Application extends App implements IBootstrap { public const MIN_CHUNK_SIZE = 500; public const DEFAULT_MAX_NUM_OF_TOKENS = 1000; public const DEFAULT_QUOTA_PERIOD = 30; + 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 f63705c1..5c493ba6 100644 --- a/lib/Service/OpenAiSettingsService.php +++ b/lib/Service/OpenAiSettingsService.php @@ -35,6 +35,7 @@ class OpenAiSettingsService { 'max_tokens' => 'integer', 'use_max_completion_tokens_param' => 'boolean', 'llm_extra_params' => 'string', + 'summary_system_prompt' => 'string', 'quota_period' => 'array', 'quotas' => 'array', 'usage_storage_time' => 'integer', @@ -297,6 +298,17 @@ public function getMaxTokens(): int { public function getLlmExtraParams(): string { return $this->appConfig->getValueString(Application::APP_ID, 'llm_extra_params', lazy: true); } + /** + * @return string + */ + public function getSummarySystemPrompt(): string { + return $this->appConfig->getValueString( + Application::APP_ID, + 'summary_system_prompt', + Application::DEFAULT_SUMMARY_SYSTEM_PROMPT, + lazy: true + ) ?: Application::DEFAULT_SUMMARY_SYSTEM_PROMPT; + } /** * @return array @@ -579,6 +591,7 @@ public function getAdminConfig(): array { 'max_tokens' => $this->getMaxTokens(), 'use_max_completion_tokens_param' => $this->getUseMaxCompletionTokensParam(), 'llm_extra_params' => $this->getLlmExtraParams(), + 'summary_system_prompt' => $this->getSummarySystemPrompt(), // Updated to get max tokens 'quota_period' => $this->getQuotaPeriod(), // Updated to get quota period @@ -926,6 +939,14 @@ public function setLlmExtraParams(string $llmExtraParams): void { } $this->appConfig->setValueString(Application::APP_ID, 'llm_extra_params', $llmExtraParams, lazy: true); } + public function setSummarySystemPrompt(string $summarySystemPrompt): void { + $this->appConfig->setValueString( + Application::APP_ID, + 'summary_system_prompt', + $summarySystemPrompt, + lazy: true + ); + } /** * Setter for quotaPeriod; minimum is 1 day. @@ -1262,6 +1283,9 @@ public function setAdminConfig(array $adminConfig): void { if (isset($adminConfig['llm_extra_params'])) { $this->setLlmExtraParams($adminConfig['llm_extra_params']); } + if (isset($adminConfig['summary_system_prompt'])) { + $this->setSummarySystemPrompt($adminConfig['summary_system_prompt']); + } if (isset($adminConfig['quota_period'])) { $this->setQuotaPeriod($adminConfig['quota_period']); } diff --git a/lib/TaskProcessing/SummaryProvider.php b/lib/TaskProcessing/SummaryProvider.php index ab9dce24..f6128802 100644 --- a/lib/TaskProcessing/SummaryProvider.php +++ b/lib/TaskProcessing/SummaryProvider.php @@ -153,8 +153,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 a018a391..6bb5a8b2 100644 --- a/src/components/AdminSettings.vue +++ b/src/components/AdminSettings.vue @@ -274,6 +274,17 @@ +