Skip to content

Commit e58dbf6

Browse files
committed
summarize chunks in proofread provider when multiple exist
Signed-off-by: Lukas Schaefer <[email protected]>
1 parent c9ecd9c commit e58dbf6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/TaskProcessing/ProofreadProvider.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function process(?string $userId, array $input, callable $reportProgress)
123123

124124
$chunks = $this->chunkService->chunkSplitPrompt($textInput, true, $maxTokens);
125125
$result = '';
126-
$increase = 1.0 / (float)count($chunks);
126+
$increase = 1.0 / ((float)count($chunks) + 1.0);
127127
$progress = 0.0;
128128

129129
foreach ($chunks as $textInput) {
@@ -147,6 +147,25 @@ public function process(?string $userId, array $input, callable $reportProgress)
147147

148148
throw new RuntimeException('No result in OpenAI/LocalAI response.');
149149
}
150+
if (count($chunks) > 1) {
151+
$systemPrompt = 'Repeat the proofread feedback list. Ensure that no information is lost, but also not duplicated. ';
152+
try {
153+
if ($this->openAiAPIService->isUsingOpenAi() || $this->openAiSettingsService->getChatEndpointEnabled()) {
154+
$completion = $this->openAiAPIService->createChatCompletion($userId, $model, $result, $systemPrompt, null, 1, $maxTokens);
155+
$completion = $completion['messages'];
156+
} else {
157+
$prompt = $systemPrompt . ' Here is the text:' . "\n\n" . $result;
158+
$completion = $this->openAiAPIService->createCompletion($userId, $prompt, 1, $model, $maxTokens);
159+
}
160+
} catch (Exception $e) {
161+
throw new RuntimeException('OpenAI/LocalAI request failed: ' . $e->getMessage());
162+
}
163+
if (count($completion) > 0) {
164+
$result = array_pop($completion);
165+
}
166+
}
167+
$progress += $increase;
168+
$reportProgress($progress);
150169
$endTime = time();
151170
$this->openAiAPIService->updateExpTextProcessingTime($endTime - $startTime);
152171
return ['output' => $result];

0 commit comments

Comments
 (0)