Skip to content
Open
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
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions lib/Service/OpenAiSettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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']);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/TaskProcessing/SummaryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. ';
Expand Down
14 changes: 14 additions & 0 deletions src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@
</template>
</NcButton>
</div>
<div class="line">
<NcTextArea
id="summary-system-prompt"
v-model="state.summary_system_prompt"
class="input"
:label="t('integration_openai', 'Summary system prompt')"
:helper-text="t('integration_openai', 'System prompt used when generating text summaries. Leave empty to use the default prompt.')"
:rows="5"
resize="vertical"
@update:model-value="onInput()" />
</div>
<div class="line">
<!--Input for max chunk size (prompt length) for a single request-->
<NcInputField
Expand Down Expand Up @@ -687,6 +698,7 @@ import NcInputField from '@nextcloud/vue/components/NcInputField'
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
import NcSelect from '@nextcloud/vue/components/NcSelect'
import NcTextField from '@nextcloud/vue/components/NcTextField'
import NcTextArea from '@nextcloud/vue/components/NcTextArea'

import axios from '@nextcloud/axios'
import { showError, showSuccess } from '@nextcloud/dialogs'
Expand Down Expand Up @@ -718,6 +730,7 @@ export default {
NcFormBox,
NcFormBoxSwitch,
NcTextField,
NcTextArea,
NcInputField,
NcNoteCard,
NcDateTimePickerNative,
Expand Down Expand Up @@ -1022,6 +1035,7 @@ export default {
chunk_size: parseInt(this.state.chunk_size),
max_tokens: parseInt(this.state.max_tokens),
llm_extra_params: this.state.llm_extra_params,
summary_system_prompt: this.state.summary_system_prompt,
default_image_size: this.state.default_image_size,
quota_period: this.state.quota_period,
quotas: this.state.quotas,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Providers/OpenAiProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ public function testSummaryProvider(): void {

$prompt = 'This is a test prompt';
$n = 1;
$this->openAiSettingsService->setSummarySystemPrompt('This is a custom summary system prompt');

$response = '{
"id": "chatcmpl-123",
Expand Down Expand Up @@ -544,8 +545,7 @@ public function testSummaryProvider(): void {
$url = self::OPENAI_API_BASE . 'chat/completions';

$options = ['timeout' => Application::OPENAI_DEFAULT_REQUEST_TIMEOUT, 'headers' => ['User-Agent' => Application::USER_AGENT, 'Authorization' => self::AUTHORIZATION_HEADER, 'Content-Type' => 'application/json']];
$systemPrompt = '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. ';
$systemPrompt = 'This is a custom summary system prompt ';
$options['body'] = json_encode([
'model' => Application::DEFAULT_COMPLETION_MODEL_ID,
'messages' => [
Expand Down