Commit graph

1387 commits

Author SHA1 Message Date
Paul Gauthier
dc4bec2986 Fix extracting file path from diff headers in udiff_coder. 2023-12-31 09:42:19 -08:00
Paul Gauthier
4dee2ab2f4 aider: Fix parsing of file paths with spaces in udiff_coder.py.
# Aider chat conversation:

USER: I just tried aider on a project where the folder names have spaces, and it has an issue parsing the diffs.

For example:

```diff
--- PRAW and URS Reddit Scraping/Classify.py
+++ PRAW and URS Reddit Scraping/Classify.py
@@ ... @@
 def classify(filename:str, model: str = 'gpt-3.5-turbo-1106'):
     d = json.load(open(filename))
     for post in d['fetched_posts']:
         messages = copy(MESSAGE_TEMPLATE_CLASSIFY)
...
```

Gives:

```Allow creation of new file PRAW? y```

Which is not correct, a new file is not being created here.

ASSISTANT: To address the issue with folder names containing spaces, we need to update the `find_diffs` function in `udiff_coder.py` to correctly parse file paths that include spaces. The current implementation seems to split the file path on spaces, which leads to incorrect behavior when folder or file names contain spaces.

Here's the diff with the necessary changes:

```diff
--- aider/coders/udiff_coder.py
+++ aider/coders/udiff_coder.py
@@ ... @@
 def find_diffs(content):
     # We can always use triple-quotes, because all the udiff content
     # is prefixed with +/-/space.

     if not content.endswith("\n"):
         content = content + "\n"

     lines = content.splitlines(keepends=True)
     line_num = 0
     edits = []
     while line_num < len(lines):
         while line_num < len(lines):
             line = lines[line_num]
             if line.startswith("```diff"):
                 line_num, these_edits = process_fenced_block(lines, line_num + 1)
                 edits += these_edits
                 break
             line_num += 1

     # For now, just take 1!
     # edits = edits[:1]

     return edits

 def process_fenced_block(lines, start_line_num):
     for line_num in range(start_line_num, len(lines)):
         line = lines[line_num]
         if line.startswith("```"):
             break

     block = lines[start_line_num:line_num]
     block.append("@@ @@")

-    if block[1].startswith("+++ "):
-        fname = block[1].split()[1]
+    if block[1].startswith("--- ") and block[2].startswith("+++ "):
+        # Extract the file path, considering that it might contain spaces
+        fname = block[1][4:].strip()
+        # Ensure that the file path is the same for both the original and new file
+        assert fname == block[2][4:].strip(), "File paths in diff headers do not match"
         block = block[2:]
     else:
         fname = None

     edits = []

     keeper = False
     hunk = []
     op = " "
     for line in block:
         hunk.append(line)
         if len(line) < 2:
             continue
         op = line[0]
         if op in "-+":
             keeper = True
             continue
         if op != "@":
             continue
         if not keeper:
             hunk = []
             continue

         hunk = hunk[:-1]
         edits.append((fname, hunk))
         hunk = []

     return line_num + 1, edits
