@@ -223,11 +223,12 @@ private static async Task ReviewButton_Click()
223223 }
224224 else
225225 {
226+ Word . Document document = CommonUtils . GetActiveDocument ( ) ; // Hash code of the active document gets changed after each comment!
226227 foreach ( Word . Paragraph p in paragraphs )
227228 // It isn't a paragraph if it doesn't contain a full stop.
228229 if ( p . Range . Text . Contains ( '.' ) )
229230 {
230- await CommentHandler . AddComment ( CommonUtils . GetComments ( ) , p . Range , Review ( paragraphs , p . Range , prompt ) ) ;
231+ await CommentHandler . AddComment ( CommonUtils . GetComments ( ) , p . Range , Review ( paragraphs , p . Range , prompt , document ) ) ;
231232 hasCommented = true ;
232233 }
233234 }
@@ -303,15 +304,15 @@ private void UpdateCheckbox()
303304 DefaultCheckBox . Checked = ( Properties . Settings . Default . DefaultModel == ThisAddIn . Model ) ;
304305 }
305306
306- private static AsyncCollectionResult < StreamingChatCompletionUpdate > Review ( Word . Paragraphs context , Word . Range p , string prompt )
307+ private static AsyncCollectionResult < StreamingChatCompletionUpdate > Review ( Word . Paragraphs context , Word . Range p , string prompt , Word . Document doc = null )
307308 {
308309 var docRange = Globals . ThisAddIn . Application . ActiveDocument . Range ( ) ;
309310 List < UserChatMessage > userChat = new List < UserChatMessage > ( )
310311 {
311312 new UserChatMessage ( $@ "Please review the following paragraph extracted from the Document: ""{ CommonUtils . SubstringTokens ( p . Text , ( int ) ( ThisAddIn . ContextLength * 0.2 ) ) } """),
312313 new UserChatMessage(prompt)
313314 };
314- return RAGControl.AskQuestion(CommentSystemPrompt, userChat, docRange);
315+ return RAGControl.AskQuestion(CommentSystemPrompt, userChat, docRange, doc );
315316 }
316317 }
317318}
0 commit comments