Commit graph

2795 commits

Author SHA1 Message Date
Paul Gauthier
de995a5d62 aider: Add sounddevice and keyboard libraries to the list of requirements.
# Aider chat conversation:

USER: add the required modules

ASSISTANT: To add the required modules, we need to modify the `requirements.txt` file.

Here are the changes:

```python
requirements.txt
<<<<<<< HEAD
openai==0.27.6
prompt-toolkit==3.0.38
Pygments==2.15.1
requests==2.30.0
rich==13.3.5
smmap==5.0.0
tqdm==4.65.0
urllib3==2.0.2
wcwidth==0.2.6
yarl==1.9.2
pytest==7.3.1
tiktoken==0.4.0
configargparse
PyYAML
backoff==2.2.1
networkx==3.1
diskcache==5.6.1
numpy==1.24.3
scipy==1.10.1
jsonschema==4.17.3
=======
openai==0.27.6
prompt-toolkit==3.0.38
Pygments==2.15.1
requests==2.30.0
rich==13.3.5
smmap==5.0.0
tqdm==4.65.0
urllib3==2.0.2
wcwidth==0.2.6
yarl==1.9.2
pytest==7.3.1
tiktoken==0.4.0
configargparse
PyYAML
backoff==2.2.1
networkx==3.1
diskcache==5.6.1
numpy==1.24.3
scipy==1.10.1
jsonschema==4.17.3
sounddevice
keyboard
>>>>>>> updated
```

These changes add the `sounddevice` and `keyboard` libraries to the list of requirements.
2023-08-10 15:48:30 -03:00
Paul Gauthier
c7d23f1b5a aider: Moved the api_key setting into the main function and pulled it from os.environ.
# Aider chat conversation:

USER: mov the `api_key` setting into main, and pull it from os.environ

ASSISTANT: To move the `api_key` setting into the main function and pull it from `os.environ`, we need to modify the `aider/voice.py` file.

Here are the changes:

```python
aider/voice.py
<<<<<<< HEAD
def record_and_transcribe():
    # Set your OpenAI API key
    openai.api_key = 'your-api-key'
=======
import os

def record_and_transcribe(api_key):
>>>>>>> updated
```

```python
aider/voice.py
<<<<<<< HEAD
if __name__ == "__main__":
    print(record_and_transcribe())
=======
if __name__ == "__main__":
    api_key = os.getenv('OPENAI_API_KEY')
    if not api_key:
        raise ValueError("Please set the OPENAI_API_KEY environment variable.")
    print(record_and_transcribe(api_key))
>>>>>>> updated
```

These changes remove the hard-coded API key from the `record_and_transcribe` function and instead pass it as an argument. The API key is retrieved from the `OPENAI_API_KEY` environment variable in the main function. If the environment variable is not set, an error is raised.
2023-08-10 15:47:18 -03:00
Paul Gauthier
c0f6cf6977 aider: Added main function to call record_and_transcribe if the script is run directly.
# Aider chat conversation:

USER: add a main func to call this if the script is run directly

ASSISTANT: To add a main function that calls `record_and_transcribe` if the script is run directly, we need to modify the `aider/voice.py` file.

Here are the changes:

```python
aider/voice.py
<<<<<<< HEAD
    # Return the transcription
    return response['choices'][0]['text']
=======
    # Return the transcription
    return response['choices'][0]['text']

if __name__ == "__main__":
    print(record_and_transcribe())
>>>>>>> updated
```

This change adds a check to see if the script is being run directly (i.e., not imported as a module). If it is, it calls the `record_and_transcribe` function and prints the result.
2023-08-10 15:46:31 -03:00
Paul Gauthier
1053d1781c aider: Added a function record_and_transcribe to aider/voice.py that records audio until the user presses a key, then submits it to the Whisper API to get the text back.
# Aider chat conversation:

USER: what file formats does the openai whisper api accept?

ASSISTANT: The OpenAI Whisper ASR API accepts audio data in the following formats:

- FLAC: Free Lossless Audio Codec. This is a lossless audio format that doesn't lose any data during compression. It's the recommended format for best performance.
- WAV: Waveform Audio File Format. This is a standard audio format used mainly in Windows PCs.
- MULAW: μ-law algorithm (or mu-law) is a companding algorithm, primarily used in the digital telecommunication systems of North America and Japan.

