martinjosifoski
commited on
Commit
·
8d9acf3
1
Parent(s):
c21b758
Add flows and subflows for plan_oracle-code_debug_collab.
Browse files- CF_CodeCriticWrongAttemptWithPlan.py +10 -0
- CF_CodeCriticWrongAttemptWithPlan.yaml +95 -0
- CF_CodeDebugCollabWithPlan.py +12 -0
- CF_CodeDebugCollabWithPlan.yaml +72 -0
- CF_CodeDebugCriticWithPlan.py +13 -0
- CF_CodeDebugCriticWithPlan.yaml +36 -0
- __init__.py +5 -0
CF_CodeCriticWrongAttemptWithPlan.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
from flows.flow_verse import load_class
|
4 |
+
repository_id = os.environ.get("OpenAIChatAtomicFlow")
|
5 |
+
OpenAIChatAtomicFlow = load_class(repository_id, "OpenAIChatAtomicFlow")
|
6 |
+
|
7 |
+
|
8 |
+
class CF_CodeCriticWrongAttemptWithPlan(OpenAIChatAtomicFlow):
|
9 |
+
def __init__(self, **kwargs):
|
10 |
+
super().__init__(**kwargs)
|
CF_CodeCriticWrongAttemptWithPlan.yaml
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "CodeCriticWrongAttemptWithPlan_Flow"
|
2 |
+
verbose: True
|
3 |
+
description: "ToDO: add description"
|
4 |
+
|
5 |
+
model_name: "gpt-4"
|
6 |
+
generation_parameters:
|
7 |
+
n: 1
|
8 |
+
max_tokens: 3000
|
9 |
+
temperature: 0.3
|
10 |
+
|
11 |
+
model_kwargs:
|
12 |
+
top_p: 0.2
|
13 |
+
frequency_penalty: 0
|
14 |
+
presence_penalty: 0
|
15 |
+
|
16 |
+
system_message_prompt_template:
|
17 |
+
_target_: langchain.PromptTemplate
|
18 |
+
template: |2-
|
19 |
+
Your goal is to identify the issues with an incorrect competitive programming solution attempt.
|
20 |
+
|
21 |
+
The user will specify the problem by providing you with:
|
22 |
+
- the problem statement
|
23 |
+
- input description
|
24 |
+
- output description
|
25 |
+
- example test cases
|
26 |
+
- (optional) explanation of the test cases
|
27 |
+
- an incorrect Python solution attempt and a description of its issue
|
28 |
+
|
29 |
+
Additionally, the user will provide you with a conceptual solution to the problem which should guide your reasoning.
|
30 |
+
|
31 |
+
Crucially, your goal is to consider all aspects of the problem and pinpoint the issues with the solution attempt, and not to provide the code implementation yourself.
|
32 |
+
Some aspects to consider: Is the input correctly parsed? Is the output correctly formatted? Is the code implementation consistent with the conceptual solution? Are the corner cases correctly handled? Is there a logical mistake with the algorithm itself?
|
33 |
+
Use the code execution results provided in the issue description to guide your reasoning/debugging.
|
34 |
+
input_variables: []
|
35 |
+
template_format: jinja2
|
36 |
+
|
37 |
+
human_message_prompt_template:
|
38 |
+
_target_: langchain.PromptTemplate
|
39 |
+
template: "{{query}}"
|
40 |
+
input_variables:
|
41 |
+
- "query"
|
42 |
+
template_format: jinja2
|
43 |
+
|
44 |
+
query_message_prompt_template:
|
45 |
+
_target_: langchain.PromptTemplate
|
46 |
+
template: |2-
|
47 |
+
# Problem statement
|
48 |
+
{{problem_description}}
|
49 |
+
|
50 |
+
# Input description
|
51 |
+
{{input_description}}
|
52 |
+
|
53 |
+
# Output description
|
54 |
+
{{output_description}}
|
55 |
+
|
56 |
+
{{io_examples_and_explanation}}
|
57 |
+
|
58 |
+
# Conceptual solution
|
59 |
+
{{plan}}
|
60 |
+
|
61 |
+
# Solution attempt to be fixed
|
62 |
+
```python
|
63 |
+
{{code}}
|
64 |
+
```
|
65 |
+
|
66 |
+
{{testing_results_summary}}
|
67 |
+
|
68 |
+
|
69 |
+
Consider the problem statement, the conceptual solution, the code implementation and the issue. Why is the solution attempt incorrect? How should it be fixed? Explain your reasoning very concisely, and do not provide code.
|
70 |
+
input_variables:
|
71 |
+
- "problem_description"
|
72 |
+
- "input_description"
|
73 |
+
- "output_description"
|
74 |
+
- "io_examples_and_explanation"
|
75 |
+
- "plan"
|
76 |
+
- "code"
|
77 |
+
- "testing_results_summary"
|
78 |
+
template_format: jinja2
|
79 |
+
|
80 |
+
input_data_transformations: []
|
81 |
+
input_keys:
|
82 |
+
- "problem_description"
|
83 |
+
- "input_description"
|
84 |
+
- "output_description"
|
85 |
+
- "io_examples_and_explanation"
|
86 |
+
- "testing_results_summary"
|
87 |
+
- "plan"
|
88 |
+
- "code"
|
89 |
+
|
90 |
+
output_data_transformations:
|
91 |
+
- _target_: flows.data_transformations.KeyRename
|
92 |
+
old_key2new_key:
|
93 |
+
raw_response: "code_feedback"
|
94 |
+
output_keys:
|
95 |
+
- "code_feedback"
|
CF_CodeDebugCollabWithPlan.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flows.base_flows import GeneratorCriticFlow
|
2 |
+
|
3 |
+
|
4 |
+
class CF_CodeDebugCollabWithPlan(GeneratorCriticFlow):
|
5 |
+
def __init__(self, **kwargs):
|
6 |
+
super().__init__(**kwargs)
|
7 |
+
|
8 |
+
def _early_exit(self):
|
9 |
+
if self.flow_state.get("all_tests_passed", False):
|
10 |
+
return True
|
11 |
+
|
12 |
+
return super()._early_exit()
|
CF_CodeDebugCollabWithPlan.yaml
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "CodeDebugCollabWithPlan_Flow"
|
2 |
+
verbose: True
|
3 |
+
description: "ToDO: add description"
|
4 |
+
|
5 |
+
reset_generator_every_round: False
|
6 |
+
reset_critic_every_round: True
|
7 |
+
max_rounds: 2 # ToDo: To increase to 4
|
8 |
+
early_exit_key: "end_of_interaction"
|
9 |
+
|
10 |
+
input_data_transformations: []
|
11 |
+
input_keys:
|
12 |
+
- "problem_description"
|
13 |
+
- "input_description"
|
14 |
+
- "output_description"
|
15 |
+
- "io_examples_and_explanation"
|
16 |
+
- "public_tests_individual_io"
|
17 |
+
- "plan"
|
18 |
+
|
19 |
+
output_data_transformations:
|
20 |
+
- _target_: flows.data_transformations.KeyRename
|
21 |
+
old_key2new_key:
|
22 |
+
raw_response.code: "code"
|
23 |
+
output_keys:
|
24 |
+
- "code"
|
25 |
+
|
26 |
+
subflows_config:
|
27 |
+
- _target_: flows.flow_verse.instantiate_flow
|
28 |
+
repository_id: ${oc.env:CC_FLOWS}
|
29 |
+
class_name: CF_CodeWithPlan
|
30 |
+
overrides:
|
31 |
+
name: "CodeGenerator"
|
32 |
+
model_name: "gpt-4"
|
33 |
+
human_message_prompt_template:
|
34 |
+
_target_: langchain.PromptTemplate
|
35 |
+
template: |2-
|
36 |
+
{{testing_results_summary}}
|
37 |
+
|
38 |
+
{{code_feedback}}
|
39 |
+
|
40 |
+
|
41 |
+
Consider the problem statement, the last proposed solution, its issue and the provided feedback. Return a corrected version of the code that solves the original problem and resolves the issue, without any explanation, in the following format:
|
42 |
+
```python
|
43 |
+
{{code_placeholder}}
|
44 |
+
```
|
45 |
+
input_variables:
|
46 |
+
- code_feedback
|
47 |
+
- testing_results_summary
|
48 |
+
partial_variables:
|
49 |
+
code_placeholder: "{{python_code}}"
|
50 |
+
template_format: jinja2
|
51 |
+
default_human_input_keys:
|
52 |
+
- "code_feedback"
|
53 |
+
- "testing_results_summary"
|
54 |
+
output_data_transformations:
|
55 |
+
- _target_: flows.data_transformations.RegexFirstOccurrenceExtractor
|
56 |
+
regex: '(?<=```python)([\s\S]*?)(?=```)'
|
57 |
+
regex_fallback: '(?<=```)([\s\S]*?)(?=```)'
|
58 |
+
input_key: "raw_response"
|
59 |
+
output_key: "code"
|
60 |
+
strip: True
|
61 |
+
assert_unique: True
|
62 |
+
verbose: True
|
63 |
+
- _target_: flows.data_transformations.EndOfInteraction
|
64 |
+
end_of_interaction_string: "Final answer"
|
65 |
+
output_key: "end_of_interaction"
|
66 |
+
verbose: True
|
67 |
+
output_keys:
|
68 |
+
- "code"
|
69 |
+
- "end_of_interaction"
|
70 |
+
- _target_: flows.flow_verse.instantiate_flow
|
71 |
+
repository_id: ${oc.env:CC_FLOWS}
|
72 |
+
class_name: CF_CodeDebugCriticWithPlan
|
CF_CodeDebugCriticWithPlan.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flows.base_flows import SequentialFlow
|
2 |
+
|
3 |
+
|
4 |
+
class CF_CodeDebugCriticWithPlan(SequentialFlow):
|
5 |
+
def __init__(self, **kwargs):
|
6 |
+
super().__init__(**kwargs)
|
7 |
+
|
8 |
+
def _early_exit(self):
|
9 |
+
if self.flow_state.get("all_tests_passed", False):
|
10 |
+
self.flow_state["code_feedback"] = None
|
11 |
+
return True
|
12 |
+
|
13 |
+
return super()._early_exit()
|
CF_CodeDebugCriticWithPlan.yaml
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "CodeDebugCriticWithPlan_Flow"
|
2 |
+
verbose: True
|
3 |
+
description: "ToDo: add description"
|
4 |
+
|
5 |
+
early_exit_key: null
|
6 |
+
|
7 |
+
input_data_transformations: []
|
8 |
+
input_keys:
|
9 |
+
- "problem_description"
|
10 |
+
- "input_description"
|
11 |
+
- "output_description"
|
12 |
+
- "io_examples_and_explanation"
|
13 |
+
- "public_tests_individual_io"
|
14 |
+
- "code"
|
15 |
+
- "plan"
|
16 |
+
|
17 |
+
output_data_transformations:
|
18 |
+
- _target_: flows.data_transformations.KeyRename
|
19 |
+
old_key2new_key:
|
20 |
+
raw_response.testing_results_summary: "testing_results_summary"
|
21 |
+
raw_response.all_tests_passed: "all_tests_passed"
|
22 |
+
raw_response.code_feedback: "code_feedback"
|
23 |
+
output_keys:
|
24 |
+
- "testing_results_summary"
|
25 |
+
- "all_tests_passed"
|
26 |
+
- "code_feedback"
|
27 |
+
|
28 |
+
subflows_config:
|
29 |
+
- _target_: flows.flow_verse.instantiate_flow
|
30 |
+
repository_id: ${oc.env:CC_FLOWS}
|
31 |
+
class_name: CF_CodeTesting
|
32 |
+
overrides:
|
33 |
+
name: "CodeTestingCritic"
|
34 |
+
- _target_: flows.flow_verse.instantiate_flow
|
35 |
+
repository_id: ${oc.env:CC_FLOWS}
|
36 |
+
class_name: CF_CodeCriticWrongAttemptWithPlan
|
__init__.py
CHANGED
@@ -32,3 +32,8 @@ from .CF_CodeDebug import CF_CodeDebug
|
|
32 |
from .CF_CodeCriticWrongAttempt import CF_CodeCriticWrongAttempt
|
33 |
from .CF_CodeDebugCritic import CF_CodeDebugCritic
|
34 |
from .CF_CodeDebugCollab import CF_CodeDebugCollab
|
|
|
|
|
|
|
|
|
|
|
|
32 |
from .CF_CodeCriticWrongAttempt import CF_CodeCriticWrongAttempt
|
33 |
from .CF_CodeDebugCritic import CF_CodeDebugCritic
|
34 |
from .CF_CodeDebugCollab import CF_CodeDebugCollab
|
35 |
+
|
36 |
+
# cf-plan_oracle-code_debug_collab
|
37 |
+
from .CF_CodeCriticWrongAttemptWithPlan import CF_CodeCriticWrongAttemptWithPlan
|
38 |
+
from .CF_CodeDebugCriticWithPlan import CF_CodeDebugCriticWithPlan
|
39 |
+
from .CF_CodeDebugCollabWithPlan import CF_CodeDebugCollabWithPlan
|