From 04fc78cdf3978551f87bfb8cfa8d255cb9966c2b Mon Sep 17 00:00:00 2001 From: Shilin He Date: Mon, 13 May 2024 07:57:31 +0000 Subject: [PATCH 1/2] update zip --- .gitignore | 2 +- setup.py | 24 +++++++++++++++++ taskweaver/cli/init.py | 58 +++++++++--------------------------------- taskweaver/cli/util.py | 2 +- 4 files changed, 38 insertions(+), 48 deletions(-) diff --git a/.gitignore b/.gitignore index f412cf69..b67ecefe 100644 --- a/.gitignore +++ b/.gitignore @@ -182,7 +182,7 @@ test_workspace # extensions template -taskweaver/cli/taskweaver-ext.zip +taskweaver/cli/taskweaver-project.zip # General .DS_Store diff --git a/setup.py b/setup.py index 33d4bf5e..0a8be396 100644 --- a/setup.py +++ b/setup.py @@ -30,6 +30,29 @@ def revert(): long_description = fh.read() +# create zip file for ext +def create_zip_file(): + import zipfile + from pathlib import Path + + root_dir = Path(__file__).parent + ext_zip_file = root_dir / "taskweaver" / "cli" / "taskweaver-project.zip" + if os.path.exists(ext_zip_file): + os.remove(ext_zip_file) + + content_root = root_dir / "project" + zipf = zipfile.ZipFile(ext_zip_file, "w", zipfile.ZIP_DEFLATED) + for root, dirs, files in os.walk(content_root): + for file in files: + zipf.write( + os.path.join(root, file), + os.path.relpath(Path(root) / file, root_dir), + ) + zipf.close() + + +create_zip_file() + cur_dir = os.path.dirname( os.path.abspath( __file__, @@ -77,6 +100,7 @@ def revert(): ], package_data={ "taskweaver": ["**/*.yaml", "**/*.yml"], + "taskweaver.cli": ["taskweaver-project.zip"], }, entry_points={ "console_scripts": ["taskweaver=taskweaver.__main__:main"], diff --git a/taskweaver/cli/init.py b/taskweaver/cli/init.py index e73712fd..815e2dfc 100644 --- a/taskweaver/cli/init.py +++ b/taskweaver/cli/init.py @@ -56,46 +56,21 @@ def init( if not os.path.exists(project): os.mkdir(project) - def get_dir(*dir: str): - return os.path.join(project, *dir) - - dir_list = [ - "codeinterpreter_examples", - "planner_examples", - "plugins", - "config", - "workspace", - ] - for dir in dir_list: - dir_path = get_dir(dir) - if not os.path.exists(dir_path): - os.mkdir(dir_path) - - init_temp_dir = get_dir("init") import zipfile from pathlib import Path - tpl_dir = os.path.join(init_temp_dir, "template") - ext_zip_file = Path(__file__).parent / "taskweaver-ext.zip" + tpl_dir = os.path.join(project, "temp") + if not os.path.exists(tpl_dir): + os.mkdir(tpl_dir) + + ext_zip_file = Path(__file__).parent / "taskweaver-project.zip" if os.path.exists(ext_zip_file): with zipfile.ZipFile(ext_zip_file, "r") as zip_ref: # Extract all files to the current directory zip_ref.extractall(tpl_dir) - - tpl_planner_example_dir = os.path.join(tpl_dir, "taskweaver-ext", "planner_examples") - tpl_ci_example_dir = os.path.join(tpl_dir, "taskweaver-ext", "codeinterpreter_examples") - tpl_plugin_dir = os.path.join(tpl_dir, "taskweaver-ext", "plugins") - tpl_config_dir = os.path.join(tpl_dir, "taskweaver-ext") - planner_example_dir = get_dir("planner_examples") - ci_example_dir = get_dir("codeinterpreter_examples") - plugin_dir = get_dir("plugins") - copy_files(tpl_planner_example_dir, planner_example_dir) - copy_files(tpl_ci_example_dir, ci_example_dir) - copy_files(tpl_plugin_dir, plugin_dir) - copy_file(tpl_config_dir, "taskweaver_config.json", get_dir("")) - + copy_files(os.path.join(tpl_dir, "project"), project) try: - shutil.rmtree(init_temp_dir) + shutil.rmtree(tpl_dir) except Exception: click.secho("Failed to remove temporary directory", fg="yellow") click.secho( @@ -105,17 +80,8 @@ def get_dir(*dir: str): def copy_files(src_dir: str, dst_dir: str): - # Get a list of all files in the source directory - files = os.listdir(src_dir) - - # Loop through the files and copy each one to the destination directory - for file in files: - if os.path.isfile(os.path.join(src_dir, file)): - copy_file(src_dir, file, dst_dir) - - -def copy_file(src_dir: str, filename: str, dst_dir: str): - shutil.copy( - os.path.join(src_dir, filename), - os.path.join(dst_dir, filename), - ) + # Check if the destination folder exists. If not, create it. + if not os.path.exists(dst_dir): + os.makedirs(dst_dir) + # Copy the content of source_folder to destination_folder + shutil.copytree(src_dir, dst_dir, dirs_exist_ok=True) diff --git a/taskweaver/cli/util.py b/taskweaver/cli/util.py index 375d7465..76cd471d 100644 --- a/taskweaver/cli/util.py +++ b/taskweaver/cli/util.py @@ -16,7 +16,7 @@ def new_func(ctx: click.Context, *args: Any, **kwargs: Any): else: click.echo( "The current directory is not a valid Task Weaver project directory. " - "There needs to be a `taskweaver-config.json` in the root of the project directory. " + "There needs to be a `taskweaver_config.json` in the root of the project directory. " "Please change the working directory to a valid project directory or initialize a new one. " "Refer to --help for more information.", ) From 36daff460f16840e628257d710a5518d2eec6c66 Mon Sep 17 00:00:00 2001 From: Shilin He Date: Wed, 15 May 2024 07:28:39 +0000 Subject: [PATCH 2/2] update readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index b0cd09f8..5df5dfab 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,10 @@ cd TaskWeaver pip install -r requirements.txt ``` +If you want to install an earlier version of TaskWeaver, you may check the [release](https://github.com/microsoft/TaskWeaver/releases) page, find the tag (e.g., `v0.0.1`) and install it by +``` +pip install git+https://github.com/microsoft/TaskWeaver@ +``` ### 🖊️ Step 2: Configure the LLMs Before running TaskWeaver, you need to provide your LLM configurations. Taking OpenAI as an example, you can configure `taskweaver_config.json` file as follows. @@ -115,6 +119,8 @@ TaskWeaver also supports WebUI for demo purpose, please refer to [web UI docs](h #### or 📋 Import as a Library TaskWeaver can be imported as a library to integrate with your existing project, more information can be found in [docs](https://microsoft.github.io/TaskWeaver/docs/usage/library) + + ## 📖 Documentation More documentations can be found on [TaskWeaver Website](https://microsoft.github.io/TaskWeaver).