Commit graph

531 commits

Author SHA1 Message Date
Paul Gauthier
084132a5f8 refactor initialization of openai into main 2023-07-11 15:06:50 -07:00
Paul Gauthier
fa3283802a aider: Add --openai-api-type, --openai-api-version, and openai-api-deployment-id args, pass them into coder.create.
# Aider chat conversation:

USER: add --openai-api-type --openai-api-version and openai-api-deployment-id args. pass them into coder.create

ASSISTANT: To add the `--openai-api-type`, `--openai-api-version`, and `--openai-api-deployment-id` arguments and pass them into `coder.create`, we need to modify the `aider/main.py` file.

Here are the steps:

1. Add the new arguments to the argument parser in the `main` function.
2. Pass these arguments to the `coder.create` function.

Here are the changes:

```python
aider/main.py
<<<<<<< ORIGINAL
    ##########
    model_group = parser.add_argument_group("Advanced Model Settings")
    model_group.add_argument(
        "--openai-api-base",
        metavar="OPENAI_API_BASE",
        default="https://api.openai.com/v1",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )
=======
    ##########
    model_group = parser.add_argument_group("Advanced Model Settings")
    model_group.add_argument(
        "--openai-api-base",
        metavar="OPENAI_API_BASE",
        default="https://api.openai.com/v1",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )
    model_group.add_argument(
        "--openai-api-type",
        metavar="OPENAI_API_TYPE",
        help="Specify the OpenAI API type",
    )
    model_group.add_argument(
        "--openai-api-version",
        metavar="OPENAI_API_VERSION",
        help="Specify the OpenAI API version",
    )
    model_group.add_argument(
        "--openai-api-deployment-id",
        metavar="OPENAI_API_DEPLOYMENT_ID",
        help="Specify the OpenAI API deployment ID",
    )
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder.create(
        main_model,
        args.edit_format,
        io,
        args.openai_api_key,
        args.openai_api_base,
        ##
        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,
        assistant_output_color=args.assistant_output_color,
        code_theme=args.code_theme,
        stream=args.stream,
        use_git=args.git,
    )
=======
    coder = Coder.create(
        main_model,
        args.edit_format,
        io,
        args.openai_api_key,
        args.openai_api_base,
        ##
        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,
        assistant_output_color=args.assistant_output_color,
        code_theme=args.code_theme,
        stream=args.stream,
        use_git=args.git,
        openai_api_type=args.openai_api_type,
        openai_api_version=args.openai_api_version,
        openai_api_deployment_id=args.openai_api_deployment_id,
    )
>>>>>>> UPDATED
```

Please note that these changes assume that the `Coder.create` method and the `Coder` class are prepared to receive and handle these new arguments. If they are not, additional changes will be needed in the `Coder` class and its subclasses.
2023-07-11 14:56:36 -07:00
Paul Gauthier
39912fdc09 more help 2023-07-10 07:23:17 -07:00
Paul Gauthier
2e437893d4 aider: Replace os.path.expanduser("~/.gitconfig") with str(Path.home() / ".gitconfig") in main function.
# Aider chat conversation:

USER: nice. use Path not os `expanduser`

ASSISTANT: To replace `os.path.expanduser` with `Path`, we need to modify the `main` function in the `aider/main.py` file. Here is the change:

```python
aider/main.py
<<<<<<< ORIGINAL
            global_git_config = git.GitConfigParser([os.path.expanduser("~/.gitconfig")], read_only=True)
=======
            global_git_config = git.GitConfigParser([str(Path.home() / ".gitconfig")], read_only=True)
>>>>>>> UPDATED
```

This change will make the code use `Path.home()` to get the home directory instead of `os.path.expanduser("~")`. The `Path` object is then converted to a string before being passed to `git.GitConfigParser`.
2023-07-08 18:42:00 -07:00
Paul Gauthier
3a6112377f aider: Change the code to check the global git configuration for the user name and email when creating a repo.
# Aider chat conversation:

USER: i have a global git name and email, but the git create code here isn't noticing and is setting the example name/email when it makes a repo

