Upload 12 files
Browse filesFiles changed (5)
16 unmodified lines171819202122232411 unmodified lines36373839404142434445464748493 unmodified lines53545556575816 unmodified lines*Output Interface*:- interpreter_output: The output of the execution of the code.- code_ran: The code that was executed."""def _prepare_code(self, input_data: Dict[str, Any]):file_location = input_data["temp_code_file_location"]start_marker = "# Code:\n"end_marker = "############"11 unmodified linesinput_data["code"] = code_strdef _check_input(self, input_data: Dict[str, Any]):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):if os.path.exists(file_location):os.remove(file_location)def _open_file_and_wait_for_upd(self, file_location):process = subprocess.Popen(["code", "--wait", file_location])while True:if process.poll() is not None:3 unmodified linesdef run(self,input_data: 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)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 linesinput_data["code"] = code_strdef _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 linesdef 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 lines456789101125 unmodified lines37383940414218 unmodified lines6162636465666 unmodified lines7374757677787915 unmodified lines95969798991001013 unmodified lines* [RunCodeFlow](#RunCodeFlow.RunCodeFlow)* [ExecuteCodeAtomicFlow](#ExecuteCodeAtomicFlow)* [ExecuteCodeAtomicFlow](#ExecuteCodeAtomicFlow.ExecuteCodeAtomicFlow)* [RunCodeAskUserFlow](#RunCodeAskUserFlow)* [RunCodeAskUserFlow](#RunCodeAskUserFlow.RunCodeAskUserFlow)* [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)<a id="ExecuteCodeAtomicFlow"></a># ExecuteCodeAtomicFlow18 unmodified lines- interpreter_output: The output of the execution of the code.- code_ran: The code that was executed.<a id="RunCodeAskUserFlow"></a># RunCodeAskUserFlow6 unmodified linesclass RunCodeAskUserFlow(HumanStandardInputFlow)```Refer to: https://huggingface.co/Tachi67/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py<a id="library"></a>15 unmodified linesclass RunCodeFileEditAtomicFlow(CodeFileEditAtomicFlow)```Refer to: https://huggingface.co/Tachi67/CodeFileEditFlowModule<a id="__init__"></a>3 unmodified lines4567891011121325 unmodified lines3940414243444546474849505118 unmodified lines707172737475767778798081828384858687888990919293949596976 unmodified lines10410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214315 unmodified lines1591601611621631641651661671681691701711721731741751761771783 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/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/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 lines101112131415161718199 unmodified linesclass RunCodeAskUserFlow(HumanStandardInputFlow):"""Refer to: https://huggingface.co/Tachi67/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py"""def run(self,input_data: Dict[str, Any]) -> 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'],9 unmodified lines10111213141516171819202122232425262728293031323334353637383940419 unmodified linesclass RunCodeAskUserFlow(HumanStandardInputFlow):"""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 lines3456789101116 unmodified lines282930313233343536373839404142439 unmodified lines5354555657582 unmodified linesfrom flow_modules.aiflows.CodeFileEditFlowModule import CodeFileEditAtomicFlowclass RunCodeFileEditAtomicFlow(CodeFileEditAtomicFlow):"""Refer to: https://huggingface.co/Tachi67/CodeFileEditFlowModule"""def _generate_content(self, code_str, comment_sign) -> str:if comment_sign == "<!-- -->":instruction = ("<!-- The below code will be executed.\n"16 unmodified linesreturn contentdef _generate_temp_file_location(self, code_lib_location, file_extension):directory = os.path.dirname(code_lib_location)ret = os.path.join(directory, 'run_code_temp'+file_extension)return retdef _check_input(self, input_data: Dict[str, Any]):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):details = {"python": {"extension": ".py", "comment": "#"},"bash": {"extension": ".sh", "comment": "#"},9 unmodified linesreturn details.get(language.lower())def _generate_input_to_writer(self, input_data: Dict[str, Any]):code_str = input_data['code']code_lib_location = input_data["memory_files"]["code_library"]2 unmodified lines3456789101112131415161718192021222324252627282930313233343516 unmodified lines52535455565758596061626364656667686970717273747576777879808182838485868788899091929 unmodified lines1021031041051061071081091101111121131141152 unmodified linesfrom flow_modules.aiflows.CodeFileEditFlowModule import CodeFileEditAtomicFlowclass RunCodeFileEditAtomicFlow(CodeFileEditAtomicFlow):"""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 linesreturn contentdef _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 retdef _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 linesreturn 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 lines171819202116 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)"""pass16 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."""pass
ExecuteCodeAtomicFlow.py+37
README.md+79-2
RunCodeAskUserFlow.py+24-2
RunCodeFileEditAtomicFlow.py+58-1
RunCodeFlow.py+8