-
Notifications
You must be signed in to change notification settings - Fork 4
ThisAddIn.cs
suncloudsmoon edited this page Dec 8, 2024
·
1 revision
ThisAddIn.cs
is a crucial component of the TextForge project, acting as the main entry point for the application. It manages the initialization, shutdown, and event handling for the add-in, integrating with Microsoft Office Word to provide advanced functionalities such as generating content, reviewing documents, and handling comments using AI models.
- OpenAIEndpoint: The endpoint URL for the OpenAI service.
- ApiKey: The API key for accessing OpenAI services.
- Model: The current model being used for AI operations.
- EmbedModel: The model used for embedding operations.
- ContextLength: The maximum context length supported by the current model.
- ClientOptions: Options for configuring the OpenAI client.
- Embedder: An instance of the embedder for processing embeddings.
- CancellationTokenSource: Manages cancellation tokens for asynchronous operations.
- IsAddinInitialized: Indicates whether the add-in has been initialized.
- ModelList: A collection of available OpenAI models.
- AllTaskPanes: A dictionary mapping Word documents to their associated task panes and controls.
- SystemPromptLocalization: A dictionary storing localized system prompts for different functionalities.
- ThisAddIn_Startup(object sender, EventArgs e): Handles the startup event of the add-in, initializing necessary components in a separate thread.
- ThisAddIn_Shutdown(object sender, EventArgs e): Handles the shutdown event of the add-in, saving settings and cleaning up event handlers.
- Application_NewDocument(Document doc): Adds task panes when a new document is created.
- Application_DocumentOpen(Document doc): Adds task panes when an existing document is opened.
- Application_DocumentChange(): Handles changes in the active document, removing task panes for closed documents.
- AddTaskPanes(Document doc): Adds task panes to a specified document.
- AddTaskPanesAsync(Document doc): Asynchronously adds task panes to a specified document.
- InitializeAddInStartup(): Initializes the add-in by setting up event handlers and performing one-time setup.
- InitializeAddIn(): Performs the actual initialization tasks, such as configuring TLS, setting environment variables, and initializing OpenAI clients.
- InitializeEnvironmentVariables(): Loads configuration settings from environment variables and sets default values.
- AssignIfNotEmptyPrompt(string key, string value): Assigns a value to the system prompt localization dictionary if the value is not empty.
- HandleSystemPromptLocalization(): Handles the localization of system prompts.
- SetEmbedModelAutomatically(): Sets the embedding model automatically based on available models.
- None
- InternalStartup(): A required method for designer support, attaching startup and shutdown events.
- _openAIEndpoint: The endpoint URL for the OpenAI service.
- _apiKey: The API key for accessing OpenAI services.
- _model: The current model being used for AI operations.
- _embedModel: The model used for embedding operations.
- _contextLength: The maximum context length supported by the current model.
- _clientOptions: Options for configuring the OpenAI client.
- _embedder: An instance of the embedder for processing embeddings.
- _cancellationTokenSource: Manages cancellation tokens for asynchronous operations.
- _isAddinInitialized: Indicates whether the add-in has been initialized.
- _modelList: A collection of available OpenAI models.
- _allTaskPanes: A dictionary mapping Word documents to their associated task panes and controls.
- _systemPromptLocalization: A dictionary storing localized system prompts for different functionalities.
- InitializeAddInStartup(): Initializes the add-in by setting up event handlers and performing one-time setup.
- InitializeAddIn(): Performs the actual initialization tasks, such as configuring TLS, setting environment variables, and initializing OpenAI clients.
- InitializeEnvironmentVariables(): Loads configuration settings from environment variables and sets default values.
- AssignIfNotEmptyPrompt(string key, string value): Assigns a value to the system prompt localization dictionary if the value is not empty.
- HandleSystemPromptLocalization(): Handles the localization of system prompts.
- SetEmbedModelAutomatically(): Sets the embedding model automatically based on available models.
- ThisAddIn_Startup: Triggered when the add-in starts up.
- ThisAddIn_Shutdown: Triggered when the add-in shuts down.
- Application_NewDocument: Triggered when a new document is created.
- Application_DocumentOpen: Triggered when an existing document is opened.
- Application_DocumentChange: Triggered when the active document changes.
- WindowSelectionChange: Handles selection changes in the document window, particularly for comment handling.