ASSISTANT: To fix this, we need to modify the `main` function in the `aider/main.py` file. Specifically, we need to change the way it checks for the global git name and email. Instead of checking the local git configuration, we should check the global git configuration.

Here is the change:

```python
aider/main.py
<<<<<<< ORIGINAL
            with repo.config_writer() as git_config:
                if not git_config.has_option("user", "name"):
                    git_config.set_value("user", "name", "Your Name")
                    io.tool_error('Update git name with: git config --global user.name "Your Name"')
                if not git_config.has_option("user", "email"):
                    git_config.set_value("user", "email", "you@example.com")
                    io.tool_error(
                        'Update git email with: git config --global user.email "you@example.com"'
                    )
=======
            global_git_config = git.GitConfigParser([os.path.expanduser("~/.gitconfig")], read_only=True)
            with repo.config_writer() as git_config:
                if not global_git_config.has_option("user", "name"):
                    git_config.set_value("user", "name", "Your Name")
                    io.tool_error('Update git name with: git config --global user.name "Your Name"')
                if not global_git_config.has_option("user", "email"):
                    git_config.set_value("user", "email", "you@example.com")
                    io.tool_error(
                        'Update git email with: git config --global user.email "you@example.com"'
                    )
>>>>>>> UPDATED
```

This change will make the code check the global git configuration (`~/.gitconfig`) for the user name and email. If they are not found, it will set the local git configuration with the example name and email and display a message to the user to update their global git configuration.
2023-07-08 18:41:18 -07:00
Paul Gauthier
f6b0d2b225 reorder args 2023-07-08 12:01:11 -07:00
Paul Gauthier
b65d0d2af3 reorder args 2023-07-08 11:55:59 -07:00
Paul Gauthier
e83e9c6ab0 Added --light-mode and made default colors acceptable for dark or light bgs 2023-07-08 11:02:31 -07:00
Paul Gauthier
8cb50a8a2e Added error color to dark mode 2023-07-08 10:50:01 -07:00
Paul Gauthier
7c1364b942 added --dark-mode 2023-07-08 08:56:05 -07:00
Paul Gauthier
4e36584392 more args re-org 2023-07-08 07:16:10 -07:00
Paul Gauthier
1ec5782200 aider: Added --apply argument to the 'Other Settings' group in the help message.
# Context:
USER: you forgot --apply ?
ASSISTANT: You're right, I apologize for missing that. The `--apply` argument should be grouped under 'Other Settings'. Here's the updated code:

```python
aider/main.py
<<<<<<< ORIGINAL
    other_group = parser.add_argument_group('Other Settings')
    other_group.add_argument(
        "--dry-run",
        action="store_true",
        help="Perform a dry run without applying changes (default: False)",
        default=False,
    )
    other_group.add_argument(
        "--show-diffs",
        action="store_true",
        help="Show diffs when committing changes (default: False)",
        default=False,
    )
    other_group.add_argument(
        "--map-tokens",
        type=int,
        default=1024,
        help="Max number of tokens to use for repo map, use 0 to disable (default: 1024)",
    )
    other_group.add_argument(
        "--yes",
        action="store_true",
        help="Always say yes to every confirmation",
        default=None,
    )
    other_group.add_argument(
        "-v",
        "--verbose",
        action="store_true",
        help="Enable verbose output",
        default=False,
    )
    other_group.add_argument(
        "--message",
        "--msg",
        "-m",
        metavar="COMMAND",
        help="Specify a single message to send GPT, process reply then exit (disables chat mode)",
    )
=======
    other_group = parser.add_argument_group('Other Settings')
    other_group.add_argument(
        "--apply",
        metavar="FILE",
        help="Apply the changes from the given file instead of running the chat (debug)",
    )
    other_group.add_argument(
        "--dry-run",
        action="store_true",
        help="Perform a dry run without applying changes (default: False)",
        default=False,
    )
    other_group.add_argument(
        "--show-diffs",
        action="store_true",
        help="Show diffs when committing changes (default: False)",
        default=False,
    )
    other_group.add_argument(
        "--map-tokens",
        type=int,
        default=1024,
        help="Max number of tokens to use for repo map, use 0 to disable (default: 1024)",
    )
    other_group.add_argument(
        "--yes",
        action="store_true",
        help="Always say yes to every confirmation",
        default=None,
    )
    other_group.add_argument(
        "-v",
        "--verbose",
        action="store_true",
        help="Enable verbose output",
        default=False,
    )
    other_group.add_argument(
        "--message",
        "--msg",
        "-m",
        metavar="COMMAND",
        help="Specify a single message to send GPT, process reply then exit (disables chat mode)",
    )
>>>>>>> UPDATED
```

This will add the `--apply` argument to the 'Other Settings' group in the help message.
2023-07-08 07:08:26 -07:00
Paul Gauthier
5590bbd6b8 aider: work in progress
# Context:
USER: does `configargparse` have a way to group the args into sections so they display grouped in --help?
ASSISTANT: Yes, `configargparse` supports argument grouping. This is done using the `add_argument_group` method of the `ArgumentParser` object. This method creates a new group of arguments and any arguments added to this group will be displayed together in the help message.

Here's an example of how you can group arguments:

```python
group = parser.add_argument_group('group name')
group.add_argument('--arg1')
group.add_argument('--arg2')
```

In the help message, `arg1` and `arg2` will be displayed under the section 'group name'.
USER: can you update the code to group them into a few sensible groups?
ASSISTANT: Sure, I can group the arguments in the `main` function of the `aider/main.py` file into several groups. Here's how I would do it:

1. General arguments: version, config, files
2. History files: input-history-file, chat-history-file
3. Model settings: model, edit-format
4. Output settings: pretty, no-pretty, no-stream, user-input-color, tool-output-color, tool-error-color, assistant-output-color, code-theme
5. Git settings: no-git, auto-commits, no-auto-commits, dirty-commits, no-dirty-commits
6. OpenAI settings: openai-api-key, openai-api-base
7. Other settings: dry-run, show-diffs, map-tokens, yes, verbose, message

Here's the updated code:

