Commit graph

173 commits

Author SHA1 Message Date
Paul Gauthier
5756812938 Adopt subprocess.run(shell=True) for /git 2023-10-18 12:37:39 -07:00
paul-gauthier
44aa5c6d63
Merge pull request #272 from alexanderkjeldaas/ak/run-shell
fix: /run (cd ..; ls) should work
2023-10-18 12:35:17 -07:00
Paul Gauthier
82dc995a04 Added helpful suggestions to /undo and /diff errors 2023-10-18 11:38:54 -07:00
Paul Gauthier
22eb344192 disable /voice if import soundfile failes #274 2023-10-12 07:00:51 -07:00
Alexander Kjeldaas
67c5bb5985 aider: Remove the use of shlex.split(args) in cmd_run method.
# Aider chat conversation:

USER: what does shlex.split(args) do?

ASSISTANT: The `shlex.split(args)` function is a method in Python's `shlex` module. It splits the string `args` into a list of substrings, using shell-like syntax. This means it handles quotes and backslashes like a Unix shell would.

For example, if `args` is a string like `"command -option 'argument with spaces'"`, `shlex.split(args)` would return the list `['command', '-option', 'argument with spaces']`.

This is useful when you want to pass a command line command as a string to a function like `subprocess.run()`, which expects a list of arguments.

USER: remove the use of shlex in cmd_run

ASSISTANT: To remove the use of `shlex.split(args)` in the `cmd_run` method, we need to modify the `aider/commands.py` file. Here's the change:

<source>python
aider/commands.py
<<<<<<< HEAD
            parsed_args = shlex.split(args)
            result = subprocess.run(
                parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, shell=True
            )
=======
            result = subprocess.run(
                args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, shell=True
            )
>>>>>>> updated
</source>
2023-10-01 19:51:38 +02:00
Alexander Kjeldaas
b2eed01051 aider: Add shell=True to subprocess.run in cmd_run.
# Aider chat conversation:

USER: add `shell=True` to subprocess.run in cmd_run

ASSISTANT: To add `shell=True` to the `subprocess.run` call in the `cmd_run` method, we need to modify the `aider/commands.py` file. Here's the change:

<source>python
aider/commands.py
<<<<<<< HEAD
            result = subprocess.run(
                parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
            )
=======
            result = subprocess.run(
                parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, shell=True
            )
>>>>>>> updated
</source>
2023-10-01 19:49:58 +02:00
Paul Gauthier
b78b8fabf4 use regex not shlex to parse quoted filenames portably on windows and others 2023-09-29 17:07:17 -07:00
Paul Gauthier
2dc01bb9bd handle abs paths on windows 2023-09-29 16:36:37 -07:00
Paul Gauthier
774589b376 test to ensure we accept abs filenames; use shlex so we handle quoted filenames; #152 #156 2023-09-29 15:02:45 -07:00
Paul Gauthier
dc19a1fe4b /add treats args as literal filenames initially, only glob if they do not exist #195 2023-09-29 13:44:49 -07:00
Paul Gauthier
399d86d437 block /add of files from outside coder.root #178 2023-09-29 13:27:43 -07:00
Paul Gauthier
98bacd0b5b test case and fix for /add blowing up in subdir #201 2023-09-29 10:49:27 -07:00
JV
041f3a4a38 initial code for working with openrouter 2023-08-23 14:39:12 +12:00
Paul Gauthier
963bc83a9c Late-bind importing sounddevice, as it was slowing down aider startup 2023-08-19 15:18:46 -07:00
Paul Gauthier
285536105e Properly handle all diff cases 2023-08-18 10:07:47 -07:00
Paul Gauthier
c07013abf4 finished roughing in --voice-language 2023-08-14 14:18:37 -03:00
Paul Gauthier
bddcdd39a8 Refactor record_and_transcribe method in voice.py to accept a language parameter. 2023-08-14 14:11:31 -03:00
Paul Gauthier
23579d4741 Refactor voice recording and transcription to allow for specifying the language. 2023-08-14 14:11:03 -03:00
Paul Gauthier
b6b271b70c pass the input history as a prompt to whisper 2023-08-11 11:03:37 -03:00
Paul Gauthier
9815d14368 rename 2023-08-11 10:49:27 -03:00
Paul Gauthier
233433cc11 properly handle ^c in /voice 2023-08-11 08:45:06 -03:00
Paul Gauthier
053751cb43 show loudness bar 2023-08-10 22:17:31 -03:00
Paul Gauthier
3ff2cb8dbe append voice messages to input history 2023-08-10 17:17:51 -03:00
Paul Gauthier
4812d17372 prettier 2023-08-10 17:12:19 -03:00
Paul Gauthier
7b993a9bbb gracefully handle missing portaudio 2023-08-10 16:55:45 -03:00
Paul Gauthier
ec91eb670e Refactor cmd_voice method to use user_input method instead of tool_output. 2023-08-10 16:23:35 -03:00
Paul Gauthier
47144a7e99 Add voice transcription to the cmd_voice command and output the transcribed text. 2023-08-10 16:18:13 -03:00
Paul Gauthier
2b1de442ed aider: Updated cmd_voice method to call record_and_transcribe function from aider/voice.py module and return its results.
# Aider chat conversation:

