Upload 12 files
Browse files- ExecuteCodeAtomicFlow.py +37 -0
- README.md +79 -2
- RunCodeAskUserFlow.py +24 -2
- RunCodeFileEditAtomicFlow.py +58 -1
- RunCodeFlow.py +8 -0
ExecuteCodeAtomicFlow.py
CHANGED
|
@@ -17,8 +17,19 @@ class ExecuteCodeAtomicFlow(InterpreterAtomicFlow):
|
|
| 17 |
*Output Interface*:
|
| 18 |
- interpreter_output: The output of the execution of the code.
|
| 19 |
- code_ran: The code that was executed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
"""
|
| 21 |
def _prepare_code(self, input_data: Dict[str, Any]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
file_location = input_data["temp_code_file_location"]
|
| 23 |
start_marker = "# Code:\n"
|
| 24 |
end_marker = "############"
|
|
@@ -36,14 +47,33 @@ class ExecuteCodeAtomicFlow(InterpreterAtomicFlow):
|
|
| 36 |
input_data["code"] = code_str
|
| 37 |
|
| 38 |
def _check_input(self, input_data: Dict[str, Any]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
assert "temp_code_file_location" in input_data, "temp_code_file_location not passed to ExecuteCodeAtomicFlow"
|
| 40 |
assert "language" in input_data, "language not passed to ExecuteCodeAtomicFlow"
|
| 41 |
|
| 42 |
def _delete_file(self, file_location):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
if os.path.exists(file_location):
|
| 44 |
os.remove(file_location)
|
| 45 |
|
| 46 |
def _open_file_and_wait_for_upd(self, file_location):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
process = subprocess.Popen(["code", "--wait", file_location])
|
| 48 |
while True:
|
| 49 |
if process.poll() is not None:
|
|
@@ -53,6 +83,13 @@ class ExecuteCodeAtomicFlow(InterpreterAtomicFlow):
|
|
| 53 |
def run(
|
| 54 |
self,
|
| 55 |
input_data: Dict[str, Any]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
self._check_input(input_data)
|
| 57 |
file_loc = input_data["temp_code_file_location"]
|
| 58 |
self._open_file_and_wait_for_upd(file_loc)
|
|
|
|
| 17 |
*Output Interface*:
|
| 18 |
- interpreter_output: The output of the execution of the code.
|
| 19 |
- code_ran: The code that was executed.
|
| 20 |
+
|
| 21 |
+
*Configuration Parameters*:
|
| 22 |
+
- `input_interface`: The input interface of the atomic flow.
|
| 23 |
+
- `output_interface`: The output interface of the atomic flow.
|
| 24 |
+
|
| 25 |
"""
|
| 26 |
def _prepare_code(self, input_data: Dict[str, Any]):
|
| 27 |
+
"""
|
| 28 |
+
This method reads the code from the file and stores it in the input_data dictionary.
|
| 29 |
+
:param input_data: The input_data dictionary.
|
| 30 |
+
:type input_data: Dict[str, Any]
|
| 31 |
+
:return: None
|
| 32 |
+
"""
|
| 33 |
file_location = input_data["temp_code_file_location"]
|
| 34 |
start_marker = "# Code:\n"
|
| 35 |
end_marker = "############"
|
|
|
|
| 47 |
input_data["code"] = code_str
|
| 48 |
|
| 49 |
def _check_input(self, input_data: Dict[str, Any]):
|
| 50 |
+
"""
|
| 51 |
+
This method checks if the input_data dictionary contains the required keys.
|
| 52 |
+
:param input_data: The input_data dictionary.
|
| 53 |
+
:type input_data: Dict[str, Any]
|
| 54 |
+
:raises AssertionError: If the input_data dictionary does not contain the required keys.
|
| 55 |
+
:return: None
|
| 56 |
+
"""
|
| 57 |
assert "temp_code_file_location" in input_data, "temp_code_file_location not passed to ExecuteCodeAtomicFlow"
|
| 58 |
assert "language" in input_data, "language not passed to ExecuteCodeAtomicFlow"
|
| 59 |
|
| 60 |
def _delete_file(self, file_location):
|
| 61 |
+
"""
|
| 62 |
+
This method deletes the file at the given location.
|
| 63 |
+
:param file_location: The location of the file to be deleted.
|
| 64 |
+
:type file_location: str
|
| 65 |
+
:return: None
|
| 66 |
+
"""
|
| 67 |
if os.path.exists(file_location):
|
| 68 |
os.remove(file_location)
|
| 69 |
|
| 70 |
def _open_file_and_wait_for_upd(self, file_location):
|
| 71 |
+
"""
|
| 72 |
+
This method opens the file at the given location in VSCode and waits for the user to save the file.
|
| 73 |
+
:param file_location: The location of the file to be opened.
|
| 74 |
+
:type file_location: str
|
| 75 |
+
:return: None
|
| 76 |
+
"""
|
| 77 |
process = subprocess.Popen(["code", "--wait", file_location])
|
| 78 |
while True:
|
| 79 |
if process.poll() is not None:
|
|
|
|
| 83 |
def run(
|
| 84 |
self,
|
| 85 |
input_data: Dict[str, Any]):
|
| 86 |
+
"""
|
| 87 |
+
This method is called when the atomic flow is called.
|
| 88 |
+
:param input_data: The input_data dictionary.
|
| 89 |
+
:type input_data: Dict[str, Any]
|
| 90 |
+
:return: The output of the execution of the code.
|
| 91 |
+
:rtype: Dict[str, Any]
|
| 92 |
+
"""
|
| 93 |
self._check_input(input_data)
|
| 94 |
file_loc = input_data["temp_code_file_location"]
|
| 95 |
self._open_file_and_wait_for_upd(file_loc)
|
README.md
CHANGED
|
@@ -4,8 +4,10 @@
|
|
| 4 |
* [RunCodeFlow](#RunCodeFlow.RunCodeFlow)
|
| 5 |
* [ExecuteCodeAtomicFlow](#ExecuteCodeAtomicFlow)
|
| 6 |
* [ExecuteCodeAtomicFlow](#ExecuteCodeAtomicFlow.ExecuteCodeAtomicFlow)
|
|
|
|
| 7 |
* [RunCodeAskUserFlow](#RunCodeAskUserFlow)
|
| 8 |
* [RunCodeAskUserFlow](#RunCodeAskUserFlow.RunCodeAskUserFlow)
|
|
|
|
| 9 |
* [library](#library)
|
| 10 |
* [run](#run)
|
| 11 |
* [RunCodeFileEditAtomicFlow](#RunCodeFileEditAtomicFlow)
|
|
@@ -37,6 +39,13 @@ Finally, the flow asks the user for feedback on the execution of the code.
|
|
| 37 |
- summary: The summary of the execution of the code. (To be written to the logs of the caller flow)
|
| 38 |
- result: The result of the execution of the code. (To be returned to the controller of the caller flow)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
<a id="ExecuteCodeAtomicFlow"></a>
|
| 41 |
|
| 42 |
# ExecuteCodeAtomicFlow
|
|
@@ -61,6 +70,28 @@ from the file and executes it. It then returns the output of the execution.
|
|
| 61 |
- interpreter_output: The output of the execution of the code.
|
| 62 |
- code_ran: The code that was executed.
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
<a id="RunCodeAskUserFlow"></a>
|
| 65 |
|
| 66 |
# RunCodeAskUserFlow
|
|
@@ -73,7 +104,40 @@ from the file and executes it. It then returns the output of the execution.
|
|
| 73 |
class RunCodeAskUserFlow(HumanStandardInputFlow)
|
| 74 |
```
|
| 75 |
|
| 76 |
-
Refer to: https://huggingface.co/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
<a id="library"></a>
|
| 79 |
|
|
@@ -95,7 +159,20 @@ Refer to: https://huggingface.co/Tachi67/ExtendLibraryFlowModule/blob/main/ExtLi
|
|
| 95 |
class RunCodeFileEditAtomicFlow(CodeFileEditAtomicFlow)
|
| 96 |
```
|
| 97 |
|
| 98 |
-
Refer to: https://huggingface.co/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
<a id="__init__"></a>
|
| 101 |
|
|
|
|
| 4 |
* [RunCodeFlow](#RunCodeFlow.RunCodeFlow)
|
| 5 |
* [ExecuteCodeAtomicFlow](#ExecuteCodeAtomicFlow)
|
| 6 |
* [ExecuteCodeAtomicFlow](#ExecuteCodeAtomicFlow.ExecuteCodeAtomicFlow)
|
| 7 |
+
* [run](#ExecuteCodeAtomicFlow.ExecuteCodeAtomicFlow.run)
|
| 8 |
* [RunCodeAskUserFlow](#RunCodeAskUserFlow)
|
| 9 |
* [RunCodeAskUserFlow](#RunCodeAskUserFlow.RunCodeAskUserFlow)
|
| 10 |
+
* [run](#RunCodeAskUserFlow.RunCodeAskUserFlow.run)
|
| 11 |
* [library](#library)
|
| 12 |
* [run](#run)
|
| 13 |
* [RunCodeFileEditAtomicFlow](#RunCodeFileEditAtomicFlow)
|
|
|
|
| 39 |
- summary: The summary of the execution of the code. (To be written to the logs of the caller flow)
|
| 40 |
- result: The result of the execution of the code. (To be returned to the controller of the caller flow)
|
| 41 |
|
| 42 |
+
*Configuration Parameters*:
|
| 43 |
+
- `input_interface`: The input interface of the flow. (Default: `['code', 'language', 'memory_files']`)
|
| 44 |
+
- `output_interface`: The output interface of the flow. (Default: `['summary', 'result']`)
|
| 45 |
+
- `subflows_config`: The configuration of the subflows of the flow.
|
| 46 |
+
- `early_exit_key`: The key to be pressed to exit the flow early.
|
| 47 |
+
- `topology`: The topology of the subflows.
|
| 48 |
+
|
| 49 |
<a id="ExecuteCodeAtomicFlow"></a>
|
| 50 |
|
| 51 |
# ExecuteCodeAtomicFlow
|
|
|
|
| 70 |
- interpreter_output: The output of the execution of the code.
|
| 71 |
- code_ran: The code that was executed.
|
| 72 |
|
| 73 |
+
*Configuration Parameters*:
|
| 74 |
+
- `input_interface`: The input interface of the atomic flow.
|
| 75 |
+
- `output_interface`: The output interface of the atomic flow.
|
| 76 |
+
|
| 77 |
+
<a id="ExecuteCodeAtomicFlow.ExecuteCodeAtomicFlow.run"></a>
|
| 78 |
+
|
| 79 |
+
#### run
|
| 80 |
+
|
| 81 |
+
```python
|
| 82 |
+
def run(input_data: Dict[str, Any])
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
This method is called when the atomic flow is called.
|
| 86 |
+
|
| 87 |
+
**Arguments**:
|
| 88 |
+
|
| 89 |
+
- `input_data` (`Dict[str, Any]`): The input_data dictionary.
|
| 90 |
+
|
| 91 |
+
**Returns**:
|
| 92 |
+
|
| 93 |
+
`Dict[str, Any]`: The output of the execution of the code.
|
| 94 |
+
|
| 95 |
<a id="RunCodeAskUserFlow"></a>
|
| 96 |
|
| 97 |
# RunCodeAskUserFlow
|
|
|
|
| 104 |
class RunCodeAskUserFlow(HumanStandardInputFlow)
|
| 105 |
```
|
| 106 |
|
| 107 |
+
Refer to: https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py
|
| 108 |
+
|
| 109 |
+
*Input Interface*:
|
| 110 |
+
- `question`: The question asked
|
| 111 |
+
|
| 112 |
+
*Expected Behaviour*:
|
| 113 |
+
- The question is displayed, and the user gives feedback by input string.
|
| 114 |
+
|
| 115 |
+
*Output Interface*:
|
| 116 |
+
- `result`: The input of the user.
|
| 117 |
+
- `summary`: The summary that will be written by the caller.
|
| 118 |
+
|
| 119 |
+
*Configuration Parameters*:
|
| 120 |
+
- `query_message_prompt_template`: The template of the message that is displayed to the user.
|
| 121 |
+
- `request_multi_line_input`: Whether the user should be able to input multiple lines. Default: False.
|
| 122 |
+
- `end_of_input_string`: The string that the user can input to indicate that he/she is done with the input. Default: EOI
|
| 123 |
+
|
| 124 |
+
<a id="RunCodeAskUserFlow.RunCodeAskUserFlow.run"></a>
|
| 125 |
+
|
| 126 |
+
#### run
|
| 127 |
+
|
| 128 |
+
```python
|
| 129 |
+
def run(input_data: Dict[str, Any]) -> Dict[str, Any]
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
Run the flow module.
|
| 133 |
+
|
| 134 |
+
**Arguments**:
|
| 135 |
+
|
| 136 |
+
- `input_data` (`Dict[str, Any]`): The input data.
|
| 137 |
+
|
| 138 |
+
**Returns**:
|
| 139 |
+
|
| 140 |
+
`Dict[str, Any]`: The output data.
|
| 141 |
|
| 142 |
<a id="library"></a>
|
| 143 |
|
|
|
|
| 159 |
class RunCodeFileEditAtomicFlow(CodeFileEditAtomicFlow)
|
| 160 |
```
|
| 161 |
|
| 162 |
+
Refer to: https://huggingface.co/aiflows/CodeFileEditFlowModule
|
| 163 |
+
|
| 164 |
+
*Input Interface*:
|
| 165 |
+
- `code`: str
|
| 166 |
+
- `language_of_code`: str
|
| 167 |
+
- `memory_files`: Dict[str, str]
|
| 168 |
+
|
| 169 |
+
*Output Interface*:
|
| 170 |
+
- `code_editor_output`: str
|
| 171 |
+
- `temp_code_file_location`: str
|
| 172 |
+
|
| 173 |
+
*Configuration Parameters*:
|
| 174 |
+
- `input_interface`: The input interface of the atomic flow.
|
| 175 |
+
- `output_interface`: The output interface of the atomic flow.
|
| 176 |
|
| 177 |
<a id="__init__"></a>
|
| 178 |
|
RunCodeAskUserFlow.py
CHANGED
|
@@ -10,10 +10,32 @@ log = logging.get_logger(f"aiflows.{__name__}")
|
|
| 10 |
|
| 11 |
|
| 12 |
class RunCodeAskUserFlow(HumanStandardInputFlow):
|
| 13 |
-
"""Refer to: https://huggingface.co/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def run(self,
|
| 15 |
input_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
query_message = self._get_message(self.query_message_prompt_template, input_data)
|
| 18 |
state_update_message = UpdateMessage_Generic(
|
| 19 |
created_by=self.flow_config['name'],
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
class RunCodeAskUserFlow(HumanStandardInputFlow):
|
| 13 |
+
"""Refer to: https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py
|
| 14 |
+
|
| 15 |
+
*Input Interface*:
|
| 16 |
+
- `question`: The question asked
|
| 17 |
+
|
| 18 |
+
*Expected Behaviour*:
|
| 19 |
+
- The question is displayed, and the user gives feedback by input string.
|
| 20 |
+
|
| 21 |
+
*Output Interface*:
|
| 22 |
+
- `result`: The input of the user.
|
| 23 |
+
- `summary`: The summary that will be written by the caller.
|
| 24 |
+
|
| 25 |
+
*Configuration Parameters*:
|
| 26 |
+
- `query_message_prompt_template`: The template of the message that is displayed to the user.
|
| 27 |
+
- `request_multi_line_input`: Whether the user should be able to input multiple lines. Default: False.
|
| 28 |
+
- `end_of_input_string`: The string that the user can input to indicate that he/she is done with the input. Default: EOI
|
| 29 |
+
|
| 30 |
+
"""
|
| 31 |
def run(self,
|
| 32 |
input_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 33 |
+
"""Run the flow module.
|
| 34 |
+
:param input_data: The input data.
|
| 35 |
+
:type input_data: Dict[str, Any]
|
| 36 |
+
:return: The output data.
|
| 37 |
+
:rtype: Dict[str, Any]
|
| 38 |
+
"""
|
| 39 |
query_message = self._get_message(self.query_message_prompt_template, input_data)
|
| 40 |
state_update_message = UpdateMessage_Generic(
|
| 41 |
created_by=self.flow_config['name'],
|
RunCodeFileEditAtomicFlow.py
CHANGED
|
@@ -3,9 +3,33 @@ from typing import Dict, Any
|
|
| 3 |
from flow_modules.aiflows.CodeFileEditFlowModule import CodeFileEditAtomicFlow
|
| 4 |
|
| 5 |
class RunCodeFileEditAtomicFlow(CodeFileEditAtomicFlow):
|
| 6 |
-
"""Refer to: https://huggingface.co/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def _generate_content(self, code_str, comment_sign) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
if comment_sign == "<!-- -->":
|
| 10 |
instruction = (
|
| 11 |
"<!-- The below code will be executed.\n"
|
|
@@ -28,16 +52,41 @@ class RunCodeFileEditAtomicFlow(CodeFileEditAtomicFlow):
|
|
| 28 |
return content
|
| 29 |
|
| 30 |
def _generate_temp_file_location(self, code_lib_location, file_extension):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
directory = os.path.dirname(code_lib_location)
|
| 32 |
ret = os.path.join(directory, 'run_code_temp'+file_extension)
|
| 33 |
return ret
|
| 34 |
|
| 35 |
def _check_input(self, input_data: Dict[str, Any]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
assert "code" in input_data, "code is not passed to RunCodeFileEditAtomicFlow"
|
| 37 |
assert "memory_files" in input_data, "memory_files is not passed to RunCodeFileEditAtomicFlow"
|
| 38 |
assert "language" in input_data, "language is not passed to RunCodeFileEditAtomicFlow"
|
| 39 |
|
| 40 |
def _generate_file_extension_and_comment_sign(self, language: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
details = {
|
| 42 |
"python": {"extension": ".py", "comment": "#"},
|
| 43 |
"bash": {"extension": ".sh", "comment": "#"},
|
|
@@ -53,6 +102,14 @@ class RunCodeFileEditAtomicFlow(CodeFileEditAtomicFlow):
|
|
| 53 |
return details.get(language.lower())
|
| 54 |
|
| 55 |
def _generate_input_to_writer(self, input_data: Dict[str, Any]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
code_str = input_data['code']
|
| 57 |
code_lib_location = input_data["memory_files"]["code_library"]
|
| 58 |
|
|
|
|
| 3 |
from flow_modules.aiflows.CodeFileEditFlowModule import CodeFileEditAtomicFlow
|
| 4 |
|
| 5 |
class RunCodeFileEditAtomicFlow(CodeFileEditAtomicFlow):
|
| 6 |
+
"""Refer to: https://huggingface.co/aiflows/CodeFileEditFlowModule
|
| 7 |
+
|
| 8 |
+
*Input Interface*:
|
| 9 |
+
- `code`: str
|
| 10 |
+
- `language_of_code`: str
|
| 11 |
+
- `memory_files`: Dict[str, str]
|
| 12 |
+
|
| 13 |
+
*Output Interface*:
|
| 14 |
+
- `code_editor_output`: str
|
| 15 |
+
- `temp_code_file_location`: str
|
| 16 |
+
|
| 17 |
+
*Configuration Parameters*:
|
| 18 |
+
- `input_interface`: The input interface of the atomic flow.
|
| 19 |
+
- `output_interface`: The output interface of the atomic flow.
|
| 20 |
+
|
| 21 |
+
"""
|
| 22 |
|
| 23 |
def _generate_content(self, code_str, comment_sign) -> str:
|
| 24 |
+
"""
|
| 25 |
+
Generate the content to write to the temp file.
|
| 26 |
+
:param code_str: The code string.
|
| 27 |
+
:type code_str: str
|
| 28 |
+
:param comment_sign: The comment sign for the language.
|
| 29 |
+
:type comment_sign: str
|
| 30 |
+
:return: The content to write to the temp file.
|
| 31 |
+
:rtype: str
|
| 32 |
+
"""
|
| 33 |
if comment_sign == "<!-- -->":
|
| 34 |
instruction = (
|
| 35 |
"<!-- The below code will be executed.\n"
|
|
|
|
| 52 |
return content
|
| 53 |
|
| 54 |
def _generate_temp_file_location(self, code_lib_location, file_extension):
|
| 55 |
+
"""
|
| 56 |
+
Generate the temp file location.
|
| 57 |
+
:param code_lib_location: The code library location.
|
| 58 |
+
:type code_lib_location: str
|
| 59 |
+
:param file_extension: The file extension.
|
| 60 |
+
:type file_extension: str
|
| 61 |
+
:return: The temp file location.
|
| 62 |
+
:rtype: str
|
| 63 |
+
"""
|
| 64 |
directory = os.path.dirname(code_lib_location)
|
| 65 |
ret = os.path.join(directory, 'run_code_temp'+file_extension)
|
| 66 |
return ret
|
| 67 |
|
| 68 |
def _check_input(self, input_data: Dict[str, Any]):
|
| 69 |
+
"""
|
| 70 |
+
Check the input data.
|
| 71 |
+
:param input_data: The input data.
|
| 72 |
+
:type input_data: Dict[str, Any]
|
| 73 |
+
:return: None
|
| 74 |
+
:rtype: None
|
| 75 |
+
:raises AssertionError: If the input data is not valid.
|
| 76 |
+
"""
|
| 77 |
assert "code" in input_data, "code is not passed to RunCodeFileEditAtomicFlow"
|
| 78 |
assert "memory_files" in input_data, "memory_files is not passed to RunCodeFileEditAtomicFlow"
|
| 79 |
assert "language" in input_data, "language is not passed to RunCodeFileEditAtomicFlow"
|
| 80 |
|
| 81 |
def _generate_file_extension_and_comment_sign(self, language: str):
|
| 82 |
+
"""
|
| 83 |
+
Generate the file extension and comment sign for the language.
|
| 84 |
+
:param language: The language.
|
| 85 |
+
:type language: str
|
| 86 |
+
:return: The file extension and comment sign.
|
| 87 |
+
:rtype: Dict[str, str]
|
| 88 |
+
:raises NotImplemented: If the language is not supported.
|
| 89 |
+
"""
|
| 90 |
details = {
|
| 91 |
"python": {"extension": ".py", "comment": "#"},
|
| 92 |
"bash": {"extension": ".sh", "comment": "#"},
|
|
|
|
| 102 |
return details.get(language.lower())
|
| 103 |
|
| 104 |
def _generate_input_to_writer(self, input_data: Dict[str, Any]):
|
| 105 |
+
"""
|
| 106 |
+
Generate the input to the writer.
|
| 107 |
+
:param input_data: The input data.
|
| 108 |
+
:type input_data: Dict[str, Any]
|
| 109 |
+
:return: The input to the writer.
|
| 110 |
+
:rtype: Tuple[str, str]
|
| 111 |
+
:raises NotImplemented: If the language is not supported.
|
| 112 |
+
"""
|
| 113 |
code_str = input_data['code']
|
| 114 |
code_lib_location = input_data["memory_files"]["code_library"]
|
| 115 |
|
RunCodeFlow.py
CHANGED
|
@@ -17,5 +17,13 @@ class RunCodeFlow(SequentialFlow):
|
|
| 17 |
*Output Interface*:
|
| 18 |
- summary: The summary of the execution of the code. (To be written to the logs of the caller flow)
|
| 19 |
- result: The result of the execution of the code. (To be returned to the controller of the caller flow)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
"""
|
| 21 |
pass
|
|
|
|
| 17 |
*Output Interface*:
|
| 18 |
- summary: The summary of the execution of the code. (To be written to the logs of the caller flow)
|
| 19 |
- result: The result of the execution of the code. (To be returned to the controller of the caller flow)
|
| 20 |
+
|
| 21 |
+
*Configuration Parameters*:
|
| 22 |
+
- `input_interface`: The input interface of the flow. (Default: `['code', 'language', 'memory_files']`)
|
| 23 |
+
- `output_interface`: The output interface of the flow. (Default: `['summary', 'result']`)
|
| 24 |
+
- `subflows_config`: The configuration of the subflows of the flow.
|
| 25 |
+
- `early_exit_key`: The key to be pressed to exit the flow early.
|
| 26 |
+
- `topology`: The topology of the subflows.
|
| 27 |
+
|
| 28 |
"""
|
| 29 |
pass
|