```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.add_argument(
        "--version",
        action="version",
        version=f"%(prog)s {__version__}",
        help="Show the version number and exit",
    )

    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, cwd"
            " or home directory)"
        ),
    )

    parser.add_argument(
        "files",
        metavar="FILE",
        nargs="*",
        help="a list of source code files (optional)",
    )
    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",
        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",
        default=default_chat_history_file,
        help=f"Specify the chat history file (default: {default_chat_history_file})",
    )
    parser.add_argument(
        "--model",
        metavar="MODEL",
        default=models.GPT4.name,
        help=f"Specify the model to use for the main chat (default: {models.GPT4.name})",
    )
    parser.add_argument(
        "-3",
        action="store_const",
        dest="model",
        const=models.GPT35_16k.name,
        help=f"Use {models.GPT35_16k.name} model for the main chat (gpt-4 is better)",
    )
    parser.add_argument(
        "--edit-format",
        metavar="EDIT_FORMAT",
        default=None,
        help="Specify what edit format GPT should use (default depends on model)",
    )
    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(
        "--no-stream",
        action="store_false",
        dest="stream",
        default=True,
        help="Disable streaming responses",
    )
    parser.add_argument(
        "--no-git",
        action="store_false",
        dest="git",
        default=True,
        help="Do not look for a git repo",
    )
    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)",
    )
    parser.add_argument(
        "--assistant-output-color",
        default="blue",
        help="Set the color for assistant output (default: blue)",
    )
    parser.add_argument(
        "--code-theme",
        default="default",
        help=(
            "Set the markdown code theme (default: default, other options include monokai,"
            " solarized-dark, solarized-light)"
        ),
    )
    parser.add_argument(
        "--apply",
        metavar="FILE",
        help="Apply the changes from the given file instead of running the chat (debug)",
    )
    parser.add_argument(
        "--auto-commits",
        action="store_true",
        dest="auto_commits",
        default=True,
        help="Enable auto commit of GPT changes (default: True)",
    )

    parser.add_argument(
        "--no-auto-commits",
        action="store_false",
        dest="auto_commits",
        help="Disable auto commit of GPT changes (implies --no-dirty-commits)",
    )
    parser.add_argument(
        "--dirty-commits",
        action="store_true",
        dest="dirty_commits",
        help="Enable commits when repo is found dirty",
        default=True,
    )
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable commits when repo is found dirty",
    )
    parser.add_argument(
        "--encoding",
        default="utf-8",
        help="Specify the encoding to use when reading files (default: utf-8)",
    )
    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",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )
    parser.add_argument(
        "--dry-run",
        action="store_true",
        help="Perform a dry run without applying changes (default: False)",
        default=False,
    )
    parser.add_argument(
        "--show-diffs",
        action="store_true",
        help="Show diffs when committing changes (default: False)",
        default=False,
    )
    parser.add_argument(
        "--map-tokens",
        type=int,
        default=1024,
        help="Max number of tokens to use for repo map, use 0 to disable (default: 1024)",
    )
    parser.add_argument(
        "--yes",
        action="store_true",
        help="Always say yes to every confirmation",
        default=None,
    )
    parser.add_argument(
        "-v",
        "--verbose",
        action="store_true",
        help="Enable verbose output",
        default=False,
    )
    parser.add_argument(
        "--message",
        "--msg",
        "-m",
        metavar="COMMAND",
        help="Specify a single message to send GPT, process reply then exit (disables chat mode)",
    )
=======
    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_",
    )

    general_group = parser.add_argument_group('General')
    general_group.add_argument(
        "--version",
        action="version",
        version=f"%(prog)s {__version__}",
        help="Show the version number and exit",
    )
    general_group.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, cwd"
            " or home directory)"
        ),
    )
    general_group.add_argument(
        "files",
        metavar="FILE",
        nargs="*",
        help="a list of source code files (optional)",
    )

    history_group = parser.add_argument_group('History Files')
    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"
    )
    history_group.add_argument(
        "--input-history-file",
        metavar="INPUT_HISTORY_FILE",
        default=default_input_history_file,
        help=f"Specify the chat input history file (default: {default_input_history_file})",
    )
    history_group.add_argument(
        "--chat-history-file",
        metavar="CHAT_HISTORY_FILE",
        default=default_chat_history_file,
        help=f"Specify the chat history file (default: {default_chat_history_file})",
    )

    model_group = parser.add_argument_group('Model Settings')
    model_group.add_argument(
        "--model",
        metavar="MODEL",
        default=models.GPT4.name,
        help=f"Specify the model to use for the main chat (default: {models.GPT4.name})",
    )
    model_group.add_argument(
        "-3",
        action="store_const",
        dest="model",
        const=models.GPT35_16k.name,
        help=f"Use {models.GPT35_16k.name} model for the main chat (gpt-4 is better)",
    )
    model_group.add_argument(
        "--edit-format",
        metavar="EDIT_FORMAT",
        default=None,
        help="Specify what edit format GPT should use (default depends on model)",
    )

    output_group = parser.add_argument_group('Output Settings')
    output_group.add_argument(
        "--pretty",
        action="store_true",
        default=True,
        help="Enable pretty, colorized output (default: True)",
    )
    output_group.add_argument(
        "--no-pretty",
        action="store_false",
        dest="pretty",
        help="Disable pretty, colorized output",
    )
    output_group.add_argument(
        "--no-stream",
        action="store_false",
        dest="stream",
        default=True,
        help="Disable streaming responses",
    )
    output_group.add_argument(
        "--user-input-color",
        default="green",
        help="Set the color for user input (default: green)",
    )
    output_group.add_argument(
        "--tool-output-color",
        default=None,
        help="Set the color for tool output (default: None)",
    )
    output_group.add_argument(
        "--tool-error-color",
        default="red",
        help="Set the color for tool error messages (default: red)",
    )
    output_group.add_argument(
        "--assistant-output-color",
        default="blue",
        help="Set the color for assistant output (default: blue)",
    )
    output_group.add_argument(
        "--code-theme",
        default="default",
        help=(
            "Set the markdown code theme (default: default, other options include monokai,"
            " solarized-dark, solarized-light)"
        ),
    )

    git_group = parser.add_argument_group('Git Settings')
    git_group.add_argument(
        "--no-git",
        action="store_false",
        dest="git",
        default=True,
        help="Do not look for a git repo",
    )
    git_group.add_argument(
        "--auto-commits",
        action="store_true",
        dest="auto_commits",
        default=True,
        help="Enable auto commit of GPT changes (default: True)",
    )
    git_group.add_argument(
        "--no-auto-commits",
        action="store_false",
        dest="auto_commits",
        help="Disable auto commit of GPT changes (implies --no-dirty-commits)",
    )
    git_group.add_argument(
        "--dirty-commits",
        action="store_true",
        dest="dirty_commits",
        help="Enable commits when repo is found dirty",
        default=True,
    )
    git_group.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable commits when repo is found dirty",
    )

    openai_group = parser.add_argument_group('OpenAI Settings')
    openai_group.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
        env_var="OPENAI_API_KEY",
    )
    openai_group.add_argument(
        "--openai-api-base",
        metavar="OPENAI_API_BASE",
        default="https://api.openai.com/v1",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )

    other_group = parser.add_argument_group('Other Settings')
    other_group.add_argument(
        "--dry-run",
        action="store_true",
        help="Perform a dry run without applying changes (default: False)",
        default=False,
    )
    other_group.add_argument(
        "--show-diffs",
        action="store_true",
        help="Show diffs when committing changes (default: False)",
        default=False,
    )
    other_group.add_argument(
        "--map-tokens",
        type=int,
        default=1024,
        help="Max number of tokens to use for repo map, use 0 to disable (default: 1024)",
    )
    other_group.add_argument(
        "--yes",
        action="store_true",
        help="Always say yes to every confirmation",
        default=None,
    )
    other_group.add_argument(
        "-v",
        "--verbose",
        action="store_true",
        help="Enable verbose output",
        default=False,
    )
    other_group.add_argument(
        "--message",
        "--msg",
        "-m",
        metavar="COMMAND",
        help="Specify a single message to send GPT, process reply then exit (disables chat mode)",
    )
>>>>>>> UPDATED
```