Please note that the audio data must be single-channel (mono), and the sample rate must be 16 kHz for FLAC and WAV formats, and 8 kHz for MULAW format.

USER: make a script that records audio until the user presses a key, then submits it to whisper to get the text back

ASSISTANT: To accomplish this, we need to create a new Python script that uses the `sounddevice` library to record audio, the `keyboard` library to listen for a key press, and the `openai.Whisper` API to transcribe the audio.

Here is the *edit block* for this new script:

```python
newfile/record_and_transcribe.py
<<<<<<< HEAD

=======
import sounddevice as sd
import numpy as np
import keyboard
import openai
import io
import os

# Set your OpenAI API key
openai.api_key = 'your-api-key'

# Set the sample rate and duration for the recording
sample_rate = 16000  # 16kHz
duration = 10  # in seconds

# Create a callback function to stop recording when a key is pressed
def on_key_press(e):
    print("Key pressed, stopping recording...")
    sd.stop()

# Start the recording
print("Recording started, press any key to stop...")
recording = sd.rec(int(sample_rate * duration), samplerate=sample_rate, channels=1, callback=on_key_press)

# Wait for a key press
keyboard.wait()

# Convert the recording to bytes
recording_bytes = io.BytesIO()
np.save(recording_bytes, recording, allow_pickle=False)
recording_bytes = recording_bytes.getvalue()

# Transcribe the audio using the Whisper API
response = openai.Whisper.asr.create(audio_data=recording_bytes)

# Print the transcription
print("Transcription: ", response['choices'][0]['text'])
>>>>>>> updated
```

Please replace `'your-api-key'` with your actual OpenAI API key. This script records audio for a maximum of 10 seconds, but it stops recording as soon as any key is pressed. The recorded audio is then transcribed using the Whisper API, and the transcription is printed to the console.

Please note that you need to install the `sounddevice`, `numpy`, `keyboard`, and `openai` Python libraries to run this script. You can install them using pip:

```bash
pip install sounddevice numpy keyboard openai
```

Also, please note that the `keyboard` library requires root privileges to work, so you might need to run your script as a superuser.

USER: make a function that records audio until the user presses a key, then submits it to whisper to get the text back

ASSISTANT: To create a function that accomplishes this, we need to modify the `aider/voice.py` file. The function should be named `record_and_transcribe` and it should use the `sounddevice` and `keyboard` libraries to record audio and listen for a key press, respectively. It should also use the `openai.Whisper` API to transcribe the audio.

Here is the *edit block* for this change:

```python
aider/voice.py
<<<<<<< HEAD

=======
import sounddevice as sd
import numpy as np
import keyboard
import openai
import io

def record_and_transcribe():
    # Set your OpenAI API key
    openai.api_key = 'your-api-key'

    # Set the sample rate and duration for the recording
    sample_rate = 16000  # 16kHz
    duration = 10  # in seconds

    # Create a callback function to stop recording when a key is pressed
    def on_key_press(e):
        print("Key pressed, stopping recording...")
        sd.stop()

    # Start the recording
    print("Recording started, press any key to stop...")
    recording = sd.rec(int(sample_rate * duration), samplerate=sample_rate, channels=1, callback=on_key_press)

    # Wait for a key press
    keyboard.wait()

    # Convert the recording to bytes
    recording_bytes = io.BytesIO()
    np.save(recording_bytes, recording, allow_pickle=False)
    recording_bytes = recording_bytes.getvalue()

    # Transcribe the audio using the Whisper API
    response = openai.Whisper.asr.create(audio_data=recording_bytes)

    # Return the transcription
    return response['choices'][0]['text']
>>>>>>> updated
```

Please replace `'your-api-key'` with your actual OpenAI API key. This function records audio for a maximum of 10 seconds, but it stops recording as soon as any key is pressed. The recorded audio is then transcribed using the Whisper API, and the transcription is returned by the function.

Please note that you need to install the `sounddevice`, `numpy`, `keyboard`, and `openai` Python libraries to use this function. You can install them using pip:

```bash
pip install sounddevice numpy keyboard openai
```

