Skip to content

Commit 4c61777

Browse files
committed
Provide insights about test results to help code gen
1 parent 11e004a commit 4c61777

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

TestRunner/GenericTestRunner.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
from abc import ABCMeta, abstractmethod
2-
31
import pytest
4-
2+
import subprocess
3+
from abc import ABCMeta, abstractmethod
54
from pytest_plugins import ResultsCollector, SessionStartPlugin
65

76

87
class GenericTestRunner(metaclass=ABCMeta):
98
@abstractmethod
109
def run(self, *args, **kwargs) -> (int, str): pass
1110

12-
import subprocess
13-
1411

1512
class SubProcessTestRunner(GenericTestRunner):
1613
code_dir: str

TestRunner/SubProcessTestRunner.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

main.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def generate_first_attempt(class_skeleton: str) -> None:
3434
_out.write(response.content)
3535

3636

37-
def generate_next_attempt(test_results: str) -> None:
37+
def generate_next_attempt(test_results: str, test_results_insights: str) -> None:
3838
cfg = lr.ChatAgentConfig(
3939
llm=lr.language_models.OpenAIGPTConfig(
4040
chat_model="ollama/llama3:latest",
@@ -53,6 +53,8 @@ def generate_next_attempt(test_results: str) -> None:
5353
{code_snippet}
5454
Here are the test results:
5555
{test_results}
56+
In addition, you may consider these insights about the test results when coming up with your solution:
57+
{test_results_insights}
5658
Update the code so that the tests will pass.
5759
Your output MUST contain all the same classes and methods as the input code.
5860
Do NOT add any other methods or commentary.
@@ -66,6 +68,27 @@ def generate_next_attempt(test_results: str) -> None:
6668
_out.write(response.content)
6769

6870

71+
def interpret_test_results(results: str) -> str:
72+
cfg = lr.ChatAgentConfig(
73+
llm=lr.language_models.OpenAIGPTConfig(
74+
chat_model="ollama/llama3:latest",
75+
chat_context_length=8000,
76+
),
77+
vecdb=None
78+
)
79+
agent = lr.ChatAgent(cfg)
80+
prompt = f"""
81+
You are an expert at interpreting the results of unit tests, and providing insight into what they mean.
82+
You should be descriptive about what variables are incorrect, and in what way.
83+
You should include information about which methods should be modified, and in what way.
84+
You should generally not provide code.
85+
Please provide insights about the following test results:
86+
{results}
87+
"""
88+
response = agent.llm_response(prompt)
89+
return response.content
90+
91+
6992
def teardown() -> None:
7093
codegen_path = os.path.join(".", "generated")
7194
build_path = os.path.join(".", "build")
@@ -89,7 +112,8 @@ def chat(class_skeleton: str, test_dir: str, test_runner: GenericTestRunner, max
89112
print("Done!")
90113
break
91114
elif test_exit_code == 1:
92-
generate_next_attempt(test_results)
115+
results_insights = interpret_test_results(test_results)
116+
generate_next_attempt(test_results, results_insights)
93117
else:
94118
solved = True
95119
print("There is some problem with the test suite itself.")
@@ -116,7 +140,7 @@ def main(
116140
assert os.path.isfile(class_skeleton), f"The class skeleton file provided does not exist! Got {class_skeleton}"
117141
assert os.path.exists(test_dir), f"The test-dir provided does not exist! Got {test_dir}"
118142

119-
tr: GenericTestRunner = InlineTestRunner("", test_dir)
143+
tr: GenericTestRunner = SubProcessTestRunner("", test_dir)
120144
chat(
121145
class_skeleton=class_skeleton,
122146
test_dir=test_dir,

0 commit comments

Comments
 (0)