This will make the help message more organized and easier to read.
2023-07-08 07:06:30 -07:00
Paul Gauthier
031c2bc34b provide default git name/email; fix tests 2023-07-07 15:02:56 -07:00
Paul Gauthier
451929f2ca aider: Added code to check if name and email are set in git configuration and set example values if not.
# Context:
USER: can i pass email and name to repo.init ?
ASSISTANT: Yes, you can pass the `name` and `email` to `git.Repo.init()`, but not directly. The `git.Repo.init()` function initializes a new repository, but it doesn't handle the configuration of user details.

To set the `name` and `email`, you need to modify the configuration of the repository after it has been initialized. This can be done using the `git.config_writer()` function.

Here's how you can do it:

```python
repo = git.Repo.init(path)
with repo.config_writer() as git_config:
    git_config.set_value("user", "name", "Your Name")
    git_config.set_value("user", "email", "your.email@example.com")
```

In the context of your `aider/main.py` file, you can add these changes after the repository initialization. Here's the modification:

```python
aider/main.py
<<<<<<< ORIGINAL
    if not git_root and args.git:
        if io.confirm_ask("
^C KeyboardInterrupt
USER: can up check if they are set first, and if not put in example values?
ASSISTANT: Sure, you can check if the `name` and `email` are already set in the git configuration before setting the example values. Here's how you can do it:

```python
repo = git.Repo.init(path)
with repo.config_writer() as git_config:
    if not git_config.has_option("user", "name"):
        git_config.set_value("user", "name", "Example Name")
    if not git_config.has_option("user", "email"):
        git_config.set_value("user", "email", "example.email@example.com")
```

In the context of your `aider/main.py` file, you can add these changes after the repository initialization. Here's the modification:

```python
aider/main.py
<<<<<<< ORIGINAL
    if not git_root and args.git:
        if io.confirm_ask("No git repo found, create one to track GPT's changes (recommended)?"):
            git.Repo.init(os.getcwd())
            io.tool_output("Git repository created in the current working directory.")