USER: the /voice cmd should call `record_and_transcribe` and return the results

ASSISTANT: To implement the `/voice` command, we need to modify the `aider/commands.py` file. Specifically, we need to update the `cmd_voice` method to call the `record_and_transcribe` function from the `aider/voice.py` module and return its results.

Here's the *edit block* for this change:

<source>python
aider/commands.py
<<<<<<< HEAD
    def cmd_voice(self, args):
        "Respond with 'hi gpt'"
        return 'hi gpt'
=======
    from .voice import record_and_transcribe

    def cmd_voice(self, args):
        "Record and transcribe voice input"
        return record_and_transcribe()
>>>>>>> updated
</source>
2023-08-10 16:15:02 -03:00
Paul Gauthier
2077bdcd79 aider: Add a new /voice command that returns 'hi gpt' when called.
# Aider chat conversation:

USER: add a new /voice command that just returns 'hi gpt' so that message gets sent

ASSISTANT: To add a new command, we need to add a new method to the `Commands` class in the `aider/commands.py` file. The method should be named `cmd_voice` and it should return the string 'hi gpt'.

Here is the *edit block* for this change:

<source>python
aider/commands.py
<<<<<<< HEAD
    def cmd_help(self, args):
        "Show help about all commands"
        commands = sorted(self.get_commands())
        for cmd in commands:
            cmd_method_name = f"cmd_{cmd[1:]}"
            cmd_method = getattr(self, cmd_method_name, None)
            if cmd_method:
                description = cmd_method.__doc__
                self.io.tool_output(f"{cmd} {description}")
            else:
                self.io.tool_output(f"{cmd} No description available.")
=======
    def cmd_help(self, args):
        "Show help about all commands"
        commands = sorted(self.get_commands())
        for cmd in commands:
            cmd_method_name = f"cmd_{cmd[1:]}"
            cmd_method = getattr(self, cmd_method_name, None)
            if cmd_method:
                description = cmd_method.__doc__
                self.io.tool_output(f"{cmd} {description}")
            else:
                self.io.tool_output(f"{cmd} No description available.")

    def cmd_voice(self, args):
        "Respond with 'hi gpt'"
        return 'hi gpt'
>>>>>>> updated
</source>
2023-08-10 15:40:54 -03:00
Joshua Vial
88d7e2ed09 disabling GIT_EDITOR when calling /git 2023-08-08 23:01:36 +12:00
Paul Gauthier
c271bfd932 Fixed /commit after repo refactor, added test coverage 2023-08-04 06:39:04 -03:00
Paul Gauthier
ecd37b1ad5 prettier cost output in /tokens 2023-07-26 17:43:16 -03:00
Paul Gauthier
2094b3176b aider: Adjusted the calculation of the cost in the cmd_tokens method to account for the prices in Model being per 1k tokens.
# Aider chat conversation:

