Commit graph

4144 commits

Author SHA1 Message Date
Paul Gauthier
8f194c8313 Add reflection tracking and limit to Coder class. 2024-05-17 19:11:48 -07:00
Paul Gauthier
4b0c38254e added lint reflection 2024-05-17 16:58:04 -07:00
Paul Gauthier
fe65b7d11f roughed in flake8 2024-05-17 16:41:36 -07:00
Paul Gauthier
c7196b8390 aider: Remove unused variable _output in the run_cmd method in aider/linter.py.
# Aider chat conversation:

USER: I ran this command:

 pre-commit run --files aider/linter.py

And got this output:

isort....................................................................Failed
- hook id: isort
- files were modified by this hook

Fixing /Users/gauthier/Projects/aider/aider/linter.py

black....................................................................Failed
- hook id: black
- files were modified by this hook

reformatted aider/linter.py

All done!  🍰 
1 file reformatted.

flake8...................................................................Failed
- hook id: flake8
- exit code: 1

aider/linter.py:37:13: F841 local variable '_output' is assigned to but never used
            _output = subprocess.check_output(cmd, cwd=self.root).decode()
            ^

ASSISTANT: Please add `aider/linter.py` to the chat so I can make the necessary changes to fix the flake8 issue.

USER: I added these files to the chat: aider/linter.py

ASSISTANT: To fix the flake8 issue, we need to remove the unused variable `_output` in the `run_cmd` method. Here is the *SEARCH/REPLACE* block:

aider/linter.py
```python
<<<<<<< SEARCH
            _output = subprocess.check_output(cmd, cwd=self.root).decode()
            return  # zero exit status
=======
            subprocess.check_output(cmd, cwd=self.root).decode()
            return  # zero exit status
>>>>>>> REPLACE
```

This change will remove the assignment to the unused variable `_output` while keeping the call to `subprocess.check_output`.
2024-05-17 15:37:06 -07:00
Paul Gauthier
4f81971a13 Add support for running custom linters and improve error handling. 2024-05-17 15:37:05 -07:00
Paul Gauthier
dc2850b53d Added a Linter class for linting files and refactored linting logic in the main function. 2024-05-17 15:21:09 -07:00
Paul Gauthier
dd2ba6e3fc pin tree-sitter==0.21.3 2024-05-17 14:49:39 -07:00
Paul Gauthier
e09d4d8e16 Upgraded deps to pickup grep-ast 0.3.0 2024-05-17 14:42:40 -07:00
Paul Gauthier
778dbcabb0 aider: Remove the unused import get_language from aider/linter.py.
# Aider chat conversation:

USER: I ran this command:

 flake8 aider/linter.py

And got this output:

aider/linter.py:9:1: F401 'tree_sitter_languages.get_language' imported but unused

ASSISTANT: Please add the file `aider/linter.py` to the chat so I can make the necessary changes.

USER: I added these files to the chat: aider/linter.py

ASSISTANT: To resolve the flake8 warning, we need to remove the unused import `get_language` from `aider/linter.py`.

Here is the *SEARCH/REPLACE* block:

aider/linter.py
```python
<<<<<<< SEARCH
from tree_sitter_languages import get_language, get_parser  # noqa: E402
=======
from tree_sitter_languages import get_parser  # noqa: E402
>>>>>>> REPLACE
```
2024-05-17 14:30:58 -07:00
Paul Gauthier
a9fd02c74d aider: Remove unused imports and variable in aider/linter.py to pass pre-commit hooks.
# Aider chat conversation:

USER: I ran this command:

 .git/hooks/pre-commit

And got this output:

