Skip to content

AndesKrrrrrrrrrrr/ai-fileworker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI File Processor CLI

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.

Features

  • 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.

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/openai-file-processor.git
    cd openai-file-processor
  2. Install dependencies:

    Ensure you have Python installed, then run:

    pip install -r requirements.txt
  3. Create a binary and copy to your bin directory:

    pyinstaller --onefile main.py
    : "${BIN_DIR:-~/.local/bin}"
    cp ./dist/main "${BIN_DIR}/"

Usage

Basic Usage

python main.py "path/to/files/*.txt" \
  --config config.yaml \
  --action "Summarize this text"

In-place Modification

python main.py "path/to/files/*.txt" \
  --config config.yaml
  --action "Refactor the following code" \
  --in-place

Dry-run Mode

To see which files would be modified without making changes:

python main.py "path/to/files/**/*.txt" --config config.yaml --dry

Help

python main.py --help

Example Command for the Binary

If you created the standalone binary with PyInstaller, you can run it like this:

./dist/main --config config.yaml --action "Fix grammar" "documents/**/*.md"

Configuration

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).

Example config.yaml

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"

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Make the AI work for you on files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages