aider is AI pair programming in your terminal https://aider.chat/
Find a file
Daniel Vainsencher abf8d5e60d aider: Refactored format_messages to use a new function format_content for line-by-line formatting.
# Aider chat conversation:

USER: Now refactor format_messages: extract a function that takes a role and content (where content is a string), and returns the line by line formatted string.

ASSISTANT: To refactor `format_messages`, we will:

1. Create a new function `format_content` that takes a role and content (where content is a string) and returns the line-by-line formatted string.
2. Update `format_messages` to use `format_content`.

Here are the *SEARCH/REPLACE* blocks:

aider/utils.py
```python
<<<<<<< SEARCH
def format_messages(messages, title=None):
=======
def format_content(role, content):
    formatted_lines = []
    for line in content.splitlines():
        formatted_lines.append(f"{role} {line}")
    return "\n".join(formatted_lines)

>>>>>>> REPLACE
```

aider/utils.py
```python
<<<<<<< SEARCH
        elif isinstance(content, str):  # Handle string content
            for line in content.splitlines():
                output.append(f"{role} {line}")
=======
        elif isinstance(content, str):  # Handle string content
            output.append(format_content(role, content))
>>>>>>> REPLACE
```

USER:
# Fix any errors below, if possible.

## Running: flake8 --select=E9,F821,F823,F831,F406,F407,F701,F702,F704,F706 --show-source --isolated aider/utils.py

aider/utils.py:94:8: F821 undefined name 'title'
    if title:
       ^
aider/utils.py:95:26: F821 undefined name 'title'
        output.append(f"{title.upper()} {'*' * 50}")
                         ^
aider/utils.py:97:16: F821 undefined name 'messages'
    for msg in messages:
               ^
aider/utils.py:115:24: F821 undefined name 'format_messages'
    formatted_output = format_messages(messages, title)
                       ^

## See relevant lines below marked with █.

aider/utils.py:
...⋮...
 87│def format_content(role, content):
 88│    formatted_lines = []
...⋮...
 91│    return "\n".join(formatted_lines)
 92│
 93│    output = []
 94█    if title:
 95█        output.append(f"{title.upper()} {'*' * 50}")
 96│
 97█    for msg in messages:
 98│        output.append("")
 99│        role = msg["role"].upper()
100│        content = msg.get("content")
...⋮...
112│
113│
114│def show_messages(messages, title=None, functions=None):
115█    formatted_output = format_messages(messages, title)
116│    print(formatted_output)
117│
118│    if functions:
...⋮...

ASSISTANT: To fix the errors, we need to ensure that the `format_messages` function is properly defined and that the misplaced code is correctly organized. Here are the corrected *SEARCH/REPLACE* blocks:

aider/utils.py
```python
<<<<<<< SEARCH
    return "\n".join(formatted_lines)

    output = []
    if title:
        output.append(f"{title.upper()} {'*' * 50}")

    for msg in messages:
        output.append("")
        role = msg["role"].upper()
        content = msg.get("content")
        if isinstance(content, list):  # Handle list content (e.g., image messages)
            for item in content:
                if isinstance(item, dict) and "image_url" in item:
                    output.append(f"{role} Image URL: {item['image_url']['url']}")
        elif isinstance(content, str):  # Handle string content
            output.append(format_content(role, content))
        content = msg.get("function_call")
        if content:
            output.append(f"{role} {content}")

    return "\n".join(output)
=======
    return "\n".join(formatted_lines)

def format_messages(messages, title=None):
    output = []
    if title:
        output.append(f"{title.upper()} {'*' * 50}")

    for msg in messages:
        output.append("")
        role = msg["role"].upper()
        content = msg.get("content")
        if isinstance(content, list):  # Handle list content (e.g., image messages)
            for item in content:
                if isinstance(item, dict) and "image_url" in item:
                    output.append(f"{role} Image URL: {item['image_url']['url']}")
        elif isinstance(content, str):  # Handle string content
            output.append(format_content(role, content))
        content = msg.get("function_call")
        if content:
            output.append(f"{role} {content}")

    return "\n".join(output)
>>>>>>> REPLACE
```
2024-06-07 09:39:03 -04:00
.github ignore README for actions 2024-06-05 16:14:21 -07:00
aider aider: Refactored format_messages to use a new function format_content for line-by-line formatting. 2024-06-07 09:39:03 -04:00
benchmark copy 2024-06-02 09:28:56 -07:00
docker Put build-essential back into dockerfile 2023-10-31 14:52:04 -07:00
scripts fixed link 2024-06-06 15:25:23 -07:00
share Adapted content for just the docs 2024-06-05 12:29:32 -07:00
tests fix unicode err 2024-05-23 15:02:31 -07:00
website copy 2024-06-07 05:30:18 -07:00
.dockerignore prep docker build to run in github action 2023-10-18 08:45:02 -07:00
.flake8 debug 2023-05-08 22:55:55 -07:00
.gitignore ignore jekyll stuff 2024-05-15 10:58:04 -07:00
.pre-commit-config.yaml do isort first 2023-05-30 13:55:28 -07:00
CNAME Create CNAME 2023-05-15 12:54:06 -07:00
CONTRIBUTING.md Updated contributing 2024-05-15 11:47:29 -07:00
dev-requirements.in cog to update usage.md 2024-06-05 19:43:24 -07:00
dev-requirements.txt cog to update usage.md 2024-06-05 19:43:24 -07:00
HISTORY.md docs: update HISTORY.md 2024-06-06 12:31:18 +09:00
LICENSE.txt Added Apache 2.0 license 2023-05-15 08:29:00 -07:00
MANIFEST.in wip 2023-06-08 12:44:41 -07:00
pytest.ini don't test _site 2024-05-15 11:46:10 -07:00
README.md fixed broken links 2024-06-06 15:14:41 -07:00
requirements.in Added lint/test_outcome 2024-05-19 08:13:20 -07:00
requirements.txt bump deps for +grep-ast==0.3.2 2024-05-20 09:19:02 -07:00
setup.py added 3.12 to pypi classifiers 2024-01-05 14:50:37 -08:00

