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 b3dcb1f891..ec0e2301e0 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): @@ -101,8 +102,13 @@ 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() + global_backend_host = helper.get_global_config("host") + if global_backend_host: + backend_host = global_backend_host + else: + backend_host = "https://cloud.agenta.ai" + + 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 @@ -186,6 +192,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__": diff --git a/agenta-cli/agenta/cli/variant_configs.py b/agenta-cli/agenta/cli/variant_configs.py new file mode 100644 index 0000000000..3f43bbc104 --- /dev/null +++ b/agenta-cli/agenta/cli/variant_configs.py @@ -0,0 +1,49 @@ +import click +from agenta.cli import helper + + +@click.group() +def config(): + """Commands for variants configurations""" + pass + + +def update_backend_host(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 global backend host...", fg="bright_black") + ) + helper.set_global_config("host", backend_host) + + +@config.command( + name="set-host", + context_settings=dict( + ignore_unknown_options=True, + allow_extra_args=True, + ), +) +@click.option( + "--backend_host", default=None, help="The URL of the backend host to use." +) +@click.pass_context +def set_config_url(ctx, 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(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"))