Commit graph

691 commits

Author SHA1 Message Date
Paul Gauthier
d8938ee033 aider: Added support for --version flag to display the version number.
# Context:
USER: should `aider --help` show the version now?
ASSISTANT: Yes, with the changes you made, running `aider --help` should show the version information. However, the version will be displayed when you run `aider --version`. The `--help` output will include a line mentioning the `--version` flag, but it won't directly show the version number.
USER: I ran this command:

 aider --version

And got this output:

Traceback (most recent call last):
  File "/Users/gauthier/Projects/aider/.venv/bin/aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/gauthier/Projects/aider/aider/main.py", line 32, in main
    parser = configargparse.ArgumentParser(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/.venv/lib/python3.11/site-packages/configargparse.py", line 433, in __init__
    argparse.ArgumentParser.__init__(self, *args, **kwargs)
TypeError: ArgumentParser.__init__() got an unexpected keyword argument 'version'

ASSISTANT: I apologize for the confusion earlier. It seems I made a mistake. `configargparse` does not have a built-in `version` parameter like `argparse`. Instead, you can add a custom argument with the `--version` flag and handle it manually. Here's how you can modify your `aider/main.py` file:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser = configargparse.ArgumentParser(
        description="aider is GPT powered coding in your terminal",
        add_config_file_help=True,
        default_config_files=default_config_files,
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        auto_env_var_prefix="AIDER_",
        version=__version__,
    )
=======
    parser = configargparse.ArgumentParser(
        description="aider is GPT powered coding in your terminal",
        add_config_file_help=True,
        default_config_files=default_config_files,
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        auto_env_var_prefix="AIDER_",
    )

    parser.add_argument(
        "--version",
        action="store_true",
        help="Show the version number and exit",
    )
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    args = parser.parse_args(args)
=======
    args, unknown_args = parser.parse_known_args(args)

    if args.version:
        print(f"aider version {__version__}")
        sys.exit(0)

    # Re-parse the arguments to include unknown_args
    args = parser.parse_args(args + unknown_args)

^C KeyboardInterrupt
USER: can we add soemthing like this: parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)

ASSISTANT: I apologize for the confusion earlier. It turns out that `configargparse` does support the `version` action, similar to `argparse`. You can add the `--version` argument as you suggested. Here's how you can modify your `aider/main.py` file:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser = configargparse.ArgumentParser(
        description="aider is GPT powered coding in your terminal",
        add_config_file_help=True,
        default_config_files=default_config_files,
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        auto_env_var_prefix="AIDER_",
        version=__version__,
    )
=======
    parser = configargparse.ArgumentParser(
        description="aider is GPT powered coding in your terminal",
        add_config_file_help=True,
        default_config_files=default_config_files,
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        auto_env_var_prefix="AIDER_",
    )

    parser.add_argument(
        "-v", "--version", action="version", version=f"%(prog)s {__version__}", help="Show the version number and exit"
    )
>>>>>>> UPDATED
```

Now, running `aider --version` or `aider -v` will display the version number as expected.
2023-06-17 07:05:58 -07:00
Paul Gauthier
cdb62c1462 aider: Added version to argparse in main.py.
# Context:
USER: now import `__version__` into main and pass it to `configargparse`
ASSISTANT: To import `__version__` into `aider/main.py` and pass it to `configargparse`, you can modify the `aider/main.py` file as follows:

```python
aider/main.py
<<<<<<< ORIGINAL
import os
import sys

import configargparse
import git

from aider import models
from aider.coder import Coder
from aider.io import InputOutput
=======
import os
import sys

import configargparse
import git

from aider import models, __version__
from aider.coder import Coder
from aider.io import InputOutput
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    parser = configargparse.ArgumentParser(
        description="aider is GPT powered coding in your terminal",
        add_config_file_help=True,
        default_config_files=default_config_files,
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        auto_env_var_prefix="AIDER_",
    )
=======
    parser = configargparse.ArgumentParser(
        description="aider is GPT powered coding in your terminal",
        add_config_file_help=True,
        default_config_files=default_config_files,
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        auto_env_var_prefix="AIDER_",
        version=__version__,
    )