=======
    if not git_root and args.git:
        if io.confirm_ask("No git repo found, create one to track GPT's changes (recommended)?"):
            repo = git.Repo.init(os.getcwd())
            with repo.config_writer() as git_config:
                if not git_config.has_option("user", "name"):
                    git_config.set_value("user", "name", "Example Name")
                if not git_config.has_option("user", "email"):
                    git_config.set_value("user", "email", "example.email@example.com")
            io.tool_output("Git repository created in the current working directory.")
>>>>>>> UPDATED
```

This code will check if the `name` and `email` are already set in the git configuration. If they are not set, it will set them to "Example Name" and "example.email@example.com" respectively.
2023-07-07 13:45:57 -07:00
Paul Gauthier
63d98b30d8 honor --no-git 2023-07-07 11:13:52 -07:00
Paul Gauthier
181062dc06 confirm_ask 2023-07-07 11:12:36 -07:00
Paul Gauthier
95c1aa2f2e aider: Initialized a new git repository in the current working directory and output a message to inform the user.
# Context:
USER: do the TODO
ASSISTANT: To clarify, are you referring to the TODO comment in the `main.py` file? The comment is:

```python
    if not git_root:
        if io.ask_confirm("Create git repo (recommended)?"):
            # TODO: create at cwd
            pass
```

It seems like the task is to create a git repository in the current working directory if one does not already exist. Is that correct?
USER: yes
ASSISTANT: To create a git repository in the current working directory, we need to use the `git` module's `Repo.init` method. Here's how to modify the `main.py` file:

```python
aider/main.py
<<<<<<< ORIGINAL
    if not git_root:
        if io.ask_confirm("Create git repo (recommended)?"):
            # TODO: create at cwd
            pass
=======
    if not git_root:
        if io.ask_confirm("Create git repo (recommended)?"):
            git.Repo.init(os.getcwd())
            io.tool_output("Git repository created in the current working directory.")
>>>>>>> UPDATED
```

This change will initialize a new git repository in the current working directory when the user confirms. It also outputs a message to inform the user that the repository has been created.
2023-07-07 11:10:25 -07:00
Paul Gauthier
b75cfaac28 Look for conf yml in cwd, gitroot and homedir 2023-07-07 11:08:34 -07:00
Paul Gauthier
1654ee422f add test for conf yml 2023-07-07 09:07:02 -07:00
Paul Gauthier
4ee5c49a04 have io.write_text handle dry_run 2023-07-05 21:20:22 -07:00
Paul Gauthier
7542449629 refactor to use io.read_text 2023-07-05 20:49:04 -07:00
Paul Gauthier
5f9947a727 aider: Add read_text function to InputOutput class and --encoding command-line switch.
# Context:
USER: Add a read_text function to the InputOutput class. It takes the file name as argument, and returns the text for that file. Internally, if we get a Unicode error or a FileNotFound error, it prints ToolErrorOutput to notify the user, and then returns None. Add a command-line switch, and dash-dash encoding, which defaults to UTF-8. That's the encoding which will be used by the read_text function.

ASSISTANT: To implement the requested changes, we need to modify the following files:

1. `aider/io.py`: To add the `read_text` function to the `InputOutput` class.
2. `aider/main.py`: To add the `--encoding` command-line switch.

Let's start with the changes to `aider/io.py`:

```python
aider/io.py
<<<<<<< ORIGINAL
class InputOutput:
    num_error_outputs = 0
    num_user_asks = 0

    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
    ):
        no_color = os.environ.get("NO_COLOR")
        if no_color is not None and no_color != "":
            pretty = False

        self.user_input_color = user_input_color if pretty else None
        self.tool_output_color = tool_output_color if pretty else None
        self.tool_error_color = tool_error_color if pretty else None

        self.input = input
        self.output = output

        self.pretty = pretty
        if self.output:
            self.pretty = False

        self.yes = yes

        self.input_history_file = input_history_file
        if chat_history_file is not None:
            self.chat_history_file = Path(chat_history_file)
        else:
            self.chat_history_file = None

        if pretty:
            self.console = Console()
        else:
            self.console = Console(force_terminal=False, no_color=True)

        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.append_chat_history(f"\n# aider chat started at {current_time}\n\n")