USER: the prices in `Model` are per 1k tokens

ASSISTANT: I see, the prices in the `Model` class are per 1k tokens. Therefore, we need to adjust the calculation of the cost in the `cmd_tokens` method in the `Commands` class in the `aider/commands.py` file.

We will divide the `completion_price` by 1000 before multiplying it with the token count to get the cost.

Here are the changes:

<source>python
aider/commands.py
<<<<<<< ORIGINAL
        total = 0
        total_cost = 0.0
        for tk, msg, tip in res:
            total += tk
            cost = tk * self.coder.main_model.completion_price
            total_cost += cost
            msg = msg.ljust(col_width)
            self.io.tool_output(f"{fmt(tk)} {msg} {tip} (cost: ${cost:.2f})")

        self.io.tool_output("=" * width)
        self.io.tool_output(f"{fmt(total)} tokens total (cost: ${total_cost:.2f})")
=======
        total = 0
        total_cost = 0.0
        for tk, msg, tip in res:
            total += tk
            cost = tk * (self.coder.main_model.completion_price / 1000)
            total_cost += cost
            msg = msg.ljust(col_width)
            self.io.tool_output(f"{fmt(tk)} {msg} {tip} (cost: ${cost:.2f})")

        self.io.tool_output("=" * width)
        self.io.tool_output(f"{fmt(total)} tokens total (cost: ${total_cost:.2f})")
>>>>>>> UPDATED
</source>
2023-07-26 17:35:42 -03:00
Paul Gauthier
35ccfac3fd aider: Updated the output of /tokens to include the total cost.
# Aider chat conversation:

USER: udpate the output of /tokens to include the total $ cost

ASSISTANT: To include the total cost in the output of the `/tokens` command, we need to modify the `cmd_tokens` method in the `Commands` class in the `aider/commands.py` file.

We will add a new variable `total_cost` to keep track of the total cost. For each token count, we will calculate the cost by multiplying the token count by the model's `completion_price` (since we're considering the cost of generating these tokens). We will then add this cost to `total_cost`.

Finally, we will add a line to the output to display the total cost.

Here are the changes:

<source>python
aider/commands.py
<<<<<<< ORIGINAL
        total = 0
        for tk, msg, tip in res:
            total += tk
            msg = msg.ljust(col_width)
            self.io.tool_output(f"{fmt(tk)} {msg} {tip}")

        self.io.tool_output("=" * width)
        self.io.tool_output(f"{fmt(total)} tokens total")
=======
        total = 0
        total_cost = 0.0
        for tk, msg, tip in res:
            total += tk
            cost = tk * self.coder.main_model.completion_price
            total_cost += cost
            msg = msg.ljust(col_width)
            self.io.tool_output(f"{fmt(tk)} {msg} {tip} (cost: ${cost:.2f})")

        self.io.tool_output("=" * width)
        self.io.tool_output(f"{fmt(total)} tokens total (cost: ${total_cost:.2f})")
>>>>>>> UPDATED
</source>
2023-07-26 17:34:50 -03:00
paul-gauthier
86309f336c
Merge pull request #137 from paul-gauthier/refactor-repo
Refactor git repo code into a new file
2023-07-26 07:24:10 -03:00
Paul Gauthier
3e77df7587 /tokens should warn when <1k tokens left 2023-07-25 09:25:01 -03:00
Paul Gauthier
143ca36733 Merge branch 'main' into refactor-repo 2023-07-23 10:23:38 -03:00
Paul Gauthier
450a5fff19 Added test case and fix for /drop too 2023-07-23 08:41:56 -03:00
Paul Gauthier
d785d9a2e2 fix for #139 2023-07-23 08:34:56 -03:00
Paul Gauthier
4a8add1b5d Refactor get_tracked_files method to be called on self.coder.repo instead of self.coder. 2023-07-21 14:28:06 -03:00
Paul Gauthier
01ea691957 Update commands to use the underlying repo 2023-07-21 13:01:48 -03:00
Paul Gauthier
296e7614c4 wip 2023-07-21 12:06:32 -03:00
Paul Gauthier
23beb7cb5d wip 2023-07-21 11:49:19 -03:00
Paul Gauthier
c05efad274 aider: Add a new /git command to run git.
# Aider chat conversation:

