A simple command-line tool that processes text files using OpenAI's API. It allows
users to apply custom actions to files (e.g., summarization, code modification)
and outputs the result either to stdout or edits the file in place. Supports recursive
file globbing and respects .gitignore
rules.
- Process files using custom actions with OpenAI's API.
- Modify files in place or output to stdout.
- Recursively match file paths.
- Exclude files ignored by
.gitignore
. - Dry-run option to show which files would be modified without making changes.
-
Clone the repository:
git clone https://github.com/yourusername/openai-file-processor.git cd openai-file-processor
-
Install dependencies:
Ensure you have Python installed, then run:
pip install -r requirements.txt
-
Create a binary and copy to your bin directory:
pyinstaller --onefile main.py : "${BIN_DIR:-~/.local/bin}" cp ./dist/main "${BIN_DIR}/"
python main.py "path/to/files/*.txt" \
--config config.yaml \
--action "Summarize this text"
python main.py "path/to/files/*.txt" \
--config config.yaml
--action "Refactor the following code" \
--in-place
To see which files would be modified without making changes:
python main.py "path/to/files/**/*.txt" --config config.yaml --dry
python main.py --help
If you created the standalone binary with PyInstaller
, you can run it like this:
./dist/main --config config.yaml --action "Fix grammar" "documents/**/*.md"
By default, the tool looks for a config.yaml
file to load the OpenAI API key and
model. You can provide this file, or use environment variables (OPENAI_API_KEY
and OPENAI_MODEL
).
model: "gpt-4"
api_key: "your-openai-api-key"
Alternatively, set the environment variables:
export OPENAI_API_KEY="your-openai-api-key"
export OPENAI_MODEL="gpt-4"
This project is licensed under the MIT License. See the LICENSE file for details.