Skip to content

JacquesvanRhynMSFT/betterdoc

 
 

Repository files navigation

BetterDoc - AI-Powered Word Document Enhancement Tool

BetterDoc is a Microsoft Office Word add-in that leverages AI/LLM technology to intelligently reimagine and improve your document content while preserving formatting, hyperlinks, and document structure.

Features

Core Functionality

  • Paragraph-by-Paragraph Processing: Navigate through your document paragraph by paragraph with intelligent skipping of short paragraphs, questions, and empty content
  • AI Content Enhancement: Use Azure OpenAI or local LLM models to rewrite content with customizable prompts
  • Formatting Preservation: Automatically detects and preserves text formatting (bold, italic, underline, font sizes)
  • Hyperlink Protection: Detects hyperlinks and ensures they remain intact during content processing
  • Leading Format Detection: Preserves special formatting at the beginning of paragraphs

Smart Processing

  • Selective Processing: Only processes paragraphs with 7+ words, skips questions and empty paragraphs
  • Word Count Control: Prevents LLM from increasing word count beyond original content
  • Retry Logic: Automatically retries if hyperlink text is lost during processing
  • Batch Operations: Select and process multiple paragraphs simultaneously

User Interface

  • Visual Navigation: Up/Down arrow buttons to move through paragraphs
  • Real-time Preview: View original and modified text side-by-side
  • Document Highlighting: Current paragraph is selected in the document for easy reference
  • Progress Tracking: Visual list of selected paragraphs with click-to-jump functionality

Architecture

The project consists of two main components:

1. Office Add-in (betterdoc-office-addin/)

  • Frontend: HTML/CSS/JavaScript task pane interface
  • Backend Integration: Communicates with Azure OpenAI via proxy service
  • Office.js Integration: Uses Microsoft Office JavaScript API for document manipulation

2. Azure Proxy Service (ollama-service/)

  • Azure OpenAI Integration: Secure connection to Azure OpenAI using managed identity
  • CORS Handling: Enables cross-origin requests from the Office add-in
  • Request Processing: Handles prompt formatting and response parsing

Setup Instructions

Prerequisites

  • Microsoft Word (Office 365 or Office 2019+)
  • Azure OpenAI service access
  • Node.js (18+)
  • Azure subscription for hosting the proxy service

1. Azure OpenAI Setup

  1. Create an Azure OpenAI resource in your Azure subscription
  2. Deploy a GPT model (e.g., GPT-4)
  3. Note your endpoint URL and deployment name
  4. Configure managed identity for authentication

2. Deploy Proxy Service

  1. Navigate to ollama-service/ directory
  2. Install dependencies:
    npm install
  3. Set environment variables:
    AZURE_OPENAI_ENDPOINT=https://your-openai-resource.openai.azure.com/
    AZURE_OPENAI_DEPLOYMENT=your-deployment-name
  4. Deploy to Azure App Service or run locally:
    npm start

3. Install Office Add-in

  1. Navigate to betterdoc-office-addin/BetterdocAddin/ directory
  2. Install dependencies:
    npm install
  3. Build the add-in:
    npm run build
  4. Sideload the add-in in Word:
    • Open Word
    • Go to Insert > My Add-ins > Upload My Add-in
    • Select the manifest.xml file

Usage Guide

Basic Workflow

  1. Open the Add-in: In Word, find "Betterdoc" in your add-ins and open the task pane

  2. Navigate Document: Use the ↑/↓ buttons to move through paragraphs

    • The tool automatically skips short paragraphs (<7 words), questions, and empty content
    • Current paragraph is highlighted in the document
  3. Select Content: Check the "Reimagine" checkbox for paragraphs you want to process

    • Use "Select All" to mark all valid paragraphs
    • Use "Unselect All" to clear selections
  4. Configure Settings:

    • Prompt Selection: Choose from predefined prompts or create custom ones
      • "Make More Professional": Enhances formal tone
      • "Reduce Word Count": Makes content more concise
      • "Custom Prompt": Write your own instructions
    • Model Selection: Choose from available AI models
    • Server Address: Configure proxy service endpoint
  5. Process Content: Click "Reimagine Now" to send selected paragraphs to the AI

    • The tool processes each paragraph individually
    • Original formatting and hyperlinks are preserved
    • Progress is shown in the debug log
  6. Review and Apply:

    • Review AI-generated content in the "Modified/LLM Text" area
    • Edit the content if needed
    • Click "Apply" for current paragraph or "Apply All" for batch processing

Advanced Features

Custom Prompts

Create specific instructions for the AI:

Rewrite this content for a technical audience. Use precise terminology and include specific details. Maintain all hyperlinks and formatting.

Formatting Preservation

The tool automatically:

  • Detects and preserves bold, italic, underline formatting
  • Maintains font sizes and special formatting
  • Handles complex formatting patterns within paragraphs

Hyperlink Protection

  • Automatically detects hyperlinks in paragraphs
  • Instructs AI to preserve exact link text
  • Retries up to 3 times if link text is modified
  • Reverts to original if preservation fails

Batch Processing

  • Select multiple paragraphs using checkboxes
  • Process all selected content with one click
  • Apply changes to all processed paragraphs simultaneously

Troubleshooting

Connection Issues

  • Ensure the Azure proxy service is running and accessible
  • Check CORS configuration if seeing network errors
  • Verify Azure OpenAI endpoint and deployment settings

Formatting Problems

  • Use "Refresh Source" button to reload document content
  • Check debug log for formatting detection issues
  • Ensure document doesn't have complex nested formatting

Processing Errors

  • Check debug log for detailed error messages
  • Verify AI model is available and responding
  • Try reducing paragraph length if processing fails

Configuration

Available Models

Edit the window.availableModels array in taskpane.html to add/remove AI models:

window.availableModels = [
  "gemma3:12b",
  "gemma3:27b", 
  "qwq:latest",        
  "deepseek-r1:14b",
  "deepseek-r1:32b"
];

Prompt Customization

Modify the PROMPTS object in taskpane.js to add predefined prompts:

const PROMPTS = {
  professional: "Rewrite this and make it sound more professional...",
  concise: "Reduce the word count as much as possible...",
  custom: ""
};

Development

Project Structure

betterdoc2/
├── betterdoc-office-addin/
│   └── BetterdocAddin/
│       ├── manifest.xml          # Office add-in manifest
│       ├── src/
│       │   └── taskpane/
│       │       ├── taskpane.html # Main UI
│       │       ├── taskpane.js   # Core logic
│       │       └── styles.css    # Styling
│       └── package.json
├── ollama-service/
│   ├── server.js                 # Azure proxy server
│   └── package.json
└── readme.md

Key Files

  • taskpane.js: Main application logic, Office.js integration
  • server.js: Azure OpenAI proxy service
  • manifest.xml: Office add-in configuration
  • taskpane.html: User interface definition

API Integration

The add-in uses Office.js APIs for:

  • Document paragraph access and manipulation
  • Text formatting detection and application
  • Hyperlink detection and preservation
  • Document selection and highlighting

Security & Privacy

  • Uses Azure managed identity for secure API authentication
  • No user credentials stored locally
  • Document content processed through secure Azure endpoints
  • All communication encrypted via HTTPS

License

This project is licensed under the MIT License.

Support

For issues and feature requests, please check the debug log in the add-in for detailed error messages and consult the troubleshooting section above.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 81.4%
  • Python 9.8%
  • HTML 6.0%
  • CSS 2.8%