Commit graph

2618 commits

Author SHA1 Message Date
Paul Gauthier
c271bfd932 Fixed /commit after repo refactor, added test coverage 2023-08-04 06:39:04 -03:00
Paul Gauthier
5fe0652099 copy 2023-08-03 14:27:15 -03:00
Paul Gauthier
9dfc23c660 copy 2023-08-03 12:43:08 -03:00
Paul Gauthier
3ef16827fc show a progress bar if there are on tags/idents caches 2023-08-03 12:07:53 -03:00
Paul Gauthier
9ef730fd97 copy 2023-08-03 11:48:24 -03:00
Paul Gauthier
1af38e943d copy 2023-08-03 11:45:51 -03:00
Paul Gauthier
c24c9d33a5 Fixed comment in -dev bump 2023-08-02 16:23:34 -03:00
Paul Gauthier
f15b8c610b set version to 0.11.0-dev 2023-08-02 16:22:00 -03:00
Paul Gauthier
ce27820e9a version bump to 0.11.0 2023-08-02 16:21:39 -03:00
Paul Gauthier
63acc7e999 Updated HISTORY 2023-08-02 16:21:07 -03:00
Paul Gauthier
4829d7ed0c Updated HISTORY 2023-08-02 13:17:26 -03:00
Paul Gauthier
1858f0504b Strip asterisks from filenames suggested by GPT-3.5 #157 #168 2023-08-02 06:58:59 -03:00
Paul Gauthier
f24c04320e copy 2023-08-01 09:35:28 -03:00
Paul Gauthier
d5a7aac560 include token/cost in log 2023-07-28 11:33:37 -03:00
Paul Gauthier
f5dd19a04f Updated HISTORY 2023-07-28 09:25:20 -03:00
paul-gauthier
4207be9aa1
Merge pull request #144 from paul-gauthier/chat-history
Automatically summarize earlier parts of the chat history
2023-07-28 09:23:57 -03:00
Paul Gauthier
80d5c0b75c use 3.5 for summaries 2023-07-27 22:54:26 -03:00
Paul Gauthier
d1d498bb24 cleanup 2023-07-27 22:34:41 -03:00
Paul Gauthier
16dea76691 Merge branch 'main' into chat-history 2023-07-27 22:32:33 -03:00
Paul Gauthier
832259b55b Bugfix reference to self.get_tracked_files, plus test coverage 2023-07-27 06:55:06 -03:00
Paul Gauthier
c6f99c9b66 Updated discord link 2023-07-27 06:47:47 -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
08ee61617f Updated discord link 2023-07-26 15:52:13 -03:00
Paul Gauthier
3e4b4d1b0d retry on APIConnectionError 2023-07-26 07:40:36 -03:00
Paul Gauthier
8ea4629e73 Merge branch 'main' into chat-history 2023-07-26 07:29:54 -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
133eff8bdf Merge branch 'refactor-repo' into chat-history 2023-07-25 09:20:22 -03:00
Paul Gauthier
5bb3935f7e ssh 2023-07-25 09:19:01 -03:00
Paul Gauthier
b3746db08b Merge branch 'main' into chat-history 2023-07-25 09:13:28 -03:00
Paul Gauthier
53e332526b Merge branch 'main' into refactor-repo 2023-07-25 09:13:20 -03:00
Paul Gauthier
05c1b3bc99 cleanup 2023-07-25 09:13:07 -03:00
Paul Gauthier
9050b9bd93 threading 2023-07-25 07:57:05 -03:00
Paul Gauthier
4e348102bf wip 2023-07-25 07:46:05 -03:00
Paul Gauthier
b849d16ec7 Updated HISTORY 2023-07-25 07:22:22 -03:00
Paul Gauthier
fcdd640a09 Strong prompt to never elide code 2023-07-25 07:04:14 -03:00
Paul Gauthier
f0ec6cb36a Expand the tail to ensure head ends with assistant msg 2023-07-25 06:58:41 -03:00
Paul Gauthier
4b41eb7525 aider: Fix variable name error in summarize method in history.py.
# Aider chat conversation:

USER:   File "/Users/gauthier/Projects/aider/aider/coders/base_coder.py", line 395, in run_loop
    return self.send_new_user_message(inp)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/aider/coders/base_coder.py", line 479, in send_new_user_message
    self.move_back_cur_messages(saved_message)
  File "/Users/gauthier/Projects/aider/aider/coders/base_coder.py", line 365, in move_back_cur_messages
    self.done_messages = self.summarizer.summarize(self.done_messages)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/gauthier/Projects/aider/aider/history.py", line 60, in summarize
    tail_tokens = sum(tokens for tokens, msg in sized[num:])
                                                      ^^^