>>>>>>> UPDATED
```

Now, the version from `aider/__init__.py` will be passed to `configargparse.ArgumentParser`, and it will be displayed in the help output when the user runs your tool with the `--version` flag.
2023-06-17 07:01:44 -07:00
Paul Gauthier
373b2e3b35 Changed the description of the CLI tool to be more descriptive. 2023-06-17 06:59:10 -07:00
Paul Gauthier
8660d35601 More flexible models 2023-06-14 17:51:17 -07:00
Paul Gauthier
25a28e6f9c Improved support for gpt-3.5-turbo-16k 2023-06-13 12:19:56 -07:00
Paul Gauthier
193901ee43 Changed OpenAI API base endpoint to https://api.openai.com/v1. 2023-06-10 10:50:45 -07:00
Paul Gauthier
3e7f791112 aider: Added support for passing openai_api_base into the Coder class.
# Context:
USER: we need to pass `openai_api_base` into Coder
ASSISTANT: To pass `openai_api_base` into the Coder class, you need to modify the `aider/main.py` file and update the Coder class instantiation. Here's the change you need to make:

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        map_tokens=args.map_tokens,
        verbose=args.verbose,
        openai_api_key=args.openai_api_key,
    )
=======
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        map_tokens=args.map_tokens,
        verbose=args.verbose,
        openai_api_key=args.openai_api_key,
        openai_api_base=args.openai_api_base,
    )
>>>>>>> UPDATED
```

Now, you also need to update the `__init__` method of the Coder class in the `aider/coder.py` file to accept the `openai_api_base` argument and use it:

```python
aider/coder.py
<<<<<<< ORIGINAL
    def __init__(
        self,
        io,
        main_model=models.GPT4.name,
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        map_tokens=1024,
        verbose=False,
        openai_api_key=None,
    ):
        if not openai_api_key:
            raise MissingAPIKeyError("No OpenAI API key provided.")
        openai.api_key = openai_api_key
        openai.api_base = args.openai_api_base
=======
    def __init__(
        self,
        io,
        main_model=models.GPT4.name,
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        map_tokens=1024,
        verbose=False,
        openai_api_key=None,
        openai_api_base=None,
    ):
        if not openai_api_key:
            raise MissingAPIKeyError("No OpenAI API key provided.")
        openai.api_key = openai_api_key
        openai.api_base = openai_api_base
>>>>>>> UPDATED
```

These changes will allow you to pass the `openai_api_base` value into the Coder class and use it.
2023-06-10 10:40:54 -07:00
Paul Gauthier
3bef60ecf0 aider: Added option to set OpenAI API base endpoint.
# Context:
USER: is it possible to add OPEN_AI_BASE or openai.api_base endpoint

default:
openai.api_base = "https://api.openai.com/v1/chat/completions"

ASSISTANT: Yes, you can add an option to set the OpenAI API base endpoint. Here's how to do it:

1. Add a new argument to the argument parser in `aider/main.py`.
2. Set the `openai.api_base` in the `Coder` class in `aider/coder.py`.

Here are the changes you need to make:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
        env_var="OPENAI_API_KEY",
    )
=======
    parser.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
        env_var="OPENAI_API_KEY",
    )
    parser.add_argument(
        "--openai-api-base",
        metavar="OPENAI_API_BASE",
        default="https://api.openai.com/v1/chat/completions",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1/chat/completions)",
    )
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
        if openai_api_key:
            openai.api_key = openai_api_key
        else:
            raise MissingAPIKeyError("No OpenAI API key provided.")
=======
        if not openai_api_key:
            raise MissingAPIKeyError("No OpenAI API key provided.")
        openai.api_key = openai_api_key
        openai.api_base = args.openai_api_base
