Skip to content
Merged
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
28 changes: 27 additions & 1 deletion lib/TaskProcessing/ProofreadProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.'),
Expand All @@ -73,13 +79,19 @@ 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),
];
}

public function getOptionalInputShapeDefaults(): array {
$adminModel = $this->openAiSettingsService->getAdminDefaultCompletionModelId();
return [
'strictness' => 'standard',
'max_tokens' => $this->openAiSettingsService->getMaxTokens(),
'model' => $adminModel,
];
Expand All @@ -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'])) {
Expand Down Expand Up @@ -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.';
}
}
2 changes: 1 addition & 1 deletion tests/unit/Providers/OpenAiProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
Loading