A script-based tool for sequentially editing files, running scripts and their tests, and recording outputs, including errors and exceptions, directly from the terminal.
Aider LLM File Editor is a powerful tool designed to automate the process of editing Python files, executing scripts, running associated tests, and recording their outputs. Leveraging OpenRouter models with aider-chat
, this tool streamlines your workflow by handling multiple directories and files efficiently. Whether you're developing, testing, or debugging, Aider LLM File Editor simplifies your tasks directly from the terminal.
- Automated File Editing: Sequentially edit multiple Python files based on provided instructions.
- Script Execution: Run Python scripts across various directories and capture their outputs.
- Test Management: Execute test files using
pytest
and record their results. - Output Recording: Log standard outputs and error messages from both scripts and tests.
- Cross-Platform Support: Compatible with Mac, Linux, and Windows operating systems.
- Environment Management: Supports both Conda and Poetry for dependency management.
Before setting up the project, ensure you have the following installed on your system:
- Python: Version 3.12.x
- Conda (optional, for environment management)
- Poetry (optional, for dependency management)
-
Clone the Repository
git clone https://github.com/TeomanEgeSelcuk/Aider-and-OpenRouter-Script-for-Processing-Multiple-Files.git cd Aider-and-OpenRouter-Script-for-Processing-Multiple-Files
-
Create and Activate the Conda Environment
conda env create -f environment.yml conda activate openrouter-aider-env
-
Install Dependencies
pip install poetry poetry install
-
Clone the Repository
git clone https://github.com/TeomanEgeSelcuk/Aider-and-OpenRouter-Script-for-Processing-Multiple-Files.git cd Aider-and-OpenRouter-Script-for-Processing-Multiple-Files
-
Install Poetry
If you don't have Poetry installed, you can install it using pip:
pip install poetry
-
Install Dependencies
poetry install
-
Activate the Poetry Environment
poetry shell
The project relies on the OPENROUTER_API_KEY
for authenticating with OpenRouter models. Follow these steps to set it up:
-
Obtain Your OpenRouter API Key
Register or log in to OpenRouter to obtain your API key.
-
Set the Environment Variable
-
Mac/Linux
Add the following line to your
~/.bashrc
,~/.zshrc
, or corresponding shell configuration file:export OPENROUTER_API_KEY='your-api-key-here'
Then, reload the shell configuration:
source ~/.bashrc # or source ~/.zshrc
-
Windows
Set the environment variable using Command Prompt:
setx OPENROUTER_API_KEY "your-api-key-here"
Or using PowerShell:
[System.Environment]::SetEnvironmentVariable('OPENROUTER_API_KEY', 'your-api-key-here', 'User')
-
After setting up the environment and installing dependencies, you can start using the Aider LLM File Editor.
-
Prepare Your Directories and Files
Organize the directories and Python files you wish to edit and test.
-
Run the Execute Function
You can run the
execute
function frommain.py
with the appropriate arguments. Here's a basic example:python main.py
Example Usage in Python:
from Aider_Project.main import execute directory_paths = ["dir1", "dir2"] files_by_directory = [["file1.py", "file2.py"], ["file3.py"]] model = "your-openrouter-model" record_output_flag = [True, True] run_tests_flag = [False, False] execute( directory_paths=directory_paths, files_by_directory=files_by_directory, model=model, record_output_flag=record_output_flag, run_tests_flag=run_tests_flag )
-
Verbose Mode
For detailed logs, enable the
verbose
flag:execute( directory_paths=directory_paths, files_by_directory=files_by_directory, model=model, record_output_flag=record_output_flag, run_tests_flag=run_tests_flag, verbose=True )
Aider-and-OpenRouter-Script-for-Processing-Multiple-Files/
├── Aider_Project/
│ ├── __init__.py
│ ├── execute_helper.py
│ ├── main.py
│ ├── runner.py
│ ├── utils.py
├── tests/
│ ├── __init__.py
│ ├── test_execute_helper.py
│ ├── test_main.py
│ ├── test_runner.py
│ ├── test_utils.py
├── .gitignore
├── environment.yml
├── poetry.lock
├── pyproject.toml
├── pytest.ini
└── README.md
- Aider_Project/: Contains the main source code.
- main.py: Entry point with the
execute
function. - utils.py: Utility functions like
get_openrouter_api_key
andlist_files
. - execute_helper.py: Helper functions for validation and flag organization.
- runner.py: Functions to run scripts and record outputs.
- main.py: Entry point with the
- tests/: Contains test cases for the project.
- pyproject.toml: Poetry configuration file managing dependencies.
- environment.yml: Conda environment configuration.
- README.md: Project documentation.
- .gitignore: Specifies files and directories to ignore in git.
Contributions are welcome! Please follow these steps:
-
Fork the Repository
-
Create a New Branch
git checkout -b feature/YourFeature
-
Commit Your Changes
git commit -m "Add your feature"
-
Push to the Branch
git push origin feature/YourFeature
-
Open a Pull Request
Describe your changes and submit the pull request for review.
Author: Teoman Selcuk
Email: [email protected]