[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /Users/gauthier/.cache/pre-commit/patch1715981257-12950.
isort....................................................................Failed
- hook id: isort
- files were modified by this hook

Fixing /Users/gauthier/Projects/aider/aider/linter.py

black....................................................................Failed
- hook id: black
- files were modified by this hook

reformatted aider/linter.py

All done!  🍰 
1 file reformatted.

flake8...................................................................Failed
- hook id: flake8
- exit code: 1

aider/linter.py:1:1: F401 'os' imported but unused
import os
^
aider/linter.py:6:1: F401 'tree_sitter' imported but unused
import tree_sitter
^
aider/linter.py:9:1: F401 'aider.dump.dump' imported but unused
from aider.dump import dump
^
aider/linter.py:21:5: F841 local variable 'language' is assigned to but never used
    language = get_language(lang)
    ^

[WARNING] Stashed changes conflicted with hook auto-fixes... Rolling back fixes...
[INFO] Restored changes from /Users/gauthier/.cache/pre-commit/patch1715981257-12950.

ASSISTANT: Please add `aider/linter.py` to the chat so I can make the necessary changes to fix the issues reported by the pre-commit hooks.

USER: I added these files to the chat: aider/linter.py

ASSISTANT: To fix the issues reported by the pre-commit hooks, we need to:

1. Remove unused imports: `os`, `tree_sitter`, and `dump`.
2. Remove the unused variable `language`.

Here are the *SEARCH/REPLACE* blocks:

aider/linter.py
```python
<<<<<<< SEARCH
import os
import sys
import warnings
from pathlib import Path

import tree_sitter
from grep_ast import TreeContext, filename_to_lang

from aider.dump import dump
=======
import sys
import warnings
from pathlib import Path

from grep_ast import TreeContext, filename_to_lang
>>>>>>> REPLACE
```

aider/linter.py
```python
<<<<<<< SEARCH
    language = get_language(lang)
=======
>>>>>>> REPLACE
```

Now, the file should pass the pre-commit hooks.
2024-05-17 14:27:54 -07:00
Paul Gauthier
494aa0140b Refactored the linter script to handle language detection and error traversal more efficiently. 2024-05-17 14:27:53 -07:00
Paul Gauthier
cb8a487c89 Display syntax errors with tree context 2024-05-17 14:22:25 -07:00
Paul Gauthier
86fdeb0597 aider: Update traverse_tree to print error type, line number, and 3 lines of context before/after the error.
# Aider chat conversation:

USER: print out the line and the N=3 lines before/after it

ASSISTANT: To print out the line with the error and the 3 lines before and after it, we need to modify the `traverse_tree` function in `aider/linter.py`. Here are the necessary changes:

aider/linter.py
```python
<<<<<<< SEARCH
    # Traverse the tree to find errors
=======
    # Traverse the tree to find errors and print context
>>>>>>> REPLACE
```

aider/linter.py
```python
<<<<<<< SEARCH
            print(f"{error_type} at line: {node.start_point[0] + 1}")
=======
            start_line = max(0, node.start_point[0] - 3)
            end_line = node.end_point[0] + 3
            error_line = node.start_point[0] + 1

            with open(file_path, 'r') as file:
                lines = file.readlines()

            print(f"{error_type} at line: {error_line}")
            print("Context:")
            for i in range(start_line, min(end_line, len(lines))):
                line_number = i + 1
                prefix = ">> " if line_number == error_line else "   "
                print(f"{prefix}{line_number}: {lines[i].rstrip()}")
            print("\n")
>>>>>>> REPLACE
```

This will ensure that the linter prints the error type, the line number, and the context of 3 lines before and after the error.
2024-05-17 14:00:59 -07:00
Paul Gauthier
0493680d57 aider: Update the linter to check for both 'ERROR' and 'MISSING' nodes.
# Aider chat conversation:

USER: is node.type 'ERROR" a standard across all tree sitter languages?

ASSISTANT: The `node.type == 'ERROR'` check is specific to the Tree-sitter library and is used to identify syntax errors in the parsed code. This is a standard feature across all languages supported by Tree-sitter.

Would you like to proceed with any changes or enhancements to the `aider/linter.py` file? If so, please specify the changes you need.

USER: is MISSING ever used to indicate a parsing/syntax problem

ASSISTANT: Yes, in Tree-sitter, `MISSING` is also used to indicate a parsing or syntax problem. Specifically, it indicates that a required element is missing in the syntax tree.

Would you like to update the `aider/linter.py` file to also check for `MISSING` nodes? If so, I can provide the necessary changes.

USER: yes

ASSISTANT: To update the `aider/linter.py` file to also check for `MISSING` nodes, we need to modify the `traverse_tree` function. Here are the necessary changes:

aider/linter.py
```python
<<<<<<< SEARCH
        if node.type == 'ERROR':
            print(f"Syntax error at line: {node.start_point[0] + 1}")
=======
        if node.type == 'ERROR' or node.is_missing:
            error_type = 'Syntax error' if node.type == 'ERROR' else 'Missing element'
            print(f"{error_type} at line: {node.start_point[0] + 1}")
>>>>>>> REPLACE
```

This change will ensure that the linter checks for both `ERROR` and `MISSING` nodes and reports them accordingly.
2024-05-17 14:00:42 -07:00
Paul Gauthier
c26833419d Fixed tree-sitter FutureWarning and refactored parsing logic in linter. 2024-05-17 14:00:41 -07:00
Paul Gauthier
3cc0a3c263 aider: Implemented function to parse file with tree-sitter and print syntax error line numbers.
# Aider chat conversation:

USER: write me a function that takes a file path and uses tree-sitter to parse the AST and print out the line number of every syntax/parse error in the file

ASSISTANT: To implement the function that takes a file path, uses tree-sitter to parse the AST, and prints out the line number of every syntax/parse error in the file, we need to:

1. Install the `tree-sitter` library.
2. Write the function in `aider/linter.py`.

Here is the *SEARCH/REPLACE* block for `aider/linter.py`:

aider/linter.py
```python
<<<<<<< SEARCH
=======
import os
import tree_sitter

def parse_file_for_errors(file_path):
    """
    Parses the given file using tree-sitter and prints out the line number of every syntax/parse error.
    """
    # Load the language
    Language = tree_sitter.Language
    PARSER = tree_sitter.Parser()
    LANGUAGE = Language(os.path.join('build', 'my-languages.so'), 'python')
    PARSER.set_language(LANGUAGE)

    # Read the file content
    with open(file_path, 'r') as file:
        content = file.read()

    # Parse the content
    tree = PARSER.parse(bytes(content, "utf8"))

    # Traverse the tree to find errors
    def traverse_tree(node):
        if node.type == 'ERROR':
            print(f"Syntax error at line: {node.start_point[0] + 1}")
        for child in node.children:
            traverse_tree(child)

    traverse_tree(tree.root_node)
>>>>>>> REPLACE
```

This code will:
1. Load the `tree-sitter` library and set up the parser for Python.
2. Read the content of the file specified by `file_path`.
3. Parse the content and traverse the AST to find and print the line numbers of any syntax errors.

You can now run this function by calling `parse_file_for_errors('path/to/your/file.py')`.
2024-05-17 13:47:52 -07:00
Paul Gauthier
4e0f8765d9 copy 2024-05-17 13:15:07 -07:00
Paul Gauthier
30179c185d copy 2024-05-17 13:14:28 -07:00
Paul Gauthier
771bea1fa4 copy 2024-05-17 13:12:26 -07:00
Paul Gauthier
2eced6ce12 copy 2024-05-17 13:05:29 -07:00
Paul Gauthier
05375fe279 link directly to examples 2024-05-17 12:55:09 -07:00
Paul Gauthier
8a960083c7 updated chat transcript divs 2024-05-17 12:51:13 -07:00
paul-gauthier
014ec6365e
Update 2024-05-13-models-over-time.md 2024-05-16 19:51:21 -07:00
Paul Gauthier
07c5cae982 copy 2024-05-16 18:17:17 -07:00
Paul Gauthier
2cd2f5439a copy 2024-05-16 18:15:28 -07:00
Paul Gauthier
6331edd954 copy 2024-05-16 18:15:11 -07:00
Paul Gauthier
47eebdb716 copy 2024-05-16 18:12:24 -07:00
Paul Gauthier
8c0bfeb392 copy 2024-05-16 18:09:41 -07:00
Paul Gauthier
6fe67d1132 added blog 2024-05-16 18:06:04 -07:00
Paul Gauthier
74c0df8df8 svg 2024-05-15 11:54:00 -07:00
Paul Gauthier
590cbbddfd Added models over time to leaderboard page 2024-05-15 11:51:28 -07:00
Paul Gauthier
170d8ff6a8 Updated contributing 2024-05-15 11:47:29 -07:00
Paul Gauthier
fa78b5fba7 don't test _site 2024-05-15 11:46:10 -07:00
Paul Gauthier
d010af6e54 Removed unnecessary directories and files from exclusion list in _config.yml. 2024-05-15 11:37:27 -07:00
Paul Gauthier
c8d2649bb8 Update model names to remove parentheses and extra whitespace in benchmark plot. 2024-05-15 11:36:37 -07:00
Paul Gauthier
445c73267a Updated plot dimensions and axis labels for better visualization in benchmark over time. 2024-05-15 11:29:44 -07:00
Paul Gauthier
d05de029e1 renamed dockerfile 2024-05-15 11:29:34 -07:00
Paul Gauthier
77ba518a1a aider: Made the border of the graph thinner and lighter by adjusting the spines properties of the axes.
# Aider chat conversation:

USER: make the border of the graph thinner and lighter

ASSISTANT: To make the border of the graph thinner and lighter, we can adjust the `spines` properties of the axes.

Here are the changes:

benchmark/over_time.py
```python
<<<<<<< SEARCH
    colors = ['red' if 'gpt-4' in model else 'green' if 'gpt-3.5' in model else 'blue' for model in models]
=======
    for spine in ax.spines.values():
        spine.set_edgecolor('#DDDDDD')
        spine.set_linewidth(0.5)

    colors = ['red' if 'gpt-4' in model else 'green' if 'gpt-3.5' in model else 'blue' for model in models]
>>>>>>> REPLACE
```
2024-05-15 11:21:01 -07:00
Paul Gauthier
a018fdfe2c aider: Make the dots bigger.
# Aider chat conversation:

USER: make the dots bigger

ASSISTANT: To make the dots bigger, we can adjust the `s` parameter in the `scatter` function, which controls the size of the dots.

Here are the changes:

benchmark/over_time.py
```python
<<<<<<< SEARCH
    ax.scatter(dates, pass_rates, c=colors, alpha=0.5)
=======
    ax.scatter(dates, pass_rates, c=colors, alpha=0.5, s=100)
>>>>>>> REPLACE
```
2024-05-15 11:20:05 -07:00
Paul Gauthier
3f1b86a1cc aider: Make the axes labels font larger.
# Aider chat conversation:

USER: I did `git reset --hard HEAD~1` to discard the last edits. Please wait for further instructions before attempting that change again. Feel free to ask relevant questions about why the changes were reverted.

ASSISTANT: Understood. If you have any specific instructions or further changes you'd like to make, please let me know!

USER: make the axes labels font larger

ASSISTANT: To make the axes labels font larger, we can adjust the `fontsize` parameter in the `set_xlabel` and `set_ylabel` methods.

Here are the changes:

benchmark/over_time.py
```python
<<<<<<< SEARCH
    ax.set_xlabel('Model release date')
    ax.set_ylabel('Aider code editing benchmark,\npercent completed correctly')
=======
    ax.set_xlabel('Model release date', fontsize=14)
    ax.set_ylabel('Aider code editing benchmark,\npercent completed correctly', fontsize=14)
>>>>>>> REPLACE
```
2024-05-15 11:14:48 -07:00
Paul Gauthier
05e34783c2 Update plot labels and annotations for better readability and clarity. 2024-05-15 11:13:17 -07:00
Paul Gauthier
75fa061016 aider: Adjust the position of labels to prevent overlap with dots.
# Aider chat conversation:

USER: make the labels not overlap the dots

ASSISTANT: To make the labels not overlap the dots, we can adjust the position of the labels slightly using the `xytext` parameter in the `annotate` function.

Here are the changes:

benchmark/over_time.py
```python
<<<<<<< SEARCH
        ax.annotate(model, (dates[i], pass_rates[i]), fontsize=8, alpha=0.75)
=======
        ax.annotate(model, (dates[i], pass_rates[i]), fontsize=8, alpha=0.75,
                    xytext=(5, 5), textcoords='offset points')
>>>>>>> REPLACE
```
2024-05-15 11:06:32 -07:00
Paul Gauthier
49eb72cc20 Updated image file format from SVG to PNG and added imgcat library for displaying the plot. 2024-05-15 11:06:31 -07:00
Paul Gauthier
8d670f187c aider: Used the colorscheme and fonts from the graphs in plots.py in over_time.py.
# Aider chat conversation:

USER: use the colorscheme and fonts from the graphs in plots.py

ASSISTANT: To use the colorscheme and fonts from the graphs in `plots.py`, we need to:

1. Import the necessary settings from `plots.py`.
2. Apply these settings to the graph in `over_time.py`.

Here are the changes:

benchmark/over_time.py
```python
<<<<<<< SEARCH
import yaml
from datetime import datetime
=======
import yaml
from datetime import datetime
from matplotlib import rc
>>>>>>> REPLACE
```

benchmark/over_time.py
```python
<<<<<<< SEARCH
    plt.figure(figsize=(10, 6))
=======
    plt.rcParams["hatch.linewidth"] = 0.5
    plt.rcParams["hatch.color"] = "#444444"

    rc("font", **{"family": "sans-serif", "sans-serif": ["Helvetica"], "size": 10})

    fig, ax = plt.subplots(figsize=(6, 4))
    ax.grid(axis="y", zorder=0, lw=0.2)
>>>>>>> REPLACE
```

benchmark/over_time.py
```python
<<<<<<< SEARCH
    plt.scatter(dates, pass_rates, c=colors, alpha=0.5)
=======
    ax.scatter(dates, pass_rates, c=colors, alpha=0.5)
>>>>>>> REPLACE
```

benchmark/over_time.py
```python
<<<<<<< SEARCH
        plt.annotate(model, (dates[i], pass_rates[i]), fontsize=8, alpha=0.75)

    plt.xlabel('Release Date')
    plt.ylabel('Pass Rate 2')
    plt.title('Model Performance Over Time')
    plt.grid(True)
    plt.tight_layout()
    plt.show()
=======
        ax.annotate(model, (dates[i], pass_rates[i]), fontsize=8, alpha=0.75)

    ax.set_xlabel('Release Date')
    ax.set_ylabel('Pass Rate 2')
    ax.set_title('Model Performance Over Time')
    plt.tight_layout()
    plt.savefig("tmp_over_time.svg")
    imgcat(fig)
>>>>>>> REPLACE
```
2024-05-15 11:04:56 -07:00
Paul Gauthier
85d9d8430f aider: Color the "gpt-3.5" models green in the plotting code.
# Aider chat conversation:

USER: color the gpt-3.5 models a new color

ASSISTANT: To color the "gpt-3.5" models a new color, we need to modify the plotting code in `benchmark/over_time.py` to check for "gpt-3.5" in the model name and assign a different color.

Here are the changes:

benchmark/over_time.py
```python
<<<<<<< SEARCH
    colors = ['red' if 'gpt-4' in model else 'blue' for model in models]
=======
    colors = ['red' if 'gpt-4' in model else 'green' if 'gpt-3.5' in model else 'blue' for model in models]
>>>>>>> REPLACE
```
2024-05-15 11:04:14 -07:00
Paul Gauthier
0d11357980 aider: Color the "gpt-4" models differently.
# Aider chat conversation:

USER: color the "gpt-4" models differently

ASSISTANT: To color the "gpt-4" models differently, we need to modify the plotting code in `benchmark/over_time.py` to check for "gpt-4" in the model name and assign a different color.

Here are the changes:

benchmark/over_time.py
```python
<<<<<<< SEARCH
    plt.scatter(dates, pass_rates, c='blue', alpha=0.5)
=======
    colors = ['red' if 'gpt-4' in model else 'blue' for model in models]
    plt.scatter(dates, pass_rates, c=colors, alpha=0.5)
>>>>>>> REPLACE
```

This change will color the points red if the model name contains "gpt-4", otherwise, it will color them blue.
2024-05-15 11:03:47 -07:00
Paul Gauthier
af2f4b73e9 aider: Use the released field directly in the plot instead of parsing it with datetime.strptime.
# Aider chat conversation:

USER: I ran this command:

 python benchmark/over_time.py

And got this output:

Traceback (most recent call last):
  File "/Users/gauthier/Projects/aider/benchmark/over_time.py", line 33, in <module>
    plot_over_time('_data/edit_leaderboard.yml')
  File "/Users/gauthier/Projects/aider/benchmark/over_time.py", line 15, in plot_over_time
    dates.append(datetime.strptime(entry['released'], '%Y-%m-%d'))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: strptime() argument 1 must be str, not datetime.date

ASSISTANT: The error indicates that the `released` field in the YAML file is already a `datetime.date` object, so we don't need to parse it with `datetime.strptime`. We can directly use it in the plot.

Here are the changes:

benchmark/over_time.py
```python
<<<<<<< SEARCH
            dates.append(datetime.strptime(entry['released'], '%Y-%m-%d'))
=======
            dates.append(entry['released'])
>>>>>>> REPLACE
```
2024-05-15 11:03:07 -07:00
Paul Gauthier
49ac9ca357 aider: Added scatter plot functionality for YAML entries with a released date and pass_rate_2.
# Aider chat conversation:

USER: in over_time.py, draw a graph for each of the yaml entries with a `released` date. plot date on x, `pass_rate_2` on y and label with the `model` name. do a scatter plot. use colors/styles similar to the other graphs.

ASSISTANT: To draw a scatter plot for each of the YAML entries with a `released` date, we need to:

1. Read the YAML file.
2. Extract the `released` date and `pass_rate_2` for each entry.
3. Plot the data using matplotlib.

Here are the changes:

benchmark/over_time.py
```python
<<<<<<< SEARCH
=======
import matplotlib.pyplot as plt
import yaml
from datetime import datetime

def plot_over_time(yaml_file):
    with open(yaml_file, 'r') as file:
        data = yaml.safe_load(file)

    dates = []
    pass_rates = []
    models = []

    for entry in data:
        if 'released' in entry and 'pass_rate_2' in entry:
            dates.append(datetime.strptime(entry['released'], '%Y-%m-%d'))
            pass_rates.append(entry['pass_rate_2'])
            models.append(entry['model'])

    plt.figure(figsize=(10, 6))
    plt.scatter(dates, pass_rates, c='blue', alpha=0.5)

    for i, model in enumerate(models):
        plt.annotate(model, (dates[i], pass_rates[i]), fontsize=8, alpha=0.75)

    plt.xlabel('Release Date')
    plt.ylabel('Pass Rate 2')
    plt.title('Model Performance Over Time')
    plt.grid(True)
    plt.tight_layout()
    plt.show()

# Example usage
plot_over_time('_data/edit_leaderboard.yml')
>>>>>>> REPLACE
```
2024-05-15 11:02:44 -07:00
Paul Gauthier
59e433996e moved 2024-05-15 11:00:18 -07:00
Paul Gauthier
e9009203c4 perms 2024-05-15 10:59:51 -07:00