Commit graph

4734 commits

Author SHA1 Message Date
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
Daniel Vainsencher
a0b279f105 Refactored format_messages to use format_content for string content handling. 2024-06-07 09:39:03 -04:00
Daniel Vainsencher
69c27d6cd1 aider: Refactored show_messages to call format_messages for formatting title and messages.
# Aider chat conversation:

USER: Refactor show_messages in utils, so that the formatting of title and messages is done in a separate function which returns a string. show_messages should call it and print its output.

ASSISTANT: To refactor the `show_messages` function, we will:

1. Create a new function `format_messages` that formats the title and messages and returns a string.
2. Update `show_messages` to call `format_messages` and print its output.

Here are the *SEARCH/REPLACE* blocks:

aider/utils.py
```python
<<<<<<< SEARCH
def show_messages(messages, title=None, functions=None):
    if title:
        print(title.upper(), "*" * 50)

    for msg in messages:
        print()
        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:
                    print(role, "Image URL:", item["image_url"]["url"])
        elif isinstance(content, str):  # Handle string content
            for line in content.splitlines():
                print(role, line)
        content = msg.get("function_call")
        if content:
            print(role, content)

    if functions:
        dump(functions)
=======
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
            for line in content.splitlines():
                output.append(f"{role} {line}")
        content = msg.get("function_call")
        if content:
            output.append(f"{role} {content}")

    return "\n".join(output)

def show_messages(messages, title=None, functions=None):
    formatted_output = format_messages(messages, title)
    print(formatted_output)

    if functions:
        dump(functions)
>>>>>>> REPLACE
```
2024-06-07 09:39:03 -04:00
Paul Gauthier
be0520f62f copy 2024-06-07 05:30:18 -07:00
Paul Gauthier
f2de9d26c7 added techfren video to tutorials 2024-06-07 05:27:32 -07:00
Paul Gauthier
2be24f207f copy 2024-06-06 16:44:00 -07:00
Paul Gauthier
329e16e59b copy 2024-06-06 16:42:24 -07:00
Paul Gauthier
519b95713b browser blog & doc need to be separate 2024-06-06 16:05:13 -07:00
Paul Gauthier
435e9a0d86 fixing broken links 2024-06-06 16:00:17 -07:00
Paul Gauthier
f760eacfd6 fixed link 2024-06-06 15:25:23 -07:00
Paul Gauthier
f97ed15dd3 fixed broken links 2024-06-06 15:14:41 -07:00
Paul Gauthier
fa3df117d9 copy 2024-06-06 14:52:31 -07:00
Paul Gauthier
30f4a905c1 renamed config/options and get_md_help() 2024-06-06 14:00:14 -07:00
Paul Gauthier
53deb04e75 use dashed-names not underscore_names in yaml 2024-06-06 13:46:32 -07:00
Paul Gauthier
65c9a7866a improved handling of defaults 2024-06-06 13:40:16 -07:00
Paul Gauthier
3be2c3e893 copy 2024-06-06 12:49:12 -07:00
Paul Gauthier
645ace1d0e fix defaults in sample yml 2024-06-06 12:46:07 -07:00
Paul Gauthier
0068a35554 Merge remote-tracking branch 'origin/main' 2024-06-06 12:41:50 -07:00
Paul Gauthier
2d62e3fb1f add sample aider.conf.yml 2024-06-06 12:40:25 -07:00
Paul Gauthier
caca261587 output nice md usage 2024-06-06 12:26:06 -07:00
Paul Gauthier
8e9cbcc014 Refactored MarkdownHelpFormatter to improve formatting and display additional information about actions. 2024-06-06 12:14:20 -07:00
Paul Gauthier
e7aafd9590 aider: Add argument formatter to print arguments in a specified format.
# Aider chat conversation:

USER: Add an args formatter that prints out args like this:

## Output Settings:

### --dark-mode
Use colors suitable for a dark terminal background
Default: False

### --light-mode
Use colors suitable for a light terminal background
Default: False

...

ASSISTANT: To add an argument formatter that prints out arguments in the specified format, we need to:

1. Create a new formatter class.
2. Update the `get_help` function to use this new formatter.

Here are the changes:

1. Create a new file `aider/args_formatter.py` with the custom formatter class.
2. Update `aider/args.py` to use this new formatter.

