Commit graph

10 commits

Author SHA1 Message Date
Paul Gauthier
6419e6c390 Move get_input function into utils.py and update the call to get_input in coder.py to use the new utils.get_input function.
# Context:
USER: move get_input into utils. pass in history_file and fnames as params rather than referencing them with self.
ASSISTANT: To move the `get_input` function into `utils.py`, we will remove it from the `Coder` class in `coder.py` and add it to `utils.py`. We will also update the function to accept `history_file` and `fnames` as parameters.

```python
coder.py
<<<<<<< ORIGINAL
    def get_input(self):
        inp = ""
        multiline_input = False

        style = Style.from_dict({'': 'green'})

        while True:
            completer_instance = FileContentCompleter(self.fnames)
            if multiline_input:
                show = ". "
            else:
                show = "> "

            try:
                line = prompt(
                    show,
                    completer=completer_instance,
                    history=FileHistory(self.history_file),
                    style=style,
                )
            except EOFError:
                return
            if line.strip() == "{" and not multiline_input:
                multiline_input = True
                continue
            elif line.strip() == "}" and multiline_input:
                break
            elif multiline_input:
                inp += line + "\n"
            else:
                inp = line
                break

        print()
        return inp
=======
>>>>>>> UPDATED
```

```python
utils.py
<<<<<<< ORIGINAL
=======
def get_input(history_file, fnames):
    inp = ""
    multiline_input = False

    style = Style.from_dict({'': 'green'})

    while True:
        completer_instance = FileContentCompleter(fnames)
        if multiline_input:
            show = ". "
        else:
            show = "> "

        try:
            line = prompt(
                show,
                completer=completer_instance,
                history=FileHistory(history_file),
                style=style,
            )
        except EOFError:
            return
        if line.strip() == "{" and not multiline_input:
            multiline_input = True
            continue
        elif line.strip() == "}" and multiline_input:
            break
        elif multiline_input:
            inp += line + "\n"
        else:
            inp = line
            break

    print()
    return inp
>>>>>>> UPDATED
```

Now, update the call to `get_input` in `coder.py` to use the new `utils.get_input` function:

```python
coder.py
<<<<<<< ORIGINAL
        inp = self.get_input()
=======
        inp = utils.get_input(self.history_file, self.fnames)
>>>>>>> UPDATED
```
2023-05-09 10:09:42 -07:00
Paul Gauthier
1c9bef484d add a trailing newline when replacing 2023-05-09 09:49:43 -07:00
Paul Gauthier
941b1e50eb added docstring to strip_quoted_wrapping 2023-05-09 07:42:05 -07:00
Paul Gauthier
8a8bc3e244 Refactor replace_most_similar_chunk function and update test cases. 2023-05-09 07:39:37 -07:00
Paul Gauthier
106b72ad70 WIP: Remove print statement in do_replace function. 2023-05-09 07:33:58 -07:00
Paul Gauthier
fb12b73975 WIP: Refactor do_replace method to utils module and update references in coder module. 2023-05-09 07:31:26 -07:00
Paul Gauthier
1b57a6a703 lint 2023-05-09 00:16:17 -07:00
Paul Gauthier
85c902843a Move quoted_file function from coder.py to utils.py and update get_files_content function in coder.py to use utils.quoted_file.
# Context:
USER: move quoted_file to utils
ASSISTANT: To move the `quoted_file` function from `coder.py` to `utils.py`, we will remove it from `coder.py` and add it to `utils.py`.

```python
coder.py
<<<<<<< ORIGINAL
    def quoted_file(self, fname):
        prompt = "\n"
        prompt += fname
        prompt += "\n```\n"
        prompt += Path(fname).read_text()
        prompt += "\n```\n"
        return prompt

    def get_files_content(self):
        prompt = ""
        for fname in self.fnames:
            prompt += self.quoted_file(fname)
        return prompt
=======
    def get_files_content(self):
        prompt = ""
        for fname in self.fnames:
            prompt += utils.quoted_file(fname)
        return prompt
>>>>>>> UPDATED
```

```python
utils.py
<<<<<<< ORIGINAL
def strip_quoted_wrapping(res, fname=None):
    if not res:
        return res

    res = res.splitlines()

    if fname and res[0].strip().endswith(Path(fname).name):
        res = res[1:]

    if res[0].startswith("```") and res[-1].startswith("```"):
        res = res[1:-1]

    res = "\n".join(res)
    if res and res[-1] != "\n":
        res += "\n"

    return res
=======
def quoted_file(fname):
    prompt = "\n"
    prompt += fname
    prompt += "\n```\n"
    prompt += Path(fname).read_text()
    prompt += "\n```\n"
    return prompt

def strip_quoted_wrapping(res, fname=None):
    if not res:
        return res

    res = res.splitlines()

    if fname and res[0].strip().endswith(Path(fname).name):
        res = res[1:]

    if res[0].startswith("```") and res[-1].startswith("```"):
        res = res[1:-1]

    res = "\n".join(res)
    if res and res[-1] != "\n":
        res += "\n"

    return res
>>>>>>> UPDATED
```

Now the `quoted_file` function has been moved to `utils.py`, and the `get_files_content` function in `coder.py` has been updated to use `utils.quoted_file`.
2023-05-09 00:00:48 -07:00
Paul Gauthier
1b4266c33c WIP: Refactor coder.py to use utils.replace_most_similar_chunk and add utils.strip_quoted_wrapping. 2023-05-08 23:58:14 -07:00
Paul Gauthier
c1db6876d6 rename 2023-05-08 23:49:14 -07:00