NameError: name 'num' is not defined. Did you mean: 'sum'?

ASSISTANT: It seems like there's a typo in the code. The variable `num` is not defined in the current scope. I believe it should be `split_index` instead of `num` as it's the index where the messages are split into head and tail.

Here's the change that needs to be made in the `aider/history.py` file:

```python
aider/history.py
<<<<<<< ORIGINAL
        tail_tokens = sum(tokens for tokens, msg in sized[num:])
=======
        tail_tokens = sum(tokens for tokens, msg in sized[split_index:])
>>>>>>> UPDATED
```

Please confirm if this is the change you want to make.
2023-07-24 19:10:58 -03:00
Paul Gauthier
3c656fe3be aider: Ensure the head ends with an assistant message.
# Aider chat conversation:

USER: but we want the head to end with an assistant msg

ASSISTANT: To ensure that the head ends with an assistant message, we need to modify the `summarize` method in the `ChatSummary` class in the `aider/history.py` file.

After splitting the messages based on the token count, we need to check if the last message in the head is from the assistant. If not, we need to move messages from the head to the tail until we find an assistant message.

Here is the *edit block* for this change:

```python
aider/history.py
<<<<<<< ORIGINAL
    def summarize(self, messages):
        if len(messages) < 2:
            return messages

        sized = self.tokenize(messages)
        total = sum(tokens for tokens, _msg in sized)
        if total <= self.max_tokens:
            return messages

        tail_tokens = 0
        split_index = len(messages)
        half_max_tokens = self.max_tokens // 2

        # Iterate over the messages in reverse order
        for i in range(len(sized)-1, -1, -1):
            tokens, _msg = sized[i]
            if tail_tokens + tokens < half_max_tokens:
                tail_tokens += tokens
                split_index = i
            else:
                break

        head = messages[:split_index]
        tail = messages[split_index:]
=======
    def summarize(self, messages):
        if len(messages) < 2:
            return messages

        sized = self.tokenize(messages)
        total = sum(tokens for tokens, _msg in sized)
        if total <= self.max_tokens:
            return messages

        tail_tokens = 0
        split_index = len(messages)
        half_max_tokens = self.max_tokens // 2

        # Iterate over the messages in reverse order
        for i in range(len(sized)-1, -1, -1):
            tokens, _msg = sized[i]
            if tail_tokens + tokens < half_max_tokens:
                tail_tokens += tokens
                split_index = i
            else:
                break

        # Ensure the head ends with an assistant message
        while messages[split_index - 1]["role"] != "assistant" and split_index < len(messages):
            split_index += 1

        head = messages[:split_index]
        tail = messages[split_index:]
>>>>>>> UPDATED
```

This change ensures that the head of the messages ends with an assistant message.
2023-07-24 19:08:51 -03:00
Paul Gauthier
270ea21c05 aider: Change the summarize method in the ChatSummary class to split the messages so that the tail holds as close as possible but less than max_tokens//2 tokens and the head holds the rest.
# Aider chat conversation:

USER: instead of splitting the history in half based on the msg number, split it in half based on the token count

ASSISTANT: To implement this change, we need to modify the `summarize` method in the `ChatSummary` class in the `aider/history.py` file.

The current implementation splits the messages in half based on the number of messages. We need to change this to split the messages based on the token count.

Here are the steps to implement this change:

1. Calculate the total token count of all messages.
2. Iterate over the messages and keep a running total of the token count.
3. Once the running total exceeds half of the total token count, split the messages at that point.

Here is the *edit block* for this change:

