Upload 12 files
Browse filesFiles changed (5)
16 unmodified lines1718192021222324252627282930313233343511 unmodified lines4748495051525354555657585960616263646566676869707172737475767778793 unmodified lines8384858687888990919293949516 unmodified lines *Output Interface*: - interpreter_output: The output of the execution of the code. - code_ran: The code that was executed.
*Configuration Parameters*: - `input_interface`: The input interface of the atomic flow. - `output_interface`: The output interface of the atomic flow.
""" def _prepare_code(self, input_data: Dict[str, Any]): """ This method reads the code from the file and stores it in the input_data dictionary. :param input_data: The input_data dictionary. :type input_data: Dict[str, Any] :return: None """ file_location = input_data["temp_code_file_location"] start_marker = "# Code:\n" end_marker = "############"11 unmodified lines input_data["code"] = code_str
def _check_input(self, input_data: Dict[str, Any]): """ This method checks if the input_data dictionary contains the required keys. :param input_data: The input_data dictionary. :type input_data: Dict[str, Any] :raises AssertionError: If the input_data dictionary does not contain the required keys. :return: None """ assert "temp_code_file_location" in input_data, "temp_code_file_location not passed to ExecuteCodeAtomicFlow" assert "language" in input_data, "language not passed to ExecuteCodeAtomicFlow"
def _delete_file(self, file_location): """ This method deletes the file at the given location. :param file_location: The location of the file to be deleted. :type file_location: str :return: None """ if os.path.exists(file_location): os.remove(file_location)
def _open_file_and_wait_for_upd(self, file_location): """ This method opens the file at the given location in VSCode and waits for the user to save the file. :param file_location: The location of the file to be opened. :type file_location: str :return: None """ process = subprocess.Popen(["code", "--wait", file_location]) while True: if process.poll() is not None:3 unmodified lines def run( self, input_data: Dict[str, Any]): """ This method is called when the atomic flow is called. :param input_data: The input_data dictionary. :type input_data: Dict[str, Any] :return: The output of the execution of the code. :rtype: Dict[str, Any] """ self._check_input(input_data) file_loc = input_data["temp_code_file_location"] self._open_file_and_wait_for_upd(file_loc)3 unmodified lines4567891011121325 unmodified lines3940414243444546474849505118 unmodified lines707172737475767778798081828384858687888990919293949596976 unmodified lines1041051067610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214315 unmodified lines159160161981621631641651661671681691701711721731741751761771783 unmodified lines * [RunCodeFlow](#RunCodeFlow.RunCodeFlow)* [ExecuteCodeAtomicFlow](#ExecuteCodeAtomicFlow) * [ExecuteCodeAtomicFlow](#ExecuteCodeAtomicFlow.ExecuteCodeAtomicFlow) * [run](#ExecuteCodeAtomicFlow.ExecuteCodeAtomicFlow.run)* [RunCodeAskUserFlow](#RunCodeAskUserFlow) * [RunCodeAskUserFlow](#RunCodeAskUserFlow.RunCodeAskUserFlow) * [run](#RunCodeAskUserFlow.RunCodeAskUserFlow.run)* [library](#library)* [run](#run)* [RunCodeFileEditAtomicFlow](#RunCodeFileEditAtomicFlow)25 unmodified lines- summary: The summary of the execution of the code. (To be written to the logs of the caller flow)- result: The result of the execution of the code. (To be returned to the controller of the caller flow)
*Configuration Parameters*:- `input_interface`: The input interface of the flow. (Default: `['code', 'language', 'memory_files']`)- `output_interface`: The output interface of the flow. (Default: `['summary', 'result']`)- `subflows_config`: The configuration of the subflows of the flow.- `early_exit_key`: The key to be pressed to exit the flow early.- `topology`: The topology of the subflows.
<a id="ExecuteCodeAtomicFlow"></a>
# ExecuteCodeAtomicFlow18 unmodified lines- interpreter_output: The output of the execution of the code.- code_ran: The code that was executed.
*Configuration Parameters*:- `input_interface`: The input interface of the atomic flow.- `output_interface`: The output interface of the atomic flow.
<a id="ExecuteCodeAtomicFlow.ExecuteCodeAtomicFlow.run"></a>
#### run
```pythondef run(input_data: Dict[str, Any])```
This method is called when the atomic flow is called.
**Arguments**:
- `input_data` (`Dict[str, Any]`): The input_data dictionary.
**Returns**:
`Dict[str, Any]`: The output of the execution of the code.
<a id="RunCodeAskUserFlow"></a>
# RunCodeAskUserFlow6 unmodified linesclass RunCodeAskUserFlow(HumanStandardInputFlow)```
Refer to: https://huggingface.co/Tachi67/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.pyRefer to: https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py
*Input Interface*:- `question`: The question asked
*Expected Behaviour*:- The question is displayed, and the user gives feedback by input string.
*Output Interface*:- `result`: The input of the user.- `summary`: The summary that will be written by the caller.
*Configuration Parameters*:- `query_message_prompt_template`: The template of the message that is displayed to the user.- `request_multi_line_input`: Whether the user should be able to input multiple lines. Default: False.- `end_of_input_string`: The string that the user can input to indicate that he/she is done with the input. Default: EOI
<a id="RunCodeAskUserFlow.RunCodeAskUserFlow.run"></a>
#### run
```pythondef run(input_data: Dict[str, Any]) -> Dict[str, Any]```
Run the flow module.
**Arguments**:
- `input_data` (`Dict[str, Any]`): The input data.
**Returns**:
`Dict[str, Any]`: The output data.
<a id="library"></a>
15 unmodified linesclass RunCodeFileEditAtomicFlow(CodeFileEditAtomicFlow)```
Refer to: https://huggingface.co/Tachi67/CodeFileEditFlowModuleRefer to: https://huggingface.co/aiflows/CodeFileEditFlowModule
*Input Interface*:- `code`: str- `language_of_code`: str- `memory_files`: Dict[str, str]
*Output Interface*:- `code_editor_output`: str- `temp_code_file_location`: str
*Configuration Parameters*:- `input_interface`: The input interface of the atomic flow.- `output_interface`: The output interface of the atomic flow.
<a id="__init__"></a>
9 unmodified lines101112131314151617181920212223242526272829303132163334353637383940419 unmodified lines
class RunCodeAskUserFlow(HumanStandardInputFlow): """Refer to: https://huggingface.co/Tachi67/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py""" """Refer to: https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py
*Input Interface*: - `question`: The question asked
*Expected Behaviour*: - The question is displayed, and the user gives feedback by input string.
*Output Interface*: - `result`: The input of the user. - `summary`: The summary that will be written by the caller.
*Configuration Parameters*: - `query_message_prompt_template`: The template of the message that is displayed to the user. - `request_multi_line_input`: Whether the user should be able to input multiple lines. Default: False. - `end_of_input_string`: The string that the user can input to indicate that he/she is done with the input. Default: EOI
""" def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
"""Run the flow module. :param input_data: The input data. :type input_data: Dict[str, Any] :return: The output data. :rtype: Dict[str, Any] """ query_message = self._get_message(self.query_message_prompt_template, input_data) state_update_message = UpdateMessage_Generic( created_by=self.flow_config['name'],2 unmodified lines34566789101112131415161718192021222324252627282930313233343516 unmodified lines52535455565758596061626364656667686970717273747576777879808182838485868788899091929 unmodified lines1021031041051061071081091101111121131141152 unmodified linesfrom flow_modules.aiflows.CodeFileEditFlowModule import CodeFileEditAtomicFlow
class RunCodeFileEditAtomicFlow(CodeFileEditAtomicFlow): """Refer to: https://huggingface.co/Tachi67/CodeFileEditFlowModule""" """Refer to: https://huggingface.co/aiflows/CodeFileEditFlowModule
*Input Interface*: - `code`: str - `language_of_code`: str - `memory_files`: Dict[str, str]
*Output Interface*: - `code_editor_output`: str - `temp_code_file_location`: str
*Configuration Parameters*: - `input_interface`: The input interface of the atomic flow. - `output_interface`: The output interface of the atomic flow.
"""
def _generate_content(self, code_str, comment_sign) -> str: """ Generate the content to write to the temp file. :param code_str: The code string. :type code_str: str :param comment_sign: The comment sign for the language. :type comment_sign: str :return: The content to write to the temp file. :rtype: str """ if comment_sign == "<!-- -->": instruction = ( "<!-- The below code will be executed.\n"16 unmodified lines return content
def _generate_temp_file_location(self, code_lib_location, file_extension): """ Generate the temp file location. :param code_lib_location: The code library location. :type code_lib_location: str :param file_extension: The file extension. :type file_extension: str :return: The temp file location. :rtype: str """ directory = os.path.dirname(code_lib_location) ret = os.path.join(directory, 'run_code_temp'+file_extension) return ret
def _check_input(self, input_data: Dict[str, Any]): """ Check the input data. :param input_data: The input data. :type input_data: Dict[str, Any] :return: None :rtype: None :raises AssertionError: If the input data is not valid. """ assert "code" in input_data, "code is not passed to RunCodeFileEditAtomicFlow" assert "memory_files" in input_data, "memory_files is not passed to RunCodeFileEditAtomicFlow" assert "language" in input_data, "language is not passed to RunCodeFileEditAtomicFlow"
def _generate_file_extension_and_comment_sign(self, language: str): """ Generate the file extension and comment sign for the language. :param language: The language. :type language: str :return: The file extension and comment sign. :rtype: Dict[str, str] :raises NotImplemented: If the language is not supported. """ details = { "python": {"extension": ".py", "comment": "#"}, "bash": {"extension": ".sh", "comment": "#"},9 unmodified lines return details.get(language.lower())
def _generate_input_to_writer(self, input_data: Dict[str, Any]): """ Generate the input to the writer. :param input_data: The input data. :type input_data: Dict[str, Any] :return: The input to the writer. :rtype: Tuple[str, str] :raises NotImplemented: If the language is not supported. """ code_str = input_data['code'] code_lib_location = input_data["memory_files"]["code_library"] 16 unmodified lines1718192021222324252627282916 unmodified lines *Output Interface*: - summary: The summary of the execution of the code. (To be written to the logs of the caller flow) - result: The result of the execution of the code. (To be returned to the controller of the caller flow)
*Configuration Parameters*: - `input_interface`: The input interface of the flow. (Default: `['code', 'language', 'memory_files']`) - `output_interface`: The output interface of the flow. (Default: `['summary', 'result']`) - `subflows_config`: The configuration of the subflows of the flow. - `early_exit_key`: The key to be pressed to exit the flow early. - `topology`: The topology of the subflows.
""" passExecuteCodeAtomicFlow.py+37
README.md+79-2
RunCodeAskUserFlow.py+24-2
RunCodeFileEditAtomicFlow.py+58-1
RunCodeFlow.py+8