Kaynağa Gözat

optimize message

Yuki Takei 1 yıl önce
ebeveyn
işleme
03ad060cfe

+ 5 - 5
apps/app/src/features/openai/server/routes/edit/index.ts

@@ -134,7 +134,7 @@ export const postMessageToEditHandlersFactory: PostMessageHandlersFactory = (cro
               You must respond with a JSON object in the following format example:
               You must respond with a JSON object in the following format example:
               {
               {
                 "contents": [
                 "contents": [
-                  { "message": "Your friendly message explaining what changes were made or suggested" },
+                  { "message": "Your brief message about the upcoming change or proposal.\n\n" },
                   { "retain": 10 },
                   { "retain": 10 },
                   { "insert": "New text 1" },
                   { "insert": "New text 1" },
                   { "message": "Additional explanation if needed" },
                   { "message": "Additional explanation if needed" },
@@ -142,12 +142,15 @@ export const postMessageToEditHandlersFactory: PostMessageHandlersFactory = (cro
                   { "delete": 15 },
                   { "delete": 15 },
                   { "insert": "New text 2" },
                   { "insert": "New text 2" },
                   ...more items if needed
                   ...more items if needed
+                  { "message": "Your friendly message explaining what changes were made or suggested." }
                 ]
                 ]
               }
               }
 
 
               The array should contain:
               The array should contain:
-              - Objects with a "message" key for explanatory text to the user
+              - [At the begining of the list] A "message" object that has your brief message about the upcoming change or proposal. Be sure to add two consecutive line feeds ('\n\n') at the end.
+              - Objects with a "message" key for explanatory text to the user if needed.
               - Objects with "insert", "delete", and "retain" keys for replacements (Delta format by Quill Rich Text Editor)
               - Objects with "insert", "delete", and "retain" keys for replacements (Delta format by Quill Rich Text Editor)
+              - [At the end of the list] A "message" object that contains your friendly message explaining that the operation was completed and what changes were made.
 
 
               If no changes are needed, include only message objects with explanations.
               If no changes are needed, include only message objects with explanations.
               Always provide messages in the same language as the user's request.`,
               Always provide messages in the same language as the user's request.`,
@@ -177,9 +180,6 @@ export const postMessageToEditHandlersFactory: PostMessageHandlersFactory = (cro
             streamProcessor.process(rawBuffer, chunk);
             streamProcessor.process(rawBuffer, chunk);
 
 
             rawBuffer += chunk;
             rawBuffer += chunk;
-
-            // Also send original delta
-            sseHelper.writeData(delta);
           }
           }
           else {
           else {
             sseHelper.writeData(delta);
             sseHelper.writeData(delta);

+ 2 - 2
apps/app/src/features/openai/server/services/editor-assistant/llm-response-stream-processor.ts

@@ -211,14 +211,14 @@ export class LlmResponseStreamProcessor {
       }
       }
 
 
       // Final notification
       // Final notification
-      const fullMessage = Array.from(this.processedMessages.values()).join('\n\n');
+      const fullMessage = Array.from(this.processedMessages.values()).join('');
       this.options?.dataFinalizedCallback?.(fullMessage, this.replacements);
       this.options?.dataFinalizedCallback?.(fullMessage, this.replacements);
     }
     }
     catch (e) {
     catch (e) {
       logger.debug('Failed to parse final JSON response:', e);
       logger.debug('Failed to parse final JSON response:', e);
 
 
       // Send final notification even on error
       // Send final notification even on error
-      const fullMessage = Array.from(this.processedMessages.values()).join('\n\n');
+      const fullMessage = Array.from(this.processedMessages.values()).join('');
       this.options?.dataFinalizedCallback?.(fullMessage, this.replacements);
       this.options?.dataFinalizedCallback?.(fullMessage, this.replacements);
     }
     }
   }
   }