![]() # Context: USER: where does configargparse look for the config file? ASSISTANT: `configargparse` looks for the configuration file in the locations specified by the `add_config_file_help` and `default_config_files` arguments when creating an `ArgumentParser` instance. If these arguments are not provided, it does not look for a configuration file by default. To specify the locations for the configuration file, you can do the following: ```python parser = configargparse.ArgumentParser( description="aider - chat with GPT about your code", add_config_file_help=True, default_config_files=["./config.ini", "/etc/aider/config.ini"], ) ``` In this example, `configargparse` will look for the configuration file in the current directory with the name `config.ini` and in the `/etc/aider/` directory with the same name. If a configuration file is found, the values from the file will be used as default values for the arguments. USER: can it search parent dirs for the conf file ASSISTANT: Yes, `configargparse` can search parent directories for the configuration file. You can use a loop to generate a list of configuration file paths in parent directories and pass it to the `default_config_files` argument. Here's an example: ```python import os def generate_config_paths(filename): config_paths = [] current_dir = os.path.abspath(os.getcwd()) while True: config_path = os.path.join(current_dir, filename) config_paths.append(config_path) parent_dir = os.path.dirname(current_dir) if parent_dir == current_dir: break current_dir = parent_dir return config_paths config_file_name = "config.ini" config_paths = generate_config_paths(config_file_name) parser = configargparse.ArgumentParser( description="aider - chat with GPT about your code", add_config_file_help=True, default_config_files=config_paths, ) ``` This code will generate a list of configuration file paths in parent directories with the given `config_file_name` and pass it to the `default_config_files` argument. `configargparse` will search for the configuration file in the specified paths. USER: nah. instead, see if cwd is part of a git repo. if so, make the default be the working dir of the repo/.aider.conf.yml, otherwise expand ~/.aider.conf.yml ASSISTANT: To achieve this, you can use the `git` command to check if the current working directory is part of a Git repository and then set the default configuration file path accordingly. Here's how you can do it: ```python import os import subprocess def get_git_root(): try: git_root = subprocess.check_output(["git", "rev-parse", "-- ^C KeyboardInterrupt USER: use import git ASSISTANT: To use the `git` Python library, first, make sure it's installed. You can install it using pip: ``` pip install GitPython ``` Then, you can modify the code to use the `git` library to check if the current working directory is part of a Git repository and set the default configuration file path accordingly: ```python import os import git import configargparse def get_git_root(): try: repo = git.Repo(search_parent_directories=True) return repo.working_tree_dir except git.InvalidGitRepositoryError: ^C KeyboardInterrupt USER: as an edit block ASSISTANT: First, install the `GitPython` library if you haven't already: ``` pip install GitPython ``` Then, update the `aider/main.py` file with the following changes: ```python aider/main.py <<<<<<< ORIGINAL import sys import configargparse from dotenv import load_dotenv from aider.coder import Coder from aider.io import InputOutput ======= import os import sys import git import configargparse from dotenv import load_dotenv from aider.coder import Coder from aider.io import InputOutput >>>>>>> UPDATED ``` ```python aider/main.py <<<<<<< ORIGINAL parser = configargparse.ArgumentParser(description="aider - chat with GPT about your code") ======= def get_git_root(): try: repo = git.Repo(search_parent_directories=True) return repo.working_tree_dir except git.InvalidGitRepositoryError: return None git_root = get_git_root() if git_root: default_config_file = os.path.join(git_root, ".aider.conf.yml") else: default_config_file = os.path.expanduser("~/.aider.conf.yml") parser = configargparse.ArgumentParser( description="aider - chat with GPT about your code", add_config_file_help=True, default_config_files=[default_config_file], ) >>>>>>> UPDATED ``` These changes will import the `git` library and define a `get_git_root()` function to find the Git repository root. The default configuration file path will be set to either the repository root with `.aider.conf.yml` or the user's home directory with `.aider.conf.yml`. |
||
---|---|---|
_layouts | ||
aider | ||
assets | ||
docs | ||
examples | ||
tests | ||
.flake8 | ||
.pre-commit-config.yaml | ||
_config.yml | ||
CNAME | ||
LICENSE.txt | ||
README.md | ||
requirements.txt | ||
screenshot.gif | ||
screenshot.png | ||
setup.py |
aider is GPT-4 powered coding in your terminal
aider
is a command-line chat tool that allows you to write and edit
code with GPT-4. You can ask GPT to help you start
a new project, or add features to your existing code.
aider
is well suited for working with code in a git repo,
as it has features to easily
commit, diff and undo changes proposed by GPT.
Example chat transcripts
Here are some example transcripts that show how you can chat with aider
to write and edit code with GPT-4.
-
Hello World Flask App: Start from scratch and have GPT create a simple Flask app with various endpoints, such as adding two numbers and calculating the Fibonacci sequence.
-
Javascript Game Modification: Dive into an existing open-source repo, and get GPT's help to understand it and make modifications.
-
Complex Multi-file Change with Debugging: GPT makes a complex code change that is coordinated across multiple source files, and resolves bugs by reviewing error output and doc snippets.
-
Create a Black Box Test Case: GPT creates a "black box" test case without access to the source of the method being tested, using only a high level map of the repository based on ctags.
-
Download, analyze and plot US Census data: GPT-4 downloads census data, suggests some hypotheses to test, tests one and then summarizes and plots a graph of the results.
You can find more chat transcripts on the examples page.
Features
- Chat with GPT-4 about your code by launching
aider
from the command line with set of source files to discuss and edit together. - Request new features, changes, improvements, or bug fixes to your code. Ask for new test cases, updated documentation or code refactors.
aider
will apply the edits suggested by GPT-4 directly to your source files.aider
will automatically commit each changeset to your local git repo with a descriptive commit message. These frequent, automatic commits provide a safety net. It's easy to undoaider
changes or use standard git workflows to manage longer sequences of changes.aider
can review multiple source files at once and make coordinated code changes across all of them in a single changeset/commit.aider
can give GPT a map of your entire git repo, which helps it understand and modify large codebases.- You can edit the files by hand using your editor while chatting with
aider
.aider
will notice if you edit the files outside the chat.- It will help you commit these out-of-band changes, if you'd like.
- It will bring the updated file contents into the chat.
- You can bounce back and forth between the
aider
chat and your editor, to fluidly collaborate.
- Live, colorized, human friendly output.
- Readline style chat input history, with autocompletion of code tokens found in the source files being discussed (via
prompt_toolkit
andpygments
lexers)
Installation
-
Install the package:
- From GitHub:
pip install git+https://github.com/paul-gauthier/aider.git
- From your local copy of the repo in develop mode to pick up local edits immediately:
pip install -e .
- From GitHub:
-
Set up your OpenAI API key as an environment variable
OPENAI_API_KEY
or by including it in a.env
file. -
Optionally, install universal ctags. This is helpful if you plan to work with repositories with more than a handful of files. This allows
aider --ctags
to build a map of your entire git repo and share it with GPT to help it better understand and modify large codebases.
Usage
Run the aider
tool by executing the following command:
aider <file1> <file2> ...
Replace <file1>
, <file2>
, etc., with the paths to the source code files you want to work on. These files will be added to the chat session.
You can also just launch aider
anywhere in a git repo without naming files on the command line.
It will discover all the files in the repo.
You can then add and remove individual files in the chat session with the /add
and /drop
chat commands described below.
You can also use additional command-line options to customize the behavior of the tool. The following options are available, along with their corresponding environment variable overrides:
--input-history-file INPUT_HISTORY_FILE
: Specify the chat input history file (default: .aider.input.history). Override the default with the environment variableAIDER_INPUT_HISTORY_FILE
.--chat-history-file CHAT_HISTORY_FILE
: Specify the chat history file (default: .aider.chat.history.md). Override the default with the environment variableAIDER_CHAT_HISTORY_FILE
.--model MODEL
: Specify the model to use for the main chat (default: gpt-4). Override the default with the environment variableAIDER_MODEL
.-3
: Use gpt-3.5-turbo model for the main chat (not advised). No environment variable override.--ctags
: Add ctags to the chat to help GPT understand the codebase (default: False,AIDER_CTAGS
). Requires universal ctags. Override the default with the environment variableAIDER_CTAGS
.--no-pretty
: Disable pretty, colorized output. Override the default with the environment variableAIDER_PRETTY
(default: 1 for enabled, 0 for disabled).--no-auto-commits
: Disable auto commit of changes. Override the default with the environment variableAIDER_AUTO_COMMITS
(default: 1 for enabled, 0 for disabled).--show-diffs
: Show diffs when committing changes (default: False). Override the default with the environment variableAIDER_SHOW_DIFFS
(default: 0 for False, 1 for True).--yes
: Always say yes to every confirmation (default: False).
For more information, run aider --help
.
Chat commands
aider
supports the following commands from within the chat:
/add <file>
: Add matching files to the chat session./drop <file>
: Remove matching files from the chat session./ls
: List all known files and those included in the chat session./commit [message]
: Commit outstanding changes to the repo. Use this to commit edits you made outside the chat, with your editor or git commands. aider will provide a commit message if you don't./undo
: Undo the last git commit if it was done by aider./diff
: Display the diff of the last aider commit./run <command>
: Run a shell command and optionally add the output to the chat./help
: Show help about all commands.
To use a command, simply type it in the chat input followed by any required arguments.
Tips
- Large changes are best performed as a sequence of bite sized steps. Same as if you were undertaking them by yourself.
- Use Control-C to safely interrupt
aider
if it isn't providing a useful response. The partial response remains in the conversation, so you can refer to it when you reply with more information or direction. - Use the
/run
command to run tests, linters, etc and show the output to GPT so it can fix any issues. - Enter a multiline chat message by entering
{
alone on the first line. End the multiline message with}
alone on the last line. - If your code is throwing an error, paste the error message and stack trace into
aider
as a multiline{}
message and letaider
fix the bug. - GPT-4 knows about a lot of standard tools and libraries, but may get some of the fine details wrong about APIs and function arguments. You can paste doc snippets into the chat with the multiline
{}
syntax. aider
will notice if you launch it on a git repo with uncommitted changes and offer to commit them before proceeding.aider
can only see the content of the files you specify, but it also gets a list of all the files in the repo. It may ask to see additional files if it feels that's needed for your requests.
Limitations
You probably need GPT-4 api access to use aider
.
You can invoke it with aider -3
to try using gpt-3.5-turbo, but it will almost certainly fail to function correctly.
GPT-3.5 is unable to consistently follow directions to generate concise code edits in a stable, parsable format.
You can only use aider
to edit code that fits in the GPT context window.
For GPT-4 that is 8k tokens.
It helps to be selective about how many source files you discuss with aider
at one time.
You might consider refactoring your code into more, smaller files (which is usually a good idea anyway).
You can use aider
to help perform such refactorings, if you start before the files get too large.
If you have access to gpt-4-32k, I would be curious to hear how it works with aider.