Skip to content

Commit 63370bd

Browse files
committed
Give input code to the test interpreter
1 parent 1a267ca commit 63370bd

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

main.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
setup_colored_logging()
1313

1414

15-
def generate_first_attempt(sandbox: CodeGenSandbox) -> None:
15+
def generate_first_attempt(sandbox: CodeGenSandbox) -> str:
1616
with open(sandbox.get_sandboxed_class_path(), "r") as f:
1717
class_skeleton = f.read()
1818

1919
cfg = lr.ChatAgentConfig(
2020
llm=lr.language_models.OpenAIGPTConfig(
2121
chat_model="ollama/llama3:latest",
22-
chat_context_length=8000,
2322
),
2423
vecdb=None
2524
)
@@ -29,17 +28,20 @@ def generate_first_attempt(sandbox: CodeGenSandbox) -> None:
2928
f"Do NOT add any other methods or commentary."
3029
f"Your response should be ONLY the python code."
3130
f"Do not say 'here is the python code'"
31+
f"Do not surround your response with quotes or backticks."
32+
f"DO NOT EVER USE ``` in your output."
3233
f"Your output MUST be valid, runnable python code and NOTHING else."
3334
f"{class_skeleton}")
3435
with open(sandbox.get_sandboxed_class_path(), "w+") as _out:
3536
_out.write(response.content)
3637

38+
return response.content
39+
3740

38-
def generate_next_attempt(sandbox: CodeGenSandbox, test_results: str, test_results_insights: str) -> None:
41+
def generate_next_attempt(sandbox: CodeGenSandbox, test_results: str, test_results_insights: str) -> str:
3942
cfg = lr.ChatAgentConfig(
4043
llm=lr.language_models.OpenAIGPTConfig(
4144
chat_model="ollama/llama3:latest",
42-
chat_context_length=8000,
4345
),
4446
vecdb=None
4547
)
@@ -62,19 +64,21 @@ def generate_next_attempt(sandbox: CodeGenSandbox, test_results: str, test_resul
6264
Your response should be ONLY the python code.
6365
Do not say 'here is the python code'
6466
Do not surround your response with quotes or backticks.
67+
DO NOT EVER USE ``` in your output.
6568
Your response should NEVER start or end with ```
6669
Your output MUST be valid, runnable python code and NOTHING else.
6770
"""
6871
response = agent.llm_response(prompt)
6972
with open(sandbox.get_sandboxed_class_path(), "w") as _out:
7073
_out.write(response.content)
7174

75+
return response.content
76+
7277

73-
def interpret_test_results(results: str) -> str:
78+
def interpret_test_results(results: str, code: str) -> str:
7479
cfg = lr.ChatAgentConfig(
7580
llm=lr.language_models.OpenAIGPTConfig(
7681
chat_model="ollama/llama3:latest",
77-
chat_context_length=8000,
7882
),
7983
vecdb=None
8084
)
@@ -86,6 +90,8 @@ def interpret_test_results(results: str) -> str:
8690
You should generally not provide code.
8791
Please provide insights about the following test results:
8892
{results}
93+
Those results were produced by the following code:
94+
{code}
8995
"""
9096
response = agent.llm_response(prompt)
9197
return response.content
@@ -103,23 +109,23 @@ def teardown() -> None:
103109

104110

105111
def chat(sandbox: CodeGenSandbox, test_runner: GenericTestRunner, max_epochs: int=5) -> None:
106-
generate_first_attempt(sandbox)
112+
code_attempt = generate_first_attempt(sandbox)
107113
solved = False
108114
for _ in range(max_epochs):
109-
# test_exit_code, test_results = get_test_results()
115+
# test_exit_code, test_result(s = get_test_results()
110116
test_exit_code, test_results = test_runner.run()
111117
print(test_results)
112118
if test_exit_code == 0:
113119
solved = True
114120
print("Done!")
115121
break
116-
elif test_exit_code == 1:
117-
results_insights = interpret_test_results(test_results)
118-
generate_next_attempt(sandbox, test_results, results_insights)
119122
else:
120-
solved = True
121-
print("There is some problem with the test suite itself.")
122-
break
123+
results_insights = interpret_test_results(test_results, code_attempt)
124+
code_attempt = generate_next_attempt(sandbox, test_results, results_insights)
125+
# else:
126+
# solved = True
127+
# print("There is some problem with the test suite itself.")
128+
# break
123129
# teardown()
124130
if not solved:
125131
print(f"Reached the end of epoch {max_epochs} without finding a solution :(")

0 commit comments

Comments
 (0)