Skip to content

Forge.cs

suncloudsmoon edited this page Dec 8, 2024 · 2 revisions

Overview

Forge.cs is a crucial component of the TextCraft project, integrating AI capabilities into Microsoft Word through an add-in. The Forge class manages various functionalities such as loading the add-in, initializing settings, handling user interactions, and interfacing with AI services for tasks like reviewing, proofreading, and rewriting text.

Public Members

Variables

  • CommentSystemPrompt: A static system chat message used for commenting functionalities.
  • CultureHelper: A helper class for culture-specific localizations.
  • InitializeDoor: An object used for locking during initialization to ensure thread safety.

Functions

  • Forge_Load(sender, e): Handles the loading event of the add-in, initializing tasks and starting the setup process in a separate thread.
  • InitializeForge(): Initializes the add-in by setting up system prompts, populating model lists, and preparing UI elements.
  • PopulateDropdownList(modelList): Populates the model selection dropdown with available language models, sorting them alphabetically.
  • ModelListDropDown_SelectionChanged(sender, e): Handles the event when a different model is selected in the dropdown, updating settings and refreshing the checkbox state.
  • DefaultCheckBox_Click(sender, e): Toggles the default model setting based on the checkbox state.
  • GenerateButton_Click(sender, e): Toggles the visibility of task panes related to content generation.
  • RAGControlButton_Click(sender, e): Toggles the visibility of task panes related to RAG controls.
  • AboutButton_Click(sender, e): Displays the about box for the add-in.
  • CancelButton_Click(sender, e): Cancels any ongoing AI operations and hides the cancel button.
  • WritingToolsGallery_ButtonClick(sender, e): Handles clicks on writing tools gallery buttons, delegating actions based on the button ID.
  • ReviewButton_Click(): Initiates the review process for selected text or entire document paragraphs, adding AI-generated comments.
  • ProofreadButton_Click(): Initiates proofreading of selected text using AI, replacing the text with corrected versions.
  • RewriteButton_Click(): Initiates rewriting of selected text using AI, offering stylistic improvements or rephrasing.
  • AnalyzeText(systemPrompt, userPrompt, temperature): A general function to analyze text based on provided prompts and temperature settings, used internally by proofreading and rewriting functions.
  • GetTextFromParagraphs(paragraphs): Extracts text from a collection of Word paragraphs, appending each with a newline.
  • AddStreamingChatContentToRange(streamingAnswer, range): Inserts streaming AI chat responses directly into a Word range, handling markdown formatting and cancellation options.
  • AddStreamingImageContentToRange(streamingAnswer, range): Handles the insertion of AI-generated images into a Word range, managing temporary file storage and cleanup.
  • UpdateCheckbox(): Updates the state of the default model checkbox based on current settings.
  • GetSelectedItemLabel(): Retrieves the label of the currently selected item in the model dropdown.
  • Review(context, p, userPrompt, doc): Prepares and sends a review request to the AI, including context and user prompts, for generating comments on specific paragraphs.
  • GetPictureAddress(newContent): Extracts the image path from generated image content, saving it temporarily if necessary.

Private Members

Variables

  • _box: An instance of the about box for displaying information about the add-in.
  • _optionsBox: A reference to the options group in the ribbon interface.

Functions

  • InitializeForge(): Initializes the add-in by setting up system prompts, populating model lists, and preparing UI elements.
  • PopulateDropdownList(modelList): Populates the model selection dropdown with available language models, sorting them alphabetically.
  • ModelListDropDown_SelectionChanged(sender, e): Handles the event when a different model is selected in the dropdown, updating settings and refreshing the checkbox state.
  • DefaultCheckBox_Click(sender, e): Toggles the default model setting based on the checkbox state.
  • GenerateButton_Click(sender, e): Toggles the visibility of task panes related to content generation.
  • RAGControlButton_Click(sender, e): Toggles the visibility of task panes related to RAG controls.
  • AboutButton_Click(sender, e): Displays the about box for the add-in.
  • CancelButton_Click(sender, e): Cancels any ongoing AI operations and hides the cancel button.
  • WritingToolsGallery_ButtonClick(sender, e): Handles clicks on writing tools gallery buttons, delegating actions based on the button ID.
  • ReviewButton_Click(): Initiates the review process for selected text or entire document paragraphs, adding AI-generated comments.
  • ProofreadButton_Click(): Initiates proofreading of selected text using AI, replacing the text with corrected versions.
  • RewriteButton_Click(): Initiates rewriting of selected text using AI, offering stylistic improvements or rephrasing.
  • AnalyzeText(systemPrompt, userPrompt, temperature): A general function to analyze text based on provided prompts and temperature settings, used internally by proofreading and rewriting functions.
  • GetTextFromParagraphs(paragraphs): Extracts text from a collection of Word paragraphs, appending each with a newline.
  • AddStreamingChatContentToRange(streamingAnswer, range): Inserts streaming AI chat responses directly into a Word range, handling markdown formatting and cancellation options.
  • AddStreamingImageContentToRange(streamingAnswer, range): Handles the insertion of AI-generated images into a Word range, managing temporary file storage and cleanup.
  • UpdateCheckbox(): Updates the state of the default model checkbox based on current settings.
  • GetSelectedItemLabel(): Retrieves the label of the currently selected item in the model dropdown.
  • Review(context, p, userPrompt, doc): Prepares and sends a review request to the AI, including context and user prompts, for generating comments on specific paragraphs.
  • GetPictureAddress(newContent): Extracts the image path from generated image content, saving it temporarily if necessary.

Events

  • Forge_Load: Triggered when the add-in is loaded, initiating necessary setups and background tasks.
  • ModelListDropDown_SelectionChanged: Fired when the user selects a different model from the dropdown, updating internal settings accordingly.
  • DefaultCheckBox_Click: Handles toggling of the default model setting through the UI.
  • GenerateButton_Click: Manages the visibility of generation task panes.
  • RAGControlButton_Click: Manages the visibility of RAG control task panes.
  • AboutButton_Click: Displays information about the add-in.
  • CancelButton_Click: Allows users to cancel ongoing AI operations.
  • WritingToolsGallery_ButtonClick: Handles various writing tool actions based on user selections.
Clone this wiki locally