Tachi67 commited on
Commit
711c00e
1 Parent(s): cea643f

Upload 6 files

Browse files
Files changed (2) hide show
  1. PlanFileEditAtomicFlow.py +52 -2
  2. README.md +28 -0
PlanFileEditAtomicFlow.py CHANGED
@@ -14,8 +14,22 @@ class PlanFileEditAtomicFlow(AtomicFlow):
14
  *Output Interface*:
15
  - `plan_editor_output`: str
16
  - `temp_plan_file_location`: str
 
 
 
 
 
17
  """
18
  def _generate_content(self, plan_file_location, plan_str) -> str:
 
 
 
 
 
 
 
 
 
19
  content = (
20
  "The below plan will be written to " +
21
  plan_file_location + "\n"
@@ -30,11 +44,27 @@ class PlanFileEditAtomicFlow(AtomicFlow):
30
  return content
31
 
32
  def _generate_temp_file_location(self, plan_file_location):
 
 
 
 
 
 
 
33
  directory = os.path.dirname(plan_file_location)
34
  ret = os.path.join(directory, 'temp_plan.txt')
35
  return ret
36
 
37
  def _write_plan_content_to_file(self, file_location, content: str):
 
 
 
 
 
 
 
 
 
38
  try:
39
  with open(file_location, "w") as file:
40
  file.write(content)
@@ -45,6 +75,14 @@ class PlanFileEditAtomicFlow(AtomicFlow):
45
  return False, str(e), file_location
46
 
47
  def _check_input(self, input_data: Dict[str, Any]):
 
 
 
 
 
 
 
 
48
  assert any(item in input_data for item in ["plan", "new_plan"]), "plan or new_plan is not passed to PlanFileEditAtomicFlow"
49
  assert "plan_file_location" in input_data, "plan_file_location not passed to PlanFileEditAtomicFlow"
50
  plan_file_loc = input_data["plan_file_location"]
@@ -53,13 +91,18 @@ class PlanFileEditAtomicFlow(AtomicFlow):
53
 
54
  def _generate_input_to_writer(self, input_data: Dict[str, Any]):
55
  """
56
- sometimes the plan generator will return an arrary of indexed plans, like
57
  [
58
  "1. Extend the code library with a function named 'import_libraries'. This function should import necessary libraries for the task...",
59
  "2. Extend the code library with a function named 'fetch_stock_prices'. This function should take two inputs: 'company_code' and 'duration'...",
60
  "3. Investigate the issue with importing the 'fetch_stock_prices' function from the library..."
61
  ]
62
- In this case we need to prase this format accorrdingly.
 
 
 
 
 
63
  """
64
 
65
  plan = input_data['plan'] if "plan" in input_data else input_data['new_plan']
@@ -78,6 +121,13 @@ class PlanFileEditAtomicFlow(AtomicFlow):
78
  self,
79
  input_data: Dict[str, Any]
80
  ):
 
 
 
 
 
 
 
81
  self._check_input(input_data)
82
 
83
  # ~~~ Getting input data to the file editor ~~~
 
14
  *Output Interface*:
15
  - `plan_editor_output`: str
16
  - `temp_plan_file_location`: str
17
+
18
+ *Configuration Parameters*:
19
+ - `input_interface`: The input interface of the atomic flow.
20
+ - `output_interface`: The output interface of the atomic flow.
21
+
22
  """
23
  def _generate_content(self, plan_file_location, plan_str) -> str:
