From 6653b657eff85c8424a2f7edd2ae6ff7d6017424 Mon Sep 17 00:00:00 2001 From: aakrem Date: Tue, 7 May 2024 08:55:03 +0200 Subject: [PATCH 1/3] add overwrite option to skip interactive mode --- agenta-cli/agenta/cli/variant_commands.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/agenta-cli/agenta/cli/variant_commands.py b/agenta-cli/agenta/cli/variant_commands.py index dd26ccb992..aff2bddcbc 100644 --- a/agenta-cli/agenta/cli/variant_commands.py +++ b/agenta-cli/agenta/cli/variant_commands.py @@ -29,7 +29,7 @@ def variant(): def add_variant( - app_folder: str, file_name: str, host: str, config_name="default" + app_folder: str, file_name: str, host: str, overwrite: bool, config_name="default" ) -> str: """ Adds a variant to the backend. Sends the code as a tar to the backend, which then containerizes it and adds it to the backend store. @@ -97,14 +97,13 @@ def add_variant( # update the config file with the variant names from the backend variant_name = f"{base_name}.{config_name}" - overwrite = False client = AgentaApi( base_url=f"{host}/{BACKEND_URL_SUFFIX}", api_key=api_key, ) - if variant_name in config["variants"]: + if variant_name in config["variants"] and not overwrite: overwrite = questionary.confirm( "This variant already exists. Do you want to overwrite it?" ).ask() @@ -443,9 +442,15 @@ def remove_variant_cli(variant_name: str, app_folder: str): ) @click.option("--app_folder", default=".") @click.option("--file_name", default=None, help="The name of the file to run") +@click.option( + "--overwrite", + is_flag=True, + default=False, + help="Overwrite the existing variant if it exists", +) @click.pass_context -def serve_cli(ctx, app_folder: str, file_name: str): - """Adds a variant to the web ui and serves the API locally.""" +def serve_cli(ctx, app_folder: str, file_name: str, overwrite: bool): + """Adds a variant to the web UI and serves the API locally.""" if not file_name: if ctx.args: @@ -480,7 +485,9 @@ def serve_cli(ctx, app_folder: str, file_name: str): return try: - variant_id = add_variant(app_folder=app_folder, file_name=file_name, host=host) + variant_id = add_variant( + app_folder=app_folder, file_name=file_name, host=host, overwrite=overwrite + ) except Exception as e: click.echo(click.style("Failed to add variant.", fg="red")) click.echo(click.style(f"Error message: {str(e)}", fg="red")) From 2aaf90223616cf0591d2e6371b2673e794a17807 Mon Sep 17 00:00:00 2001 From: aakrem Date: Tue, 7 May 2024 08:58:50 +0200 Subject: [PATCH 2/3] update docs --- docs/developer_guides/cli/quick-usage.mdx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/developer_guides/cli/quick-usage.mdx b/docs/developer_guides/cli/quick-usage.mdx index 0c48f77afa..deafd20c93 100644 --- a/docs/developer_guides/cli/quick-usage.mdx +++ b/docs/developer_guides/cli/quick-usage.mdx @@ -40,7 +40,14 @@ def translate(sentence:str, language:str): ## Serve the application ```bash -agenta variant serve myapp.py +agenta variant serve --file_name myapp.py ``` This command deploys a new variant to the Agenta platform. It processes the code in the specified folder, with `myapp.py` as the entrypoint. This command builds a Docker image and deploys a container based on it. As a result, the variant becomes accessible in the web UI, allowing for prediction generation and API calls. The variant is named as `myapp.default` in the UI. + + +## Overwrite an application + +```bash +agenta variant serve --file_name myapp.py --overwrite +``` \ No newline at end of file From 253301362d3cd1be64daa46dd031696b0340d9a3 Mon Sep 17 00:00:00 2001 From: aakrem Date: Tue, 7 May 2024 11:43:27 +0200 Subject: [PATCH 3/3] revert to initial command --- docs/developer_guides/cli/quick-usage.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/developer_guides/cli/quick-usage.mdx b/docs/developer_guides/cli/quick-usage.mdx index deafd20c93..9abd0219f7 100644 --- a/docs/developer_guides/cli/quick-usage.mdx +++ b/docs/developer_guides/cli/quick-usage.mdx @@ -40,7 +40,7 @@ def translate(sentence:str, language:str): ## Serve the application ```bash -agenta variant serve --file_name myapp.py +agenta variant serve myapp.py ``` This command deploys a new variant to the Agenta platform. It processes the code in the specified folder, with `myapp.py` as the entrypoint. This command builds a Docker image and deploys a container based on it. As a result, the variant becomes accessible in the web UI, allowing for prediction generation and API calls. The variant is named as `myapp.default` in the UI.