-
Notifications
You must be signed in to change notification settings - Fork 4
CommentHandler.cs
suncloudsmoon edited this page Dec 8, 2024
·
2 revisions
The CommentHandler
class is an integral part of the TextForge
namespace, designed to manage and automate responses to comments within a Word document using artificial intelligence capabilities. It leverages the Microsoft Office Interop library to interact with Word documents and utilizes an AI model to generate responses to specific types of comments.
- Automated Responses: The primary function is to automatically reply to comments that mention the AI model or are part of a review process.
- Event Handling: It listens for changes in document comments and processes new comments accordingly.
- Integration with AI: Uses an AI model to generate responses based on the context of the comments and the document content.
- None defined in this class.
- Document_CommentsEventHandler(Word.Selection selection): Handles events related to changes in document comments. It checks for new comments and triggers appropriate responses.
public static async void Document_CommentsEventHandler(Word.Selection selection)
- _prevNumComments: Tracks the previous number of comments in the document to avoid redundant processing.
- _isDraftingComment: A flag to indicate whether a comment is currently being drafted to prevent overlapping operations.
- AICommentReplyTask(): Asynchronously processes unanswered AI-generated comments and generates replies using an AI model.
private static async Task<bool> AICommentReplyTask()
- UserMentionTask(): Asynchronously processes comments where the AI model is mentioned and generates replies.
private static async Task<bool> UserMentionTask()
- GetCommentMessagesWithoutMention(Comment parentComment): Prepares a history of comments excluding mentions for AI processing.
private static IEnumerable<ChatMessage> GetCommentMessagesWithoutMention(Comment parentComment)
- GetCleanedCommentText(Comment c, string modelName): Cleans comment text by removing model mentions.
private static string GetCleanedCommentText(Comment c, string modelName)
- GetCommentMessages(Comment parentComment): Converts Word comments into a format suitable for AI processing.
private static IEnumerable<ChatMessage> GetCommentMessages(Comment parentComment)
- GetUnansweredMentionedComments(Comments allComments): Identifies comments that mention the AI model and require a response.
private static IEnumerable<Comment> GetUnansweredMentionedComments(Comments allComments)
- AreRepliesUnbalanced(Comments replies): Determines if there are unmatched user mentions in comment replies.
private static bool AreRepliesUnbalanced(Comments replies)
- GetCommentMentionCount(string mention, Comments comments): Counts mentions of a specific string in comments.
private static int GetCommentMentionCount(string mention, Comments comments)
- GetCommentAuthorCount(string author, Comments comments): Counts comments by a specific author.
private static int GetCommentAuthorCount(string author, Comments comments)
- GetUnansweredAIComments(Comments allComments): Identifies AI-generated comments that need further response.
private static IEnumerable<Comment> GetUnansweredAIComments(Comments allComments)
- AddComment(Comments comments, Range range, AsyncCollectionResult streamingContent): Adds a new comment to the document with text generated asynchronously.
public static async Task AddComment(Comments comments, Range range, AsyncCollectionResult<StreamingChatCompletionUpdate> streamingContent)
- Document_CommentsEventHandler: Event handler for comment changes in the Word document. It processes new comments and triggers AI responses as needed.