Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Sep 9, 2024
1 parent 9d66401 commit 3c98d5d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 44 deletions.
2 changes: 1 addition & 1 deletion gptme/codeblock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from collections.abc import Generator
from dataclasses import dataclass
from xml.etree import ElementTree


Expand Down
2 changes: 1 addition & 1 deletion gptme/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections.abc import Generator
from copy import copy

from ..codeblock import Codeblock
from .codeblock import Codeblock
from .message import Message, len_tokens
from .models import get_model

Expand Down
6 changes: 2 additions & 4 deletions gptme/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def get_doc(self, _doc="") -> str:
_doc += "\n\n"
_doc += f"ToolSpec: {self.name}\n{self.desc}"
if self.instructions:
_doc += f"\n# Instructions: {self.instructions}"
_doc += f"\n\n# Instructions\n\n{self.instructions}"
if self.examples:
_doc += (
f"\n# Examples: {transform_examples_to_chat_directives(self.examples)}"
)
_doc += f"\n\n# Examples\n\n{transform_examples_to_chat_directives(self.examples)}"
return _doc
33 changes: 1 addition & 32 deletions gptme/tools/patch.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,8 @@
"""
Gives the LLM agent the ability to patch text files, by using a adapted version git conflict markers.
The format is suitable for small changes to files we have written in the past, without having to rewrite the whole file.
Format:
.. code-block:: patch
```patch <filename>
<<<<<<< ORIGINAL
original code
=======
modified code
>>>>>>> UPDATED
```
Example:
.. chat::
User: edit `hello.py` to ask for the name to greet
Assistant:
```patch hello.py
<<<<<<< ORIGINAL
print("Hello world")
=======
name = input("What is your name? ")
print(f"Hello {name}")
>>>>>>> UPDATED
```
System: Patch applied
"""

# TODO: support multiple patches in one codeblock (or make it clear that only one patch per codeblock is supported/applied)

import re
from collections.abc import Generator
from pathlib import Path
Expand Down Expand Up @@ -90,6 +58,7 @@ def patch_to_output(patch: str, filename: str, append: bool = False) -> str:
print(f"Hello {name}")
>>>>>>> UPDATED
''')}
> System: Patch applied
> User: change the codeblock to append to the file
> Assistant: {patch_to_output("patch.py", '''
Expand Down
10 changes: 5 additions & 5 deletions tests/test_codeblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def hello():
More text
"""
assert Codeblock.iter_from_markdown(markdown) == [
("python", 'def hello():\n print("Hello, World!")')
Codeblock("python", 'def hello():\n print("Hello, World!")')
]


Expand All @@ -31,11 +31,11 @@ def greet(name):
```
"""
assert Codeblock.iter_from_markdown(markdown) == [
(
Codeblock(
"java",
'public class Main {\n public static void main(String[] args) {\n System.out.println("Hello, Java!");\n }\n}',
),
("python", 'def greet(name):\n return f"Hello, {name}!"'),
Codeblock("python", 'def greet(name):\n return f"Hello, {name}!"'),
]


Expand All @@ -51,7 +51,7 @@ def print_readme():
```
"""
assert Codeblock.iter_from_markdown(markdown) == [
(
Codeblock(
"python",
"def print_readme():\n print('''Usage:\n```javascript\ncallme()\n```\n''')",
)
Expand All @@ -77,5 +77,5 @@ def hello():
```
"""
assert Codeblock.iter_from_markdown(markdown) == [
("", 'def hello():\n print("Hello, World!")')
Codeblock("", 'def hello():\n print("Hello, World!")')
]
3 changes: 2 additions & 1 deletion tests/test_logmanager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from gptme.codeblock import Codeblock
from gptme.logmanager import LogManager, Message


Expand All @@ -18,7 +19,7 @@ def test_get_last_codeblock():
""",
)
)
assert ("python", "print('world')") == log.get_last_codeblock()
assert Codeblock("python", "print('world')") == log.get_last_codeblock()


def test_branch():
Expand Down

0 comments on commit 3c98d5d

Please sign in to comment.