USER: Add a new /git command to run git. so you could do `/git commit -a -m "message goes here"` or any other git command. It should work like `cmd_run` but prepends "git" to the `args`. Don't offer to send the output to gpt.

ASSISTANT: To add a new `/git` command, we need to modify the `aider/commands.py` file. We will add a new method `cmd_git` that will prepend "git" to the `args` and run the command. This method will be similar to `cmd_run` but will not offer to send the output to gpt.

Here is the change:

<source>python
aider/commands.py
<<<<<<< ORIGINAL
    def cmd_run(self, args):
        "Run a shell command and optionally add the output to the chat"
        combined_output = None
        try:
            parsed_args = shlex.split(args)
            result = subprocess.run(
                parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
            )
            combined_output = result.stdout
        except Exception as e:
            self.io.tool_error(f"Error running command: {e}")

        if combined_output is None:
            return

        self.io.tool_output(combined_output)

        if self.io.confirm_ask("Add the output to the chat?", default="y"):
            for line in combined_output.splitlines():
                self.io.tool_output(line, log_only=True)

            msg = prompts.run_output.format(
                command=args,
                output=combined_output,
            )
            return msg

    def cmd_exit(self, args):
        "Exit the application"
        sys.exit()
=======
    def cmd_git(self, args):
        "Run a git command"
        combined_output = None
        try:
            parsed_args = shlex.split("git " + args)
            result = subprocess.run(
                parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
            )
            combined_output = result.stdout
        except Exception as e:
            self.io.tool_error(f"Error running git command: {e}")

        if combined_output is None:
            return

        self.io.tool_output(combined_output)

    def cmd_run(self, args):
        "Run a shell command and optionally add the output to the chat"
        combined_output = None
        try:
            parsed_args = shlex.split(args)
            result = subprocess.run(
                parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
            )
            combined_output = result.stdout
        except Exception as e:
            self.io.tool_error(f"Error running command: {e}")

        if combined_output is None:
            return

        self.io.tool_output(combined_output)

        if self.io.confirm_ask("Add the output to the chat?", default="y"):
            for line in combined_output.splitlines():
                self.io.tool_output(line, log_only=True)

            msg = prompts.run_output.format(
                command=args,
                output=combined_output,
            )
            return msg

    def cmd_exit(self, args):
        "Exit the application"
        sys.exit()
>>>>>>> UPDATED
</source>
2023-07-17 15:51:14 -03:00
Amer Amayreh
a2d8bed155
Handled Issue #114
Handled the UnboundLocalError tat occurs when wrong prams are passed to the `/run` command
2023-07-17 06:04:47 +03:00
Paul Gauthier
967cb1bd8d notify when preparing dirty commit; skip if /exit or /commit is input 2023-07-11 13:21:36 -07:00
Paul Gauthier
c4e4d071fa Handle the case where we fail to expand a dir 2023-07-11 08:12:18 -07:00
Paul Gauthier
baa11b0c0d cleanup 2023-07-10 15:23:25 -07:00
Paul Gauthier
56f465b7f3 move the expansion into glob_filtered_to_repo so it works in drop too 2023-07-10 15:17:41 -07:00
Paul Gauthier
a88b2a70e8 cleanup 2023-07-10 15:10:23 -07:00