martinjosifoski commited on
Commit
9741e89
•
1 Parent(s): 2719b23

Add all CF flow modulo the ones that require debugging.

Browse files
DirectCode.py → CF_Code.py RENAMED
@@ -3,6 +3,6 @@ OpenAIChatAtomicFlow = load_class("martinjosifoski/OpenAIChatAtomicFlow", "OpenA
3
  # OpenAIChatAtomicFlow = load_class("/Users/josifosk/Documents/PhD/OpenAIChatAtomicFlow", "OpenAIChatAtomicFlow")
4
 
5
 
6
- class DirectCode(OpenAIChatAtomicFlow):
7
  def __init__(self, **kwargs):
8
  super().__init__(**kwargs)
 
3
  # OpenAIChatAtomicFlow = load_class("/Users/josifosk/Documents/PhD/OpenAIChatAtomicFlow", "OpenAIChatAtomicFlow")
4
 
5
 
6
+ class CF_Code(OpenAIChatAtomicFlow):
7
  def __init__(self, **kwargs):
8
  super().__init__(**kwargs)
DirectCode.yaml → CF_Code.yaml RENAMED
@@ -1,4 +1,4 @@
1
- name: "CodeAgent"
2
  verbose: True
3
  description: "ToDO: add description"
4
 
@@ -65,12 +65,22 @@ query_message_prompt_template:
65
  code_placeholder: "{{python_code}}"
66
  template_format: jinja2
67
 
 
 
 
 
 
 
 
 
 
 
68
  response_annotators:
69
  code_extractor:
70
  _target_: flows.message_annotators.RegexFirstOccurrenceExtractor
71
  regex: '(?<=```python)([\s\S]*?)(?=```)'
72
  regex_fallback: '(?<=```)([\s\S]*?)(?=```)'
73
- key: code
74
  strip: True
75
  assert_unique: True
76
  verbose: True
 
1
+ name: "Code_Flow"
2
  verbose: True
3
  description: "ToDO: add description"
4
 
 
65
  code_placeholder: "{{python_code}}"
66
  template_format: jinja2
67
 
68
+ expected_inputs:
69
+ - "problem_description"
70
+ - "input_description"
71
+ - "output_description"
72
+ - "io_examples_and_explanation"
73
+ - "api_key"
74
+
75
+ expected_outputs:
76
+ - "code"
77
+
78
  response_annotators:
79
  code_extractor:
80
  _target_: flows.message_annotators.RegexFirstOccurrenceExtractor
81
  regex: '(?<=```python)([\s\S]*?)(?=```)'
82
  regex_fallback: '(?<=```)([\s\S]*?)(?=```)'
83
+ key: "code"
84
  strip: True
85
  assert_unique: True
86
  verbose: True
CF_CodeCollab.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from flows.base_flows import GeneratorCriticFlow
2
+
3
+
4
+ class CF_CodeCollab(GeneratorCriticFlow):
5
+ def __init__(self, **kwargs):
6
+ super().__init__(**kwargs)
CF_CodeCollab.yaml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "CodeCollab_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
+ subflows_config:
11
+ - _target_: flows.flow_verse.instantiate_flow
12
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
13
+ repository_id: "martinjosifoski/CC_flows"
14
+ class_name: CF_Code
15
+ overrides:
16
+ name: "CodeGenerator"
17
+ human_message_prompt_template:
18
+ _target_: langchain.PromptTemplate
19
+ template: |2-
20
+ # Feedback on the last proposed solution
21
+ {{query}}
22
+
23
+
24
+ Consider the original problem statement, the last proposed solution and the provided feedback. Does the solution need to be updated? If so, provide the corrected version of the code in the following format:
25
+ ```python
26
+ {{code_placeholder}}
27
+ ```
28
+ otherwise, reply:
29
+ "Final answer."
30
+ input_variables:
31
+ - query
32
+ partial_variables:
33
+ code_placeholder: "{{python_code}}"
34
+ template_format: jinja2
35
+ response_annotators:
36
+ end_of_interaction_annotator:
37
+ _target_: flows.message_annotators.EndOfInteraction
38
+ end_of_interaction_message: "Final answer"
39
+ key: "end_of_interaction"
40
+ verbose: True
41
+ expected_outputs:
42
+ - "code"
43
+ - "end_of_interaction"
44
+ - _target_: flows.flow_verse.instantiate_flow
45
+ repository_id: "martinjosifoski/CC_flows"
46
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
47
+ class_name: CF_CodeCritic
48
+ overrides:
49
+ name: CodeCritic
CF_CodeCritic.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from flows.flow_verse import load_class
2
+ OpenAIChatAtomicFlow = load_class("martinjosifoski/OpenAIChatAtomicFlow", "OpenAIChatAtomicFlow")
3
+ # OpenAIChatAtomicFlow = load_class("/Users/josifosk/Documents/PhD/OpenAIChatAtomicFlow", "OpenAIChatAtomicFlow")
4
+
5
+
6
+ class CF_CodeCritic(OpenAIChatAtomicFlow):
7
+ def __init__(self, **kwargs):
8
+ super().__init__(**kwargs)
CF_CodeCritic.yaml ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "CodeCritic_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 potential issues with a 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
+ - a Python solution attempt
28
+
29
+ Crucially, your goal is to correctly identify potential issues with the solution attempt, and not to provide the code implementation yourself.
30
+ The user will provide you with a task and an output format that you will strictly follow.
31
+ input_variables: []
32
+ template_format: jinja2
33
+
34
+ human_message_prompt_template:
35
+ _target_: langchain.PromptTemplate
36
+ template: "{{query}}"
37
+ input_variables:
38
+ - "query"
39
+ template_format: jinja2
40
+
41
+ query_message_prompt_template:
42
+ _target_: langchain.PromptTemplate
43
+ template: |2-
44
+ # Problem statement
45
+ {{problem_description}}
46
+
47
+ # Input description
48
+ {{input_description}}
49
+
50
+ # Output description
51
+ {{output_description}}
52
+
53
+ {{io_examples_and_explanation}}
54
+
55
+ # Python solution attempt:
56
+ ```python
57
+ {{code}}
58
+ ```
59
+
60
+
61
+ Consider the problem statement and the solution attempt. Are there any issues with the proposed solution or it is correct? Explain your reasoning very concisely, and do not provide code.
62
+ input_variables:
63
+ - "problem_description"
64
+ - "input_description"
65
+ - "output_description"
66
+ - "io_examples_and_explanation"
67
+ - "code"
68
+ template_format: jinja2
69
+
70
+ expected_inputs:
71
+ - "problem_description"
72
+ - "input_description"
73
+ - "output_description"
74
+ - "io_examples_and_explanation"
75
+ - "code"
76
+ - "api_key"
77
+
78
+ expected_outputs:
79
+ - "query"
CF_CodeReflect.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from flows.base_flows import GeneratorCriticFlow
2
+
3
+
4
+ class CF_CodeReflect(GeneratorCriticFlow):
5
+ def __init__(self, **kwargs):
6
+ super().__init__(**kwargs)
CF_CodeReflect.yaml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "CodeReflect_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
+ subflows_config:
11
+ - _target_: flows.flow_verse.instantiate_flow
12
+ repository_id: "martinjosifoski/CC_flows"
13
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
14
+ class_name: CF_Code
15
+ overrides:
16
+ name: "CodeGenerator"
17
+ model_name: "gpt-4"
18
+ expected_outputs:
19
+ - "code"
20
+ - "end_of_interaction"
21
+ response_annotators:
22
+ end_of_interaction_annotator:
23
+ _target_: flows.message_annotators.EndOfInteraction
24
+ end_of_interaction_message: "Final answer"
25
+ key: "end_of_interaction"
26
+ verbose: True
27
+ - _target_: flows.base_flows.FixedReplyAtomicFlow.instantiate_with_overrides
28
+ overrides:
29
+ name: "CodeCritic"
30
+ description: "ToDo: Add description"
31
+ expected_outputs:
32
+ - "query"
33
+ fixed_reply: |2-
34
+ Consider the problem statement and the last proposed solution. Are you sure that the solution is provided in the requested format, and crucially, solves the problem?
35
+ If that is not the case, provide the corrected version of the code in the following format:
36
+ ```python
37
+ {{python_code}}
38
+ ```
39
+ otherwise, reply:
40
+ "Final answer."
CF_CodeWithPlan.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from flows.flow_verse import load_class
2
+ OpenAIChatAtomicFlow = load_class("martinjosifoski/OpenAIChatAtomicFlow", "OpenAIChatAtomicFlow")
3
+ # OpenAIChatAtomicFlow = load_class("/Users/josifosk/Documents/PhD/OpenAIChatAtomicFlow", "OpenAIChatAtomicFlow")
4
+
5
+
6
+ class CF_CodeWithPlan(OpenAIChatAtomicFlow):
7
+ def __init__(self, **kwargs):
8
+ super().__init__(**kwargs)
CF_CodeWithPlan.yaml ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "CodeFlowWithPlan_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 provide executable Python code that solves a competitive programming problem. The code should correctly handle all corner cases in order to pass the hidden test cases, which are used to evaluate the correctness of the solution.
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
+
28
+ Additionally, the user will provide you with a conceptual solution to the problem which should guide your reasoning and the code implementation.
29
+
30
+ The user will provide you with a task and an output format that you will strictly follow.
31
+ input_variables: []
32
+ template_format: jinja2
33
+
34
+ human_message_prompt_template:
35
+ _target_: langchain.PromptTemplate
36
+ template: "{{query}}"
37
+ input_variables:
38
+ - "query"
39
+ template_format: jinja2
40
+
41
+ query_message_prompt_template:
42
+ _target_: langchain.PromptTemplate
43
+ template: |2-
44
+ # Problem statement
45
+ {{problem_description}}
46
+
47
+ # Input description
48
+ {{input_description}}
49
+
50
+ # Output description
51
+ {{output_description}}
52
+
53
+ {{io_examples_and_explanation}}
54
+
55
+ # Conceptual solution
56
+ {{plan}}
57
+
58
+
59
+ The input should be read from the standard input and the output should be passed to the standard output.
60
+ Consider the problem statement and the conceptual solution, and return Python code that solves the problem. Reply in the following format:
61
+ ```python
62
+ {{code_placeholder}}
63
+ ```
64
+ input_variables:
65
+ - "problem_description"
66
+ - "input_description"
67
+ - "output_description"
68
+ - "io_examples_and_explanation"
69
+ - "plan"
70
+ partial_variables:
71
+ code_placeholder: "{{python_code}}"
72
+ template_format: jinja2
73
+
74
+ expected_inputs:
75
+ - "problem_description"
76
+ - "input_description"
77
+ - "output_description"
78
+ - "io_examples_and_explanation"
79
+ - "plan"
80
+ - "api_key"
81
+
82
+ expected_outputs:
83
+ - "code"
84
+
85
+ response_annotators:
86
+ code_extractor:
87
+ _target_: flows.message_annotators.RegexFirstOccurrenceExtractor
88
+ regex: '(?<=```python)([\s\S]*?)(?=```)'
89
+ regex_fallback: '(?<=```)([\s\S]*?)(?=```)'
90
+ key: "code"
91
+ strip: True
92
+ assert_unique: True
93
+ verbose: True
CF_Plan.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from flows.flow_verse import load_class
2
+ OpenAIChatAtomicFlow = load_class("martinjosifoski/OpenAIChatAtomicFlow", "OpenAIChatAtomicFlow")
3
+ # OpenAIChatAtomicFlow = load_class("/Users/josifosk/Documents/PhD/OpenAIChatAtomicFlow", "OpenAIChatAtomicFlow")
4
+
5
+
6
+ class CF_Plan(OpenAIChatAtomicFlow):
7
+ def __init__(self, **kwargs):
8
+ super().__init__(**kwargs)
CF_Plan.yaml ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "Plan_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 provide a high-level conceptual solution that, if implemented, will solve a given competitive programming problem.
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
+
28
+ The proposed algorithm should be computationally efficient, logically correct and handle all corner cases.
29
+
30
+ The user will provide you with a task and an output format that you will strictly follow.
31
+ input_variables: []
32
+ template_format: jinja2
33
+
34
+ human_message_prompt_template:
35
+ _target_: langchain.PromptTemplate
36
+ template: "{{query}}"
37
+ input_variables:
38
+ - "query"
39
+ template_format: jinja2
40
+
41
+ query_message_prompt_template:
42
+ _target_: langchain.PromptTemplate
43
+ template: |2-
44
+ # Problem statement
45
+ {{problem_description}}
46
+
47
+ # Input description
48
+ {{input_description}}
49
+
50
+ # Output description
51
+ {{output_description}}
52
+
53
+ {{io_examples_and_explanation}}
54
+
55
+
56
+ Return a high-level conceptual solution that would solve the problem. Be very concise, and do not provide code.
57
+ Reply in the following format:
58
+ # Conceptual solution
59
+ {{plan_placeholder}}
60
+ input_variables:
61
+ - "problem_description"
62
+ - "input_description"
63
+ - "output_description"
64
+ - "io_examples_and_explanation"
65
+ partial_variables:
66
+ plan_placeholder: "{{conceptual_solution}}"
67
+ template_format: jinja2
68
+
69
+ expected_inputs:
70
+ - "problem_description"
71
+ - "input_description"
72
+ - "output_description"
73
+ - "io_examples_and_explanation"
74
+ - "api_key"
75
+
76
+ expected_outputs:
77
+ - "plan"
78
+
79
+ response_annotators:
80
+ plan_extractor:
81
+ _target_: flows.message_annotators.RegexFirstOccurrenceExtractor
82
+ regex: '(?<=Conceptual solution)([\s\S]*?)(?=\n\n# [A-Z]|\Z)'
83
+ regex_fallback:
84
+ - '(?<=Conceptual solution:)([\s\S]*?)(?=\n\n# [A-Z]|\Z)'
85
+ key: "plan"
86
+ strip: True
87
+ assert_unique: True
88
+ verbose: True
CF_PlanCollab.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from flows.base_flows import GeneratorCriticFlow
2
+
3
+
4
+ class CF_PlanCollab(GeneratorCriticFlow):
5
+ def __init__(self, **kwargs):
6
+ super().__init__(**kwargs)
CF_PlanCollab.yaml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "PlanCollab_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
+ expected_inputs:
11
+ - "problem_description"
12
+ - "input_description"
13
+ - "output_description"
14
+ - "io_examples_and_explanation"
15
+ - "api_key"
16
+
17
+ expected_outputs:
18
+ - "plan"
19
+
20
+ subflows_config:
21
+ - _target_: flows.flow_verse.instantiate_flow
22
+ repository_id: "martinjosifoski/CC_flows"
23
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
24
+ class_name: CF_Plan
25
+ overrides:
26
+ name: "CodeGenerator"
27
+ human_message_prompt_template:
28
+ _target_: langchain.PromptTemplate
29
+ template: |2-
30
+ # Feedback on the last proposed conceptual solution
31
+ {{query}}
32
+
33
+
34
+ Consider the original problem statement, the last proposed solution and the provided feedback. Does the solution need to be updated? If so, provide the corrected version of the conceptual solution in the following format:
35
+ # Conceptual solution
36
+ {{plan_placeholder}}
37
+ otherwise, reply:
38
+ "Final answer."
39
+ input_variables:
40
+ - query
41
+ partial_variables:
42
+ plan_placeholder: "{{conceptual_solution}}"
43
+ template_format: jinja2
44
+ response_annotators:
45
+ end_of_interaction_annotator:
46
+ _target_: flows.message_annotators.EndOfInteraction
47
+ end_of_interaction_message: "Final answer"
48
+ key: "end_of_interaction"
49
+ verbose: True
50
+ expected_outputs:
51
+ - "plan"
52
+ - "end_of_interaction"
53
+ - _target_: flows.flow_verse.instantiate_flow
54
+ repository_id: "martinjosifoski/CC_flows"
55
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
56
+ class_name: CF_PlanCritic
57
+ overrides:
58
+ name: PlanCritic
CF_PlanCollab_Code.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from flows.base_flows import SequentialFlow
2
+
3
+
4
+ class CF_PlanCollab_Code(SequentialFlow):
5
+ def __init__(self, **kwargs):
6
+ super().__init__(**kwargs)
CF_PlanCollab_Code.yaml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "PlanCollab_Code"
2
+ description: "ToDO: add description"
3
+
4
+ early_exit_key: null
5
+
6
+ subflows_config:
7
+ - _target_: flows.flow_verse.instantiate_flow
8
+ repository_id: "martinjosifoski/CC_flows"
9
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
10
+ class_name: CF_PlanCollab
11
+ - _target_: flows.flow_verse.instantiate_flow
12
+ repository_id: "martinjosifoski/CC_flows"
13
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
14
+ class_name: CF_CodeWithPlan
CF_PlanCritic.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from flows.flow_verse import load_class
2
+ OpenAIChatAtomicFlow = load_class("martinjosifoski/OpenAIChatAtomicFlow", "OpenAIChatAtomicFlow")
3
+ # OpenAIChatAtomicFlow = load_class("/Users/josifosk/Documents/PhD/OpenAIChatAtomicFlow", "OpenAIChatAtomicFlow")
4
+
5
+
6
+ class CF_PlanCritic(OpenAIChatAtomicFlow):
7
+ def __init__(self, **kwargs):
8
+ super().__init__(**kwargs)
CF_PlanCritic.yaml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "PlanCritic_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 potential issues with a conceptual solution to a given competitive programming problem.
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
+ - a conceptual solution attempt
28
+
29
+ Crucially, your goal is to consider all aspects of the problem and pinpoint potential issues with the conceptual solution attempt (if any), and not to provide the conceptual solution or the code implementation yourself.
30
+ Some aspects to consider: Are there any logical mistakes with the proposed algorithm? Are the corner cases correctly handled?
31
+ The user will provide you with a task and an output format that you will strictly follow.
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
+ # Conceptual solution attempt
57
+ {{plan}}
58
+
59
+
60
+ Consider the problem statement and the solution attempt. Are there any issues with the proposed conceptual solution or it is correct? Explain your reasoning very concisely.
61
+ input_variables:
62
+ - "problem_description"
63
+ - "input_description"
64
+ - "output_description"
65
+ - "io_examples_and_explanation"
66
+ - "plan"
67
+ template_format: jinja2
68
+
69
+ expected_inputs:
70
+ - "problem_description"
71
+ - "input_description"
72
+ - "output_description"
73
+ - "io_examples_and_explanation"
74
+ - "plan"
75
+ - "api_key"
76
+
77
+ expected_outputs:
78
+ - "query"
CF_PlanReflect.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from flows.base_flows import GeneratorCriticFlow
2
+
3
+
4
+ class CF_PlanReflect(GeneratorCriticFlow):
5
+ def __init__(self, **kwargs):
6
+ super().__init__(**kwargs)
CF_PlanReflect.yaml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "PlanReflect_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 # To increase to 4
8
+ early_exit_key: "end_of_interaction"
9
+
10
+ expected_inputs:
11
+ - "problem_description"
12
+ - "input_description"
13
+ - "output_description"
14
+ - "io_examples_and_explanation"
15
+ - "api_key"
16
+
17
+ expected_outputs:
18
+ - "plan"
19
+
20
+ subflows_config:
21
+ - _target_: flows.flow_verse.instantiate_flow
22
+ repository_id: "martinjosifoski/CC_flows"
23
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
24
+ class_name: CF_Plan
25
+ overrides:
26
+ name: "PlanGenerator"
27
+ model_name: "gpt-4"
28
+ response_annotators:
29
+ end_of_interaction_annotator:
30
+ _target_: flows.message_annotators.EndOfInteraction
31
+ end_of_interaction_message: "Final answer"
32
+ key: "end_of_interaction"
33
+ verbose: True
34
+ expected_outputs:
35
+ - "plan"
36
+ - "end_of_interaction"
37
+ - _target_: flows.base_flows.FixedReplyAtomicFlow.instantiate_with_overrides
38
+ overrides:
39
+ name: "PlanCritic"
40
+ description: "ToDo: Add description"
41
+ expected_outputs:
42
+ - "query"
43
+ fixed_reply: |2-
44
+ Consider the problem statement and the last proposed solution. Are you sure that the solution is provided in the requested format, and crucially, solves the problem?
45
+ If that is not the case, provide the corrected version of the conceptual solution in the following format:
46
+ # Conceptual solution
47
+ {{conceptual_solution}}
48
+ otherwise, reply:
49
+ "Final answer."
CF_PlanReflect_Code.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from flows.base_flows import SequentialFlow
2
+
3
+
4
+ class CF_PlanReflect_Code(SequentialFlow):
5
+ def __init__(self, **kwargs):
6
+ super().__init__(**kwargs)
CF_PlanReflect_Code.yaml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "PlanReflect_Code_Flow"
2
+ description: "ToDO: add description"
3
+
4
+ early_exit_key: null
5
+
6
+ subflows_config:
7
+ - _target_: flows.flow_verse.instantiate_flow
8
+ repository_id: "martinjosifoski/CC_flows"
9
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
10
+ class_name: CF_PlanReflect
11
+ - _target_: flows.flow_verse.instantiate_flow
12
+ repository_id: "martinjosifoski/CC_flows"
13
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
14
+ class_name: CF_CodeWithPlan
CF_Plan_Code.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from flows.base_flows import SequentialFlow
2
+
3
+
4
+ class CF_Plan_Code(SequentialFlow):
5
+ def __init__(self, **kwargs):
6
+ super().__init__(**kwargs)
CF_Plan_Code.yaml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "Plan_Code_Flow"
2
+ description: "ToDO: add description"
3
+
4
+ early_exit_key: null
5
+
6
+ subflows_config:
7
+ - _target_: flows.flow_verse.instantiate_flow
8
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
9
+ repository_id: "martinjosifoski/CC_flows"
10
+ class_name: CF_Plan
11
+ overrides:
12
+ model_name: "gpt-4"
13
+ - _target_: flows.flow_verse.instantiate_flow
14
+ # repository_id: "/Users/josifosk/Documents/PhD/CC_flows"
15
+ repository_id: "martinjosifoski/CC_flows"
16
+ class_name: CF_CodeWithPlan
17
+ overrides:
18
+ model_name: "gpt-4"
RockPaperScissorsJudge.py DELETED
@@ -1,46 +0,0 @@
1
- from flows.base_flows import Flow
2
- from typing import Dict
3
-
4
- from .RockPaperScissorsPlayer import RockPaperScissorsPlayer
5
-
6
-
7
- class RockPaperScissorsJudge(Flow):
8
-
9
- def __init__(self, **kwargs):
10
- super(RockPaperScissorsJudge, self).__init__(**kwargs)
11
-
12
- self.flow_state["A"] = RockPaperScissorsPlayer(name="Player A", description="RockPaperScissorsPlayer")
13
- self.flow_state["B"] = RockPaperScissorsPlayer(name="Player B", description="RockPaperScissorsPlayer")
14
- self.flow_state["A_score"] = 0
15
- self.flow_state["B_score"] = 0
16
- self.flow_state["n_party_played"] = 0
17
-
18
- def run(self, input_data, expected_outputs) -> Dict:
19
- flow_a = self.flow_state["A"]
20
- flow_b = self.flow_state["B"]
21
-
22
- for _ in range(3):
23
- A_task = self.package_task_message(flow_a, "run", {}, expected_outputs=["choice"])
24
- B_task = self.package_task_message(flow_b, "run", {}, expected_outputs=["choice"])
25
- # play another round
26
- A_output = flow_a(A_task)
27
- self._log_message(A_output)
28
- B_output = flow_b(B_task)
29
- self._log_message(B_output)
30
-
31
- A_choice = A_output.data["choice"]
32
- B_choice = B_output.data["choice"]
33
-
34
- self._update_state({"n_party_played": self.flow_state["n_party_played"] + 1})
35
-
36
- if A_choice == B_choice:
37
- # neither has won
38
- pass
39
- elif (A_choice == "rock" and B_choice == "scissors"
40
- or A_choice == "paper" and B_choice == "rock"
41
- or A_choice == "scissors" and B_choice == "paper"):
42
- self._update_state({"A_score": self.flow_state["A_score"] + 1})
43
- else:
44
- self._update_state({"B_score": self.flow_state["B_score"] + 1})
45
-
46
- return self._get_keys_from_state(expected_outputs, allow_class_namespace=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
RockPaperScissorsPlayer.py DELETED
@@ -1,15 +0,0 @@
1
- from flows.base_flows import Flow
2
- from typing import List
3
-
4
- import random
5
-
6
-
7
- class RockPaperScissorsPlayer(Flow):
8
-
9
- def __init__(self, **kwargs):
10
- super(RockPaperScissorsPlayer, self).__init__(**kwargs)
11
-
12
- def run(self, input_data, expected_outputs: List[str] = None):
13
- choice = random.choice(["rock", "paper", "scissors"])
14
-
15
- return {"choice": choice}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
__init__.py CHANGED
@@ -1 +1,12 @@
1
- from .DirectCode import DirectCode
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .CF_Code import CF_Code
2
+ from .CF_CodeWithPlan import CF_CodeWithPlan
3
+ from .CF_CodeReflect import CF_CodeReflect
4
+ from .CF_Plan import CF_Plan
5
+ from .CF_Plan_Code import CF_Plan_Code
6
+ from .CF_CodeCritic import CF_CodeCritic
7
+ from .CF_CodeCollab import CF_CodeCollab
8
+ from .CF_PlanReflect import CF_PlanReflect
9
+ from .CF_PlanReflect_Code import CF_PlanReflect_Code
10
+ from .CF_PlanCritic import CF_PlanCritic
11
+ from .CF_PlanCollab import CF_PlanCollab
12
+ from .CF_PlanCollab_Code import CF_PlanCollab_Code