Also, please note that the `keyboard` library requires root privileges to work, so you might need to run your script as a superuser.
2023-08-10 15:45:49 -03:00
Paul Gauthier
fdb1cac20b aider: Added aider/voice.py 2023-08-10 15:41:42 -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
Paul Gauthier
2872137005 Updated HISTORY 2023-08-10 15:35:07 -03:00
Paul Gauthier
a1da6cab24 ensure we diff properly in all cases, with tests #191 2023-08-10 15:33:53 -03:00
Paul Gauthier
7924900bc4 updated tests, disabled send cache 2023-08-10 12:27:46 -03:00
Paul Gauthier
7eab7b54b8 Improved summarization split logic 2023-08-10 12:21:51 -03:00
Paul Gauthier
ea87a350c2 Updated HISTORY 2023-08-10 12:19:11 -03:00
Paul Gauthier
529079ec01 quote the HEAD 2023-08-09 18:51:11 -03:00
Paul Gauthier
fb80377d18 ORIGINAL/UPDATED -> HEAD/updated 2023-08-09 16:16:43 -03:00
Paul Gauthier
fa2da0ef70 bound the summarize() recursion 2023-08-09 12:04:10 -03:00
Paul Gauthier
73c4efea94 ssh 2023-08-09 12:00:37 -03:00
Paul Gauthier
9e64e7bb9d precise edit blocks prompting language 2023-08-09 11:57:00 -03:00
Paul Gauthier
2c53c153b8 Updated ORIGINAL prompting 2023-08-09 11:38:39 -03:00
Paul Gauthier
0aa2ff2cf9 roughed in cache; elide full dirnames from test results to make them deterministic 2023-08-09 11:30:13 -03:00
Paul Gauthier
2eeee67ee5 support --keywords 2023-08-09 11:12:27 -03:00
Paul Gauthier
00512e3d1c no fuzy matching, stronger prompt for whitespace 2023-08-09 08:25:49 -03:00
Paul Gauthier
c6f6ab6070 corrected perfect replace 2023-08-09 08:20:16 -03:00
Paul Gauthier
6c2cafc1ed Removed "pause often to ask the user" prompting 2023-08-08 17:40:45 -03:00
Paul Gauthier
c43d7e9a69 initial --diffs implementation 2023-08-08 17:40:32 -03:00
Paul Gauthier
77be993708 Merge branch 'main' into indent-bad-edit 2023-08-08 12:43:57 -03:00
Paul Gauthier
68a3e4f74d set version to 0.11.2-dev 2023-08-08 12:32:49 -03:00
Paul Gauthier
655f6aef2a version bump to 0.11.1 2023-08-08 12:32:25 -03:00
Paul Gauthier
237dc09c26 Updated HISTORY 2023-08-08 12:32:19 -03:00
Paul Gauthier
ae645f929e Updated HISTORY 2023-08-08 12:07:01 -03:00
Paul Gauthier
f26e40d48e Skip non-files when building repomap #174 2023-08-08 12:02:40 -03:00
Paul Gauthier
500a22c306 copy 2023-08-08 09:05:58 -03:00
Paul Gauthier
486bcdb815 Merge remote-tracking branch 'origin/main' 2023-08-08 09:01:09 -03:00
Paul Gauthier
589e7eefea We always want diffs of working-dir + index versus repo #184 2023-08-08 09:00:19 -03:00
Paul Gauthier
af854182dc added failing test case for diffs of empty repo with new file added 2023-08-08 08:20:26 -03:00
paul-gauthier
67b7107786
Merge pull request #187 from joshuavial/fix-git-editor-crash
disabling GIT_EDITOR when calling /git
2023-08-08 08:11:41 -03:00
Paul Gauthier
fe44627042 copy 2023-08-08 08:02:56 -03:00
Joshua Vial
88d7e2ed09 disabling GIT_EDITOR when calling /git 2023-08-08 23:01:36 +12:00
Paul Gauthier
20c7eb549c aider: Mocked get_commit_message to return "I added str(fname)".
# Aider chat conversation:

USER: mock `get_commit_message` to return "I added str(fname)"

ASSISTANT: To mock the `get_commit_message` method to return "I added str(fname)", we need to modify the `test_new_file_commit_message` function in the `tests/test_coder.py` file.

Here is the change needed:

<source>python
tests/test_coder.py
<<<<<<< ORIGINAL
            # Get the latest commit message
            commit_message = repo.head.commit.message
            # Check that the latest commit message contains the filename
            self.assertIn(str(fname), commit_message)