@@ ... @@
```

This change ensures that the file path is correctly extracted from the diff headers, even if it contains spaces. It also adds an assertion to check that the file paths for the original and new files match, which is a common requirement in diffs.
2023-12-31 09:40:08 -08:00
Christopher Toth
5f65d5d036 Respect --encoding instead of defaulting to UTF-8 when running commands with /run 2023-12-29 13:40:33 -05:00
Christopher Toth
8be1af8721 Use UTF-8 encoding while running commands by default
This fixes issues with /run on Windows which usually manifested as encoding errors.

Sample: Error running command: 'charmap' codec can't decode byte 0x9d in position 298: character maps to <undefined>
2023-12-29 13:31:42 -05:00
Christopher Toth
ba87510db1 Fix issue with path normalization that was causing files to be marked dirty on Windows when they were not 2023-12-29 13:04:46 -05:00
Paul Gauthier
2aca415b31 set version to 0.19.2-dev 2023-12-21 08:59:40 -04:00
Paul Gauthier
0272881bc2 version bump to 0.19.1 2023-12-21 08:59:09 -04:00
Paul Gauthier
f4dc8c776b sssh 2023-12-21 08:58:06 -04:00
Paul Gauthier
3a7998fdc6 set version to 0.19.1-dev 2023-12-19 20:13:09 -06:00
Paul Gauthier
ac280f54b3 version bump to 0.19.0 2023-12-19 20:12:27 -06:00
Paul Gauthier
4c330bcd48 Revert "folk prompting"
This reverts commit 29150bc6f4.
2023-12-19 10:40:46 -08:00
Paul Gauthier
80d6312817 Revert "folk prompting for udiff"
This reverts commit cb55165c81.
2023-12-19 10:40:35 -08:00
Paul Gauthier
cb55165c81 folk prompting for udiff 2023-12-19 10:12:05 -08:00
Paul Gauthier
29150bc6f4 folk prompting 2023-12-19 09:55:49 -08:00
Paul Gauthier
ef2a1f3875 diff with move hint 2023-12-18 19:09:32 -08:00
Paul Gauthier
d9a301c9f8 laziness24-turbo-diff-never2x 2023-12-18 18:49:30 -08:00
Paul Gauthier
308007a8e9 laziness24-turbo-udiff-never2x 2023-12-18 18:43:15 -08:00
Paul Gauthier
f0b60a0052 Add clear instruction on how to make a new file 2023-12-17 15:25:15 -08:00
Paul Gauthier
042a2b8a08 pull the filename from the +++ line 2023-12-17 15:19:34 -08:00
Paul Gauthier
1e38577a3c Announce repo size 2023-12-17 13:01:47 -08:00
Paul Gauthier
0d4b6b6885 added missing files 2023-12-17 13:00:32 -08:00
Paul Gauthier
360846320f announce the edit format 2023-12-17 12:58:48 -08:00
Paul Gauthier
7113a30271 unified diffs 2023-12-17 12:54:34 -08:00
Paul Gauthier
3aa17c46dd set version to 0.18.2-dev 2023-12-14 12:21:50 -08:00
Paul Gauthier
52fdb17e96 version bump to 0.18.1 2023-12-14 12:21:20 -08:00
Paul Gauthier
92f4100c92 be careful about too much convo history, avoid swamping the model with too much context 2023-12-08 12:11:57 -08:00
Paul Gauthier
560759f0c0 show the repomap before the added files 2023-12-08 09:18:03 -08:00
Paul Gauthier
cab7460f94 catch 404s from azure on models.list 2023-12-07 07:44:21 -08:00
Paul Gauthier
ad092152d0 Revert "max_apply_update_errors = 1 for quick benchmark"
This reverts commit fd71b6a4a5.
2023-12-07 07:43:06 -08:00
Paul Gauthier
fd71b6a4a5 max_apply_update_errors = 1 for quick benchmark 2023-12-06 14:35:57 -08:00
Paul Gauthier
ff96369ed6 cleanup 2023-12-06 14:09:32 -08:00
Paul Gauthier
922a56b194 Merge branch 'main' into openai-upgrade 2023-12-06 09:26:05 -08:00
Paul Gauthier
b85ed45504 add deployment_id to AzureOpenAI call per @itlackey 2023-12-06 09:22:04 -08:00
Paul Gauthier
57ab2cc9da Revert "implement deployment id"
This reverts commit b107db98fa.
2023-12-06 09:20:53 -08:00
Your Name
4692a689fe Improvements: flag -f (not -mf); unitest improvements. 2023-12-05 23:55:10 +01:00
Your Name
743179a4bd aider: Add --message-file flag to specify a file containing the message to send GPT, process reply, then exit (disables chat mode).
# Aider chat conversation:

USER: Am I correct that currently if one wants to launch aider from commandline , the way to go is to use --message flag that allows providing prompt as command line parameter?

ASSISTANT: Yes, you are correct. The `--message` or `-m` flag can be used to provide a single message to send to GPT, process the reply, and then exit the application. This flag disables the interactive chat mode and is suitable for scripting or when you want to issue a single command without entering the interactive chat session.

USER: Is there a way to run prompt from command line like `--message` or `-m` however by providing prompt as file ?

ASSISTANT: Currently, there is no direct command-line option in the `aider` tool to provide a prompt from a file. The `--message` or `-m` flag only accepts a string as an argument. If you want to provide a prompt from a file, you would need to read the content of the file and pass it as a string to the `--message` flag.

However, this functionality can be added to the `aider` tool by implementing a new command-line option that reads the content of a specified file and uses it as the prompt message.

Would you like me to implement this feature for you? If so, please provide the `aider/main.py` file, and I will suggest the necessary changes.

USER: How would you name such flag to match current convention and how would you describe it?

ASSISTANT: Following the current naming convention used in the `aider` tool, a suitable name for the flag that allows providing a prompt from a file could be `--message-file` or `-mf`. This flag would be described as:

"Specify a file containing the message to send to GPT, process the reply, then exit (disables chat mode)."

This description aligns with the existing `--message` flag while clearly indicating that the input is expected to be a file containing the message rather than a direct string input.

USER: could you please add such flag?

ASSISTANT: To add the `--message-file` flag to the `aider` tool, we need to modify the `aider/main.py` file. Please add the `aider/main.py` file to the chat so I can provide you with the necessary changes.

USER: could you please add such flag?

ASSISTANT: To add the `--message-file` flag to the `aider` tool, we need to modify the `aider/main.py` file. Please add the `aider/main.py` file to the chat so I can provide you with the necessary changes.

USER: could you please add such flag?

ASSISTANT: To add the `--message-file` flag to the `aider` tool, we need to modify the `aider/main.py` file. Please add the `aider/main.py` file to the chat so I can provide you with the necessary changes.

USER: I added these *read-write* files: /home/gw-t490/github/VariousForks/aider-patching-for-pull-requests/aider/main.py

ASSISTANT: Great, now that you've added the `aider/main.py` file, I will provide you with the necessary changes to implement the `--message-file` flag.

We will need to:

1. Add a new command-line argument `--message-file` to the argument parser.
2. Read the content of the file specified by `--message-file` and pass it to the `coder.run()` method.

Here are the *SEARCH/REPLACE* blocks for the changes:

aider/main.py
```python
<<<<<<< SEARCH
    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.add_argument(
        "--message",
        "--msg",
        "-m",
        metavar="COMMAND",
        help="Specify a single message to send GPT, process reply then exit (disables chat mode)",
    )
    other_group.add_argument(
        "--message-file",
        "-mf",
        metavar="MESSAGE_FILE",
        help="Specify a file containing the message to send GPT, process reply, then exit (disables chat mode)",
    )
