|
import os |
|
from typing import Dict, Any |
|
from flow_modules.aiflows.CodeFileEditFlowModule import CodeFileEditAtomicFlow |
|
|
|
class TestCodeFileEditAtomicFlow(CodeFileEditAtomicFlow): |
|
"""Refer to: https://huggingface.co/Tachi67/CodeFileEditFlowModule/tree/main""" |
|
def _generate_import_statement(self, code_lib_location): |
|
module_dir = os.path.dirname(code_lib_location) |
|
module_name = os.path.splitext(os.path.basename(code_lib_location))[0] |
|
|
|
import_code = ( |
|
f"import sys\n" |
|
f"sys.path.insert(0, '{module_dir}')\n" |
|
f"from {module_name} import *\n" |
|
) |
|
return import_code |
|
|
|
def _generate_content(self, code_lib_location, code_str) -> str: |
|
import_code_lib_str = self._generate_import_statement(code_lib_location) |
|
content = ( |
|
"# Don't touch this import statement \n" |
|
+ import_code_lib_str + "\n" |
|
"# Here is the code just generated \n" + |
|
code_str + "\n" |
|
"# Below, please provide code to test it.\n" |
|
"# The simplest form could be just calling it with appropriate parameters. \n" |
|
"# You could also assert the output, anyway, the test results will be informed to JARVIS. \n" |
|
"# If you do not write anything, JARVIS just checks if the syntax is alright. \n" |
|
"###########\n" |
|
"# Test Code:\n" + |
|
"\n############\n" |
|
) |
|
return content |
|
|
|
def _generate_temp_file_location(self, code_lib_location): |
|
directory = os.path.dirname(code_lib_location) |
|
ret = os.path.join(directory, 'temp_tests.py') |
|
return ret |
|
|
|
def _check_input(self, input_data: Dict[str, Any]): |
|
assert "code" in input_data, "code is not passed to TestCodeFileEditAtomicFlow" |
|
assert "memory_files" in input_data, "memory_files is not passed to TestCodeFileEditAtomicFlow" |
|
|
|
|