>>>>>>> UPDATED
```

Now you can use the `--openai-api-base` option to set the OpenAI API base endpoint when running the script.
2023-06-10 06:40:15 -07:00
Paul Gauthier
a874d617d3 rename 2023-06-07 12:29:51 -07:00
Paul Gauthier
9cef379abd refac 2023-06-07 12:28:45 -07:00
Paul Gauthier
c44cc12b42 The --no-auto-commits flag implies --no-dirty-commits 2023-06-05 22:13:20 -07:00
Paul Gauthier
c30b302363 improved --help 2023-06-05 11:15:38 -07:00
Paul Gauthier
95b32a74a9 Moved all model names into an enum 2023-06-05 09:19:29 -07:00
Paul Gauthier
9168331f4b bugfix 2023-06-04 12:04:51 -07:00
Paul Gauthier
14289ab44f tweaked --map-tokens help 2023-06-03 18:07:01 -07:00
Paul Gauthier
15f34e2864 aider: Changed use_ctags to map_tokens parameter in main.py to pass to Coder class.
# Context:
USER: pass it to Coder as map_tokens instead of `use_ctags`
ASSISTANT: I will modify the `aider/main.py` file to pass `map_tokens` to the `Coder` class instead of `use_ctags`.

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        use_ctags=args.ctags,
        verbose=args.verbose,
        openai_api_key=args.openai_api_key,
    )
=======
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        map_tokens=args.map_tokens,
        verbose=args.verbose,
        openai_api_key=args.openai_api_key,
    )
>>>>>>> UPDATED
```

Now, the `map_tokens` value is passed to the `Coder` class instead of `use_ctags`. Please make sure to update the `Coder` class in `aider/coder.py` to accept and use the `map_tokens` parameter.
2023-06-03 17:47:05 -07:00
Paul Gauthier
dcdad393c8 aider: Changed the --ctags switch into --map-tokens, which is an int that defaults to 1024.
# Context:
USER: change the --ctags switch into --map-tokens, which is an int that defaults to 1024
ASSISTANT: To make this change, I need to modify the `aider/main.py` file. Please make it *read-write* and let me know when it's done.
USER: I added these *read-write* files: aider/main.py
ASSISTANT: Great! I will now modify the `aider/main.py` file to change the `--ctags` switch into `--map-tokens`, which is an int that defaults to 1024.

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--ctags",
        type=lambda x: (str(x).lower() == "true"),
        nargs="?",
        const=True,
        default=None,
        help=(
            "Add ctags to the chat to help GPT understand the codebase (default: check for ctags"
            " executable)"
        ),
    )
=======
    parser.add_argument(
        "--map-tokens",
        type=int,
        default=1024,
        help="Number of tokens to map for code understanding (default: 1024)",
    )
>>>>>>> UPDATED
```

This change replaces the `--ctags` argument with the `--map-tokens` argument, which takes an integer value and defaults to 1024.
2023-06-03 17:46:11 -07:00
Paul Gauthier
92cd2f3ce6 isort 2023-05-28 22:47:38 -07:00
Paul Gauthier
2ec6757f86 aider: Added new arguments --user-input-color, --tool-output-color, and --tool-error-color to main function and passed them to InputOutput class.
# Context:
USER: add args --user-input-color default green, --tool-output-color default None and --tool-error-color default red. pass them to InputOutput
ASSISTANT: I will add the new arguments to the `main` function and pass them to the `InputOutput` class.

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--pretty",
        action="store_true",
        default=True,
        help="Enable pretty, colorized output (default: True)",
    )
    parser.add_argument(
        "--no-pretty",
        action="store_false",
        dest="pretty",
        help="Disable pretty, colorized output",
    )
=======
    parser.add_argument(
        "--pretty",
        action="store_true",
        default=True,
        help="Enable pretty, colorized output (default: True)",
    )
    parser.add_argument(
        "--no-pretty",
        action="store_false",
        dest="pretty",
        help="Disable pretty, colorized output",
    )
    parser.add_argument(
        "--user-input-color",
        default="green",
        help="Set the color for user input (default: green)",
    )
    parser.add_argument(
        "--tool-output-color",
        default=None,
        help="Set the color for tool output (default: None)",
    )
    parser.add_argument(
        "--tool-error-color",
        default="red",
        help="Set the color for tool error messages (default: red)",
    )
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    io = InputOutput(
        args.pretty,
        args.yes,
        args.input_history_file,
        args.chat_history_file,
        input=input,
        output=output,
    )
=======
    io = InputOutput(
        args.pretty,
        args.yes,
        args.input_history_file,
        args.chat_history_file,
        input=input,
        output=output,
        user_input_color=args.user_input_color,
        tool_output_color=args.tool_output_color,
        tool_error_color=args.tool_error_color,
    )
>>>>>>> UPDATED
```

