This script runs in the background and listens for hotkeys, then uses a Large Language Model to fix or improve text. It's inspired by Andrej Karpathy's tweet about GPT's ability to correct minor typos, allowing for faster writing.
- Uses Ollama or any external model supported by PyLLMs for text processing
- Supports multiple hotkeys for different text operations
- Can fix typos, improve writing style, and restructure notes
-
Set up Ollama (if using Ollama):
- Install Ollama: https://github.com/ollama/ollama
- Run:
ollama run mistral:7b-instruct-v0.2-q4_K_S
-
Install dependencies:
pip install pynput pyperclip httpx pyllms
-
Run the script:
python key.py
Default Hotkeys:
- F8: Restructure and polish the entire note
- F9: Fix typos in the current line
- F10: Fix typos in the current selection
- F11: Improve writing style of the current selection
Note: On macOS, you may need to add the script (IDE/terminal) to both accessibility and input monitoring settings.
The script can be easily customized:
- Modify
OLLAMA_CONFIG
to change the Ollama model or settings - Edit
PROMPT_TEMPLATES
to change how text is processed - Adjust
function_key_map
to modify hotkey assignments or add new operations
To extend mappings:
- Add a new prompt template to
PROMPT_TEMPLATES
:"new_operation": Template("Your prompt here $text"),
- Add a new entry to
function_key_map
:Where"<key_code>": ("Key_Name", select_function, "new_operation"),
<key_code>
is the pynput key code,"Key_Name"
is a descriptive name,select_function
is eitherNone
or a function to select text, and"new_operation"
is the key of your new prompt template.
- Use
-m
or--model
to specify a PyLLMs model instead of Ollama
Examples:
python key.py -m gpt-4o-mini
- The script is designed for macOS. Keyboard shortcuts may need adjustment for Linux or Windows.
- Ensure you have the necessary permissions for keyboard input monitoring.
- When using PyLLMs models, make sure you have the required API keys set up in your environment.