Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement - Add support for configurable Agenta Cloud URL in CLI #938

Merged
merged 11 commits into from
Nov 28, 2023
Merged
11 changes: 9 additions & 2 deletions agenta-cli/agenta/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -101,7 +102,12 @@ 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"
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()
aybruhm marked this conversation as resolved.
Show resolved Hide resolved
client.validate_api_key(api_key, backend_host)

Expand Down Expand Up @@ -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__":
Expand Down
49 changes: 49 additions & 0 deletions agenta-cli/agenta/cli/variant_configs.py
Original file line number Diff line number Diff line change
@@ -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"))
Loading