Let's start with the new file:

aider/args_formatter.py
```python
<<<<<<< SEARCH
=======
import argparse

class CustomHelpFormatter(argparse.HelpFormatter):
    def start_section(self, heading):
        super().start_section(f"## {heading}:")

    def _format_action(self, action):
        parts = []
        if action.help:
            parts.append(f"### --{action.dest}")
            parts.append(action.help)
            if action.default is not argparse.SUPPRESS:
                parts.append(f"Default: {action.default}")
        return "\n".join(parts)

    def _format_action_invocation(self, action):
        return ""

    def _format_args(self, action, default_metavar):
        return ""
>>>>>>> REPLACE
```

Next, update `aider/args.py` to use this new formatter:

aider/args.py
```python
<<<<<<< SEARCH
from aider import __version__, models
=======
from aider import __version__, models
from aider.args_formatter import CustomHelpFormatter
>>>>>>> REPLACE
```

aider/args.py
```python
<<<<<<< SEARCH
        description="aider is GPT powered coding in your terminal",
=======
        description="aider is GPT powered coding in your terminal",
        formatter_class=CustomHelpFormatter,
>>>>>>> REPLACE
```

aider/args.py
```python
<<<<<<< SEARCH
    parser = get_parser([], None)
=======
    parser = get_parser([], None)
    parser.formatter_class = CustomHelpFormatter
>>>>>>> REPLACE
```
2024-06-06 11:38:45 -07:00
paul-gauthier
1b7a04f168
Merge pull request #647 from eltociear/patch-4
docs: update HISTORY.md
2024-06-06 11:14:26 -07:00
Paul Gauthier
0e5342fdb8 copy 2024-06-06 11:01:27 -07:00
Paul Gauthier
3cda6d7dd3 copy 2024-06-06 10:40:57 -07:00
Paul Gauthier
ef08b2fa1b copy 2024-06-06 10:37:16 -07:00
Paul Gauthier
9873db94f0 copy 2024-06-06 10:23:27 -07:00
Paul Gauthier
3e6a4d5edc copy 2024-06-06 10:21:09 -07:00
Paul Gauthier
3073a02450 copy 2024-06-06 10:11:49 -07:00
Paul Gauthier
36d6dc820a copy 2024-06-06 10:02:18 -07:00
Paul Gauthier
8c3ccf5054 copy 2024-06-06 09:54:24 -07:00
Paul Gauthier
f2ab3c6966 copy 2024-06-06 09:44:53 -07:00
Paul Gauthier
542bcaab76 copy 2024-06-06 09:36:41 -07:00
Paul Gauthier
8e868e3a2d copy 2024-06-06 09:22:25 -07:00
Paul Gauthier
ed8a807b6a moved _include -> _includes; added footer 2024-06-06 09:22:08 -07:00
Paul Gauthier
6847ce5434 copy 2024-06-06 09:01:06 -07:00
Paul Gauthier
da2a7638ab copy 2024-06-06 07:27:00 -07:00
Paul Gauthier
4f42b6038a copy 2024-06-06 06:52:43 -07:00
Paul Gauthier
6d4c87a54a copy 2024-06-06 06:43:56 -07:00
Paul Gauthier
bd52643dbe copy 2024-06-06 06:30:15 -07:00
Paul Gauthier
e341fb9baa copy 2024-06-06 06:26:57 -07:00
Paul Gauthier
c6074c16f3 copy 2024-06-05 21:17:50 -07:00
Paul Gauthier
dc66f8e8e3 copy 2024-06-05 21:17:41 -07:00
Paul Gauthier
220ae44725 copy 2024-06-05 21:16:18 -07:00
Paul Gauthier
9437fb28c4 removed configargparse.YAMLConfigFileParser 2024-06-05 21:14:54 -07:00
Paul Gauthier
01f1e62269 split up install 2024-06-05 21:13:56 -07:00
Paul Gauthier
7bd8d26f95 copy 2024-06-05 21:05:15 -07:00
Paul Gauthier
f8b30e0703 added .env docs 2024-06-05 20:58:34 -07:00
Paul Gauthier
0b7bee8712 repo-map 2024-06-05 20:55:41 -07:00
Paul Gauthier
c5e127d6fa Broke apart llms 2024-06-05 20:50:55 -07:00