Now the new arguments are added and passed to the `InputOutput` class.
2023-05-27 15:21:57 -07:00
Paul Gauthier
cc9b21df06 renamed io.tool() -> io.tool_output() 2023-05-27 15:17:33 -07:00
Paul Gauthier
40d764e9f8 removed wip: prefix from dirty commits 2023-05-27 08:49:16 -07:00
Paul Gauthier
090b46983c Explain /help on launch 2023-05-27 07:51:56 -07:00
Paul Gauthier
976c5c8e74 Handle missing api key gracefully 2023-05-27 06:35:50 -07:00
Paul Gauthier
b0d860bcf4 Handle missing api key gracefully 2023-05-27 06:35:37 -07:00
Paul Gauthier
9832807814 aider: Added custom exception MissingAPIKeyError to Coder class to raise an error when no OpenAI API key is provided.
# Context:
USER: what's a good exception to raise in coder if no api key
ASSISTANT: A good exception to raise in this case would be a custom exception, such as `MissingAPIKeyError`. You can define this custom exception by subclassing the built-in `ValueError` class. Here's how to define and raise the custom exception:

```python
aider/coder.py
<<<<<<< ORIGINAL
class Coder:
    abs_fnames = None
    repo = None
    last_aider_commit_hash = None
    last_asked_for_commit_time = 0

    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
        openai_api_key=None,
    ):
        if openai_api_key:
            openai.api_key = openai_api_key
        else:
            io.tool_error('No OpenAI API key provided.')
=======
class MissingAPIKeyError(ValueError):
    pass

class Coder:
    abs_fnames = None
    repo = None
    last_aider_commit_hash = None
    last_asked_for_commit_time = 0

    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
        openai_api_key=None,
    ):
        if openai_api_key:
            openai.api_key = openai_api_key
        else:
            raise MissingAPIKeyError('No OpenAI API key provided.')
>>>>>>> UPDATED
```

This custom exception `MissingAPIKeyError` will provide a more specific and informative error message when the API key is not provided.
2023-05-27 06:21:06 -07:00
Paul Gauthier
abf73d00a2 aider: Added --openai-api-key argument to the command-line parser, passed it to the Coder class, and set the openai.api_key accordingly.
# Context:
USER: add a new arg --openai-api-key. pass it to Coder
ASSISTANT: I will add a new argument `--openai-api-key` and pass it to the `Coder` class. Here are the changes:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
=======
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
    parser.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
    )
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        use_ctags=args.ctags,
        verbose=args.verbose,
    )
=======
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        use_ctags=args.ctags,
        verbose=args.verbose,
        openai_api_key=args.openai_api_key,
    )
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
openai.api_key = os.getenv("OPENAI_API_KEY")

class Coder:
    abs_fnames = None
    repo = None
    last_aider_commit_hash = None
    last_asked_for_commit_time = 0

    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
    ):
=======
class Coder:
    abs_fnames = None
    repo = None
    last_aider_commit_hash = None
    last_asked_for_commit_time = 0

    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
        openai_api_key=None,
    ):
        if openai_api_key:
            openai.api_key = openai_api_key
        else:
            openai.api_key = os.getenv("OPENAI_API_KEY")
>>>>>>> UPDATED
```

These changes add the `--openai-api-key` argument to the command-line parser, pass it to the `Coder` class, and set the `openai.api_key` accordingly.
2023-05-27 06:17:11 -07:00
Paul Gauthier
139a141be9 removed dotenv 2023-05-27 06:13:34 -07:00
Paul Gauthier
1fb1765b38 drop dotenv 2023-05-27 06:06:51 -07:00
Paul Gauthier
e02b612126 aider: Added functionality to load .env file from git_root if available.
# Context:
USER: load_dotenv from the git_root if avail
ASSISTANT: To load the `.env` file from the `git_root` if available, you can modify the `load_dotenv()` function call in `aider/main.py`. Here's the change:

```python
aider/main.py
<<<<<<< ORIGINAL
    load_dotenv()
