From 8a3a3c3e53d7eb433c133a86a4a9fc413bacb8e0 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 27 Nov 2023 14:21:41 +0100 Subject: [PATCH 01/11] Update - added functionality to set the url for backend host in cloud --- agenta-cli/agenta/cli/main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/agenta-cli/agenta/cli/main.py b/agenta-cli/agenta/cli/main.py index b3dcb1f891..cf8c14c568 100644 --- a/agenta-cli/agenta/cli/main.py +++ b/agenta-cli/agenta/cli/main.py @@ -101,8 +101,14 @@ def init(app_name: str): "Please provide the IP or URL of your remote host" ).ask() elif where_question == "On agenta cloud": - backend_host = "https://cloud.agenta.ai" - api_key = helper.get_api_key() + backend_host = questionary.text( + "Please provide the URL for the backend host. Defaults to: https://cloud.agenta.ai", + ).ask() + backend_host = ( + "https://cloud.agenta.ai" if not backend_host else backend_host + ) + + api_key = helper.get_api_key(backend_host) client.validate_api_key(api_key, backend_host) elif where_question is None: # User pressed Ctrl+C From a8142123d6ca95a1b702f72605cf1141d8ca633b Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 27 Nov 2023 14:22:04 +0100 Subject: [PATCH 02/11] Update - specify backend_host to retrieve api key from --- agenta-cli/agenta/cli/helper.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/agenta-cli/agenta/cli/helper.py b/agenta-cli/agenta/cli/helper.py index 17d5cc05e7..731bd01bf7 100644 --- a/agenta-cli/agenta/cli/helper.py +++ b/agenta-cli/agenta/cli/helper.py @@ -57,7 +57,7 @@ def set_global_config(var_name: str, var_value: Any) -> None: toml.dump(global_config, config_file) -def get_api_key() -> str: +def get_api_key(backend_host: str) -> str: """ Retrieve or request the API key for accessing the Agenta platform. @@ -65,6 +65,9 @@ def get_api_key() -> str: If found, it prompts the user to confirm whether they'd like to use that key. If not found, it asks the user to input a new key. + Args: + backend_host (str): The URL to the backend + Returns: str: The API key to be used for accessing the Agenta platform. @@ -85,7 +88,7 @@ def get_api_key() -> str: sys.exit(0) api_key = questionary.text( - "(You can get your API Key here: https://cloud.agenta.ai/settings?tab=apiKeys) " + f"(You can get your API Key here: {backend_host}/settings?tab=apiKeys) " "Please provide your API key:" ).ask() From fcba6cf9a0ab81795a7d101969ce517792f236f4 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 27 Nov 2023 14:55:47 +0100 Subject: [PATCH 03/11] Feat - implemented cli command to set variant backend host --- agenta-cli/agenta/cli/variant_configs.py | 66 ++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 agenta-cli/agenta/cli/variant_configs.py diff --git a/agenta-cli/agenta/cli/variant_configs.py b/agenta-cli/agenta/cli/variant_configs.py new file mode 100644 index 0000000000..5648d0b193 --- /dev/null +++ b/agenta-cli/agenta/cli/variant_configs.py @@ -0,0 +1,66 @@ +from pathlib import Path + +import click +import toml + + +@click.group() +def config(): + """Commands for variants configurations""" + pass + + +def update_backend_host(app_folder: str, backend_host: str): + """Check the config file and update the backend URL + + Arguments: + app_folder -- the app folder + backend_host -- the backend host + """ + + click.echo( + click.style("\nChecking and updating backend host...", fg="bright_black") + ) + app_folder = Path(app_folder) + config_file = app_folder / "config.toml" + if not config_file.exists(): + click.echo( + click.style( + f"Config file not found in {app_folder}. Make sure you are in the right folder and that you have run agenta init first.", + fg="red", + ) + ) + return + + # Update the config file + config = toml.load(config_file) + config["backend_host"] = backend_host + toml.dump(config, config_file.open("w")) + + +@config.command( + name="url", + context_settings=dict( + ignore_unknown_options=True, + allow_extra_args=True, + ), +) +@click.option("--app_folder", default=".") +@click.option( + "--backend_host", default=None, help="The URL of the backend host to use." +) +@click.pass_context +def set_config_url(ctx, app_folder: str, backend_host: str): + """Set the backend URL in the app configuration""" + + try: + if not backend_host: + if ctx.args: + backend_host = ctx.args[0] + else: + click.echo(click.style("Backend host URL not specified", fg="red")) + + update_backend_host(app_folder, backend_host) + click.echo(click.style("Backend host updated successfully! 🎉\n")) + except Exception as ex: + click.echo(click.style(f"Error updating backend host: {ex}", fg="red")) From 5208c79583c88b88c0b0c6ed6531ada8876b0198 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 27 Nov 2023 14:56:41 +0100 Subject: [PATCH 04/11] Update - add variant config command to cli --- agenta-cli/agenta/cli/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/agenta-cli/agenta/cli/main.py b/agenta-cli/agenta/cli/main.py index cf8c14c568..fa8be7a8d9 100644 --- a/agenta-cli/agenta/cli/main.py +++ b/agenta-cli/agenta/cli/main.py @@ -8,9 +8,10 @@ import questionary import toml +from agenta.cli import helper from agenta.client import client +from agenta.cli import variant_configs from agenta.cli import variant_commands -from agenta.cli import helper def print_version(ctx, param, value): @@ -192,6 +193,7 @@ def init(app_name: str): # Add the commands to the CLI group cli.add_command(init) +cli.add_command(variant_configs.config) cli.add_command(variant_commands.variant) if __name__ == "__main__": From 04219d017f5a4c93ca87fd497fcbd9c74c5dcc67 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 27 Nov 2023 15:14:01 +0100 Subject: [PATCH 05/11] Update - remove friction in where_question for agenta cloud --- agenta-cli/agenta/cli/main.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/agenta-cli/agenta/cli/main.py b/agenta-cli/agenta/cli/main.py index fa8be7a8d9..d9474a2566 100644 --- a/agenta-cli/agenta/cli/main.py +++ b/agenta-cli/agenta/cli/main.py @@ -102,12 +102,7 @@ def init(app_name: str): "Please provide the IP or URL of your remote host" ).ask() elif where_question == "On agenta cloud": - backend_host = questionary.text( - "Please provide the URL for the backend host. Defaults to: https://cloud.agenta.ai", - ).ask() - backend_host = ( - "https://cloud.agenta.ai" if not backend_host else backend_host - ) + backend_host = "https://cloud.agenta.ai" api_key = helper.get_api_key(backend_host) client.validate_api_key(api_key, backend_host) From 895842df7a2dbd06a7cb52bdacb70ca1e9a69174 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 27 Nov 2023 15:15:32 +0100 Subject: [PATCH 06/11] Update - remove backend_host from get_api_key arg --- agenta-cli/agenta/cli/helper.py | 7 ++----- agenta-cli/agenta/cli/main.py | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/agenta-cli/agenta/cli/helper.py b/agenta-cli/agenta/cli/helper.py index 731bd01bf7..17d5cc05e7 100644 --- a/agenta-cli/agenta/cli/helper.py +++ b/agenta-cli/agenta/cli/helper.py @@ -57,7 +57,7 @@ def set_global_config(var_name: str, var_value: Any) -> None: toml.dump(global_config, config_file) -def get_api_key(backend_host: str) -> str: +def get_api_key() -> str: """ Retrieve or request the API key for accessing the Agenta platform. @@ -65,9 +65,6 @@ def get_api_key(backend_host: str) -> str: If found, it prompts the user to confirm whether they'd like to use that key. If not found, it asks the user to input a new key. - Args: - backend_host (str): The URL to the backend - Returns: str: The API key to be used for accessing the Agenta platform. @@ -88,7 +85,7 @@ def get_api_key(backend_host: str) -> str: sys.exit(0) api_key = questionary.text( - f"(You can get your API Key here: {backend_host}/settings?tab=apiKeys) " + "(You can get your API Key here: https://cloud.agenta.ai/settings?tab=apiKeys) " "Please provide your API key:" ).ask() diff --git a/agenta-cli/agenta/cli/main.py b/agenta-cli/agenta/cli/main.py index d9474a2566..293eeab41c 100644 --- a/agenta-cli/agenta/cli/main.py +++ b/agenta-cli/agenta/cli/main.py @@ -104,7 +104,7 @@ def init(app_name: str): elif where_question == "On agenta cloud": backend_host = "https://cloud.agenta.ai" - api_key = helper.get_api_key(backend_host) + api_key = helper.get_api_key() client.validate_api_key(api_key, backend_host) elif where_question is None: # User pressed Ctrl+C From 9519f4d8f7c7ea6e172fd8b5d30470f879699b1b Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 27 Nov 2023 15:58:51 +0100 Subject: [PATCH 07/11] Update - rename url to set-host and modified update_backend_host logic --- agenta-cli/agenta/cli/variant_configs.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/agenta-cli/agenta/cli/variant_configs.py b/agenta-cli/agenta/cli/variant_configs.py index 5648d0b193..8a7cc4df01 100644 --- a/agenta-cli/agenta/cli/variant_configs.py +++ b/agenta-cli/agenta/cli/variant_configs.py @@ -24,12 +24,12 @@ def update_backend_host(app_folder: str, backend_host: str): app_folder = Path(app_folder) config_file = app_folder / "config.toml" if not config_file.exists(): - click.echo( - click.style( - f"Config file not found in {app_folder}. Make sure you are in the right folder and that you have run agenta init first.", - fg="red", - ) - ) + # Set app toml configuration + config = { + "backend_host": backend_host, + } + with open("config.toml", "w") as config_file: + toml.dump(config, config_file) return # Update the config file @@ -39,7 +39,7 @@ def update_backend_host(app_folder: str, backend_host: str): @config.command( - name="url", + name="set-host", context_settings=dict( ignore_unknown_options=True, allow_extra_args=True, From dbc733197a6c80c3f264bc27a78c667975d7729a Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 27 Nov 2023 16:12:33 +0100 Subject: [PATCH 08/11] Update - make use of backend_host if it exists in config.toml --- agenta-cli/agenta/cli/main.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/agenta-cli/agenta/cli/main.py b/agenta-cli/agenta/cli/main.py index 293eeab41c..d70fffc020 100644 --- a/agenta-cli/agenta/cli/main.py +++ b/agenta-cli/agenta/cli/main.py @@ -73,8 +73,9 @@ def cli(): @click.command() +@click.option("--working_dir", default=".") @click.option("--app_name", default="") -def init(app_name: str): +def init(working_dir: str, app_name: str): """Initialize a new Agenta app with the template files.""" if not app_name: while True: @@ -89,6 +90,11 @@ def init(app_name: str): "Invalid input. Please use only alphanumeric characters without spaces." ) + # Get config.toml from current working directory + app_folder = Path(working_dir) + config_file = app_folder / "config.toml" + loaded_config = toml.load(config_file) + try: where_question = questionary.select( "Where are you running agenta?", @@ -102,7 +108,10 @@ def init(app_name: str): "Please provide the IP or URL of your remote host" ).ask() elif where_question == "On agenta cloud": - backend_host = "https://cloud.agenta.ai" + if loaded_config: + backend_host = loaded_config["backend_host"] + else: + backend_host = "https://cloud.agenta.ai" api_key = helper.get_api_key() client.validate_api_key(api_key, backend_host) From d83b21d195784f1663321c4a0be2654e65897edb Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 27 Nov 2023 16:58:51 +0100 Subject: [PATCH 09/11] Update - set the backend host to the global config --- agenta-cli/agenta/cli/variant_configs.py | 29 +++++------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/agenta-cli/agenta/cli/variant_configs.py b/agenta-cli/agenta/cli/variant_configs.py index 8a7cc4df01..3f43bbc104 100644 --- a/agenta-cli/agenta/cli/variant_configs.py +++ b/agenta-cli/agenta/cli/variant_configs.py @@ -1,7 +1,5 @@ -from pathlib import Path - import click -import toml +from agenta.cli import helper @click.group() @@ -10,7 +8,7 @@ def config(): pass -def update_backend_host(app_folder: str, backend_host: str): +def update_backend_host(backend_host: str): """Check the config file and update the backend URL Arguments: @@ -19,23 +17,9 @@ def update_backend_host(app_folder: str, backend_host: str): """ click.echo( - click.style("\nChecking and updating backend host...", fg="bright_black") + click.style("\nChecking and updating global backend host...", fg="bright_black") ) - app_folder = Path(app_folder) - config_file = app_folder / "config.toml" - if not config_file.exists(): - # Set app toml configuration - config = { - "backend_host": backend_host, - } - with open("config.toml", "w") as config_file: - toml.dump(config, config_file) - return - - # Update the config file - config = toml.load(config_file) - config["backend_host"] = backend_host - toml.dump(config, config_file.open("w")) + helper.set_global_config("host", backend_host) @config.command( @@ -45,12 +29,11 @@ def update_backend_host(app_folder: str, backend_host: str): allow_extra_args=True, ), ) -@click.option("--app_folder", default=".") @click.option( "--backend_host", default=None, help="The URL of the backend host to use." ) @click.pass_context -def set_config_url(ctx, app_folder: str, backend_host: str): +def set_config_url(ctx, backend_host: str): """Set the backend URL in the app configuration""" try: @@ -60,7 +43,7 @@ def set_config_url(ctx, app_folder: str, backend_host: str): else: click.echo(click.style("Backend host URL not specified", fg="red")) - update_backend_host(app_folder, backend_host) + update_backend_host(backend_host) click.echo(click.style("Backend host updated successfully! 🎉\n")) except Exception as ex: click.echo(click.style(f"Error updating backend host: {ex}", fg="red")) From bd8f21807b20d9198838b581cdd2d90d1a39189e Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 27 Nov 2023 16:59:21 +0100 Subject: [PATCH 10/11] Update - make use of backend_host from global config --- agenta-cli/agenta/cli/main.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/agenta-cli/agenta/cli/main.py b/agenta-cli/agenta/cli/main.py index d70fffc020..43b442c024 100644 --- a/agenta-cli/agenta/cli/main.py +++ b/agenta-cli/agenta/cli/main.py @@ -73,9 +73,8 @@ def cli(): @click.command() -@click.option("--working_dir", default=".") @click.option("--app_name", default="") -def init(working_dir: str, app_name: str): +def init(app_name: str): """Initialize a new Agenta app with the template files.""" if not app_name: while True: @@ -90,11 +89,6 @@ def init(working_dir: str, app_name: str): "Invalid input. Please use only alphanumeric characters without spaces." ) - # Get config.toml from current working directory - app_folder = Path(working_dir) - config_file = app_folder / "config.toml" - loaded_config = toml.load(config_file) - try: where_question = questionary.select( "Where are you running agenta?", @@ -108,8 +102,9 @@ def init(working_dir: str, app_name: str): "Please provide the IP or URL of your remote host" ).ask() elif where_question == "On agenta cloud": - if loaded_config: - backend_host = loaded_config["backend_host"] + global_backend_host = helper.get_global_config("host") + if global_backend_host: + backend_host = global_backend_host else: backend_host = "https://cloud.agenta.ai" From f6dec80076684e7d6f9f5f9a6634985e151f63c6 Mon Sep 17 00:00:00 2001 From: Abram Date: Tue, 28 Nov 2023 07:34:08 +0100 Subject: [PATCH 11/11] Update - include backend_host in get_api_key function to notify where to get key from --- agenta-cli/agenta/cli/helper.py | 7 +++++-- agenta-cli/agenta/cli/main.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/agenta-cli/agenta/cli/helper.py b/agenta-cli/agenta/cli/helper.py index 17d5cc05e7..96fd406bae 100644 --- a/agenta-cli/agenta/cli/helper.py +++ b/agenta-cli/agenta/cli/helper.py @@ -57,7 +57,7 @@ def set_global_config(var_name: str, var_value: Any) -> None: toml.dump(global_config, config_file) -def get_api_key() -> str: +def get_api_key(backend_host: str) -> str: """ Retrieve or request the API key for accessing the Agenta platform. @@ -65,6 +65,9 @@ def get_api_key() -> str: If found, it prompts the user to confirm whether they'd like to use that key. If not found, it asks the user to input a new key. + Args: + backend_host (str): The URL of the backend host. + Returns: str: The API key to be used for accessing the Agenta platform. @@ -85,7 +88,7 @@ def get_api_key() -> str: sys.exit(0) api_key = questionary.text( - "(You can get your API Key here: https://cloud.agenta.ai/settings?tab=apiKeys) " + f"(You can get your API Key here: {backend_host}/settings?tab=apiKeys) " "Please provide your API key:" ).ask() diff --git a/agenta-cli/agenta/cli/main.py b/agenta-cli/agenta/cli/main.py index 43b442c024..ec0e2301e0 100644 --- a/agenta-cli/agenta/cli/main.py +++ b/agenta-cli/agenta/cli/main.py @@ -108,7 +108,7 @@ def init(app_name: str): else: backend_host = "https://cloud.agenta.ai" - api_key = helper.get_api_key() + api_key = helper.get_api_key(backend_host) client.validate_api_key(api_key, backend_host) elif where_question is None: # User pressed Ctrl+C