Skip to content

Commit 68d9806

Browse files
committed
Bug fix
1 parent a2e4580 commit 68d9806

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Forge.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

RAGControl.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,10 @@ public string GetRAGContext(string query, int maxTokens)
390390
}
391391

392392
// UTILS
393-
public static AsyncCollectionResult<StreamingChatCompletionUpdate> AskQuestion(SystemChatMessage systemPrompt, IEnumerable<ChatMessage> messages, Word.Range context)
393+
public static AsyncCollectionResult<StreamingChatCompletionUpdate> AskQuestion(SystemChatMessage systemPrompt, IEnumerable<ChatMessage> messages, Word.Range context, Word.Document doc = null)
394394
{
395+
if (doc == null)
396+
doc = context.Document;
395397
string document = context.Text;
396398
int userPromptLen = GetUserPromptLen(messages);
397399
ChatMessage lastUserPrompt = messages.Last();
@@ -406,7 +408,7 @@ public static AsyncCollectionResult<StreamingChatCompletionUpdate> AskQuestion(S
406408
document = RAGControl.GetWordDocumentAsRAG(lastUserPrompt.Content[0].Text, context);
407409

408410
string ragQuery =
409-
(constraints["rag_context"] == 0f) ? string.Empty : ThisAddIn.AllTaskPanes[Globals.ThisAddIn.Application.ActiveDocument].Item3.GetRAGContext(lastUserPrompt.Content[0].Text, (int)(ThisAddIn.ContextLength * constraints["rag_context"]));
411+
(constraints["rag_context"] == 0f) ? string.Empty : ThisAddIn.AllTaskPanes[doc].Item3.GetRAGContext(lastUserPrompt.Content[0].Text, (int)(ThisAddIn.ContextLength * constraints["rag_context"]));
410412

411413
List<ChatMessage> chatHistory = new List<ChatMessage>()
412414
{

0 commit comments

Comments
 (0)