=======
    if git_root:
        load_dotenv(os.path.join(git_root, ".env"))
    else:
        load_dotenv()
>>>>>>> UPDATED
```

This change checks if `git_root` is available and loads the `.env` file from the `git_root` directory. If `git_root` is not available, it falls back to the default behavior of loading the `.env` file from the current working directory.
2023-05-27 05:15:05 -07:00
Paul Gauthier
4c76a8a242 Added --dirty-commits 2023-05-27 05:12:50 -07:00
Paul Gauthier
a2fa4f2929 aider: Added --dirty-commits argument to the argument parser in aider/main.py.
# Context:
USER: add --dirty-commits too
ASSISTANT: To add the `--dirty-commits` argument, we need to modify the `aider/main.py` file. Here are the changes:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
=======
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
    parser.add_argument(
        "--dirty-commits",
        action="store_true",
        dest="dirty_commits",
        help="Enable dirty commit of changes",
    )
>>>>>>> UPDATED
```

These changes add the `--dirty-commits` argument to the argument parser in `aider/main.py`.
2023-05-27 05:10:23 -07:00
Paul Gauthier
ed1a886a4f aider: Added --no-dirty-commits argument to the argument parser in aider/main.py, passed it to the Coder class, and set the self.dirty_commits attribute in the Coder class in aider/coder.py.
# Context:
USER: add a new arg like --no-auto-commits, but called --no-dirty-commits. pass it to Coder and set self.dirty_commits
ASSISTANT: To add the `--no-dirty-commits` argument, we need to modify the `aider/main.py` file and pass the new argument to the `Coder` class in the `aider/coder.py` file.

Here are the changes:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-auto-commits",
        action="store_false",
        dest="auto_commits",
        help="Disable auto commit of changes",
    )
=======
    parser.add_argument(
        "--no-auto-commits",
        action="store_false",
        dest="auto_commits",
        help="Disable auto commit of changes",
    )
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dry_run=args.dry_run,
        use_ctags=args.ctags,
        verbose=args.verbose,
    )
=======
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        use_ctags=args.ctags,
        verbose=args.verbose,
    )
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
    ):
        self.verbose = verbose
        self.abs_fnames = set()
        self.cur_messages = []
        self.done_messages = []

        self.io = io
        self.auto_commits = auto_commits
        self.dry_run = dry_run
=======
    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
    ):
        self.verbose = verbose
        self.abs_fnames = set()
        self.cur_messages = []
        self.done_messages = []

        self.io = io
        self.auto_commits = auto_commits
        self.dirty_commits = dirty_commits
        self.dry_run = dry_run
>>>>>>> UPDATED
```

These changes add the `--no-dirty-commits` argument to the argument parser in `aider/main.py`, pass it to the `Coder` class, and set the `self.dirty_commits` attribute in the `Coder` class in `aider/coder.py`.
2023-05-27 05:09:28 -07:00
Paul Gauthier
d240e5ebc0 Show options on -v 2023-05-27 04:49:16 -07:00
Paul Gauthier
c33169756a tweaking cmd line args, readme usage 2023-05-26 16:40:04 -07:00
Paul Gauthier
905a81d78e auto-commitS 2023-05-26 16:32:10 -07:00
Paul Gauthier
1761325eef aider: Added support for --no-auto-commit argument.
# Context:
USER: do the same for --no-auto-commit
ASSISTANT: To support `auto_commit: true` in the configuration file, you can add a `--auto-commit` argument with the `store_true` action. Here's how to modify the `aider/main.py` file:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-auto-commits",
        action="store_false",
        dest="auto_commits",
        env_var=f"{env_prefix}AUTO_COMMITS",
        help="Disable auto commit of changes",
        default=True,
    )
=======
    parser.add_argument(
        "--auto-commit",
        action="store_true",
        default=True,
        help="Enable auto commit of changes (default: True)",
    )

    parser.add_argument(
        "--no-auto-commit",
        action="store_false",
        dest="auto_commit",
        env_var=f"{env_prefix}AUTO_COMMIT",
        help="Disable auto commit of changes",
    )
>>>>>>> UPDATED
```