>>>>>>> REPLACE
```

aider/main.py
```python
<<<<<<< SEARCH
    if args.message:
        io.tool_output()
        coder.run(with_message=args.message)
    else:
        coder.run()
=======
    if args.message:
        io.tool_output()
        coder.run(with_message=args.message)
    elif args.message_file:
        try:
            with open(args.message_file, 'r', encoding='utf-8') as file:
                message_from_file = file.read()
            io.tool_output()
            coder.run(with_message=message_from_file)
        except FileNotFoundError:
            io.tool_error(f"Message file not found: {args.message_file}")
            return 1
        except IOError as e:
            io.tool_error(f"Error reading message file: {e}")
            return 1
    else:
        coder.run()
>>>>>>> REPLACE
```

These changes will add the `--message-file` flag to the argument parser and handle the case where a message file is provided. If the file is found and can be read, its content will be used as the message to send to GPT. If there is an error reading the file, an error message will be displayed, and the program will exit with a status code of 1.
2023-12-05 23:55:10 +01:00
Paul Gauthier
b107db98fa implement deployment id 2023-12-05 11:31:17 -08:00
Paul Gauthier
bf03f43b44 fixed benchmark 2023-12-05 11:21:11 -08:00
Paul Gauthier
5b21d5704a fixed test_sendchat 2023-12-05 11:08:14 -08:00
Paul Gauthier
2ed0c8fb66 fixed test_repo 2023-12-05 10:58:44 -08:00
Paul Gauthier
23e6c4ee55 fixed test_coder 2023-12-05 10:51:50 -08:00
Paul Gauthier
fb07b784f6 move to gpt-3.5-turbo-1106 2023-12-05 10:28:27 -08:00
Paul Gauthier
6ebc142377 roughed in openai 1.x 2023-12-05 07:37:05 -08:00
Your Name
015ffa13e1 Fixes #374 - logging add_to_input_history if args.message is used.
Fixes https://github.com/paul-gauthier/aider/issues/374
2023-11-30 13:19:54 +01:00
Paul Gauthier
ec95cd2d76 allow longer conversation histories for models with larger context windows 2023-11-27 10:55:36 -08:00
Paul Gauthier
e771adbff5 Refactor model_ids to be sorted in check_model_availability function. 2023-11-21 14:08:17 -08:00
Paul Gauthier
3d65217bed set version to 0.18.1-dev 2023-11-17 15:51:31 -08:00
Paul Gauthier
93f45a6d6b version bump to 0.18.0 2023-11-17 15:51:07 -08:00
Paul Gauthier
bf6cd8294e handle submodules (or other dirs) which are git tracked #336 2023-11-15 13:34:29 -08:00
Paul Gauthier
5d0e92296a number -> numbered 2023-11-15 13:06:58 -08:00