24
+ """
25
+ This function generates the content to be written to the plan file.
26
+ :param plan_file_location: The location of the plan file.
27
+ :type plan_file_location: str
28
+ :param plan_str: The plan to be written to the plan file.
29
+ :type plan_str: str
30
+ :return: The content to be written to the plan file.
31
+ :rtype: str
32
+ """
33
  content = (
34
  "The below plan will be written to " +
35
  plan_file_location + "\n"
 
44
  return content
45
 
46
  def _generate_temp_file_location(self, plan_file_location):
47
+ """
48
+ This function generates the location of the temp plan file.
49
+ :param plan_file_location: The location of the plan file.
50
+ :type plan_file_location: str
51
+ :return: The location of the temp plan file.
52
+ :rtype: str
53
+ """
54
  directory = os.path.dirname(plan_file_location)
55
  ret = os.path.join(directory, 'temp_plan.txt')
56
  return ret
57
 
58
  def _write_plan_content_to_file(self, file_location, content: str):
59
+ """
60
+ This function writes the plan content to the plan file.
61
+ :param file_location: The location of the plan file.
62
+ :type file_location: str
63
+ :param content: The content to be written to the plan file.
64
+ :type content: str
65
+ :return: The result of writing the plan content to the plan file.
66
+ :rtype: Tuple[bool, str, str]
67
+ """
68
  try:
69
  with open(file_location, "w") as file:
70
  file.write(content)
 
75
  return False, str(e), file_location
76
 
77
  def _check_input(self, input_data: Dict[str, Any]):
78
+ """
79
+ This function checks if the input data is valid.
80
+ :param input_data: The input data.
81
+ :type input_data: Dict[str, Any]
82
+ :return: None
83
+ :rtype: None
84
+ :raises AssertionError: If the input data is invalid.
85
+ """
86
  assert any(item in input_data for item in ["plan", "new_plan"]), "plan or new_plan is not passed to PlanFileEditAtomicFlow"
87
  assert "plan_file_location" in input_data, "plan_file_location not passed to PlanFileEditAtomicFlow"
88
  plan_file_loc = input_data["plan_file_location"]
 
91
 
92
  def _generate_input_to_writer(self, input_data: Dict[str, Any]):
93
  """
94
+ sometimes the plan generator will return an array of indexed plans, like
95
  [
96
  "1. Extend the code library with a function named 'import_libraries'. This function should import necessary libraries for the task...",
97
  "2. Extend the code library with a function named 'fetch_stock_prices'. This function should take two inputs: 'company_code' and 'duration'...",
98
  "3. Investigate the issue with importing the 'fetch_stock_prices' function from the library..."
99
  ]
100
+ In this case we need to parse this format accordingly.
101
+
102
+ :param input_data: The input data.
103
+ :type input_data: Dict[str, Any]
104
+ :return: The content to be written to the plan file and the location of the temp plan file.
105
+ :rtype: Tuple[str, str]
106
  """
107
 
108
  plan = input_data['plan'] if "plan" in input_data else input_data['new_plan']
 
121
  self,
122
  input_data: Dict[str, Any]
123
  ):
124
+ """
125
+ This function runs the atomic flow.
126
+ :param input_data: The input data.
127
+ :type input_data: Dict[str, Any]
128
+ :return: The output data.
129
+ :rtype: Dict[str, Any]
130
+ """
131
  self._check_input(input_data)
132
 
133
  # ~~~ Getting input data to the file editor ~~~
README.md CHANGED
@@ -2,6 +2,8 @@
2
 
3
  * [PlanFileEditAtomicFlow](#PlanFileEditAtomicFlow)
4
  * [PlanFileEditAtomicFlow](#PlanFileEditAtomicFlow.PlanFileEditAtomicFlow)
 
 
5
  * [\_\_init\_\_](#__init__)
6
 
7
  <a id="PlanFileEditAtomicFlow"></a>
@@ -27,6 +29,32 @@ to the user.
27
  - `plan_editor_output`: str
28
  - `temp_plan_file_location`: str
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  <a id="__init__"></a>
31
 
32
  # \_\_init\_\_
 
2
 
3
  * [PlanFileEditAtomicFlow](#PlanFileEditAtomicFlow)
4
  * [PlanFileEditAtomicFlow](#PlanFileEditAtomicFlow.PlanFileEditAtomicFlow)
5
+ * [run](#PlanFileEditAtomicFlow.PlanFileEditAtomicFlow.run)
6
+ * [run](#run)
7
  * [\_\_init\_\_](#__init__)
8
 
9
  <a id="PlanFileEditAtomicFlow"></a>
 
29
  - `plan_editor_output`: str
30
  - `temp_plan_file_location`: str
31
 
32
+ *Configuration Parameters*:
33
+ - `input_interface`: The input interface of the atomic flow.
34
+ - `output_interface`: The output interface of the atomic flow.
35
+
36
+ <a id="PlanFileEditAtomicFlow.PlanFileEditAtomicFlow.run"></a>
37
+
38
+ #### run
39
+
40
+ ```python
41
+ def run(input_data: Dict[str, Any])
42
+ ```
43
+
44
+ This function runs the atomic flow.
45
+
46
+ **Arguments**:
47
+
48
+ - `input_data` (`Dict[str, Any]`): The input data.
49
+
50
+ **Returns**:
51
+
52
+ `Dict[str, Any]`: The output data.
53
+
54
+ <a id="run"></a>
55
+
56
+ # run
57
+
58
  <a id="__init__"></a>
59
 
60
  # \_\_init\_\_