Now, you can use `auto_commit: true` in your configuration file without any issues.
2023-05-26 16:31:01 -07:00
Paul Gauthier
69f591a194 Added an environment variable for pretty output. 2023-05-26 16:30:14 -07:00
Paul Gauthier
000fd853d2 aider: Added --pretty argument with store_true action to support pretty: true in conf yaml.
# Context:
USER: does configargparse support bool args like `--thing' and `--no-thing`
ASSISTANT: Yes, `configargparse` supports boolean arguments. You can create a boolean argument with `--thing` and `--no-thing` by using the `action` parameter with values `"store_true"` and `"store_false"` respectively. Here's an example:

```python
parser.add_argument(
    "--thing",
    action="store_true",
    default=False,
    help="Enable thing (default: False)",
)

parser.add_argument(
    "--no-thing",
    action="store_false",
    dest="thing",
    help="Disable thing (default: True)",
)
```

In this example, the `--thing` argument will set the `thing` variable to `True`, and the `--no-thing` argument will set the `thing` variable to `False`.
USER: i have --no-pretty, but if I add `pretty: true` to the conf yaml, it throws error: aider: error: unrecognized arguments: --pretty=False
ASSISTANT: The error occurs because the `--pretty` argument is not explicitly defined in the parser. To fix this, you can add a `--pretty` argument with the `store_true` action. Here's how to modify the `aider/main.py` file:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-pretty",
        action="store_false",
        dest="pretty",
        env_var=f"{env_prefix}PRETTY",
        help="Disable pretty, colorized output",
        default=True,
    )
=======
    parser.add_argument(
        "--pretty",
        action="store_true",
        default=True,
        help="Enable pretty, colorized output (default: True)",
    )

    parser.add_argument(
        "--no-pretty",
        action="store_false",
        dest="pretty",
        env_var=f"{env_prefix}PRETTY",
        help="Disable pretty, colorized output",
    )
>>>>>>> UPDATED
```

Now, you can use `pretty: true` in your configuration file without any issues.
2023-05-26 16:29:29 -07:00
Paul Gauthier
b706c36565 aider: Added --config/-c option to specify the config file and updated the configargparse.ArgumentParser to use the YAMLConfigFileParser.
# Context:
USER: add --config/-c to specify the config file
ASSISTANT: To add the `--config/-c` option to specify the config file, you need to modify the `aider/main.py` file. Update the `configargparse.ArgumentParser` arguments and add a new argument for the `--config/-c` option.

Here's the change:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser = configargparse.ArgumentParser(
        description="aider - chat with GPT about your code",
        add_config_file_help=True,
        default_config_files=default_config_files,
    )
=======
    parser = configargparse.ArgumentParser(
        description="aider - chat with GPT about your code",
        add_config_file_help=True,
        default_config_files=default_config_files,
        config_file_parser_class=configargparse.YAMLConfigFileParser,
    )

    parser.add_argument(
        "-c",
        "--config",
        is_config_file=True,
        metavar="CONFIG_FILE",
        help="Specify the config file (default: search for .aider.conf.yml in git root or home directory)",
    )
