Skip to content

Commit 350fec0

Browse files
- added "gpt-v2-only-error" prompter, which prompts for error correction
but is otherwise the same as the fully ablated prompter;
1 parent d57705b commit 350fec0

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

src/coverup/prompt.py

+50-13
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def missing_coverage_prompt(self, segment: CodeSegment,
102102

103103

104104
class Gpt4PrompterV2(Prompter):
105-
"""Prompter for GPT-4."""
105+
"""Prompter for GPT."""
106106

107107
def __init__(self, *args, **kwargs):
108108
Prompter.__init__(self, *args, **kwargs)
@@ -188,7 +188,7 @@ def get_functions(self) -> T.List[T.Callable]:
188188

189189

190190
class Gpt4PrompterV2Ablated(Prompter):
191-
"""Prompter for GPT-4 that does not use coverage information."""
191+
"""Fully ablated GPT prompter."""
192192

193193
def __init__(self, *args, **kwargs):
194194
Prompter.__init__(self, *args, **kwargs)
@@ -218,23 +218,58 @@ def initial_prompt(self, segment: CodeSegment) -> T.List[dict]:
218218
""")
219219
]
220220

221+
221222
def error_prompt(self, segment: CodeSegment, error: str) -> T.List[dict] | None:
222223
return None
223-
# return [_message(f"""\
224-
#Executing the test yields an error, shown below.
225-
#Modify the test to correct it; respond only with the complete Python code in backticks.
226-
#
227-
#{error}""")
228-
# ]
224+
225+
226+
def missing_coverage_prompt(self, segment: CodeSegment,
227+
missing_lines: set, missing_branches: set) -> T.List[dict] | None:
228+
return None
229+
230+
231+
class Gpt4PrompterV2OnlyError(Prompter):
232+
"""Partially ablated GPT prompter that attempts error correction."""
233+
234+
def __init__(self, *args, **kwargs):
235+
Prompter.__init__(self, *args, **kwargs)
236+
237+
def initial_prompt(self, segment: CodeSegment) -> T.List[dict]:
238+
args = self.args
239+
module_name = get_module_name(segment.path, args.package_dir)
240+
filename = segment.path.relative_to(args.package_dir.parent)
241+
242+
return [
243+
_message(f"""
244+
You are an expert Python test-driven developer.
245+
The code below, extracted from {filename}, does not achieve full coverage.
246+
Create new pytest test functions that execute all lines and branches, always making
247+
sure that each test is correct and indeed improves coverage.
248+
Always send entire Python test scripts when proposing a new test or correcting one you
249+
previously proposed.
250+
Be sure to include assertions in the test that verify any applicable postconditions.
251+
Please also make VERY SURE to clean up after the test, so as to avoid state pollution;
252+
use 'monkeypatch' or 'pytest-mock' if appropriate.
253+
Write as little top-level code as possible, and in particular do not include any top-level code
254+
calling into pytest.main or the test itself.
255+
Respond ONLY with the Python code enclosed in backticks, without any explanation.
256+
```python
257+
{segment.get_excerpt(tag_lines=False, include_imports=False)}
258+
```
259+
""")
260+
]
261+
262+
def error_prompt(self, segment: CodeSegment, error: str) -> T.List[dict] | None:
263+
return [_message(f"""\
264+
Executing the test yields an error, shown below.
265+
Modify the test to correct it; respond only with the complete Python code in backticks.
266+
267+
{error}""")
268+
]
229269

230270
def missing_coverage_prompt(self, segment: CodeSegment,
231271
missing_lines: set, missing_branches: set) -> T.List[dict] | None:
232272
return None
233-
# return [_message(f"""\
234-
#The tests still lack coverage.
235-
#Modify to correct that; respond only with the complete Python code in backticks.
236-
#""")
237-
# ]
238273

239274

240275
class ClaudePrompter(Prompter):
@@ -313,6 +348,8 @@ def missing_coverage_prompt(self, segment: CodeSegment,
313348
"gpt": Gpt4PrompterV1,
314349
"gpt-v1": Gpt4PrompterV1,
315350
"gpt-v2": Gpt4PrompterV2,
351+
"gpt-v2-fully-ablated": Gpt4PrompterV2Ablated,
316352
"gpt-v2-ablated": Gpt4PrompterV2Ablated,
353+
"gpt-v2-only-error": Gpt4PrompterV2OnlyError,
317354
"claude": ClaudePrompter
318355
}

0 commit comments

Comments
 (0)