```python
aider/history.py
<<<<<<< ORIGINAL
    def summarize(self, messages):
        num = len(messages)
        dump(num)
        if num < 2:
            return messages

        sized = self.tokenize(messages)
        total = sum(tokens for tokens, _msg in sized)
        if total <= self.max_tokens:
            return messages

        num = num // 2

        # we want the head to end with an assistant msg
        while messages[num]["role"] == "assistant" and num < len(messages) - 1:
            num += 1

        head = messages[:num]
        tail = messages[num:]
=======
    def summarize(self, messages):

^C KeyboardInterrupt

USER: instead of splitting the history in half based on the msg number, split it so that the tail holds as close as possible but less than `max_tokens`//2 tokens and head holds the rest

ASSISTANT: To implement this change, we need to modify the `summarize` method in the `ChatSummary` class in the `aider/history.py` file.

The current implementation splits the messages in half based on the number of messages. We need to change this to split the messages so that the tail holds as close as possible but less than `max_tokens`//2 tokens and head holds the rest.

Here are the steps to implement this change:

1. Iterate over the messages in reverse order and keep a running total of the token count.
2. Once the running total exceeds `max_tokens`//2, split the messages at that point.

Here is the *edit block* for this change:

```python
aider/history.py
<<<<<<< ORIGINAL
    def summarize(self, messages):
        num = len(messages)
        dump(num)
        if num < 2:
            return messages

        sized = self.tokenize(messages)
        total = sum(tokens for tokens, _msg in sized)
        if total <= self.max_tokens:
            return messages

        num = num // 2

        # we want the head to end with an assistant msg
        while messages[num]["role"] == "assistant" and num < len(messages) - 1:
            num += 1

        head = messages[:num]
        tail = messages[num:]
=======
    def summarize(self, messages):
        if len(messages) < 2:
            return messages

        sized = self.tokenize(messages)
        total = sum(tokens for tokens, _msg in sized)
        if total <= self.max_tokens:
            return messages

        tail_tokens = 0
        split_index = len(messages)
        half_max_tokens = self.max_tokens // 2

        # Iterate over the messages in reverse order
        for i in range(len(sized)-1, -1, -1):
            tokens, _msg = sized[i]
            if tail_tokens + tokens < half_max_tokens:
                tail_tokens += tokens
                split_index = i
            else:
                break

        head = messages[:split_index]
        tail = messages[split_index:]
>>>>>>> UPDATED
```

This change ensures that the tail of the messages holds as close as possible but less than `max_tokens`//2 tokens and the head holds the rest.
2023-07-24 19:08:13 -03:00
Paul Gauthier
0db9d210d7 Advise the user when chat history is being summarized 2023-07-24 19:05:57 -03:00
Paul Gauthier
844194c268 Merge branch 'refactor-repo' into chat-history 2023-07-24 18:48:26 -03:00
Paul Gauthier
c8f1c0609d tests and bugfix 2023-07-24 17:47:53 -03:00
Paul Gauthier
957f59c011 updated help 2023-07-24 17:35:47 -03:00
Paul Gauthier
cac627ae5f aider: Add None as the third argument in all calls to GitRepo.
# Aider chat conversation:

USER: `GitRepo` now takes a 3rd arg. add None as the missing arg in all calls

ASSISTANT: To add `None` as the third argument in all calls to `GitRepo`, we need to modify the `tests/test_repo.py` file.

Here are the changes:

```python
tests/test_repo.py
<<<<<<< ORIGINAL
        repo = GitRepo(InputOutput(), None)
=======
        repo = GitRepo(InputOutput(), None, None)
>>>>>>> UPDATED
```

```python
tests/test_repo.py
<<<<<<< ORIGINAL
        repo = GitRepo(InputOutput(), None)
=======
        repo = GitRepo(InputOutput(), None, None)
>>>>>>> UPDATED
```

```python
tests/test_repo.py
<<<<<<< ORIGINAL
        repo = GitRepo(InputOutput(), None)
=======
        repo = GitRepo(InputOutput(), None, None)
>>>>>>> UPDATED
```

```python
tests/test_repo.py
<<<<<<< ORIGINAL
        tracked_files = GitRepo(InputOutput(), [tempdir]).get_tracked_files()
=======
        tracked_files = GitRepo(InputOutput(), [tempdir], None).get_tracked_files()
>>>>>>> UPDATED
```

```python
tests/test_repo.py
<<<<<<< ORIGINAL
            git_repo = GitRepo(InputOutput(), None)
=======
            git_repo = GitRepo(InputOutput(), None, None)
>>>>>>> UPDATED
```
2023-07-24 17:32:09 -03:00
Paul Gauthier
64c50bab48 Accept either a git dname or a list of fnames 2023-07-24 17:31:00 -03:00
Paul Gauthier
256dd7bbd9 Merge branch 'main' into refactor-repo 2023-07-24 15:22:20 -03:00
Paul Gauthier
d146398434 set version to 0.10.1-dev 2023-07-24 15:12:37 -03:00