>>>>>>> UPDATED
```

This change adds the `--config/-c` option to specify the config file and updates the `configargparse.ArgumentParser` to use the YAMLConfigFileParser for parsing the config file.
2023-05-26 16:23:47 -07:00
Paul Gauthier
ddc97dacf8 aider: Set default values for input and chat history files to be in the git root directory if there is one, otherwise, use the current directory.
# Context:
USER: have the input and chat history files default to be located in the git root, if there is one
ASSISTANT: To change the default location of the input and chat history files to the git root, you need to modify the `aider/main.py` file. Update the default values for `--input-history-file` and `--chat-history-file` arguments.

Here's the change:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--input-history-file",
        metavar="INPUT_HISTORY_FILE",
        env_var=f"{env_prefix}INPUT_HISTORY_FILE",
        default=".aider.input.history",
        help="Specify the chat input history file (default: .aider.input.history)",
    )
    parser.add_argument(
        "--chat-history-file",
        metavar="CHAT_HISTORY_FILE",
        env_var=f"{env_prefix}CHAT_HISTORY_FILE",
        default=".aider.chat.history.md",
        help="Specify the chat history file (default: .aider.chat.history.md)",
    )
=======
    default_input_history_file = os.path.join(git_root, ".aider.input.history") if git_root else ".aider.input.history"
    default_chat_history_file = os.path.join(git_root, ".aider.chat.history.md") if git_root else ".aider.chat.history.md"

    parser.add_argument(
        "--input-history-file",
        metavar="INPUT_HISTORY_FILE",
        env_var=f"{env_prefix}INPUT_HISTORY_FILE",
        default=default_input_history_file,
        help=f"Specify the chat input history file (default: {default_input_history_file})",
    )
    parser.add_argument(
        "--chat-history-file",
        metavar="CHAT_HISTORY_FILE",
        env_var=f"{env_prefix}CHAT_HISTORY_FILE",
        default=default_chat_history_file,
        help=f"Specify the chat history file (default: {default_chat_history_file})",
    )
>>>>>>> UPDATED
```

This change sets the default values for the input and chat history files to be in the git root directory if there is one, otherwise, it will use the current directory.
2023-05-26 16:22:49 -07:00
Paul Gauthier
ec933f4417 updated ctags help 2023-05-26 16:07:05 -07:00
Paul Gauthier
81f3c7ac7e aider: Changed default value of --ctags to None and allowed it to be set to true or false via the command line or config.
# Context:
USER: --ctags should default to None now. it should be possible to set it to true or false via cmd line or config
ASSISTANT: To make the `--ctags` option default to `None` and allow it to be set to `true` or `false` via the command line or config, you need to modify the `aider/main.py` file. Here's the change:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--ctags",
        action="store_true",
        env_var=f"{env_prefix}CTAGS",
        help="Add ctags to the chat to help GPT understand the codebase (default: False)",
        default=False,
    )
=======
    parser.add_argument(
        "--ctags",
        type=lambda x: (str(x).lower() == 'true'),
        nargs='?',
        const=True,
        default=None,
        env_var=f"{env_prefix}CTAGS",
        help="Add ctags to the chat to help GPT understand the codebase (default: None)",
    )
>>>>>>> UPDATED
```

This change will make the `--ctags` option default to `None` and allow it to be set to `true` or `false` via the command line or config.
2023-05-26 16:04:39 -07:00
Paul Gauthier
7fe7f1e279 fix 2023-05-26 15:48:26 -07:00
Paul Gauthier
6b5c93f046 refac 2023-05-26 15:45:26 -07:00
Paul Gauthier
a7aa95b18c aider: Fixed indentation for get_git_root() function and following lines.
# Context:
USER: fix the indentation!
ASSISTANT: I apologize for the indentation issue. Here's the corrected version of the `aider/main.py` file:

```python
aider/main.py
<<<<<<< ORIGINAL
def main(args=None, input=None, output=None):
    if args is None:
        args = sys.argv[1:]

    load_dotenv()
    env_prefix = "AIDER_"
    def get_git_root():
    try:
        repo = git.Repo(search_parent_directories=True)
        return repo.working_tree_dir
    except git.InvalidGitRepositoryError:
        return None

default_config_files = [
    os.path.expanduser("~/.aider.conf.yml"),
]

git_root = get_git_root()
if git_root:
    default_config_files.insert(0, os.path.join(git_root, ".aider.conf.yml"))
=======
def main(args=None, input=None, output=None):
    if args is None:
        args = sys.argv[1:]

    load_dotenv()
    env_prefix = "AIDER_"

    def get_git_root():
        try:
            repo = git.Repo(search_parent_directories=True)
            return repo.working_tree_dir
        except git.InvalidGitRepositoryError:
            return None

    default_config_files = [
        os.path.expanduser("~/.aider.conf.yml"),
    ]

    git_root = get_git_root()
    if git_root:
        default_config_files.insert(0, os.path.join(git_root, ".aider.conf.yml"))
