From f23f3fbe135e74d494770fd06976257d14acaa24 Mon Sep 17 00:00:00 2001 From: Lukas Schaefer Date: Fri, 26 Jun 2026 15:43:46 -0400 Subject: [PATCH] Add strictness levels to proofread Signed-off-by: Lukas Schaefer --- lib/TaskProcessing/ProofreadProvider.php | 28 ++++++++++++++++++++- tests/unit/Providers/OpenAiProviderTest.php | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/TaskProcessing/ProofreadProvider.php b/lib/TaskProcessing/ProofreadProvider.php index 695667f6..6e02d061 100644 --- a/lib/TaskProcessing/ProofreadProvider.php +++ b/lib/TaskProcessing/ProofreadProvider.php @@ -19,6 +19,7 @@ use OCP\TaskProcessing\Exception\UserFacingProcessingException; use OCP\TaskProcessing\ISynchronousProvider; use OCP\TaskProcessing\ShapeDescriptor; +use OCP\TaskProcessing\ShapeEnumValue; use OCP\TaskProcessing\TaskTypes\TextToTextProofread; class ProofreadProvider implements ISynchronousProvider { @@ -58,6 +59,11 @@ public function getInputShapeDefaults(): array { public function getOptionalInputShape(): array { return [ + 'strictness' => new ShapeDescriptor( + $this->l->t('Strictness'), + $this->l->t('How thoroughly to check spelling and grammar.'), + EShapeType::Enum + ), 'max_tokens' => new ShapeDescriptor( $this->l->t('Maximum output words'), $this->l->t('The maximum number of words/tokens that can be generated in the completion.'), @@ -73,6 +79,11 @@ public function getOptionalInputShape(): array { public function getOptionalInputShapeEnumValues(): array { return [ + 'strictness' => [ + new ShapeEnumValue($this->l->t('Minimal'), 'minimal'), + new ShapeEnumValue($this->l->t('Standard'), 'standard'), + new ShapeEnumValue($this->l->t('Strict'), 'strict'), + ], 'model' => $this->openAiAPIService->getModelEnumValues($this->userId), ]; } @@ -80,6 +91,7 @@ public function getOptionalInputShapeEnumValues(): array { public function getOptionalInputShapeDefaults(): array { $adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId(); return [ + 'strictness' => 'standard', 'max_tokens' => $this->openAiSettingsService->getMaxTokens(), 'model' => $adminModel, ]; @@ -104,7 +116,11 @@ public function process(?string $userId, array $input, callable $reportProgress) throw new ProcessingException('Invalid prompt'); } $textInput = $input['input']; - $systemPrompt = 'Proofread the following text. List all spelling and grammar mistakes and how to correct them. Output only the list.'; + $strictness = 'standard'; + if (isset($input['strictness']) && is_string($input['strictness'])) { + $strictness = $input['strictness']; + } + $systemPrompt = $this->getSystemPrompt($strictness); $maxTokens = null; if (isset($input['max_tokens']) && is_int($input['max_tokens'])) { @@ -173,4 +189,14 @@ public function process(?string $userId, array $input, callable $reportProgress) $this->openAiAPIService->updateExpTextProcessingTime($endTime - $startTime); return ['output' => $result]; } + + private function getSystemPrompt(string $strictness): string { + $instruction = match ($strictness) { + 'minimal' => 'List only grammatical and spelling errors that clearly affect meaning or readability, and list how to correct them.', + 'strict' => 'List every conceivable issue, including minor grammar rules, and list how to correct them. Also flag redundancy, and phrasing that could be clearer.', + default => 'List all spelling and grammar mistakes and list how to correct them.', + }; + + return 'Proofread the following text. ' . $instruction . ' Output only the list.'; + } } diff --git a/tests/unit/Providers/OpenAiProviderTest.php b/tests/unit/Providers/OpenAiProviderTest.php index 0dab97aa..9d8c1417 100644 --- a/tests/unit/Providers/OpenAiProviderTest.php +++ b/tests/unit/Providers/OpenAiProviderTest.php @@ -602,7 +602,7 @@ public function testProofreadProvider(): 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 = 'Proofread the following text. List all spelling and grammar mistakes and how to correct them. Output only the list.'; + $systemPrompt = 'Proofread the following text. List all spelling and grammar mistakes and list how to correct them. Output only the list.'; $options['body'] = json_encode([ 'model' => Application::DEFAULT_COMPLETION_MODEL_ID, 'messages' => [