martinjosifoski
commited on
Commit
•
8a7fcb3
1
Parent(s):
91b62cb
Implement remaining CF Flows.
Browse files- CF_CodeCriticWrongAttemptWithPlan.py +6 -0
- CF_CodeCriticWrongAttemptWithPlan.yaml +97 -0
- CF_CodeDebugCollabWithPlan.py +12 -0
- CF_CodeDebugCollabWithPlan.yaml +90 -0
- CF_CodeDebugCriticWithPlan.py +13 -0
- CF_CodeDebugCriticWithPlan.yaml +131 -0
- CF_CodeWithPlan.py +6 -0
- CF_CodeWithPlan.yaml +89 -0
- CF_Plan.py +6 -0
- CF_Plan.yaml +82 -0
- CF_PlanCollab.py +6 -0
- CF_PlanCollab.yaml +94 -0
- CF_PlanCollab_Code.py +6 -0
- CF_PlanCollab_Code.yaml +67 -0
- CF_PlanCritic.py +6 -0
- CF_PlanCritic.yaml +84 -0
- CF_PlanReflect.py +6 -0
- CF_PlanReflect.yaml +84 -0
- CF_PlanReflect_Code.py +6 -0
- CF_PlanReflect_Code.yaml +67 -0
- CF_Plan_Code.py +6 -0
- CF_Plan_Code.yaml +77 -0
- FixedReply_PlanReflect.py +6 -0
- FixedReply_PlanReflect.yaml +16 -0
CF_CodeCriticWrongAttemptWithPlan.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flow_modules.aiflows.OpenAIChatFlowModule import OpenAIChatAtomicFlow
|
2 |
+
|
3 |
+
|
4 |
+
class CF_CodeCriticWrongAttemptWithPlan(OpenAIChatAtomicFlow):
|
5 |
+
def __init__(self, **kwargs):
|
6 |
+
super().__init__(**kwargs)
|
CF_CodeCriticWrongAttemptWithPlan.yaml
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "CodeCriticWrongAttempt_Flow"
|
2 |
+
description: |2-
|
3 |
+
Given a problem description, a correct solution strategy, and an incorrect solution candidate, provide useful feedback for correcting the mistakes in the solution.
|
4 |
+
|
5 |
+
# ~~~ Input interface specification ~~~
|
6 |
+
input_interface_non_initialized:
|
7 |
+
- "problem_description"
|
8 |
+
- "input_description"
|
9 |
+
- "output_description"
|
10 |
+
- "io_examples_and_explanation"
|
11 |
+
- "testing_results_summary"
|
12 |
+
- "code"
|
13 |
+
- "plan"
|
14 |
+
|
15 |
+
input_interface_initialized:
|
16 |
+
- "query"
|
17 |
+
|
18 |
+
# ~~~ Output interface specification ~~~
|
19 |
+
output_interface:
|
20 |
+
- "api_output"
|
21 |
+
|
22 |
+
# ~~~ Flow specification ~~~
|
23 |
+
model_name: "gpt-4"
|
24 |
+
|
25 |
+
generation_parameters:
|
26 |
+
n: 1
|
27 |
+
max_tokens: 3000
|
28 |
+
temperature: 0.3
|
29 |
+
|
30 |
+
model_kwargs:
|
31 |
+
top_p: 0.2
|
32 |
+
frequency_penalty: 0
|
33 |
+
presence_penalty: 0
|
34 |
+
|
35 |
+
system_message_prompt_template:
|
36 |
+
_target_: langchain.PromptTemplate
|
37 |
+
template: |2-
|
38 |
+
Your goal is to identify the issues with an incorrect competitive programming solution attempt.
|
39 |
+
|
40 |
+
The user will specify the problem by providing you with:
|
41 |
+
- the problem statement
|
42 |
+
- input description
|
43 |
+
- output description
|
44 |
+
- example test cases
|
45 |
+
- (optional) explanation of the test cases
|
46 |
+
- an incorrect Python solution attempt and a description of its issue
|
47 |
+
|
48 |
+
Additionally, the user will provide you with a conceptual solution to the problem which should guide your reasoning.
|
49 |
+
|
50 |
+
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.
|
51 |
+
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?
|
52 |
+
Use the code execution results provided in the issue description to guide your reasoning/debugging.
|
53 |
+
input_variables: []
|
54 |
+
template_format: jinja2
|
55 |
+
|
56 |
+
human_message_prompt_template:
|
57 |
+
_target_: langchain.PromptTemplate
|
58 |
+
template: "{{query}}"
|
59 |
+
input_variables:
|
60 |
+
- "query"
|
61 |
+
template_format: jinja2
|
62 |
+
|
63 |
+
init_human_message_prompt_template:
|
64 |
+
_target_: langchain.PromptTemplate
|
65 |
+
template: |2-
|
66 |
+
# Problem statement
|
67 |
+
{{problem_description}}
|
68 |
+
|
69 |
+
# Input description
|
70 |
+
{{input_description}}
|
71 |
+
|
72 |
+
# Output description
|
73 |
+
{{output_description}}
|
74 |
+
|
75 |
+
{{io_examples_and_explanation}}
|
76 |
+
|
77 |
+
# Conceptual solution
|
78 |
+
{{plan}}
|
79 |
+
|
80 |
+
# Solution attempt to be fixed
|
81 |
+
```python
|
82 |
+
{{code}}
|
83 |
+
```
|
84 |
+
|
85 |
+
{{testing_results_summary}}
|
86 |
+
|
87 |
+
|
88 |
+
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.
|
89 |
+
input_variables:
|
90 |
+
- "problem_description"
|
91 |
+
- "input_description"
|
92 |
+
- "output_description"
|
93 |
+
- "io_examples_and_explanation"
|
94 |
+
- "plan"
|
95 |
+
- "code"
|
96 |
+
- "testing_results_summary"
|
97 |
+
template_format: jinja2
|
CF_CodeDebugCollabWithPlan.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flows.base_flows import CircularFlow
|
2 |
+
|
3 |
+
|
4 |
+
class CF_CodeDebugCollabWithPlan(CircularFlow):
|
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,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "CodeDebugCollab_Flow"
|
2 |
+
description: |2-
|
3 |
+
Given a problem description and a correct solution strategy, alternate between a step in which code is generated, and a step in which the produced code is evaluated and useful feedback is provided.
|
4 |
+
|
5 |
+
# ~~~ Input interface specification ~~~
|
6 |
+
input_interface:
|
7 |
+
- "problem_description"
|
8 |
+
- "input_description"
|
9 |
+
- "output_description"
|
10 |
+
- "io_examples_and_explanation"
|
11 |
+
- "public_tests_individual_io"
|
12 |
+
- "plan"
|
13 |
+
|
14 |
+
# ~~~ Output interface specification ~~~
|
15 |
+
output_interface:
|
16 |
+
- "code"
|
17 |
+
|
18 |
+
# ~~~ Flow specification ~~~
|
19 |
+
max_rounds: 4
|
20 |
+
|
21 |
+
subflows_config:
|
22 |
+
CodeGenerator:
|
23 |
+
_target_: .CF_CodeWithPlan.instantiate_from_default_config
|
24 |
+
name: "CodeGenerator"
|
25 |
+
model_name: "gpt-4"
|
26 |
+
human_message_prompt_template:
|
27 |
+
_target_: langchain.PromptTemplate
|
28 |
+
template: |2-
|
29 |
+
{{testing_results_summary}}
|
30 |
+
|
31 |
+
{{code_feedback}}
|
32 |
+
|
33 |
+
|
34 |
+
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:
|
35 |
+
```python
|
36 |
+
{{code_placeholder}}
|
37 |
+
```
|
38 |
+
input_variables:
|
39 |
+
- code_feedback
|
40 |
+
- testing_results_summary
|
41 |
+
partial_variables:
|
42 |
+
code_placeholder: "{{python_code}}"
|
43 |
+
input_interface_initialized:
|
44 |
+
- "code_feedback"
|
45 |
+
- "testing_results_summary"
|
46 |
+
CodeDebugCritic:
|
47 |
+
_target_: .CF_CodeDebugCriticWithPlan.instantiate_from_default_config
|
48 |
+
|
49 |
+
topology:
|
50 |
+
# ~~~ Code Generator ~~~
|
51 |
+
- goal: "Generate/refine a solution."
|
52 |
+
|
53 |
+
### Input Interface
|
54 |
+
input_interface:
|
55 |
+
_target_: flows.interfaces.KeyInterface
|
56 |
+
additional_transformations:
|
57 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
58 |
+
|
59 |
+
### Flow Specification
|
60 |
+
flow: CodeGenerator
|
61 |
+
|
62 |
+
### Output Interface
|
63 |
+
output_interface:
|
64 |
+
_target_: flows.interfaces.KeyInterface
|
65 |
+
additional_transformations:
|
66 |
+
- _target_: flows.data_transformations.RegexFirstOccurrenceExtractor
|
67 |
+
regex: '(?<=```python)([\s\S]*?)(?=```)'
|
68 |
+
regex_fallback: '(?<=```)([\s\S]*?)(?=```)'
|
69 |
+
input_key: "api_output"
|
70 |
+
output_key: "code"
|
71 |
+
strip: True
|
72 |
+
assert_unique: True
|
73 |
+
keys_to_select:
|
74 |
+
- "code"
|
75 |
+
|
76 |
+
reset: false
|
77 |
+
|
78 |
+
# ~~~ Code Critic Grounded in Tests ~~~
|
79 |
+
- goal: ""
|
80 |
+
|
81 |
+
### Input Interface
|
82 |
+
input_interface:
|
83 |
+
_target_: flows.interfaces.KeyInterface
|
84 |
+
additional_transformations:
|
85 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
86 |
+
|
87 |
+
### Flow Specification
|
88 |
+
flow: CodeDebugCritic
|
89 |
+
|
90 |
+
reset: true
|
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,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "CodeDebugCritic_Flow"
|
2 |
+
description: |-2
|
3 |
+
Given a problem description, a correct solution strategy, and a candidate solution, test the code and provide useful feedback concerning the correctness of the solution and the potential mistakes.
|
4 |
+
|
5 |
+
# ~~~ Input interface specification ~~~
|
6 |
+
input_interface:
|
7 |
+
- "problem_description"
|
8 |
+
- "input_description"
|
9 |
+
- "output_description"
|
10 |
+
- "io_examples_and_explanation"
|
11 |
+
- "public_tests_individual_io"
|
12 |
+
- "code"
|
13 |
+
- "plan"
|
14 |
+
|
15 |
+
# ~~~ Output interface specification ~~~
|
16 |
+
output_interface:
|
17 |
+
- "testing_results_summary"
|
18 |
+
- "all_tests_passed"
|
19 |
+
- "code_feedback"
|
20 |
+
|
21 |
+
# ~~~ Flow specification ~~~
|
22 |
+
subflows_config:
|
23 |
+
CodeTestingCritic:
|
24 |
+
_target_: .CF_CodeTesting.instantiate_from_default_config
|
25 |
+
CodeCriticWrongAttempt:
|
26 |
+
_target_: .CF_CodeCriticWrongAttemptWithPlan.instantiate_from_default_config
|
27 |
+
|
28 |
+
topology:
|
29 |
+
# ~~~ Code Testing Critic ~~~
|
30 |
+
- goal: "Test the code on the public tests and provide a results summary."
|
31 |
+
|
32 |
+
### Input Interface
|
33 |
+
input_interface:
|
34 |
+
_target_: flows.interfaces.KeyInterface
|
35 |
+
additional_transformations:
|
36 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
37 |
+
|
38 |
+
### Flow Specification
|
39 |
+
flow: CodeTestingCritic
|
40 |
+
|
41 |
+
### Output Interface
|
42 |
+
output_interface:
|
43 |
+
_target_: flows.interfaces.KeyInterface
|
44 |
+
additional_transformations:
|
45 |
+
- _target_: .src.data_transformations.CorrectnessFlag
|
46 |
+
input_key: "public_tests_results"
|
47 |
+
output_key: "all_tests_passed"
|
48 |
+
- _target_: .src.data_transformations.TestingResultsSummaryGeneration
|
49 |
+
output_key: "testing_results_summary"
|
50 |
+
|
51 |
+
single_test_error_message: True
|
52 |
+
|
53 |
+
no_error_template: |2-
|
54 |
+
${.issue_title}
|
55 |
+
All of the executed tests passed.
|
56 |
+
|
57 |
+
compilation_error_template: |2-
|
58 |
+
${.issue_title}
|
59 |
+
The execution resulted in a compilation error.
|
60 |
+
## Compilation error message:
|
61 |
+
{{error_message}}
|
62 |
+
timeout_error_template: |2-
|
63 |
+
${.issue_title}
|
64 |
+
The execution timed out, the solution is not efficient enough.
|
65 |
+
runtime_error_template: |2-
|
66 |
+
${.issue_title}
|
67 |
+
The execution resulted in a runtime error on the following test.
|
68 |
+
## [Failed test] Input
|
69 |
+
```
|
70 |
+
{{test_input}}
|
71 |
+
```
|
72 |
+
## [Failed test] Runtime error message
|
73 |
+
{{error_message}}
|
74 |
+
single_test_error_template: |2-
|
75 |
+
${.issue_title}
|
76 |
+
The Python code does not solve the problem in the problem description due to logical errors. It fails the following test:
|
77 |
+
## [Failed test] Input
|
78 |
+
```
|
79 |
+
{{test_input}}
|
80 |
+
```
|
81 |
+
## [Failed test] Expected output
|
82 |
+
```
|
83 |
+
{{expected_output}}
|
84 |
+
```
|
85 |
+
## [Failed test] Generated output
|
86 |
+
```
|
87 |
+
{{generated_output}}
|
88 |
+
```
|
89 |
+
all_tests_header: |2-
|
90 |
+
${.issue_title}
|
91 |
+
The Python code does not solve the problem in the problem description due to logical errors. It fails on the following tests.
|
92 |
+
test_error_template: |2-
|
93 |
+
## [Failed test {{idx}}]
|
94 |
+
### [Failed test {{idx}}] Input
|
95 |
+
```
|
96 |
+
{{test_input}}
|
97 |
+
```
|
98 |
+
### [Failed test {{idx}}] Expected output
|
99 |
+
```
|
100 |
+
{{expected_output}}
|
101 |
+
```
|
102 |
+
### [Failed test {{idx}}] Generated output
|
103 |
+
```
|
104 |
+
{{generated_output}}
|
105 |
+
```
|
106 |
+
tests_separator: "\n\n"
|
107 |
+
|
108 |
+
issue_title: "# Issue with the last proposed solution"
|
109 |
+
|
110 |
+
# ~~~ Feedback Generator ~~~
|
111 |
+
- goal: "Generate feedback grounded in the test results summary."
|
112 |
+
|
113 |
+
### Input Interface
|
114 |
+
input_interface:
|
115 |
+
_target_: flows.interfaces.KeyInterface
|
116 |
+
additional_transformations:
|
117 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
118 |
+
|
119 |
+
### Flow Specification
|
120 |
+
flow: CodeCriticWrongAttempt
|
121 |
+
|
122 |
+
### Output Interface
|
123 |
+
output_interface:
|
124 |
+
_target_: flows.interfaces.KeyInterface
|
125 |
+
additional_transformations:
|
126 |
+
- _target_: flows.data_transformations.KeyRename
|
127 |
+
old_key2new_key:
|
128 |
+
api_output: "code_feedback"
|
129 |
+
|
130 |
+
reset: true
|
131 |
+
|
CF_CodeWithPlan.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flow_modules.aiflows.OpenAIChatFlowModule import OpenAIChatAtomicFlow
|
2 |
+
|
3 |
+
|
4 |
+
class CF_CodeWithPlan(OpenAIChatAtomicFlow):
|
5 |
+
def __init__(self, **kwargs):
|
6 |
+
super().__init__(**kwargs)
|
CF_CodeWithPlan.yaml
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "CodeFlowWithPlan_Flow"
|
2 |
+
description: |2-
|
3 |
+
Given a problem description and a high-level solution strategy implement the code.
|
4 |
+
|
5 |
+
# ~~~ Input interface specification ~~~
|
6 |
+
input_interface_non_initialized: # Applied when constructing the first user message.
|
7 |
+
- "problem_description"
|
8 |
+
- "input_description"
|
9 |
+
- "output_description"
|
10 |
+
- "io_examples_and_explanation"
|
11 |
+
- "plan"
|
12 |
+
|
13 |
+
input_interface_initialized: # Applied when constructing all subsequent user messages.
|
14 |
+
- "query"
|
15 |
+
|
16 |
+
# ~~~ Output interface specification ~~~
|
17 |
+
output_interface:
|
18 |
+
- "api_output"
|
19 |
+
|
20 |
+
# ~~~ Flow specification ~~~
|
21 |
+
model_name: "gpt-4"
|
22 |
+
|
23 |
+
generation_parameters:
|
24 |
+
n: 1
|
25 |
+
max_tokens: 3000
|
26 |
+
temperature: 0.3
|
27 |
+
|
28 |
+
model_kwargs:
|
29 |
+
top_p: 0.2
|
30 |
+
frequency_penalty: 0
|
31 |
+
presence_penalty: 0
|
32 |
+
|
33 |
+
system_message_prompt_template:
|
34 |
+
_target_: langchain.PromptTemplate
|
35 |
+
template: |2-
|
36 |
+
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.
|
37 |
+
|
38 |
+
The user will specify the problem by providing you with:
|
39 |
+
- the problem statement
|
40 |
+
- input description
|
41 |
+
- output description
|
42 |
+
- example test cases
|
43 |
+
- (optional) explanation of the test cases
|
44 |
+
|
45 |
+
Additionally, the user will provide you with a conceptual solution to the problem which should guide your reasoning and the code implementation.
|
46 |
+
|
47 |
+
The user will provide you with a task and an output format that you will strictly follow.
|
48 |
+
input_variables: []
|
49 |
+
template_format: jinja2
|
50 |
+
|
51 |
+
human_message_prompt_template:
|
52 |
+
_target_: langchain.PromptTemplate
|
53 |
+
template: "{{query}}"
|
54 |
+
input_variables:
|
55 |
+
- "query"
|
56 |
+
template_format: jinja2
|
57 |
+
|
58 |
+
init_human_message_prompt_template:
|
59 |
+
_target_: langchain.PromptTemplate
|
60 |
+
template: |2-
|
61 |
+
# Problem statement
|
62 |
+
{{problem_description}}
|
63 |
+
|
64 |
+
# Input description
|
65 |
+
{{input_description}}
|
66 |
+
|
67 |
+
# Output description
|
68 |
+
{{output_description}}
|
69 |
+
|
70 |
+
{{io_examples_and_explanation}}
|
71 |
+
|
72 |
+
# Conceptual solution
|
73 |
+
{{plan}}
|
74 |
+
|
75 |
+
|
76 |
+
The input should be read from the standard input and the output should be passed to the standard output.
|
77 |
+
Consider the problem statement and the conceptual solution, and return Python code that solves the problem. Reply in the following format:
|
78 |
+
```python
|
79 |
+
{{code_placeholder}}
|
80 |
+
```
|
81 |
+
input_variables:
|
82 |
+
- "problem_description"
|
83 |
+
- "input_description"
|
84 |
+
- "output_description"
|
85 |
+
- "io_examples_and_explanation"
|
86 |
+
- "plan"
|
87 |
+
partial_variables:
|
88 |
+
code_placeholder: "{{python_code}}"
|
89 |
+
template_format: jinja2
|
CF_Plan.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flow_modules.aiflows.OpenAIChatFlowModule import OpenAIChatAtomicFlow
|
2 |
+
|
3 |
+
|
4 |
+
class CF_Plan(OpenAIChatAtomicFlow):
|
5 |
+
def __init__(self, **kwargs):
|
6 |
+
super().__init__(**kwargs)
|
CF_Plan.yaml
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "Plan_Flow"
|
2 |
+
description: |2-
|
3 |
+
Given a problem description, generate a high-level solution strategy.
|
4 |
+
|
5 |
+
# ~~~ Input interface specification ~~~
|
6 |
+
input_interface_non_initialized: # Applied when constructing the first user message.
|
7 |
+
- "problem_description"
|
8 |
+
- "input_description"
|
9 |
+
- "output_description"
|
10 |
+
- "io_examples_and_explanation"
|
11 |
+
|
12 |
+
input_interface_initialized: # Applied when constructing all subsequent user messages.
|
13 |
+
- "query"
|
14 |
+
|
15 |
+
# ~~~ Output interface specification ~~~
|
16 |
+
output_interface:
|
17 |
+
- "api_output"
|
18 |
+
|
19 |
+
# ~~~ Flow specification ~~~
|
20 |
+
model_name: "gpt-4"
|
21 |
+
generation_parameters:
|
22 |
+
n: 1
|
23 |
+
max_tokens: 3000
|
24 |
+
temperature: 0.3
|
25 |
+
|
26 |
+
model_kwargs:
|
27 |
+
top_p: 0.2
|
28 |
+
frequency_penalty: 0
|
29 |
+
presence_penalty: 0
|
30 |
+
|
31 |
+
system_message_prompt_template:
|
32 |
+
_target_: langchain.PromptTemplate
|
33 |
+
template: |2-
|
34 |
+
Your goal is to provide a high-level conceptual solution that, if implemented, will solve a given competitive programming problem.
|
35 |
+
|
36 |
+
The user will specify the problem by providing you with:
|
37 |
+
- the problem statement
|
38 |
+
- input description
|
39 |
+
- output description
|
40 |
+
- example test cases
|
41 |
+
- (optional) explanation of the test cases
|
42 |
+
|
43 |
+
The proposed algorithm should be computationally efficient, logically correct and handle all corner cases.
|
44 |
+
|
45 |
+
The user will provide you with a task and an output format that you will strictly follow.
|
46 |
+
input_variables: []
|
47 |
+
template_format: jinja2
|
48 |
+
|
49 |
+
human_message_prompt_template:
|
50 |
+
_target_: langchain.PromptTemplate
|
51 |
+
template: "{{query}}"
|
52 |
+
input_variables:
|
53 |
+
- "query"
|
54 |
+
template_format: jinja2
|
55 |
+
|
56 |
+
init_human_message_prompt_template:
|
57 |
+
_target_: langchain.PromptTemplate
|
58 |
+
template: |2-
|
59 |
+
# Problem statement
|
60 |
+
{{problem_description}}
|
61 |
+
|
62 |
+
# Input description
|
63 |
+
{{input_description}}
|
64 |
+
|
65 |
+
# Output description
|
66 |
+
{{output_description}}
|
67 |
+
|
68 |
+
{{io_examples_and_explanation}}
|
69 |
+
|
70 |
+
|
71 |
+
Return a high-level conceptual solution that would solve the problem. Be very concise, and do not provide code.
|
72 |
+
Reply in the following format:
|
73 |
+
# Conceptual solution
|
74 |
+
{{plan_placeholder}}
|
75 |
+
input_variables:
|
76 |
+
- "problem_description"
|
77 |
+
- "input_description"
|
78 |
+
- "output_description"
|
79 |
+
- "io_examples_and_explanation"
|
80 |
+
partial_variables:
|
81 |
+
plan_placeholder: "{{conceptual_solution}}"
|
82 |
+
template_format: jinja2
|
CF_PlanCollab.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flows.base_flows import CircularFlow
|
2 |
+
|
3 |
+
|
4 |
+
class CF_PlanCollab(CircularFlow):
|
5 |
+
def __init__(self, **kwargs):
|
6 |
+
super().__init__(**kwargs)
|
CF_PlanCollab.yaml
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "PlanCollab_Flow"
|
2 |
+
description: |2-
|
3 |
+
Given a problem description, alternate between a step in which a solution strategy is generated, and a step in which the solution strategy is evaluated and useful feedback is provided.
|
4 |
+
|
5 |
+
# ~~~ Input interface specification ~~~
|
6 |
+
input_interface:
|
7 |
+
- "problem_description"
|
8 |
+
- "input_description"
|
9 |
+
- "output_description"
|
10 |
+
- "io_examples_and_explanation"
|
11 |
+
|
12 |
+
# ~~~ Output interface specification ~~~
|
13 |
+
output_interface:
|
14 |
+
- "plan"
|
15 |
+
|
16 |
+
# ~~~ Flow specification ~~~
|
17 |
+
max_rounds: 4
|
18 |
+
early_exit_key: "end_of_interaction"
|
19 |
+
|
20 |
+
subflows_config:
|
21 |
+
PlanGenerator:
|
22 |
+
_target_: .CF_Plan.instantiate_from_default_config
|
23 |
+
human_message_prompt_template:
|
24 |
+
_target_: langchain.PromptTemplate
|
25 |
+
template: |2-
|
26 |
+
# Feedback on the last proposed conceptual solution
|
27 |
+
{{plan_feedback}}
|
28 |
+
|
29 |
+
|
30 |
+
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:
|
31 |
+
# Conceptual solution
|
32 |
+
{{plan_placeholder}}
|
33 |
+
otherwise, reply:
|
34 |
+
"Final answer."
|
35 |
+
input_variables:
|
36 |
+
- plan_feedback
|
37 |
+
partial_variables:
|
38 |
+
plan_placeholder: "{{conceptual_solution}}"
|
39 |
+
template_format: jinja2
|
40 |
+
input_interface_initialized:
|
41 |
+
- "plan_feedback"
|
42 |
+
PlanCritic:
|
43 |
+
_target_: .CF_PlanCritic.instantiate_from_default_config
|
44 |
+
|
45 |
+
topology:
|
46 |
+
# ~~~ Plan Generator ~~~
|
47 |
+
- goal: "Generate/refine a solution."
|
48 |
+
|
49 |
+
### Input Interface
|
50 |
+
input_interface:
|
51 |
+
_target_: flows.interfaces.KeyInterface
|
52 |
+
additional_transformations:
|
53 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
54 |
+
|
55 |
+
### Flow Specification
|
56 |
+
flow: PlanGenerator
|
57 |
+
|
58 |
+
### Output Interface
|
59 |
+
output_interface:
|
60 |
+
_target_: flows.interfaces.KeyInterface
|
61 |
+
additional_transformations:
|
62 |
+
- _target_: flows.data_transformations.RegexFirstOccurrenceExtractor
|
63 |
+
regex: '(?<=Conceptual solution)([\s\S]*?)(?=\n\n# [A-Z]|\Z)'
|
64 |
+
regex_fallback:
|
65 |
+
- '(?<=Conceptual solution:)([\s\S]*?)(?=\n\n# [A-Z]|\Z)'
|
66 |
+
input_key: "api_output"
|
67 |
+
output_key: "plan"
|
68 |
+
strip: True
|
69 |
+
assert_unique: True
|
70 |
+
- _target_: flows.data_transformations.EndOfInteraction
|
71 |
+
end_of_interaction_string: "Final answer"
|
72 |
+
input_key: "api_output"
|
73 |
+
output_key: "end_of_interaction"
|
74 |
+
- _target_: flows.data_transformations.PrintPreviousMessages
|
75 |
+
reset: false
|
76 |
+
# ~~~ Plan Critic ~~~
|
77 |
+
- goal: "Provide feedback for the candidate solution."
|
78 |
+
|
79 |
+
### Input Interface
|
80 |
+
input_interface:
|
81 |
+
_target_: flows.interfaces.KeyInterface
|
82 |
+
additional_transformations:
|
83 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
84 |
+
|
85 |
+
### Flow Specification
|
86 |
+
flow: PlanCritic
|
87 |
+
|
88 |
+
### Output Interface
|
89 |
+
output_interface:
|
90 |
+
_target_: flows.interfaces.KeyInterface
|
91 |
+
keys_to_rename:
|
92 |
+
api_output: "plan_feedback"
|
93 |
+
|
94 |
+
reset: true
|
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,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "PlanCollab_Code_Flow"
|
2 |
+
description: |2-
|
3 |
+
Given a problem description, first generate a solution strategy in collaboration with at critic, and then implement the code.
|
4 |
+
|
5 |
+
# ~~~ Input interface specification ~~~
|
6 |
+
input_interface:
|
7 |
+
- "problem_description"
|
8 |
+
- "input_description"
|
9 |
+
- "output_description"
|
10 |
+
- "io_examples_and_explanation"
|
11 |
+
|
12 |
+
# ~~~ Output interface specification ~~~
|
13 |
+
output_interface:
|
14 |
+
- "code"
|
15 |
+
|
16 |
+
subflows_config:
|
17 |
+
PlanGenerator:
|
18 |
+
_target_: .CF_PlanCollab.instantiate_from_default_config
|
19 |
+
CodeGenerator:
|
20 |
+
_target_: .CF_CodeWithPlan.instantiate_from_default_config
|
21 |
+
|
22 |
+
### Topology specification (specifies how the sequence of messages will flow from one of the subflows to another)
|
23 |
+
topology:
|
24 |
+
# ~~~ Plan Generator ~~~
|
25 |
+
- goal: "Generate a plan and reflect on it."
|
26 |
+
|
27 |
+
### Input Interface
|
28 |
+
input_interface:
|
29 |
+
_target_: flows.interfaces.KeyInterface
|
30 |
+
additional_transformations:
|
31 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
32 |
+
|
33 |
+
### Flow Specification
|
34 |
+
flow: PlanGenerator
|
35 |
+
|
36 |
+
### Output Interface
|
37 |
+
output_interface:
|
38 |
+
_target_: flows.interfaces.KeyInterface
|
39 |
+
keys_to_select:
|
40 |
+
- "plan"
|
41 |
+
|
42 |
+
# ~~~ Code Generator ~~~
|
43 |
+
- goal: "Generate/refine a solution."
|
44 |
+
|
45 |
+
### Input Interface
|
46 |
+
input_interface:
|
47 |
+
_target_: flows.interfaces.KeyInterface
|
48 |
+
additional_transformations:
|
49 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
50 |
+
|
51 |
+
### Flow Specification
|
52 |
+
flow: CodeGenerator
|
53 |
+
|
54 |
+
### Output Interface
|
55 |
+
output_interface:
|
56 |
+
_target_: flows.interfaces.KeyInterface
|
57 |
+
additional_transformations:
|
58 |
+
- _target_: flows.data_transformations.RegexFirstOccurrenceExtractor
|
59 |
+
regex: '(?<=```python)([\s\S]*?)(?=```)'
|
60 |
+
regex_fallback: '(?<=```)([\s\S]*?)(?=```)'
|
61 |
+
input_key: "api_output"
|
62 |
+
output_key: "code"
|
63 |
+
strip: True
|
64 |
+
assert_unique: True
|
65 |
+
- _target_: flows.data_transformations.PrintPreviousMessages
|
66 |
+
keys_to_select:
|
67 |
+
- "code"
|
CF_PlanCritic.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flow_modules.aiflows.OpenAIChatFlowModule import OpenAIChatAtomicFlow
|
2 |
+
|
3 |
+
|
4 |
+
class CF_PlanCritic(OpenAIChatAtomicFlow):
|
5 |
+
def __init__(self, **kwargs):
|
6 |
+
super().__init__(**kwargs)
|
CF_PlanCritic.yaml
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "PlanCritic_Flow"
|
2 |
+
description: |2-
|
3 |
+
Given a problem description and a solution strategy candidate, provide useful feedback concerning its correctness.
|
4 |
+
|
5 |
+
# ~~~ Input interface specification ~~~
|
6 |
+
input_interface_non_initialized:
|
7 |
+
- "problem_description"
|
8 |
+
- "input_description"
|
9 |
+
- "output_description"
|
10 |
+
- "io_examples_and_explanation"
|
11 |
+
- "plan"
|
12 |
+
|
13 |
+
input_interface_initialized:
|
14 |
+
- "query"
|
15 |
+
|
16 |
+
# ~~~ Output interface specification ~~~
|
17 |
+
output_interface:
|
18 |
+
- "api_output"
|
19 |
+
|
20 |
+
# ~~~ Flow specification ~~~
|
21 |
+
model_name: "gpt-4"
|
22 |
+
|
23 |
+
generation_parameters:
|
24 |
+
n: 1
|
25 |
+
max_tokens: 3000
|
26 |
+
temperature: 0.3
|
27 |
+
|
28 |
+
model_kwargs:
|
29 |
+
top_p: 0.2
|
30 |
+
frequency_penalty: 0
|
31 |
+
presence_penalty: 0
|
32 |
+
|
33 |
+
system_message_prompt_template:
|
34 |
+
_target_: langchain.PromptTemplate
|
35 |
+
template: |2-
|
36 |
+
Your goal is to identify potential issues with a conceptual solution to a given competitive programming problem.
|
37 |
+
|
38 |
+
The user will specify the problem by providing you with:
|
39 |
+
- the problem statement
|
40 |
+
- input description
|
41 |
+
- output description
|
42 |
+
- example test cases
|
43 |
+
- (optional) explanation of the test cases
|
44 |
+
- a conceptual solution attempt
|
45 |
+
|
46 |
+
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.
|
47 |
+
Some aspects to consider: Are there any logical mistakes with the proposed algorithm? Are the corner cases correctly handled?
|
48 |
+
The user will provide you with a task and an output format that you will strictly follow.
|
49 |
+
input_variables: []
|
50 |
+
template_format: jinja2
|
51 |
+
|
52 |
+
human_message_prompt_template:
|
53 |
+
_target_: langchain.PromptTemplate
|
54 |
+
template: "{{query}}"
|
55 |
+
input_variables:
|
56 |
+
- "query"
|
57 |
+
template_format: jinja2
|
58 |
+
|
59 |
+
init_human_message_prompt_template:
|
60 |
+
_target_: langchain.PromptTemplate
|
61 |
+
template: |2-
|
62 |
+
# Problem statement
|
63 |
+
{{problem_description}}
|
64 |
+
|
65 |
+
# Input description
|
66 |
+
{{input_description}}
|
67 |
+
|
68 |
+
# Output description
|
69 |
+
{{output_description}}
|
70 |
+
|
71 |
+
{{io_examples_and_explanation}}
|
72 |
+
|
73 |
+
# Conceptual solution attempt
|
74 |
+
{{plan}}
|
75 |
+
|
76 |
+
|
77 |
+
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.
|
78 |
+
input_variables:
|
79 |
+
- "problem_description"
|
80 |
+
- "input_description"
|
81 |
+
- "output_description"
|
82 |
+
- "io_examples_and_explanation"
|
83 |
+
- "plan"
|
84 |
+
template_format: jinja2
|
CF_PlanReflect.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flows.base_flows import CircularFlow
|
2 |
+
|
3 |
+
|
4 |
+
class CF_PlanReflect(CircularFlow):
|
5 |
+
def __init__(self, **kwargs):
|
6 |
+
super().__init__(**kwargs)
|
CF_PlanReflect.yaml
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "PlanReflect_Flow"
|
2 |
+
description: |-2
|
3 |
+
Given a problem description, generate a plan, reflect on it and improve it until a message suggesting that the code seems correct or a maximum number of rounds is reached.
|
4 |
+
|
5 |
+
# ~~~ Input interface specification ~~~
|
6 |
+
input_interface:
|
7 |
+
- "problem_description"
|
8 |
+
- "input_description"
|
9 |
+
- "output_description"
|
10 |
+
- "io_examples_and_explanation"
|
11 |
+
|
12 |
+
# ~~~ Output interface specification ~~~
|
13 |
+
output_interface:
|
14 |
+
- "plan"
|
15 |
+
|
16 |
+
# ~~~ Flow specification ~~~
|
17 |
+
max_rounds: 4
|
18 |
+
early_exit_key: "end_of_interaction"
|
19 |
+
|
20 |
+
subflows_config:
|
21 |
+
PlanGenerator:
|
22 |
+
_target_: .CF_Plan.instantiate_from_default_config
|
23 |
+
PlanReflectCritic:
|
24 |
+
_target_: .FixedReply_PlanReflect.instantiate_from_default_config
|
25 |
+
|
26 |
+
### Topology specification (specifies how the sequence of messages will flow from one of the subflows to another)
|
27 |
+
topology:
|
28 |
+
# ~~~ Code Generator ~~~
|
29 |
+
- goal: "Generate/refine a plan."
|
30 |
+
|
31 |
+
### Input Interface
|
32 |
+
input_interface:
|
33 |
+
_target_: flows.interfaces.KeyInterface
|
34 |
+
additional_transformations:
|
35 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
36 |
+
keys_to_rename:
|
37 |
+
plan_reflect_message: "query"
|
38 |
+
|
39 |
+
### Flow Specification
|
40 |
+
flow: PlanGenerator
|
41 |
+
|
42 |
+
### Output Interface
|
43 |
+
output_interface:
|
44 |
+
_target_: flows.interfaces.KeyInterface
|
45 |
+
additional_transformations:
|
46 |
+
- _target_: flows.data_transformations.RegexFirstOccurrenceExtractor
|
47 |
+
regex: '(?<=Conceptual solution)([\s\S]*?)(?=\n\n# [A-Z]|\Z)'
|
48 |
+
regex_fallback:
|
49 |
+
- '(?<=Conceptual solution:)([\s\S]*?)(?=\n\n# [A-Z]|\Z)'
|
50 |
+
input_key: "api_output"
|
51 |
+
output_key: "plan"
|
52 |
+
strip: True
|
53 |
+
assert_unique: True
|
54 |
+
- _target_: flows.data_transformations.EndOfInteraction
|
55 |
+
end_of_interaction_string: "Final answer"
|
56 |
+
input_key: "api_output"
|
57 |
+
output_key: "end_of_interaction"
|
58 |
+
- _target_: flows.data_transformations.PrintPreviousMessages
|
59 |
+
keys_to_select:
|
60 |
+
- "plan"
|
61 |
+
- "end_of_interaction"
|
62 |
+
|
63 |
+
### Reset flag
|
64 |
+
reset: false
|
65 |
+
|
66 |
+
- goal: "Generate a message that encourages reflection."
|
67 |
+
|
68 |
+
### Input Interface
|
69 |
+
input_interface:
|
70 |
+
_target_: flows.interfaces.KeyInterface
|
71 |
+
additional_transformations:
|
72 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
73 |
+
|
74 |
+
### Flow Specification
|
75 |
+
flow: PlanReflectCritic
|
76 |
+
|
77 |
+
### Output Interface
|
78 |
+
output_interface:
|
79 |
+
_target_: flows.interfaces.KeyInterface
|
80 |
+
keys_to_rename:
|
81 |
+
fixed_reply: "plan_reflect_message"
|
82 |
+
|
83 |
+
### Reset flag
|
84 |
+
reset: true
|
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,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "Plan_Code_Flow"
|
2 |
+
description: |2-
|
3 |
+
Given a problem description, first generate a solution strategy, reflect on it, and then implement the code.
|
4 |
+
|
5 |
+
# ~~~ Input interface specification ~~~
|
6 |
+
input_interface:
|
7 |
+
- "problem_description"
|
8 |
+
- "input_description"
|
9 |
+
- "output_description"
|
10 |
+
- "io_examples_and_explanation"
|
11 |
+
|
12 |
+
# ~~~ Output interface specification ~~~
|
13 |
+
output_interface:
|
14 |
+
- "code"
|
15 |
+
|
16 |
+
subflows_config:
|
17 |
+
PlanGenerator:
|
18 |
+
_target_: .CF_PlanReflect.instantiate_from_default_config
|
19 |
+
CodeGenerator:
|
20 |
+
_target_: .CF_CodeWithPlan.instantiate_from_default_config
|
21 |
+
|
22 |
+
### Topology specification (specifies how the sequence of messages will flow from one of the subflows to another)
|
23 |
+
topology:
|
24 |
+
# ~~~ Plan Generator ~~~
|
25 |
+
- goal: "Generate a plan and reflect on it."
|
26 |
+
|
27 |
+
### Input Interface
|
28 |
+
input_interface:
|
29 |
+
_target_: flows.interfaces.KeyInterface
|
30 |
+
additional_transformations:
|
31 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
32 |
+
|
33 |
+
### Flow Specification
|
34 |
+
flow: PlanGenerator
|
35 |
+
|
36 |
+
### Output Interface
|
37 |
+
output_interface:
|
38 |
+
_target_: flows.interfaces.KeyInterface
|
39 |
+
keys_to_select:
|
40 |
+
- "plan"
|
41 |
+
|
42 |
+
# ~~~ Code Generator ~~~
|
43 |
+
- goal: "Generate/refine a solution."
|
44 |
+
|
45 |
+
### Input Interface
|
46 |
+
input_interface:
|
47 |
+
_target_: flows.interfaces.KeyInterface
|
48 |
+
additional_transformations:
|
49 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
50 |
+
|
51 |
+
### Flow Specification
|
52 |
+
flow: CodeGenerator
|
53 |
+
|
54 |
+
### Output Interface
|
55 |
+
output_interface:
|
56 |
+
_target_: flows.interfaces.KeyInterface
|
57 |
+
additional_transformations:
|
58 |
+
- _target_: flows.data_transformations.RegexFirstOccurrenceExtractor
|
59 |
+
regex: '(?<=```python)([\s\S]*?)(?=```)'
|
60 |
+
regex_fallback: '(?<=```)([\s\S]*?)(?=```)'
|
61 |
+
input_key: "api_output"
|
62 |
+
output_key: "code"
|
63 |
+
strip: True
|
64 |
+
assert_unique: True
|
65 |
+
- _target_: flows.data_transformations.PrintPreviousMessages
|
66 |
+
keys_to_select:
|
67 |
+
- "code"
|
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,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "Plan_Code_Flow"
|
2 |
+
description: |2-
|
3 |
+
Given a problem description, first generate a solution strategy and then implement the code.
|
4 |
+
|
5 |
+
# ~~~ Input interface specification ~~~
|
6 |
+
input_interface:
|
7 |
+
- "problem_description"
|
8 |
+
- "input_description"
|
9 |
+
- "output_description"
|
10 |
+
- "io_examples_and_explanation"
|
11 |
+
|
12 |
+
# ~~~ Output interface specification ~~~
|
13 |
+
output_interface:
|
14 |
+
- "code"
|
15 |
+
|
16 |
+
subflows_config:
|
17 |
+
PlanGenerator:
|
18 |
+
_target_: .CF_Plan.instantiate_from_default_config
|
19 |
+
CodeGenerator:
|
20 |
+
_target_: .CF_CodeWithPlan.instantiate_from_default_config
|
21 |
+
|
22 |
+
### Topology specification (specifies how the sequence of messages will flow from one of the subflows to another)
|
23 |
+
topology:
|
24 |
+
# ~~~ Code Generator ~~~
|
25 |
+
- goal: "Generate a plan."
|
26 |
+
|
27 |
+
### Input Interface
|
28 |
+
input_interface:
|
29 |
+
_target_: flows.interfaces.KeyInterface
|
30 |
+
additional_transformations:
|
31 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
32 |
+
|
33 |
+
### Flow Specification
|
34 |
+
flow: PlanGenerator
|
35 |
+
|
36 |
+
### Output Interface
|
37 |
+
output_interface:
|
38 |
+
_target_: flows.interfaces.KeyInterface
|
39 |
+
additional_transformations:
|
40 |
+
- _target_: flows.data_transformations.RegexFirstOccurrenceExtractor
|
41 |
+
regex: '(?<=Conceptual solution)([\s\S]*?)(?=\n\n# [A-Z]|\Z)'
|
42 |
+
regex_fallback:
|
43 |
+
- '(?<=Conceptual solution:)([\s\S]*?)(?=\n\n# [A-Z]|\Z)'
|
44 |
+
input_key: "api_output"
|
45 |
+
output_key: "plan"
|
46 |
+
strip: True
|
47 |
+
assert_unique: True
|
48 |
+
- _target_: flows.data_transformations.PrintPreviousMessages
|
49 |
+
keys_to_select:
|
50 |
+
- "plan"
|
51 |
+
|
52 |
+
# ~~~ Code Generator ~~~
|
53 |
+
- goal: "Generate/refine a solution."
|
54 |
+
|
55 |
+
### Input Interface
|
56 |
+
input_interface:
|
57 |
+
_target_: flows.interfaces.KeyInterface
|
58 |
+
additional_transformations:
|
59 |
+
- _target_: flows.data_transformations.KeyMatchInput
|
60 |
+
|
61 |
+
### Flow Specification
|
62 |
+
flow: CodeGenerator
|
63 |
+
|
64 |
+
### Output Interface
|
65 |
+
output_interface:
|
66 |
+
_target_: flows.interfaces.KeyInterface
|
67 |
+
additional_transformations:
|
68 |
+
- _target_: flows.data_transformations.RegexFirstOccurrenceExtractor
|
69 |
+
regex: '(?<=```python)([\s\S]*?)(?=```)'
|
70 |
+
regex_fallback: '(?<=```)([\s\S]*?)(?=```)'
|
71 |
+
input_key: "api_output"
|
72 |
+
output_key: "code"
|
73 |
+
strip: True
|
74 |
+
assert_unique: True
|
75 |
+
- _target_: flows.data_transformations.PrintPreviousMessages
|
76 |
+
keys_to_select:
|
77 |
+
- "code"
|
FixedReply_PlanReflect.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flow_modules.aiflows.FixedReplyFlowModule import FixedReplyFlow
|
2 |
+
|
3 |
+
|
4 |
+
class FixedReply_PlanReflect(FixedReplyFlow):
|
5 |
+
def __init__(self, **kwargs):
|
6 |
+
super().__init__(**kwargs)
|
FixedReply_PlanReflect.yaml
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "PlanReflectCritic"
|
2 |
+
description: |-2
|
3 |
+
A flow that prompts the user to reflect on their conceptual solution and provide a corrected version if necessary.
|
4 |
+
|
5 |
+
|
6 |
+
input_interface: []
|
7 |
+
output_interface:
|
8 |
+
- fixed_reply
|
9 |
+
|
10 |
+
fixed_reply: |2-
|
11 |
+
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?
|
12 |
+
If that is not the case, provide the corrected version of the conceptual solution in the following format:
|
13 |
+
# Conceptual solution
|
14 |
+
{{conceptual_solution}}
|
15 |
+
otherwise, reply:
|
16 |
+
"Final answer."
|