>>>>>>> UPDATED
```

This update fixes the indentation for the `get_git_root()` function and the following lines.
2023-05-26 15:44:49 -07:00
Paul Gauthier
05e976a2b6 aider: Set default configuration file path to prefer Git repository root and fallback to user's home directory.
# Context:
USER: give them both, preferring the git one
ASSISTANT: To set the default configuration file path to prefer the Git repository root and fallback to the user's home directory, update the `aider/main.py` file with the following changes:

```python
aider/main.py
<<<<<<< ORIGINAL
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")
=======
default_config_files = [
    os.path.expanduser("~/.aider.conf.yml"),
]

git_root = get_git_root()
if git_root:
    default_config_files.insert(0, os.path.join(git_root, ".aider.conf.yml"))

>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
parser = configargparse.ArgumentParser(
    description="aider - chat with GPT about your code",
    add_config_file_help=True,
    default_config_files=[default_config_file],
)
=======
parser = configargparse.ArgumentParser(
    description="aider - chat with GPT about your code",
    add_config_file_help=True,
    default_config_files=default_config_files,
)
>>>>>>> UPDATED
```

These changes will set the `default_config_files` list to include both the Git repository root and the user's home directory, with preference given to the Git repository root.
2023-05-26 15:43:49 -07:00
Paul Gauthier
e17265c998 aider: Set default config file path based on whether the current working directory is part of a Git repository or not.
# 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`.
2023-05-26 15:42:44 -07:00
Paul Gauthier
80c195b323 aider: Removed ${env_prefix}XXXX info from help strings in aider/main.py.
# Context:
USER: don't include the ${env_prefix}XXXX info in the help strings. configargparse adds that info to the help message automatically
ASSISTANT: I will remove the `${env_prefix}XXXX` info from the help strings in the `aider/main.py` file.

```python
aider/main.py
<<<<<<< ORIGINAL
        help=(
            "Specify the chat input history file (default: .aider.input.history,"
            f" ${env_prefix}INPUT_HISTORY_FILE)"
        ),
=======
        help="Specify the chat input history file (default: .aider.input.history)",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=(
            "Specify the chat history file (default: .aider.chat.history.md,"
            f" ${env_prefix}CHAT_HISTORY_FILE)"
        ),
=======
        help="Specify the chat history file (default: .aider.chat.history.md)",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=f"Specify the model to use for the main chat (default: gpt-4, ${env_prefix}MODEL)",
=======
        help="Specify the model to use for the main chat (default: gpt-4)",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=f"Disable pretty, colorized output (${env_prefix}PRETTY)",
=======
        help="Disable pretty, colorized output",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=f"Disable auto commit of changes (${env_prefix}AUTO_COMMITS)",
=======
        help="Disable auto commit of changes",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=f"Show diffs when committing changes (default: False, ${env_prefix}SHOW_DIFFS)",
=======
        help="Show diffs when committing changes (default: False)",
>>>>>>> UPDATED

```python
aider/main.py
<<<<<<< ORIGINAL
        help=(
            "Add ctags to the chat to help GPT understand the codebase (default: False,"
            f" ${env_prefix}CTAGS)"
        ),
=======
        help="Add ctags to the chat to help GPT understand the codebase (default: False)",
>>>>>>> UPDATED
2023-05-26 13:07:19 -07:00
Paul Gauthier
17184dd2df added configargparse 2023-05-26 13:04:48 -07:00
Paul Gauthier
c441906a22 aider: Made -v a short option for --verbose.
# Context:
USER: make -v short for --verbose
ASSISTANT: To make `-v` a short option for `--verbose`, you can modify the `aider/main.py` file. Here's the change:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--verbose",
        action="store_true",
        help="Enable verbose output",
        default=False,
    )
=======
    parser.add_argument(
        "-v", "--verbose",
        action="store_true",
        help="Enable verbose output",
        default=False,
    )
>>>>>>> UPDATED
```
2023-05-19 10:57:59 -07:00