=======
            # Mock the get_commit_message method to return "I added str(fname)"
            repo.get_commit_message = MagicMock(return_value=f"I added {str(fname)}")
            # Get the latest commit message
            commit_message = repo.get_commit_message()
            # Check that the latest commit message is "I added str(fname)"
            self.assertEqual(commit_message, f"I added {str(fname)}")
>>>>>>> UPDATED
</source>
2023-08-08 08:01:15 -03:00
Paul Gauthier
737c2e0b5f aider: Check that the latest commit message contains the filename.
# Aider chat conversation:

USER: do the todo

ASSISTANT: To complete the TODO task in the `test_new_file_commit_message` function, we need to check that the latest commit message contains the filename. We can do this by getting the latest commit message from the git repository and checking if the filename is in it.

Here is the change needed in the `tests/test_coder.py` file:

<source>python
tests/test_coder.py
<<<<<<< ORIGINAL
            # TODO: check that the latest commit message contains str(fname)
=======
            # Get the latest commit message
            commit_message = repo.head.commit.message
            # Check that the latest commit message contains the filename
            self.assertIn(str(fname), commit_message)
>>>>>>> UPDATED
</source>
2023-08-08 07:59:57 -03:00
Paul Gauthier
3698b12215 copy 2023-08-08 07:55:42 -03:00
Paul Gauthier
75d8115597 copy 2023-08-08 07:53:14 -03:00
Paul Gauthier
9cb1a9b186 cleanup 2023-08-08 07:38:37 -03:00
Paul Gauthier
6c4017ecfe Merge remote-tracking branch 'origin/main' 2023-08-08 07:38:14 -03:00
paul-gauthier
6a88d0f2b9
Merge pull request #177 from h0x91b/h0x91b-patch-1
Update base_coder.py
2023-08-08 07:37:51 -03:00
Paul Gauthier
445785a3a1 Updated HISTORY 2023-08-08 07:04:16 -03:00
Paul Gauthier
3c0720ff1c Fix corner case of undefined text when using --no-pretty 2023-08-08 07:00:21 -03:00
Paul Gauthier
94e5aeac62 copy 2023-08-07 13:00:21 -03:00
Paul Gauthier
b12899f8f3 copy 2023-08-07 11:35:20 -03:00
Paul Gauthier
14c683bfdf more specific selector 2023-08-07 11:33:06 -03:00
Paul Gauthier
68f043bd96 copy 2023-08-07 11:30:22 -03:00
Paul Gauthier
0f682570a4 aider: Fix the issue with forming the raw URL for a non-raw GitHub gist by including the username in the URL.
# Aider chat conversation:

USER: if the mdurl is a non-raw github gist like this `https://gist.github.com/paul-gauthier/2a4ac695b77f6374c923b0b165a6872b` pull out the h
ash and turn into a raw url like this: `4fd2ac290d
64100e51206fb6874e9ac20644fcd`. Right now it's not including the username (paul-gauthier) portion in the raw url

ASSISTANT: To fix this issue, we need to modify the JavaScript code in the `share/index.md` file. The current code is not correctly forming the raw URL for a non-raw GitHub gist. It's missing the username in the raw URL.

Here is the step-by-step plan:

1. Modify the regular expression to capture the username and the gist hash.
2. Update the raw URL formation to include the captured username.

Here is the *edit block* for the change:

```markdown
share/index.md
<<<<<<< ORIGINAL
    var gistRegex = /^https:\/\/gist\.github\.com\/[^\/]+\/([a-f0-9]+)$/;
    var match = gistRegex.exec(conv);
    if (match) {
        // If it is, convert it into a raw URL
        conv = 'https://gist.githubusercontent.com/' + match[1] + '/raw';
    }
=======
    var gistRegex = /^https:\/\/gist\.github\.com\/([^\/]+)\/([a-f0-9]+)$/;
    var match = gistRegex.exec(conv);
    if (match) {
        // If it is, convert it into a raw URL
        conv = 'https://gist.githubusercontent.com/' + match[1] + '/' + match[2] + '/raw';
    }
>>>>>>> UPDATED
```

This change will correctly form the raw URL for a non-raw GitHub gist by including the username in the URL.
2023-08-07 11:16:56 -03:00