=======
This macro provides AI-powered text autocompletion and transformation capabilities within LibreOffice/OpenOffice using OpenAI's API.
(It's pretty similar to https://github.com/balisujohn/localwriter, from which borrows some code, but as a macro, which is easier to customize).
- Autocomplete: Continue writing naturally from the cursor position
- Text Transformation: Modify selected text based on instructions
- Customizable: Configure API settings and prompt templates
- Logging: View API call history and debug information
-
Save the
llm_writer_macro.pyfile to your LibreOffice macro directory:- Linux:
~/.config/libreoffice/4/user/Scripts/python/ - Windows:
%APPDATA%\LibreOffice\4\user\Scripts\python\ - macOS:
~/Library/Application Support/LibreOffice/4/user/Scripts/python/
- Linux:
-
Restart LibreOffice/OpenOffice
-
Set up your OpenAI API key:
- Go to Tools > Macros > Organize Macros > Python
- Run the
modify_configmacro - Enter your OpenAI API key and other settings
- Go to Tools > Customize
- Select the toolbar you want to add the macro to
- Click "Add..."
- In the Category list, select "Python"
- Choose the desired macro (autocomplete, transform_text, etc.)
- Click "Add" and "Close"
- Go to Tools > Customize > Keyboard
- Select a function key combination
- In the Category list, select "Python"
- Choose the desired macro
- Click "Modify" and "OK"
- Autocomplete: Place cursor where you want text to continue and run the macro
- Transform Text: Select text to modify, run the macro, and enter instructions. In absence of instructions, the llm will run the explicit or implied instruction of the text (for example, translate this: xxx). The original text may be kept or replaced by the generation.
- View Logs: Run the
show_logsmacro to see API call history - Modify Config: Run the
modify_configmacro to change API settings
The following parameters can be configured:
- OPENAI_ENDPOINT: API endpoint URL (may be used with openrouter or any other compatible platform).
- OPENAI_API_KEY: Your OpenAI API key
- MODEL: GPT model to use (e.g., gpt-4o, gpt-4o-mini, etc..)
- MAX_GENERATION_WORDS: Maximum words to generate (aprox)
- AUTOCOMPLETE_ADDITIONAL_INSTRUCTIONS: Prompt template for autocomplete
- CONTEXT_PREVIOUS_CHARS: Number of previous characters to use as context
- CONTEXT_NEXT_CHARS: Number of following characters to use as context
- TEMPERATURE: Creativity level (0.0 to 2.0)
- LibreOffice/OpenOffice with Python support
- OpenAI-compatible API key (OpenAI, OpenRouter, Ollama, vLLM, etc...)
- Internet connection (unless running server locally)
- Check API logs using the
show_logsmacro - Verify your API key is correct
- Ensure you have an active internet connection
- Make sure the macro file is in the correct directory
The macro uses two files stored in the user's home directory:
-
llm_writer_params.json
Location:- Linux/macOS:
~/.llm_writer/llm_writer_params.json - Windows:
%USERPROFILE%\.llm_writer\llm_writer_params.json
Purpose: Stores all configuration parameters including API key, model settings, and prompt templates.
Format: JSON file that can be manually edited if needed.
- Linux/macOS:
-
llm_writer_api_logs.log
Location:- Linux/macOS:
~/.llm_writer/llm_writer_api_logs.log - Windows:
%USERPROFILE%\.llm_writer\llm_writer_api_logs.log
Purpose: Logs all API calls made by the macro including requests, responses, and timestamps.
Format: Plain text file that can be viewed with any text editor.
- Linux/macOS:
These files are automatically created when the macro is first run. The configuration file can be modified either through the macro's configuration dialog or by directly editing the JSON file.
This project is licensed under the MIT License - see the LICENSE file for details.
