Repository navigation
Feat/custom system prompts #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f94ae80
7fbbe02
5f04f50
e2ebd4c
3d530f1
75dc75b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,8 @@ class ServiceConfig implements JsonSerializable { | |
| 'llm_extra_params' => 'string', | ||
| 'max_tokens' => 'integer', | ||
| 'chunk_size' => 'integer', | ||
| 'system_prompt_summary' => 'string', | ||
| 'system_prompt_translate' => 'string', | ||
| 'multimodal_image_enabled' => 'boolean', | ||
| 'multimodal_audio_enabled' => 'boolean', | ||
| 'multimodal_video_enabled' => 'boolean', | ||
|
|
@@ -83,6 +85,8 @@ public function __construct( | |
| private string $llmExtraParams = '', | ||
| private int $maxTokens = Application::DEFAULT_MAX_NUM_OF_TOKENS, | ||
| private int $chunkSize = Application::DEFAULT_CHUNK_SIZE, | ||
| private string $systemPromptSummary = '', | ||
| private string $systemPromptTranslate = '', | ||
| // these mirror the defaults of the single-service configuration, so | ||
| // that a migrated service and a newly connected one accept the same | ||
| // kinds of attachment | ||
|
|
@@ -150,6 +154,10 @@ public function with(array $values): self { | |
| break; | ||
| case 'chunk_size': $new->chunkSize = (int)$value === 0 ? 0 : max(Application::MIN_CHUNK_SIZE, (int)$value); | ||
| break; | ||
| case 'system_prompt_summary': $new->systemPromptSummary = (string)$value; | ||
| break; | ||
| case 'system_prompt_translate': $new->systemPromptTranslate = (string)$value; | ||
| break; | ||
| case 'multimodal_image_enabled': $new->multimodalImageEnabled = (bool)$value; | ||
| break; | ||
| case 'multimodal_audio_enabled': $new->multimodalAudioEnabled = (bool)$value; | ||
|
|
@@ -349,6 +357,24 @@ public function getChunkSize(): int { | |
| return $this->chunkSize; | ||
| } | ||
|
|
||
| /** | ||
| * The admin-configured fallback system prompt for the summary task type. | ||
| * An empty string means the built-in default prompt is used. | ||
| */ | ||
| public function getSystemPromptSummary(): string { | ||
| return $this->systemPromptSummary; | ||
| } | ||
|
|
||
| /** | ||
| * The admin-configured system prompt appended to the built-in translation | ||
| * prompt for the translation task type. The built-in prompt is always kept, | ||
| * as it enforces the expected JSON response format. | ||
| * An empty string means only the built-in prompt is used. | ||
| */ | ||
|
Comment on lines
+368
to
+373
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment isn't relevant to this particular function. Also, I think the code is |
||
| public function getSystemPromptTranslate(): string { | ||
| return $this->systemPromptTranslate; | ||
| } | ||
|
|
||
| public function getMultimodalImageEnabled(): bool { | ||
| return $this->multimodalImageEnabled; | ||
| } | ||
|
|
@@ -466,6 +492,8 @@ public function jsonSerialize(): array { | |
| 'llm_extra_params' => $this->llmExtraParams, | ||
| 'max_tokens' => $this->maxTokens, | ||
| 'chunk_size' => $this->chunkSize, | ||
| 'system_prompt_summary' => $this->systemPromptSummary, | ||
| 'system_prompt_translate' => $this->systemPromptTranslate, | ||
| 'multimodal_image_enabled' => $this->multimodalImageEnabled, | ||
| 'multimodal_audio_enabled' => $this->multimodalAudioEnabled, | ||
| 'multimodal_video_enabled' => $this->multimodalVideoEnabled, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,19 +58,6 @@ | |
| </NcButton> | ||
| </div> | ||
|
|
||
| <h3>{{ t('integration_openai', 'Text generation') }}</h3> | ||
| <div class="line line--full"> | ||
| <NcTextArea | ||
| id="summary-system-prompt" | ||
| v-model="state.summary_system_prompt" | ||
| class="input input--full" | ||
| :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> | ||
|
|
||
| <h3>{{ t('integration_openai', 'Usage limits') }}</h3> | ||
| <div class="line"> | ||
| <QuotaPeriodPicker | ||
|
|
@@ -128,7 +115,6 @@ import NcInputField from '@nextcloud/vue/components/NcInputField' | |
| import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon' | ||
| import NcNoteCard from '@nextcloud/vue/components/NcNoteCard' | ||
| import NcSelect from '@nextcloud/vue/components/NcSelect' | ||
| import NcTextArea from '@nextcloud/vue/components/NcTextArea' | ||
|
|
||
| import axios from '@nextcloud/axios' | ||
| import { showError, showSuccess, showWarning } from '@nextcloud/dialogs' | ||
|
|
@@ -155,7 +141,6 @@ export default { | |
| NcLoadingIcon, | ||
| NcNoteCard, | ||
| NcSelect, | ||
| NcTextArea, | ||
| }, | ||
|
|
||
| data() { | ||
|
|
@@ -385,6 +370,8 @@ export default { | |
| llm_extra_params: service.llm_extra_params, | ||
| max_tokens: parseInt(service.max_tokens) || 1, | ||
| chunk_size: parseInt(service.chunk_size) || 0, | ||
| system_prompt_summary: service.system_prompt_summary, | ||
| system_prompt_translate: service.system_prompt_translate, | ||
| multimodal_image_enabled: service.multimodal_image_enabled, | ||
| multimodal_audio_enabled: service.multimodal_audio_enabled, | ||
| multimodal_video_enabled: service.multimodal_video_enabled, | ||
|
|
@@ -430,7 +417,6 @@ export default { | |
| await this.saveAdminConfig({ | ||
| quota_period: this.state.quota_period, | ||
| usage_storage_time: parseInt(this.state.usage_storage_time) || 1, | ||
| summary_system_prompt: this.state.summary_system_prompt, | ||
| }) | ||
| }, 2000), | ||
| async saveAdminConfig(values) { | ||
|
|
@@ -491,14 +477,6 @@ export default { | |
| width: 300px; | ||
| } | ||
|
|
||
| .line--full { | ||
| width: 100%; | ||
| } | ||
|
|
||
| .line .input--full { | ||
| width: 100%; | ||
| } | ||
|
Comment on lines
-494
to
-500
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the new text boxes should keep their full width too. The current boxes are too small to comfortably fit longer prompts. |
||
|
|
||
| .services { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment isn't relevant to this particular function. Plus, it is redundant anyway, so it should be removed.