=======
class InputOutput:
    num_error_outputs = 0
    num_user_asks = 0

    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
        encoding="utf-8",
    ):
        no_color = os.environ.get("NO_COLOR")
        if no_color is not None and no_color != "":
            pretty = False

        self.user_input_color = user_input_color if pretty else None
        self.tool_output_color = tool_output_color if pretty else None
        self.tool_error_color = tool_error_color if pretty else None

        self.input = input
        self.output = output

        self.pretty = pretty
        if self.output:
            self.pretty = False

        self.yes = yes

        self.input_history_file = input_history_file
        if chat_history_file is not None:
            self.chat_history_file = Path(chat_history_file)
        else:
            self.chat_history_file = None

        self.encoding = encoding

        if pretty:
            self.console = Console()
        else:
            self.console = Console(force_terminal=False, no_color=True)

        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.append_chat_history(f"\n# aider chat started at {current_time}\n\n")

    def read_text(self, filename):
        try:
            with open(filename, "r", encoding=self.encoding) as f:
                return f.read()
        except (FileNotFoundError, UnicodeError) as e:
            self.tool_error(str(e))
            return None
>>>>>>> UPDATED
```

Now, let's add the `--encoding` command-line switch to `aider/main.py`:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable commits when repo is found dirty",
    )
    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",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )
=======
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable commits when repo is found dirty",
    )
    parser.add_argument(
        "--encoding",
        default="utf-8",
        help="Specify the encoding to use when reading files (default: utf-8)",
    )
    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",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )
>>>>>>> UPDATED
```

These changes should implement the requested functionality. Please review and let me know if any further changes are needed.
2023-07-05 19:33:59 -07:00
Paul Gauthier
ae5b4057e8 Merge remote-tracking branch 'origin/main' 2023-07-05 13:39:49 -07:00
Paul Gauthier
77a230f005 improved windows instructions, error message 2023-07-05 10:27:07 -07:00
kwmiebach
b80c83c6cb Add program argument for syntax highlighting theme.
The source code output in the chat will be colored in the given
color scheme. Syntax highlighting is powered by pygments, which
supports many styles out of the box. For example:

- default (the default)
- dracula
- emacs
- github-dark
- monokai
- vim
- solarized-dark
- solarized-light

See https://pygments.org/styles/
2023-07-05 00:29:40 +02:00
Paul Gauthier
a521d4a3ce Renamed --cmd to --msg 2023-06-24 13:50:45 -07:00
Paul Gauthier
39c1aeac9e Renamed --cmd to --msg 2023-06-24 13:49:27 -07:00
Paul Gauthier
146efe3278 Allow yes to be False 2023-06-24 13:38:54 -07:00
Paul Gauthier
b5b0c1cbc2 Added --no-git 2023-06-23 13:44:24 -07:00
Paul Gauthier
d2b9cb9e98 added --no-stream 2023-06-23 13:29:09 -07:00
Paul Gauthier
7e18fb7f5f Help for --cmd 2023-06-23 11:03:33 -07:00
Paul Gauthier
eceef49947 Use --cmd as short form 2023-06-23 11:02:19 -07:00
Paul Gauthier
a77e4419cc aider: Added a --command,-c option to specify the command to pass to coder.run().
# Context:
USER: add a --command,-c option which takes a string to pass to coder.run(with_message=args.command)
ASSISTANT: No changes are needed.
2023-06-23 11:01:05 -07:00
Paul Gauthier
75e84017b3 Added manual control of --edit-format 2023-06-21 12:12:12 -07:00
Paul Gauthier
c379cf3286 auto select edit mode 2023-06-20 17:13:26 -07:00
Paul Gauthier
02c9a30c45 refac 2023-06-20 16:47:37 -07:00
Paul Gauthier
602094aca3 refac 2023-06-20 16:35:56 -07:00
Paul Gauthier
d76bf0b8b0 added --assistant-output-color 2023-06-19 15:59:47 -07:00
Paul Gauthier
8fc4f32117 Changed version flag to use long option. 2023-06-17 07:06:33 -07:00
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