Aider is AI pair programming in your terminal

Aider lets you pair program with LLMs, to edit code in your local git repository. Start a new project or work with an existing git repo. Aider works best with GPT-4o and Claude 3 Opus and can connect to almost any LLM.

aider screencast

Getting started

You can get started quickly like this:

$ pip install aider-chat

# To work with GPT-4o
$ export OPENAI_API_KEY=your-key-goes-here
$ aider 

# To work with Claude 3 Opus:
$ export ANTHROPIC_API_KEY=your-key-goes-here
$ aider --opus

See the installation instructions and other documentation for more details.

Features

  • Chat with aider about your code: aider <file1> <file2> ...
  • Ask for changes:
    • New features, test cases, improvements.
    • Bug fixes, updated docs or code refactors.
    • Paste in a GitHub issue that needs to be solved.
  • Aider will edit your files to complete your request.
  • Aider automatically git commits changes with a sensible commit message.
  • Aider works with most popular languages: python, javascript, typescript, php, html, css, and more...
  • Aider works best with GPT-4o and Claude 3 Opus and can connect to almost any LLM.
  • Aider can make coordinated changes across multiple files at once.
  • Aider uses a map of your entire git repo, which helps it work well in larger codebases.
  • You can also edit files in your editor while chatting with aider. Aider will notice and always use the latest version. So you can bounce back and forth between aider and your editor, to collaboratively code with AI.
  • Images can be added to the chat (GPT-4o, GPT-4 Turbo, etc).
  • URLs can be added to the chat and aider will read their content.
  • Code with your voice using speech recognition.

State of the art

Aider has the top score on SWE Bench. SWE Bench is a challenging software engineering benchmark where aider solved real GitHub issues from popular open source projects like django, scikitlearn, matplotlib, etc.

aider swe bench

Documentation

Kind words from users

  • The best AI coding assistant so far. -- Matthew Berman
  • Hands down, this is the best AI coding assistant tool so far. -- IndyDevDan
  • Aider ... has easily quadrupled my coding productivity. -- SOLAR_FIELDS
  • It's a cool workflow... Aider's ergonomics are perfect for me. -- qup
  • It's really like having your senior developer live right in your Git repo - truly amazing! -- rappster
  • What an amazing tool. It's incredible. -- valyagolev
  • Aider is such an astounding thing! -- cgrothaus
  • It was WAY faster than I would be getting off the ground and making the first few working versions. -- Daniel Feldman
  • THANK YOU for Aider! It really feels like a glimpse into the future of coding. -- derwiki
  • It's just amazing. It is freeing me to do things I felt were out my comfort zone before. -- Dougie
  • This project is stellar. -- funkytaco
  • Amazing project, definitely the best AI coding assistant I've used. -- joshuavial
  • I absolutely love using Aider ... It makes software development feel so much lighter as an experience. -- principalideal0
  • I have been recovering from multiple shoulder surgeries ... and have used aider extensively. It has allowed me to continue productivity. -- codeninja
  • I am an aider addict. I'm getting so much more work done, but in less time. -- dandandan
  • After wasting $100 on tokens trying to find something better, I'm back to Aider. It blows everything else out of the water hands down, there's no competition whatsoever. -- SystemSculpt
  • Best agent for actual dev work in existing codebases. -- Nick Dobos