martinjosifoski commited on
Commit
c21b758
1 Parent(s): 68afe75

Add support for cf-code_debug_collab.

Browse files
CF_CodeCriticWrongAttempt.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_CodeCriticWrongAttempt(OpenAIChatAtomicFlow):
9
+ def __init__(self, **kwargs):
10
+ super().__init__(**kwargs)
CF_CodeCriticWrongAttempt.yaml ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "CodeCriticWrongAttempt_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
+ 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.
30
+ Some aspects to consider: Is the input correctly parsed? Is the output correctly formatted? Are the corner cases correctly handled? Is there a logical mistake with the algorithm itself?
31
+ Use the code execution results provided in the issue description to guide your reasoning/debugging.
32
+ input_variables: []
33
+ template_format: jinja2
34
+
35
+ human_message_prompt_template:
36
+ _target_: langchain.PromptTemplate
37
+ template: "{{query}}"
38
+ input_variables:
39
+ - "query"
40
+ template_format: jinja2
41
+
42
+ query_message_prompt_template:
43
+ _target_: langchain.PromptTemplate
44
+ template: |2-
45
+ # Problem statement
46
+ {{problem_description}}
47
+
48
+ # Input description
49
+ {{input_description}}
50
+
51
+ # Output description
52
+ {{output_description}}
53
+
54
+ {{io_examples_and_explanation}}
55
+
56
+ # Solution attempt to be fixed
57
+ ```python
58
+ {{code}}
59
+ ```
60
+
61
+ {{testing_results_summary}}
62
+
63
+
64
+ Consider the problem statement, the solution attempt and the issue. Why is the solution attempt incorrect? How should it be fixed? Explain your reasoning very concisely, and do not provide code.
65
+ input_variables:
66
+ - "problem_description"
67
+ - "input_description"
68
+ - "output_description"
69
+ - "io_examples_and_explanation"
70
+ - "code"
71
+ - "testing_results_summary"
72
+ template_format: jinja2
73
+
74
+ input_data_transformations: []
75
+ input_keys:
76
+ - "problem_description"
77
+ - "input_description"
78
+ - "output_description"
79
+ - "io_examples_and_explanation"
80
+ - "testing_results_summary"
81
+ - "code"
82
+
83
+ output_data_transformations:
84
+ - _target_: flows.data_transformations.KeyRename
85
+ old_key2new_key:
86
+ raw_response: "code_feedback"
87
+ output_keys:
88
+ - "code_feedback"
CF_CodeDebugCollab.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flows.base_flows import GeneratorCriticFlow
2
+
3
+
4
+ class CF_CodeDebugCollab(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_CodeDebugCollab.yaml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "CodeDebugCollab_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
+
18
+ output_data_transformations:
19
+ - _target_: flows.data_transformations.KeyRename
20
+ old_key2new_key:
21
+ raw_response.code: "code"
22
+ output_keys:
23
+ - "code"
24
+
25
+ subflows_config:
26
+ - _target_: flows.flow_verse.instantiate_flow
27
+ repository_id: ${oc.env:CC_FLOWS}
28
+ class_name: CF_Code
29
+ overrides:
30
+ name: "CodeGenerator"
31
+ model_name: "gpt-4"
32
+ human_message_prompt_template:
33
+ _target_: langchain.PromptTemplate
34
+ template: |2-
35
+ {{testing_results_summary}}
36
+
37
+ {{code_feedback}}
38
+
39
+
40
+ 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:
41
+ ```python
42
+ {{code_placeholder}}
43
+ ```
44
+ input_variables:
45
+ - code_feedback
46
+ - testing_results_summary
47
+ partial_variables:
48
+ code_placeholder: "{{python_code}}"
49
+ template_format: jinja2
50
+ default_human_input_keys:
51
+ - "code_feedback"
52
+ - "testing_results_summary"
53
+ output_data_transformations:
54
+ - _target_: flows.data_transformations.RegexFirstOccurrenceExtractor
55
+ regex: '(?<=```python)([\s\S]*?)(?=```)'
56
+ regex_fallback: '(?<=```)([\s\S]*?)(?=```)'
57
+ input_key: "raw_response"
58
+ output_key: "code"
59
+ strip: True
60
+ assert_unique: True
61
+ verbose: True
62
+ - _target_: flows.data_transformations.EndOfInteraction
63
+ end_of_interaction_string: "Final answer"
64
+ output_key: "end_of_interaction"
65
+ verbose: True
66
+ output_keys:
67
+ - "code"
68
+ - "end_of_interaction"
69
+ - _target_: flows.flow_verse.instantiate_flow
70
+ repository_id: ${oc.env:CC_FLOWS}
71
+ class_name: CF_CodeDebugCritic
CF_CodeDebugCritic.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flows.base_flows import SequentialFlow
2
+
3
+
4
+ class CF_CodeDebugCritic(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_CodeDebugCritic.yaml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "CodeDebugCritic_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
+
16
+ output_data_transformations:
17
+ - _target_: flows.data_transformations.KeyRename
18
+ old_key2new_key:
19
+ raw_response.testing_results_summary: "testing_results_summary"
20
+ raw_response.all_tests_passed: "all_tests_passed"
21
+ raw_response.code_feedback: "code_feedback"
22
+ output_keys:
23
+ - "testing_results_summary"
24
+ - "all_tests_passed"
25
+ - "code_feedback"
26
+
27
+ subflows_config:
28
+ - _target_: flows.flow_verse.instantiate_flow
29
+ repository_id: ${oc.env:CC_FLOWS}
30
+ class_name: CF_CodeTesting
31
+ overrides:
32
+ name: "CodeTestingCritic"
33
+ - _target_: flows.flow_verse.instantiate_flow
34
+ repository_id: ${oc.env:CC_FLOWS}
35
+ class_name: CF_CodeCriticWrongAttempt
__init__.py CHANGED
@@ -27,3 +27,8 @@ from .CF_PlanCollab_Code import CF_PlanCollab_Code
27
  # cf-code_debug
28
  from .CF_CodeTesting import CF_CodeTesting
29
  from .CF_CodeDebug import CF_CodeDebug
 
 
 
 
 
 
27
  # cf-code_debug
28
  from .CF_CodeTesting import CF_CodeTesting
29
  from .CF_CodeDebug import CF_CodeDebug
30
+
31
+ # cf-code_debug_collab
32
+ from .CF_CodeCriticWrongAttempt import CF_CodeCriticWrongAttempt
33
+ from .CF_CodeDebugCritic import CF_CodeDebugCritic
34
+ from .CF_CodeDebugCollab import CF_CodeDebugCollab