@@ -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